Permalink
Browse files

Implement BlockQuote, add RDoc::Markup::BlockQuote.

Implement more of list parsing ("loose"), fix numbered lists
  • Loading branch information...
1 parent be56d55 commit 0b75cecf8318ae57c46ce3dbe62e271f0bbc1781 @drbrain drbrain committed Oct 23, 2011
Showing with 110 additions and 27 deletions.
  1. +14 −0 lib/rdoc/markup/block_quote.rb
  2. +11 −26 pegdown.kpeg
  3. +85 −1 test/test_pegdown.rb
@@ -0,0 +1,14 @@
+##
+# A quoted section of text
+
+class RDoc::Markup::BlockQuote < RDoc::Markup::Raw
+
+ ##
+ # Calls #accept_block_quote on +visitor+
+
+ def accept visitor
+ visitor.accept_block_quote self
+ end
+
+end
+
View
@@ -65,18 +65,14 @@ SetextHeading2 = &(RawLine SetextBottom2)
Heading = SetextHeading | AtxHeading
BlockQuote = BlockQuoteRaw:a
- { raise "$$ = mk_element(BLOCKQUOTE);
- $$->children = a;"
- }
+ { RDoc::Markup::BlockQuote.new(*a) }
BlockQuoteRaw = StartList:a
- (( ">" " "? Line { raise " a = cons($$, a); " } )
- ( !">" !BlankLine Line { raise " a = cons($$, a); " } )*
- ( BlankLine { raise ' a = cons(mk_str("\n"), a); ' } )*
+ (( ">" " "? Line:l { a << l } )
+ ( !">" !BlankLine Line:c { a << c } )*
+ ( BlankLine:n { a << n } )*
)+
- { raise '$$ = mk_str_from_list(a, true);
- $$->key = RAW;'
- }
+ { a }
NonblankIndentedLine = !BlankLine IndentedLine
@@ -104,25 +100,14 @@ ListTight = ListItemTight+:a
{ a }
ListLoose = StartList:a
- ( b:listItem BlankLine*
- { raise 'element *li;
- li = b->children;
- li->contents.str = realloc(li->contents.str, strlen(li->contents.str) + 3);
- strcat(li->contents.str, "\n\n"); /* In loose list, \n\n added to end of each element */
- a = cons(b, a);'
- } )+
- { raise " $$ = mk_list(LIST, a); " }
+ ( ListItem:b BlankLine* { a << b } )+
+ { a }
ListItem = ( Bullet | Enumerator )
StartList:a
- ListBlock { raise " a = cons($$, a); " }
+ ListBlock:b { a << b }
( ListContinuationBlock { raise " a = cons($$, a); " } )*
- { raise 'element *raw;
- raw = mk_str_from_list(a, false);
- raw->key = RAW;
- $$ = mk_element(LISTITEM);
- $$->children = raw;'
- }
+ { RDoc::Markup::ListItem.new(nil, *a) }
ListItemTight =
( Bullet | Enumerator )
@@ -145,7 +130,7 @@ ListContinuationBlock = StartList:a
Enumerator = NonindentSpace [0-9]+ "." Spacechar+
OrderedList = &Enumerator (ListTight | ListLoose):a
- { RDoc::Markup::List.new(:BULLET, *a) }
+ { RDoc::Markup::List.new(:NUMBER, *a) }
ListBlockLine = !BlankLine
!( Indent? (Bullet | Enumerator) )
@@ -584,7 +569,7 @@ RawHtml = < (HtmlComment | HtmlBlockScript | HtmlTag) >
}'
}
-BlankLine = Sp Newline
+BlankLine = Sp Newline { "\n" }
Quoted = "\"" (!"\"" .)* "\"" | "'" (!"'" .)* "'"
HtmlAttribute = (AlphanumericAscii | "-")+ Spnl ("=" Spnl (Quoted | (!">" Nonspacechar)+))? Spnl
View
@@ -4,6 +4,7 @@
require 'pegdown'
require 'rdoc'
+require 'rdoc/markup/block_quote'
class TestPegdown < MiniTest::Unit::TestCase
@@ -18,6 +19,59 @@ def mu_pp obj
s.chomp
end
+ def test_parse_block_quote
+ doc = parse <<-BLOCK_QUOTE
+> this is
+> a block quote
+ BLOCK_QUOTE
+
+ expected = @RM::Document.new(
+ @RM::BlockQuote.new("this is\n", "a block quote\n"))
+
+ assert_equal expected, doc
+ end
+
+ def test_parse_block_quote_continue
+ doc = parse <<-BLOCK_QUOTE
+> this is
+a block quote
+ BLOCK_QUOTE
+
+ expected = @RM::Document.new(
+ @RM::BlockQuote.new("this is\n", "a block quote\n"))
+
+ assert_equal expected, doc
+ end
+
+ def test_parse_block_quote_newline
+ doc = parse <<-BLOCK_QUOTE
+> this is
+a block quote
+
+ BLOCK_QUOTE
+
+ expected = @RM::Document.new(
+ @RM::BlockQuote.new("this is\n", "a block quote\n", "\n"))
+
+ assert_equal expected, doc
+ end
+
+ def test_parse_block_quote_separate
+ doc = parse <<-BLOCK_QUOTE
+> this is
+a block quote
+
+> that continues
+ BLOCK_QUOTE
+
+ expected = @RM::Document.new(
+ @RM::BlockQuote.new("this is\n", "a block quote\n",
+ "\n",
+ "that continues\n"))
+
+ assert_equal expected, doc
+ end
+
def test_parse_heading_atx
doc = parse "# heading\n"
@@ -65,14 +119,44 @@ def test_parse_list_bullet
assert_equal expected, doc
end
+ def test_parse_list_bullet_continue
+ doc = parse <<-MD
+* one
+
+* two
+ MD
+
+ expected = @RM::Document.new(
+ @RM::List.new(:BULLET, *[
+ @RM::ListItem.new(nil, @RM::Paragraph.new("one\n")),
+ @RM::ListItem.new(nil, @RM::Paragraph.new("two\n"))]))
+
+ assert_equal expected, doc
+ end
+
def test_parse_list_number
doc = parse <<-MD
1. one
1. two
MD
expected = @RM::Document.new(
- @RM::List.new(:BULLET, *[
+ @RM::List.new(:NUMBER, *[
+ @RM::ListItem.new(nil, @RM::Paragraph.new("one\n")),
+ @RM::ListItem.new(nil, @RM::Paragraph.new("two\n"))]))
+
+ assert_equal expected, doc
+ end
+
+ def test_parse_list_number_continue
+ doc = parse <<-MD
+1. one
+
+1. two
+ MD
+
+ expected = @RM::Document.new(
+ @RM::List.new(:NUMBER, *[
@RM::ListItem.new(nil, @RM::Paragraph.new("one\n")),
@RM::ListItem.new(nil, @RM::Paragraph.new("two\n"))]))

0 comments on commit 0b75cec

Please sign in to comment.