Skip to content

Commit b02b37d

Browse files
committed
Support blockquote
RDoc::Markup::BlockQuote is supported by RDoc::Markdown, but not RDoc::Markup yet and the syntax for it is not too. This patch implements `>>>` as blockquote tentatively, ``` >>> foo ``` to ``` <blockquote><p>foo</p><blockquote> ```
1 parent b94edb0 commit b02b37d

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

lib/rdoc/markup/parser.rb

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
# RDoc::Markup::ToHTML.
1010
#
1111
# The parser only handles the block-level constructs Paragraph, List,
12-
# ListItem, Heading, Verbatim, BlankLine and Rule. Inline markup such as
13-
# <tt>\+blah\+</tt> is handled separately by RDoc::Markup::AttributeManager.
12+
# ListItem, Heading, Verbatim, BlankLine, Rule and BlockQuote.
13+
# Inline markup such as <tt>\+blah\+</tt> is handled separately by
14+
# RDoc::Markup::AttributeManager.
1415
#
1516
# To see what markup the Parser implements read RDoc. To see how to use
1617
# RDoc markup to format text in your program read RDoc::Markup.
@@ -381,6 +382,17 @@ def parse parent, indent = 0
381382
when :TEXT then
382383
unget
383384
parse_text parent, indent
385+
when :BLOCKQUOTE then
386+
type, _, column = get
387+
if type == :NEWLINE
388+
type, _, column = get
389+
end
390+
unget if type
391+
bq = RDoc::Markup::BlockQuote.new
392+
p :blockquote_start => [data, column] if @debug
393+
parse bq, column
394+
p :blockquote_end => indent if @debug
395+
parent << bq
384396
when *LIST_TOKENS then
385397
unget
386398
parent << build_list(indent)
@@ -504,6 +516,9 @@ def tokenize input
504516
# text:: followed by spaces or end of line => :NOTE
505517
when @s.scan(/(.*?)::( +|\r?$)/) then
506518
[:NOTE, @s[1], *token_pos(pos)]
519+
# >>> followed by end of line => :BLOCKQUOTE
520+
when @s.scan(/>>> *(\w+)?$/) then
521+
[:BLOCKQUOTE, @s[1], *token_pos(pos)]
507522
# anything else: :TEXT
508523
else @s.scan(/(.*?)( )?\r?$/)
509524
token = [:TEXT, @s[1], *token_pos(pos)]

test/test_rdoc_markup_parser.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,41 @@ def test_parse_whitespace
10451045
assert_equal expected, @RMP.parse(" 1\n 2\n\n 3").parts
10461046
end
10471047

1048+
def test_parse_block_quote
1049+
expected = [
1050+
@RM::BlockQuote.new(@RM::Paragraph.new("foo"))
1051+
]
1052+
assert_equal expected, @RMP.parse(<<-DOC).parts
1053+
>>>
1054+
foo
1055+
DOC
1056+
1057+
expected = [
1058+
@RM::BlockQuote.new(@RM::Paragraph.new("foo"),
1059+
@RM::Verbatim.new("code\n"),
1060+
@RM::Paragraph.new("bar"))
1061+
]
1062+
assert_equal expected, @RMP.parse(<<-DOC).parts
1063+
>>>
1064+
foo
1065+
code
1066+
bar
1067+
DOC
1068+
1069+
expected = [
1070+
@RM::BlockQuote.new(@RM::Paragraph.new("foo"),
1071+
@RM::BlockQuote.new(@RM::Paragraph.new("bar")),
1072+
@RM::Paragraph.new("zot"))
1073+
]
1074+
assert_equal expected, @RMP.parse(<<-DOC).parts
1075+
>>>
1076+
foo
1077+
>>>
1078+
bar
1079+
zot
1080+
DOC
1081+
end
1082+
10481083
def test_peek_token
10491084
parser = util_parser
10501085

0 commit comments

Comments
 (0)