Permalink
Browse files

Parse paragraphs

  • Loading branch information...
1 parent ce2e6d5 commit d88298975cafa06b1bd2669f5a7f12f34919677f @drbrain drbrain committed Oct 2, 2011
Showing with 48 additions and 10 deletions.
  1. +5 −6 pegdown.kpeg
  2. +43 −4 test/test_pegdown.rb
View
11 pegdown.kpeg
@@ -33,10 +33,10 @@ Block = BlankLine*
| Plain )
Para = NonindentSpace Inlines:a BlankLine+
- { raise "$$ = a; $$->key = PARA;" }
+ { RDoc::Markup::Paragraph.new(*a) }
Plain = Inlines:a
- { RDoc::Markup::Paragraph.new(*a) } # raise "$$ = a; $$->key = PLAIN;" }
+ { RDoc::Markup::Paragraph.new(*a) }
AtxInline = !Newline !(Sp? "#"* Sp Newline) Inline
@@ -412,11 +412,10 @@ Endline = LineBreak | TerminalEndline | NormalEndline
NormalEndline = Sp Newline !BlankLine !">" !AtxStart
!(Line ("===" "="* | "---" "-"*) Newline)
- { raise '$$ = mk_str("\n");
- $$->key = SPACE;' }
+ { "\n" }
TerminalEndline = Sp Newline Eof
- { raise " $$ = NULL; " }
+ { }
LineBreak = " " NormalEndline
{ raise " $$ = mk_element(LINEBREAK); " }
@@ -631,7 +630,7 @@ StartList = &.
{ [] }
Line = RawLine
- { raise " $$ = mk_str(yytext); " }
+ #{ a = text }
RawLine = ( < (!"\r" !"\n" .)* Newline > | < .+ > Eof )
SkipBlock = ( !BlankLine RawLine )+ BlankLine*
View
47 test/test_pegdown.rb
@@ -17,16 +17,55 @@ def mu_pp obj
s.force_encoding Encoding.default_external if defined? Encoding
s.chomp
end
-
- def test_parse
- doc = parse 'it worked'
+
+ def test_parse_para
+ doc = parse "it worked\n"
+
+ expected = @RM::Document.new(
+ @RM::Paragraph.new("it worked"))
+
+ assert_equal expected, doc
+ end
+
+ def test_parse_para_multiline
+ doc = parse "one\ntwo"
+
+ expected = @RM::Document.new(
+ @RM::Paragraph.new("one\n", "two"))
+
+ assert_equal expected, doc
+ end
+
+ def test_parse_para_two
+ doc = parse "one\n\ntwo"
+
+ expected = @RM::Document.new(
+ @RM::Paragraph.new("one"),
+ @RM::Paragraph.new("two"))
+
+ assert_equal expected, doc
+ end
+
+ def test_parse_plain
+ doc = parse "it worked"
expected = @RM::Document.new(
- @RM::Paragraph.new('it worked'))
+ @RM::Paragraph.new("it worked"))
assert_equal expected, doc
end
+# def test_parse_style
+# doc = parse <<-MD
+#<style></style>
+# MD
+#
+# expected = @RM::Document.new(
+# @RM::Paragraph.new("it worked"))
+#
+# assert_equal expected, doc
+# end
+
def parse text
Pegdown.parse text
end

0 comments on commit d882989

Please sign in to comment.