lib/kramdown/converter/man.rb in kramdown-man-0.1.3 vs lib/kramdown/converter/man.rb in kramdown-man-0.1.4

- old
+ new

@@ -113,11 +113,11 @@ # # @return [String] # The roff output. # def convert_text(text) - escape(text.value) + escape(text.value.gsub(/^( +|\t)/,'')) end # # Converts a `kd:typographic_sym` element. # @@ -323,17 +323,22 @@ # def convert_p(p) children = p.children if (children.length >= 2) && - (children[0].type == :em || children[0].type == :codespan) && - (children[1].type == :text && children[1].value =~ /^( |\t)/) - [ - '.TP', - convert_element(children[0]), - convert_text(children[1]).lstrip, - convert_children(children[2..-1]) - ].join("\n").rstrip + (children.first.type == :em || children.first.type == :codespan) + newline = children.find_index { |el| + el.type == :text && el.value.start_with?("\n") + } + + if newline + first_line = convert_children(children[0...newline]) + rest = convert_children(children[newline..-1]).strip + + ".TP\n#{first_line}\n#{rest}" + else + ".HP\n#{convert_children(children)}" + end else ".PP\n#{convert_children(children)}" end end