1
0
mirror of https://github.com/meineerde/redmine.git synced 2025-12-19 15:01:14 +00:00

code cleanup: rubocop: fix Layout/SpaceInsideStringInterpolation in lib/redmine/wiki_formatting/textile/redcloth3.rb

git-svn-id: http://svn.redmine.org/redmine/trunk@18684 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Toshi MARUYAMA 2019-10-15 17:25:19 +00:00
parent 2117705cbc
commit d7d85cd85f
2 changed files with 65 additions and 66 deletions

View File

@ -404,7 +404,6 @@ Layout/SpaceInsideStringInterpolation:
- 'app/models/issue_query.rb' - 'app/models/issue_query.rb'
- 'app/models/mail_handler.rb' - 'app/models/mail_handler.rb'
- 'lib/redmine/core_ext/string/inflections.rb' - 'lib/redmine/core_ext/string/inflections.rb'
- 'lib/redmine/wiki_formatting/textile/redcloth3.rb'
- 'test/integration/admin_test.rb' - 'test/integration/admin_test.rb'
Lint/AmbiguousBlockAssociation: Lint/AmbiguousBlockAssociation:

View File

@ -255,7 +255,7 @@ class RedCloth3 < String
# #=>"<h1>A &lt;b&gt;bold&lt;/b&gt; man</h1>" # #=>"<h1>A &lt;b&gt;bold&lt;/b&gt; man</h1>"
# #
def initialize( string, restrictions = [] ) def initialize( string, restrictions = [] )
restrictions.each { |r| method( "#{ r }=" ).call( true ) } restrictions.each { |r| method( "#{r}=" ).call( true ) }
super( string ) super( string )
end end
@ -333,7 +333,7 @@ class RedCloth3 < String
[147, 8220], [148, 8221], [149, 8226], [150, 8211], [151, 8212], [152, 732], [147, 8220], [148, 8221], [149, 8226], [150, 8211], [151, 8212], [152, 732],
[153, 8482], [154, 353], [155, 8250], [156, 339], [157, 0], [158, 0], [159, 376]]. [153, 8482], [154, 353], [155, 8250], [156, 339], [157, 0], [158, 0], [159, 376]].
collect! do |a, b| collect! do |a, b|
[a.chr, ( b.zero? and "" or "&#{ b };" )] [a.chr, ( b.zero? and "" or "&#{b};" )]
end end
# #
# Regular expressions to convert to HTML. # Regular expressions to convert to HTML.
@ -471,12 +471,12 @@ class RedCloth3 < String
if element == 'td' if element == 'td'
colspan = $1 if text =~ /\\(\d+)/ colspan = $1 if text =~ /\\(\d+)/
rowspan = $1 if text =~ /\/(\d+)/ rowspan = $1 if text =~ /\/(\d+)/
style << "vertical-align:#{ v_align( $& ) };" if text =~ A_VLGN style << "vertical-align:#{v_align($&)};" if text =~ A_VLGN
end end
if text.sub!( /\{([^"}]*)\}/, '' ) && !filter_styles if text.sub!( /\{([^"}]*)\}/, '' ) && !filter_styles
sanitized = sanitize_styles($1) sanitized = sanitize_styles($1)
style << "#{ sanitized };" unless sanitized.blank? style << "#{sanitized};" unless sanitized.blank?
end end
lang = $1 if lang = $1 if
@ -485,12 +485,12 @@ class RedCloth3 < String
cls = $1 if cls = $1 if
text.sub!( /\(([^()]+?)\)/, '' ) text.sub!( /\(([^()]+?)\)/, '' )
style << "padding-left:#{ $1.length }em;" if style << "padding-left:#{$1.length}em;" if
text.sub!( /([(]+)/, '' ) text.sub!( /([(]+)/, '' )
style << "padding-right:#{ $1.length }em;" if text.sub!( /([)]+)/, '' ) style << "padding-right:#{$1.length}em;" if text.sub!( /([)]+)/, '' )
style << "text-align:#{ h_align( $& ) };" if text =~ A_HLGN style << "text-align:#{h_align($&)};" if text =~ A_HLGN
cls, id = $1, $2 if cls =~ /^(.*?)#(.*)$/ cls, id = $1, $2 if cls =~ /^(.*?)#(.*)$/
@ -503,12 +503,12 @@ class RedCloth3 < String
id = id.starts_with?('wiki-id-') ? id : "wiki-id-#{id}" if id id = id.starts_with?('wiki-id-') ? id : "wiki-id-#{id}" if id
atts = +'' atts = +''
atts << " style=\"#{ style.join }\"" unless style.empty? atts << " style=\"#{style.join}\"" unless style.empty?
atts << " class=\"#{ cls }\"" unless cls.to_s.empty? atts << " class=\"#{cls}\"" unless cls.to_s.empty?
atts << " lang=\"#{ lang }\"" if lang atts << " lang=\"#{lang}\"" if lang
atts << " id=\"#{ id }\"" if id atts << " id=\"#{id}\"" if id
atts << " colspan=\"#{ colspan }\"" if colspan atts << " colspan=\"#{colspan}\"" if colspan
atts << " rowspan=\"#{ rowspan }\"" if rowspan atts << " rowspan=\"#{rowspan}\"" if rowspan
atts atts
end end
@ -545,12 +545,12 @@ class RedCloth3 < String
catts = pba( modifiers, 'td' ) if modifiers catts = pba( modifiers, 'td' ) if modifiers
catts = shelve( catts ) if catts catts = shelve( catts ) if catts
cells << "\t\t\t<t#{ ctyp }#{ catts }>#{ cell }</t#{ ctyp }>" cells << "\t\t\t<t#{ctyp}#{catts}>#{cell}</t#{ctyp}>"
end end
ratts = shelve( ratts ) if ratts ratts = shelve( ratts ) if ratts
rows << "\t\t<tr#{ ratts }>\n#{ cells.join( "\n" ) }\n\t\t</tr>" rows << "\t\t<tr#{ratts}>\n#{cells.join("\n")}\n\t\t</tr>"
end end
"\t<table#{ tatts }>\n#{ rows.join( "\n" ) }\n\t</table>\n\n" "\t<table#{tatts}>\n#{rows.join("\n")}\n\t</table>\n\n"
end end
end end
@ -570,7 +570,7 @@ class RedCloth3 < String
if depth.last.length > tl.length if depth.last.length > tl.length
(depth.length - 1).downto(0) do |i| (depth.length - 1).downto(0) do |i|
break if depth[i].length == tl.length break if depth[i].length == tl.length
lines[line_id - 1] << "</li>\n\t</#{ lT( depth[i] ) }l>\n\t" lines[line_id - 1] << "</li>\n\t</#{lT(depth[i])}l>\n\t"
depth.pop depth.pop
end end
end end
@ -582,9 +582,9 @@ class RedCloth3 < String
depth << tl depth << tl
atts = pba( atts ) atts = pba( atts )
atts = shelve( atts ) if atts atts = shelve( atts ) if atts
lines[line_id] = +"\t<#{ lT(tl) }l#{ atts }>\n\t<li>#{ content }" lines[line_id] = +"\t<#{lT(tl)}l#{atts}>\n\t<li>#{content}"
else else
lines[line_id] = +"\t\t<li>#{ content }" lines[line_id] = +"\t\t<li>#{content}"
end end
last_line = line_id last_line = line_id
@ -593,7 +593,7 @@ class RedCloth3 < String
end end
if line_id - last_line > 1 or line_id == lines.length - 1 if line_id - last_line > 1 or line_id == lines.length - 1
while v = depth.pop while v = depth.pop
lines[last_line] << "</li>\n\t</#{ lT( v ) }l>" lines[last_line] << "</li>\n\t</#{lT(v)}l>"
end end
end end
end end
@ -634,8 +634,8 @@ class RedCloth3 < String
def inline_textile_code( text ) def inline_textile_code( text )
text.gsub!( CODE_RE ) do |m| text.gsub!( CODE_RE ) do |m|
before,lang,code,after = $~[1..4] before,lang,code,after = $~[1..4]
lang = " lang=\"#{ lang }\"" if lang lang = " lang=\"#{lang}\"" if lang
rip_offtags( +"#{ before }<code#{ lang }>#{ code }</code>#{ after }", false ) rip_offtags( +"#{before}<code#{lang}>#{code}</code>#{after}", false )
end end
end end
@ -680,13 +680,13 @@ class RedCloth3 < String
end end
if block_applied.zero? if block_applied.zero?
if deep_code if deep_code
blk = "\t<pre><code>#{ blk }</code></pre>" blk = "\t<pre><code>#{blk}</code></pre>"
else else
blk = "\t<p>#{ blk }</p>" blk = "\t<p>#{blk}</p>"
end end
end end
# hard_break blk # hard_break blk
blk + "\n#{ code_blk }" blk + "\n#{code_blk}"
end end
end end
end.join( "\n\n" ) ) end.join( "\n\n" ) )
@ -694,14 +694,14 @@ class RedCloth3 < String
def textile_bq( tag, atts, cite, content ) def textile_bq( tag, atts, cite, content )
cite, cite_title = check_refs( cite ) cite, cite_title = check_refs( cite )
cite = " cite=\"#{ cite }\"" if cite cite = " cite=\"#{cite}\"" if cite
atts = shelve( atts ) if atts atts = shelve( atts ) if atts
"\t<blockquote#{ cite }>\n\t\t<p#{ atts }>#{ content }</p>\n\t</blockquote>" "\t<blockquote#{cite}>\n\t\t<p#{atts}>#{content}</p>\n\t</blockquote>"
end end
def textile_p( tag, atts, cite, content ) def textile_p( tag, atts, cite, content )
atts = shelve( atts ) if atts atts = shelve( atts ) if atts
"\t<#{ tag }#{ atts }>#{ content }</#{ tag }>" "\t<#{tag}#{atts}>#{content}</#{tag}>"
end end
alias textile_h1 textile_p alias textile_h1 textile_p
@ -712,10 +712,10 @@ class RedCloth3 < String
alias textile_h6 textile_p alias textile_h6 textile_p
def textile_fn_( tag, num, atts, cite, content ) def textile_fn_( tag, num, atts, cite, content )
atts << " id=\"fn#{ num }\" class=\"footnote\"" atts << " id=\"fn#{num}\" class=\"footnote\""
content = "<sup>#{ num }</sup> #{ content }" content = "<sup>#{num}</sup> #{content}"
atts = shelve( atts ) if atts atts = shelve( atts ) if atts
"\t<p#{ atts }>#{ content }</p>" "\t<p#{atts}>#{content}</p>"
end end
BLOCK_RE = /^(([a-z]+)(\d*))(#{A}#{C})\.(?::(\S+))? (.*)$/m BLOCK_RE = /^(([a-z]+)(\d*))(#{A}#{C})\.(?::(\S+))? (.*)$/m
@ -727,10 +727,10 @@ class RedCloth3 < String
# pass to prefix handler # pass to prefix handler
replacement = nil replacement = nil
if respond_to? "textile_#{ tag }", true if respond_to? "textile_#{tag}", true
replacement = method( "textile_#{ tag }" ).call( tag, atts, cite, content ) replacement = method( "textile_#{tag}" ).call( tag, atts, cite, content )
elsif respond_to? "textile_#{ tagpre }_", true elsif respond_to? "textile_#{tagpre}_", true
replacement = method( "textile_#{ tagpre }_" ).call( tagpre, num, atts, cite, content ) replacement = method( "textile_#{tagpre}_" ).call( tagpre, num, atts, cite, content )
end end
text.gsub!( $& ) { replacement } if replacement text.gsub!( $& ) { replacement } if replacement
end end
@ -740,7 +740,7 @@ class RedCloth3 < String
def block_markdown_setext( text ) def block_markdown_setext( text )
if text =~ SETEXT_RE if text =~ SETEXT_RE
tag = ($2 == "=" ? "h1" : "h2") tag = ($2 == "=" ? "h1" : "h2")
blk, cont = "<#{ tag }>#{ $1 }</#{ tag }>", $' blk, cont = "<#{tag}>#{$1}</#{tag}>", $'
blocks cont blocks cont
text.replace( blk + cont ) text.replace( blk + cont )
end end
@ -754,8 +754,8 @@ class RedCloth3 < String
$/x $/x
def block_markdown_atx( text ) def block_markdown_atx( text )
if text =~ ATX_RE if text =~ ATX_RE
tag = "h#{ $1.length }" tag = "h#{$1.length}"
blk, cont = "<#{ tag }>#{ $2 }</#{ tag }>\n\n", $' blk, cont = "<#{tag}>#{$2}</#{tag}>\n\n", $'
blocks cont blocks cont
text.replace( blk + cont ) text.replace( blk + cont )
end end
@ -769,7 +769,7 @@ class RedCloth3 < String
flush_left blk flush_left blk
blocks blk blocks blk
blk.gsub!( /^(\S)/, "\t\\1" ) blk.gsub!( /^(\S)/, "\t\\1" )
"<blockquote>\n#{ blk }\n</blockquote>\n\n" "<blockquote>\n#{blk}\n</blockquote>\n\n"
end end
end end
@ -804,7 +804,7 @@ class RedCloth3 < String
atts = pba( atts ) atts = pba( atts )
atts = shelve( atts ) if atts atts = shelve( atts ) if atts
"#{ sta }#{ oqs }<#{ ht }#{ atts }>#{ content }</#{ ht }>#{ oqa }" "#{sta}#{oqs}<#{ht}#{atts}>#{content}</#{ht}>#{oqa}"
end end
end end
end end
@ -844,13 +844,13 @@ class RedCloth3 < String
post = ")"+post # add closing parenth to post post = ")"+post # add closing parenth to post
end end
atts = pba( atts ) atts = pba( atts )
atts = +" href=\"#{ htmlesc url }#{ slash }\"#{ atts }" atts = +" href=\"#{htmlesc url}#{slash}\"#{atts}"
atts << " title=\"#{ htmlesc title }\"" if title atts << " title=\"#{htmlesc title}\"" if title
atts = shelve( atts ) if atts atts = shelve( atts ) if atts
external = (url =~ /^https?:\/\//) ? ' class="external"' : '' external = (url =~ /^https?:\/\//) ? ' class="external"' : ''
"#{ pre }<a#{ atts }#{ external }>#{ text }</a>#{ post }" "#{pre}<a#{atts}#{external}>#{text}</a>#{post}"
end end
end end
end end
@ -872,11 +872,11 @@ class RedCloth3 < String
url, title = check_refs( id ) url, title = check_refs( id )
end end
atts = " href=\"#{ url }\"" atts = " href=\"#{url}\""
atts << " title=\"#{ title }\"" if title atts << " title=\"#{title}\"" if title
atts = shelve( atts ) atts = shelve( atts )
"<a#{ atts }>#{ text }</a>" "<a#{atts}>#{text}</a>"
end end
end end
@ -898,11 +898,11 @@ class RedCloth3 < String
text.gsub!( MARKDOWN_LINK_RE ) do |m| text.gsub!( MARKDOWN_LINK_RE ) do |m|
text, url, quote, title = $~[1..4] text, url, quote, title = $~[1..4]
atts = " href=\"#{ url }\"" atts = " href=\"#{url}\""
atts << " title=\"#{ title }\"" if title atts << " title=\"#{title}\"" if title
atts = shelve( atts ) atts = shelve( atts )
"<a#{ atts }>#{ text }</a>" "<a#{atts}>#{text}</a>"
end end
end end
@ -947,7 +947,7 @@ class RedCloth3 < String
\s? # optional space \s? # optional space
(?:\(((?:[^\(\)]|\([^\)]+\))+?)\))? # optional title (?:\(((?:[^\(\)]|\([^\)]+\))+?)\))? # optional title
\! # closing \! # closing
(?::#{ HYPERLINK })? # optional href (?::#{HYPERLINK})? # optional href
/x /x
def inline_textile_image( text ) def inline_textile_image( text )
@ -955,9 +955,9 @@ class RedCloth3 < String
stln,algn,atts,url,title,href,href_a1,href_a2 = $~[1..8] stln,algn,atts,url,title,href,href_a1,href_a2 = $~[1..8]
htmlesc title htmlesc title
atts = pba( atts ) atts = pba( atts )
atts = +" src=\"#{ htmlesc url.dup }\"#{ atts }" atts = +" src=\"#{htmlesc url.dup}\"#{atts}"
atts << " title=\"#{ title }\"" if title atts << " title=\"#{title}\"" if title
atts << " alt=\"#{ title }\"" atts << " alt=\"#{title}\""
# size = @getimagesize($url); # size = @getimagesize($url);
# if($size) $atts.= " $size[3]"; # if($size) $atts.= " $size[3]";
@ -967,16 +967,16 @@ class RedCloth3 < String
next m unless uri_with_safe_scheme?(url) next m unless uri_with_safe_scheme?(url)
out = +'' out = +''
out << "<a#{ shelve( " href=\"#{ href }\"" ) }>" if href out << "<a#{shelve(" href=\"#{href}\"")}>" if href
out << "<img#{ shelve( atts ) } />" out << "<img#{shelve(atts)} />"
out << "</a>#{ href_a1 }#{ href_a2 }" if href out << "</a>#{href_a1}#{href_a2}" if href
if algn if algn
algn = h_align( algn ) algn = h_align( algn )
if stln == "<p>" if stln == "<p>"
out = "<p style=\"float:#{ algn }\">#{ out }" out = "<p style=\"float:#{algn}\">#{out}"
else else
out = "#{ stln }<span style=\"float:#{ algn }\">#{ out }</span>" out = "#{stln}<span style=\"float:#{algn}\">#{out}</span>"
end end
else else
out = stln + out out = stln + out
@ -988,7 +988,7 @@ class RedCloth3 < String
def shelve( val ) def shelve( val )
@shelf << val @shelf << val
" :redsh##{ @shelf.length }:" " :redsh##{@shelf.length}:"
end end
def retrieve( text ) def retrieve( text )
@ -1044,9 +1044,9 @@ class RedCloth3 < String
end end
OFFTAGS = /(code|pre|kbd|notextile)/ OFFTAGS = /(code|pre|kbd|notextile)/
OFFTAG_MATCH = /(?:(<\/#{ OFFTAGS }\b>)|(<#{ OFFTAGS }\b[^>]*>))(.*?)(?=<\/?#{ OFFTAGS }\b\W|\Z)/mi OFFTAG_MATCH = /(?:(<\/#{OFFTAGS}\b>)|(<#{OFFTAGS}\b[^>]*>))(.*?)(?=<\/?#{OFFTAGS}\b\W|\Z)/mi
OFFTAG_OPEN = /<#{ OFFTAGS }/ OFFTAG_OPEN = /<#{OFFTAGS}/
OFFTAG_CLOSE = /<\/?#{ OFFTAGS }/ OFFTAG_CLOSE = /<\/?#{OFFTAGS}/
HASTAG_MATCH = /(<\/?\w[^\n]*?>)/m HASTAG_MATCH = /(<\/?\w[^\n]*?>)/m
ALLTAG_MATCH = /(<\/?\w[^\n]*?>)|.*?(?=<\/?\w[^\n]*?>|$)/m ALLTAG_MATCH = /(<\/?\w[^\n]*?>)|.*?(?=<\/?\w[^\n]*?>|$)/m
@ -1096,12 +1096,12 @@ class RedCloth3 < String
### NB: some changes were made not to use $N variables, because we use "match" ### NB: some changes were made not to use $N variables, because we use "match"
### and it breaks following lines ### and it breaks following lines
htmlesc( aftertag, :NoQuotes ) if aftertag && escape_aftertag && !first.match(/<code\s+class="(\w+)">/) htmlesc( aftertag, :NoQuotes ) if aftertag && escape_aftertag && !first.match(/<code\s+class="(\w+)">/)
line = +"<redpre##{ @pre_list.length }>" line = +"<redpre##{@pre_list.length}>"
first.match(/<#{ OFFTAGS }([^>]*)>/) first.match(/<#{OFFTAGS}([^>]*)>/)
tag = $1 tag = $1
$2.to_s.match(/(class\=("[^"]+"|'[^']+'))/i) $2.to_s.match(/(class\=("[^"]+"|'[^']+'))/i)
tag << " #{$1}" if $1 && tag == 'code' tag << " #{$1}" if $1 && tag == 'code'
@pre_list << +"<#{ tag }>#{ aftertag }" @pre_list << +"<#{tag}>#{aftertag}"
end end
elsif $1 and codepre > 0 elsif $1 and codepre > 0
if codepre - used_offtags.length > 0 if codepre - used_offtags.length > 0