From a9c8214c08a901cae5f93d4b40f9d8e30de4b0f4 Mon Sep 17 00:00:00 2001 From: tompng Date: Sat, 27 Dec 2025 00:22:32 +0900 Subject: [PATCH] Simplify newline handling of comment token in TokenStream#to_html The logic of newline handling to make html tag pretty does not need to be restricted to comment token. Remove comment-specific condition and make it simple. --- lib/rdoc/token_stream.rb | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/rdoc/token_stream.rb b/lib/rdoc/token_stream.rb index 5a4ca82a67..8b0d49d295 100644 --- a/lib/rdoc/token_stream.rb +++ b/lib/rdoc/token_stream.rb @@ -45,13 +45,7 @@ def self.to_html(token_stream) then 'ruby-identifier' end - comment_with_nl = false - if :on_comment == t[:kind] or :on_embdoc == t[:kind] or :on_heredoc_end == t[:kind] - comment_with_nl = true if "\n" == t[:text][-1] - text = t[:text].rstrip - else - text = t[:text] - end + text = t[:text] if :on_ident == t[:kind] && starting_title starting_title = false @@ -65,7 +59,11 @@ def self.to_html(token_stream) text = CGI.escapeHTML text if style then - "#{text}#{"\n" if comment_with_nl}" + if text.end_with?("\n") + newline = "\n" + text = text.byteslice(0...-1) + end + "#{text}#{newline}" else text end