Skip to content

Commit

Permalink
Fix escaping of colon for conversion to kramdown
Browse files Browse the repository at this point in the history
  • Loading branch information
gettalong committed Mar 31, 2022
1 parent 70121c0 commit 4ffcc56
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/kramdown/converter/kramdown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ def convert_text(el, opts)
else
el.value.gsub(/\A\n/) do
opts[:prev] && opts[:prev].type == :br ? '' : "\n"
end.gsub(/\s+/, ' ').gsub(ESCAPED_CHAR_RE) { "\\#{$1 || $2}" }
end.gsub(/\s+/, ' ').gsub(ESCAPED_CHAR_RE) do
$1 || !opts[:prev] || opts[:prev].type == :br ? "\\#{$1 || $2}" : $&
end
end
end

Expand All @@ -87,6 +89,7 @@ def convert_p(el, opts)
first&.gsub!(/^(?:(#|>)|(\d+)\.|([+-]\s))/) { $1 || $3 ? "\\#{$1 || $3}" : "#{$2}\\." }
second&.gsub!(/^([=-]+\s*?)$/, "\\\1")
res = [first, second, *rest].compact.join("\n") + "\n"
res.gsub!(/^[ ]{0,3}:/, "\\:")
if el.children.length == 1 && el.children.first.type == :math
res = "\\#{res}"
elsif res.start_with?('\$$') && res.end_with?("\\$$\n")
Expand Down
7 changes: 7 additions & 0 deletions test/testcases/block/03_paragraph/to_kramdown.kramdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
aa aaaa aaaa aaaa aaaa aaaa aaaa aaaa aaaa aaaa aaaa aaaa aaaa aaaa aaaa
\: No definiion list

a:

*a*:

5 changes: 5 additions & 0 deletions test/testcases/block/03_paragraph/to_kramdown.text
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
aa aaaa aaaa aaaa aaaa aaaa aaaa aaaa aaaa aaaa aaaa aaaa aaaa aaaa aaaa : No definiion list

a:

*a*:

0 comments on commit 4ffcc56

Please sign in to comment.