Skip to content

Commit a9c8214

Browse files
committed
Simplify newline handling of comment token in TokenStream#to_html
The logic of newline handling to make html <span> tag pretty does not need to be restricted to comment token. Remove comment-specific condition and make it simple.
1 parent d676630 commit a9c8214

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

lib/rdoc/token_stream.rb

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,7 @@ def self.to_html(token_stream)
4545
then 'ruby-identifier'
4646
end
4747

48-
comment_with_nl = false
49-
if :on_comment == t[:kind] or :on_embdoc == t[:kind] or :on_heredoc_end == t[:kind]
50-
comment_with_nl = true if "\n" == t[:text][-1]
51-
text = t[:text].rstrip
52-
else
53-
text = t[:text]
54-
end
48+
text = t[:text]
5549

5650
if :on_ident == t[:kind] && starting_title
5751
starting_title = false
@@ -65,7 +59,11 @@ def self.to_html(token_stream)
6559
text = CGI.escapeHTML text
6660

6761
if style then
68-
"<span class=\"#{style}\">#{text}</span>#{"\n" if comment_with_nl}"
62+
if text.end_with?("\n")
63+
newline = "\n"
64+
text = text.byteslice(0...-1)
65+
end
66+
"<span class=\"#{style}\">#{text}</span>#{newline}"
6967
else
7068
text
7169
end

0 commit comments

Comments
 (0)