[前][次][番号順一覧][スレッド一覧]

ruby-changes:72752

From: Nobuyoshi <ko1@a...>
Date: Sat, 30 Jul 2022 11:04:24 +0900 (JST)
Subject: [ruby-changes:72752] af265d73fb (master): [ruby/rdoc] Fix blockquote with word in verbatim

https://git.ruby-lang.org/ruby.git/commit/?id=af265d73fb

From af265d73fb2726fcd405d86d37d28bbf03de3b04 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Sat, 30 Jul 2022 01:18:04 +0900
Subject: [ruby/rdoc] Fix blockquote with word in verbatim

https://github.com/ruby/rdoc/commit/75eee668a5
---
 lib/rdoc/markup/parser.rb             | 16 ++++++++++------
 test/rdoc/test_rdoc_markup_to_html.rb |  9 +++++++++
 2 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/lib/rdoc/markup/parser.rb b/lib/rdoc/markup/parser.rb
index b0fcb61f50..0029df7e65 100644
--- a/lib/rdoc/markup/parser.rb
+++ b/lib/rdoc/markup/parser.rb
@@ -289,6 +289,10 @@ class RDoc::Markup::Parser https://github.com/ruby/ruby/blob/trunk/lib/rdoc/markup/parser.rb#L289
         line << data
       when :BLOCKQUOTE then
         line << '>>>'
+        peek_type, _, peek_column = peek_token
+        if peek_type != :NEWLINE and peek_column
+          line << ' ' * (peek_column - column - 3)
+        end
       else # *LIST_TOKENS
         list_marker = case type
                       when :BULLET then data
@@ -374,11 +378,8 @@ class RDoc::Markup::Parser https://github.com/ruby/ruby/blob/trunk/lib/rdoc/markup/parser.rb#L378
         unget
         parse_text parent, indent
       when :BLOCKQUOTE then
-        type, _, column = get
-        if type == :NEWLINE
-          type, _, column = get
-        end
-        unget if type
+        nil while (type, = get; type) and type != :NEWLINE
+        _, _, column, = peek_token
         bq = RDoc::Markup::BlockQuote.new
         p :blockquote_start => [data, column] if @debug
         parse bq, column
@@ -546,7 +547,10 @@ class RDoc::Markup::Parser https://github.com/ruby/ruby/blob/trunk/lib/rdoc/markup/parser.rb#L547
                    [:NOTE, @s[1], *pos]
                  # >>> followed by end of line => :BLOCKQUOTE
                  when @s.scan(/>>> *(\w+)?$/) then
-                   [:BLOCKQUOTE, @s[1], *pos]
+                   if word = @s[1]
+                     @s.unscan(word)
+                   end
+                   [:BLOCKQUOTE, word, *pos]
                  # anything else: :TEXT
                  else
                    @s.scan(/(.*?)(  )?\r?$/)
diff --git a/test/rdoc/test_rdoc_markup_to_html.rb b/test/rdoc/test_rdoc_markup_to_html.rb
index 3cf42d7c5e..a5927dccae 100644
--- a/test/rdoc/test_rdoc_markup_to_html.rb
+++ b/test/rdoc/test_rdoc_markup_to_html.rb
@@ -821,6 +821,15 @@ EXPECTED https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_markup_to_html.rb#L821
     EXPECTED
 
     assert_equal expected, @m.convert(str, @to).gsub(/^\n/, "")
+
+    str = "BlockQuote\n  >>>  word\n"
+
+    expected = <<-EXPECTED
+<p>BlockQuote</p>
+<pre>&gt;&gt;&gt;  word</pre>
+    EXPECTED
+
+    assert_equal expected, @m.convert(str, @to).gsub(/^\n/, "")
   end
 
   def test_parseable_eh
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]