Skip to content

Commit

Permalink
Fix escaping of dots at beginnings of lines inside multi-line text ru…
Browse files Browse the repository at this point in the history
…ns passed to write()
  • Loading branch information
apjanke committed Dec 25, 2018
1 parent 1a81697 commit 3dca20c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/ronn/roff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,8 @@ def quote(text)
def write(text)
return if text.nil? || text.empty?
# lines cannot start with a '.'. insert zero-width character before.
if text[0, 2] == '\.' &&
(@buf.last && @buf.last[-1] == "\n")
text = text.gsub(/\n\\\./s, "\n\\\\&\\.")
if text[0, 2] == '\.' && (@buf.last && @buf.last[-1] == "\n")
@buf << '\&'
end
@buf << text
Expand Down
12 changes: 12 additions & 0 deletions test/dots_at_line_start_test.roff
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,15 @@
There\'s a weird issue where dots at the beginning of a line generate troff warnings due to escaping\.
.P
\&\.\. let\'s see what happens\.
.IP "" 4
.nf
\&\. A dot on an indented line

\&\. Another dot on an indented line

some text
some more text
\&\. A dot on an indented line as part of a paragraph
.fi
.IP "" 0

8 changes: 8 additions & 0 deletions test/dots_at_line_start_test.ronn
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,11 @@ There's a weird issue where dots at the beginning of a line
generate troff warnings due to escaping.

.. let's see what happens.

. A dot on an indented line

. Another dot on an indented line

some text
some more text
. A dot on an indented line as part of a paragraph
2 changes: 1 addition & 1 deletion test/markdown_syntax.roff
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ _ underscore
# hash mark
+ plus sign
\- minus sign (hyphen)
\. dot
\&\. dot
! exclamation mark
.fi
.IP "" 0
Expand Down

0 comments on commit 3dca20c

Please sign in to comment.