Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions lib/ronn/roff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,9 @@ def escape(text)
text.gsub!(/&#(\d+);/) { $1.to_i.chr } # dec entities
text.gsub!('\\', '\e') # backslash
text.gsub!('...', '\|.\|.\|.') # ellipses
text.gsub!(/['.-]/) { |m| "\\#{m}" } # control chars
# lines cannot start with a '.', insert zero-width character before
text.gsub!(/^\./, '\\\\&.') # dot at line start
text.gsub!(/['-]/) { |m| "\\#{m}" } # control chars
text.gsub!(/(&[A-Za-z]+;)/) { ent[$1] || $1 } # named entities
text.gsub!('&', '&') # amps
text
Expand All @@ -269,11 +271,6 @@ def quote(text)
# write text to output buffer
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)
@buf << '\&'
end
@buf << text
end

Expand Down
2 changes: 1 addition & 1 deletion test/definition_list_syntax.roff
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ new paragraphs
.
.TP
\fB\-\-somearg\fR=\fIVALUE\fR
We can do that too\.
We can do that too.

24 changes: 22 additions & 2 deletions test/dots_at_line_start_test.roff
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,27 @@
\fBdots_at_line_start_test\fR
.
.P
There\'s a weird issue where dots at the beginning of a line generate troff warnings due to escaping\.
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\.
\&.. let\'s see what happens.
.
.IP "" 4
.
.nf

\&. This dot is escaped correctly.

a test
b test
\&. This one is too.
.
.fi
.
.IP "" 0
.
.P
\&.
.
.P
(Single dots should get replaced correctly, too.)
10 changes: 10 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,13 @@ There's a weird issue where dots at the beginning of a line
generate troff warnings due to escaping.

.. let's see what happens.

. This dot is escaped correctly.

a test
b test
. This one is too.

.

(Single dots should get replaced correctly, too.)
4 changes: 2 additions & 2 deletions test/ellipses.roff
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
\fBellipses\fR \- testing ellipses
.
.P
Ellipses should be replaced\|\.\|\.\|\.
Ellipses should be replaced\|.\|.\|.
.
.P
\|\.\|\.\|\.also, they shouldn\'t interfere with regular dots at the beginning of a line\.
\|.\|.\|.also, they shouldn\'t interfere with regular dots at the beginning of a line.
2 changes: 1 addition & 1 deletion test/entity_encoding_test.roff
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ Here\'s some special entities:
.IP "" 0
.
.P
Here\'s a line that uses non\-breaking spaces to force the last\~few\~words\~to\~wrap\~together\.
Here\'s a line that uses non\-breaking spaces to force the last\~few\~words\~to\~wrap\~together.
364 changes: 182 additions & 182 deletions test/markdown_syntax.roff

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/middle_paragraph.roff
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Foo
.
.P
Always use \fBattr_reader\fR, \fBattr_writer\fR or \fBattr_accessor\fR\. Do not use \fBfor\|\.\|\.\|\.in\fR; use each instead\. Do not use \fBand\fR/\fBor\fR; use \fB&&\fR/\fB||\fR instead\.
Always use \fBattr_reader\fR, \fBattr_writer\fR or \fBattr_accessor\fR\&. Do not use \fBfor\|.\|.\|.in\fR; use each instead. Do not use \fBand\fR/\fBor\fR; use \fB&&\fR/\fB||\fR instead.
.
.P
Bar
2 changes: 1 addition & 1 deletion test/missing_spaces.roff
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
.
.TP
\fB\-S\fR \fItext\fR, \fBsearch\fR \fItext\fR
Performs a substring search of formula names for \fItext\fR\.
Performs a substring search of formula names for \fItext\fR\&.

2 changes: 1 addition & 1 deletion test/nested_list_with_code.roff
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
\fBtoggle_status\fR
.
.IP "\[ci]" 4
Toggle the display of the status bar\.
Toggle the display of the status bar.
.
.IP "" 0

Expand Down
2 changes: 1 addition & 1 deletion test/section_reference_links.roff
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
\fBsection_reference_links\fR \- linking to sections
.
.SH "SECTION 1"
See the following section\.
See the following section.
.
.SH "SECTION 2"
See \fISECTION 1\fR or \fIto put it another way\fR or even \fIlink this\fR
6 changes: 3 additions & 3 deletions test/underline_spacing_test.roff
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ This input
.
.TP
\fB\-S\fR \fItext\fR, \fBsearch\fR \fItext\fR
Performs a substring search of formula names for \fItext\fR\.
Performs a substring search of formula names for \fItext\fR\&.
.
.TP
\fB\-O\fR \fItext\fR, \fBother\fR \fItext\fR
Does something else\.
Does something else.
.
.P
Should space text properly\.
Should space text properly.
.
.P
\fI!\-\- this is a comment \-\-\fR