lib/kramdown/converter/kramdown.rb in kramdown-2.3.2 vs lib/kramdown/converter/kramdown.rb in kramdown-2.4.0
- old
+ new
@@ -25,10 +25,12 @@
super
@linkrefs = []
@footnotes = []
@abbrevs = []
@stack = []
+ @list_indent = @options[:list_indent]
+ @list_spacing = ' ' * (@list_indent - 2)
end
def convert(el, opts = {indent: 0})
res = send("convert_#{el.type}", el, opts)
res = res.dup if res.frozen?
@@ -75,20 +77,23 @@
if opts[:raw_text]
el.value
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
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}\\." }
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")
res.sub!(/^\\\$\$/, '\$\$')
end
@@ -122,11 +127,11 @@
alias convert_ol convert_ul
alias convert_dl convert_ul
def convert_li(el, opts)
sym, width = if @stack.last.type == :ul
- [+'* ', el.children.first && el.children.first.type == :codeblock ? 4 : 2]
+ ['* ' + @list_spacing, el.children.first && el.children.first.type == :codeblock ? 4 : @list_indent]
else
["#{opts[:index] + 1}.".ljust(4), 4]
end
if (ial = ial_for_element(el))
sym << ial << " "
@@ -149,10 +154,10 @@
"#{sym}#{text}"
end
end
def convert_dd(el, opts)
- sym, width = +": ", (el.children.first && el.children.first.type == :codeblock ? 4 : 2)
+ sym, width = ": " + @list_spacing, (el.children.first && el.children.first.type == :codeblock ? 4 : @list_indent)
if (ial = ial_for_element(el))
sym << ial << " "
end
opts[:indent] += width