Skip to content

Support blockquote #676

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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?$/)
token = [:TEXT, @s[1], *token_pos(pos)]
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