Skip to content

Commit

Permalink
Prevent unnecessary escaping of numbers
Browse files Browse the repository at this point in the history
When a line starts with a number that ends with a period, e.g. `1984.`, it
needs to be escaped, as otherwise markdown interprets it as a list.

However, if a line begins with a number that includes a period in it, e.g.
`1984.5`, it does not need to be escaped, as it won't be interpreted as a list.
  • Loading branch information
pwim authored and gettalong committed Nov 16, 2024
1 parent a5f172d commit 8fe657c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/kramdown/converter/kramdown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ def convert_text(el, opts)

def convert_p(el, opts)
w = @options[:line_width] - opts[:indent].to_s.to_i
first, second, *rest = inner(el, opts).strip.gsub(/(.{1,#{w}})( +|$\n?)/, "\\1\n").split("\n")
first&.gsub!(/^(?:(#|>)|(\d+)\.|([+-]\s))/) { $1 || $3 ? "\\#{$1 || $3}" : "#{$2}\\." }
first, second, *rest = inner(el, opts).strip.gsub(/(.{1,#{w}})( +|$\n?)/, "\\1\n").split(/\n/)
first&.gsub!(/^(?:(#|>)|(\d+)\.([\s\z])|([+-]\s))/) { $1 || $4 ? "\\#{$1 || $4}" : "#{$2}\\.#{$3}" }
second&.gsub!(/^([=-]+\s*?)$/, "\\\1")
res = [first, second, *rest].compact.join("\n") + "\n"
res.gsub!(/^ {0,3}:/, "\\:")
Expand Down
2 changes: 2 additions & 0 deletions test/testcases/block/08_list/escaping.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@

<p>1984. Was great!</p>

<p>1984.5 is not a book.</p>

<p>- This too!</p>
2 changes: 2 additions & 0 deletions test/testcases/block/08_list/escaping.text
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ I have read the book 1984.

1984\. Was great!

1984.5 is not a book.

\- This too!

0 comments on commit 8fe657c

Please sign in to comment.