Skip to content

Commit

Permalink
Merge pull request #676 from nobu/feature/blockquote
Browse files Browse the repository at this point in the history
Support blockquote
  • Loading branch information
aycabta authored Dec 8, 2018
2 parents 92f6dd9 + b02b37d commit bcc91fe
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
19 changes: 17 additions & 2 deletions lib/rdoc/markup/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
# RDoc::Markup::ToHTML.
#
# The parser only handles the block-level constructs Paragraph, List,
# ListItem, Heading, Verbatim, BlankLine and Rule. Inline markup such as
# <tt>\+blah\+</tt> is handled separately by RDoc::Markup::AttributeManager.
# ListItem, Heading, Verbatim, BlankLine, Rule and BlockQuote.
# Inline markup such as <tt>\+blah\+</tt> is handled separately by
# RDoc::Markup::AttributeManager.
#
# To see what markup the Parser implements read RDoc. To see how to use
# RDoc markup to format text in your program read RDoc::Markup.
Expand Down Expand Up @@ -381,6 +382,17 @@ def parse parent, indent = 0
when :TEXT then
unget
parse_text parent, indent
when :BLOCKQUOTE then
type, _, column = get
if type == :NEWLINE
type, _, column = get
end
unget if type
bq = RDoc::Markup::BlockQuote.new
p :blockquote_start => [data, column] if @debug
parse bq, column
p :blockquote_end => indent if @debug
parent << bq
when *LIST_TOKENS then
unget
parent << build_list(indent)
Expand Down Expand Up @@ -504,6 +516,9 @@ def tokenize input
# text:: followed by spaces or end of line => :NOTE
when @s.scan(/(.*?)::( +|\r?$)/) then
[:NOTE, @s[1], *token_pos(pos)]
# >>> followed by end of line => :BLOCKQUOTE
when @s.scan(/>>> *(\w+)?$/) then
[:BLOCKQUOTE, @s[1], *token_pos(pos)]
# anything else: :TEXT
else
@s.scan(/(.*?)( )?\r?$/)
Expand Down
35 changes: 35 additions & 0 deletions test/test_rdoc_markup_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,41 @@ def test_parse_whitespace
assert_equal expected, @RMP.parse(" 1\n 2\n\n 3").parts
end

def test_parse_block_quote
expected = [
@RM::BlockQuote.new(@RM::Paragraph.new("foo"))
]
assert_equal expected, @RMP.parse(<<-DOC).parts
>>>
foo
DOC

expected = [
@RM::BlockQuote.new(@RM::Paragraph.new("foo"),
@RM::Verbatim.new("code\n"),
@RM::Paragraph.new("bar"))
]
assert_equal expected, @RMP.parse(<<-DOC).parts
>>>
foo
code
bar
DOC

expected = [
@RM::BlockQuote.new(@RM::Paragraph.new("foo"),
@RM::BlockQuote.new(@RM::Paragraph.new("bar")),
@RM::Paragraph.new("zot"))
]
assert_equal expected, @RMP.parse(<<-DOC).parts
>>>
foo
>>>
bar
zot
DOC
end

def test_peek_token
parser = util_parser

Expand Down

0 comments on commit bcc91fe

Please sign in to comment.