1- require 'cgi'
2- require 'uri'
1+ # frozen_string_literal: true
2+ if RUBY_VERSION < '3.5'
3+ require 'cgi/util'
4+ else
5+ require 'cgi/escape'
6+ end
37
48module YARD
59 module Templates
@@ -265,7 +269,7 @@ def parse_table(lines, index)
265269 index += 1
266270 end
267271
268- html = "<table>\n <thead>\n <tr>\n "
272+ html = "<table>\n <thead>\n <tr>\n " . dup
269273 header . each_with_index do |cell , i |
270274 attrs = alignments [ i ] ? %( align="#{ alignments [ i ] } ") : ""
271275 html << "<th#{ attrs } >#{ format_inline ( cell ) } </th>\n "
@@ -290,7 +294,6 @@ def parse_list(lines, index)
290294 start_attr = ordered && marker [ :start ] != 1 ? %( start="#{ marker [ :start ] } ") : ''
291295 items = [ ]
292296 tight = true
293- loose_by_separator = false
294297 list_indent = marker [ :indent ]
295298
296299 while index < lines . length
@@ -322,7 +325,6 @@ def parse_list(lines, index)
322325 ( next_marker [ :indent ] == item_marker [ :indent ] || ( blank_seen && next_marker [ :indent ] <= list_indent + 3 ) )
323326 if blank_seen
324327 tight = false
325- loose_by_separator = true
326328 end
327329 break
328330 end
@@ -534,7 +536,7 @@ def format_inline(text)
534536 end
535537
536538 def protect_code_spans ( text , placeholders )
537- output = ''
539+ output = String . new
538540 index = 0
539541
540542 while index < text . length
@@ -661,8 +663,8 @@ def format_emphasis(text)
661663 :position => output . length ,
662664 :left_consumed => 0 ,
663665 :right_consumed => 0 ,
664- :opening_html => '' ,
665- :closing_html => '' ,
666+ :opening_html => String . new ,
667+ :closing_html => String . new ,
666668 :can_open => can_open ,
667669 :can_close => can_close
668670 }
@@ -1071,7 +1073,7 @@ def parse_reference_definition(label, definition)
10711073 if delimiter == '"' || delimiter == "'" || delimiter == '('
10721074 index += 1
10731075 start = index
1074- buffer = ''
1076+ buffer = String . new
10751077 while index < definition . length
10761078 char = definition [ index , 1 ]
10771079 if char == '\\' && index + 1 < definition . length
@@ -1100,7 +1102,7 @@ def parse_reference_definition(label, definition)
11001102 end
11011103
11021104 def replace_inline_constructs ( text , placeholders , prefix )
1103- output = ''
1105+ output = String . new
11041106 index = 0
11051107
11061108 while index < text . length
@@ -1148,7 +1150,7 @@ def replace_inline_constructs(text, placeholders, prefix)
11481150 end
11491151
11501152 def scan_reference_constructs ( text , placeholders , kind )
1151- output = ''
1153+ output = String . new
11521154 index = 0
11531155
11541156 while index < text . length
@@ -1298,7 +1300,7 @@ def parse_inline_destination(text, index, placeholders = nil)
12981300 if text [ index , 1 ] == '"' || text [ index , 1 ] == "'"
12991301 delimiter = text [ index , 1 ]
13001302 index += 1
1301- buffer = ''
1303+ buffer = String . new
13021304 while index < text . length
13031305 char = text [ index , 1 ]
13041306 if char == '\\' && index + 1 < text . length
@@ -1315,7 +1317,7 @@ def parse_inline_destination(text, index, placeholders = nil)
13151317 index += 1
13161318 elsif text [ index , 1 ] == '('
13171319 index += 1
1318- buffer = ''
1320+ buffer = String . new
13191321 depth = 1
13201322 while index < text . length
13211323 char = text [ index , 1 ]
@@ -1375,10 +1377,6 @@ def decode_entities(text)
13751377 end
13761378 end
13771379
1378- def unescape_markdown_punctuation ( text )
1379- text . to_s . gsub ( /\\ ([\\ `*_{}\[ \] ()#+\- .!<>~|])/ , '\1' )
1380- end
1381-
13821380 def reference_definition_continuation? ( line )
13831381 return true if line =~ /^(?: {1,3}|\t )(.*)$/
13841382 return true if line =~ /\A <(?:[^>\n ]*)>\s *\z /
@@ -1479,8 +1477,8 @@ def strip_list_item_indent(line, content_indent)
14791477 end
14801478
14811479 def escape_list_marker_text ( line )
1482- source = line . to_s
1483- newline = source . sub! ( / \n \z / , '' ) ? "\n " : ''
1480+ source = line . to_s . sub ( / \n \z / , '' )
1481+ newline = source . length == line . to_s . length ? '' : "\n "
14841482
14851483 if source =~ /\A ([*+-])([ \t ].*)\z /
14861484 "\\ #{ $1} #{ $2} #{ newline } "
@@ -1579,7 +1577,7 @@ def reference_definition_context?(previous_line)
15791577 end
15801578
15811579 def split_reference_container_prefix ( line )
1582- prefix = ''
1580+ prefix = String . new
15831581 content = line . chomp
15841582
15851583 while ( split = split_blockquote_prefix ( content ) )
@@ -1656,7 +1654,7 @@ def unclosed_reference_title?(text)
16561654 end
16571655
16581656 def percent_encode_url ( text , allowed_re )
1659- encoded = ''
1657+ encoded = String . new
16601658
16611659 each_char_compat ( text . to_s ) do |char |
16621660 if ascii_only_compat? ( char ) && char =~ /\A #{ allowed_re . source } \z /
@@ -1951,7 +1949,7 @@ def utf8_bytes(char)
19511949
19521950 def unicode_casefold_compat ( text )
19531951 codepoints = text . to_s . unpack ( 'U*' )
1954- folded = ''
1952+ folded = String . new
19551953
19561954 codepoints . each do |codepoint |
19571955 append_folded_codepoint ( folded , codepoint )
0 commit comments