Permalink
Browse files

Parse Verbatim

  • Loading branch information...
1 parent 884cb4c commit 2ec322f87b58ec093092d76f916b4e38684cfbf1 @drbrain drbrain committed Oct 2, 2011
Showing with 46 additions and 8 deletions.
  1. +6 −8 pegdown.kpeg
  2. +40 −0 test/test_pegdown.rb
View
@@ -79,14 +79,12 @@ BlockQuoteRaw = StartList:a
NonblankIndentedLine = !BlankLine IndentedLine
-VerbatimChunk = StartList:a
- ( BlankLine { raise ' a = cons(mk_str("\n"), a); ' } )*
- ( NonblankIndentedLine { raise " a = cons($$, a); " } )+
- { raise " $$ = mk_str_from_list(a, false); " }
-
-Verbatim = StartList:a ( VerbatimChunk { raise " a = cons($$, a); " } )+
- { raise '$$ = mk_str_from_list(a, false);
- $$->key = VERBATIM;' }
+VerbatimChunk = BlankLine*:a
+ NonblankIndentedLine+:b
+ { a.push(*b) }
+
+Verbatim = VerbatimChunk+:a
+ { RDoc::Markup::Verbatim.new(*a) }
HorizontalRule = NonindentSpace
( "*" Sp "*" Sp "*" (Sp "*")*
View
@@ -32,6 +32,36 @@ def test_parse_bullet_list
assert_equal expected, doc
end
+ def test_parse_paragraph_indent_one
+ doc = parse <<-MD
+ text
+ MD
+
+ expected = @RM::Document.new(@RM::Paragraph.new(" text"))
+
+ assert_equal expected, doc
+ end
+
+ def test_parse_paragraph_indent_two
+ doc = parse <<-MD
+ text
+ MD
+
+ expected = @RM::Document.new(@RM::Paragraph.new(" text"))
+
+ assert_equal expected, doc
+ end
+
+ def test_parse_paragraph_indent_three
+ doc = parse <<-MD
+ text
+ MD
+
+ expected = @RM::Document.new(@RM::Paragraph.new(" text"))
+
+ assert_equal expected, doc
+ end
+
def test_parse_para
doc = parse "it worked\n"
@@ -80,6 +110,16 @@ def test_parse_plain
# assert_equal expected, doc
# end
+ def test_parse_verbatim
+ doc = parse <<-MD
+ text
+ MD
+
+ expected = @RM::Document.new(@RM::Verbatim.new(["text\n"]))
+
+ assert_equal expected, doc
+ end
+
def parse text
Pegdown.parse text
end

0 comments on commit 2ec322f

Please sign in to comment.