Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Parse paragraphs

  • Loading branch information...
commit d88298975cafa06b1bd2669f5a7f12f34919677f 1 parent ce2e6d5
Eric Hodel drbrain authored

Showing 2 changed files with 48 additions and 10 deletions. Show diff stats Hide diff stats

  1. +5 6 pegdown.kpeg
  2. +43 4 test/test_pegdown.rb
11 pegdown.kpeg
@@ -33,10 +33,10 @@ Block = BlankLine*
33 33 | Plain )
34 34
35 35 Para = NonindentSpace Inlines:a BlankLine+
36   - { raise "$$ = a; $$->key = PARA;" }
  36 + { RDoc::Markup::Paragraph.new(*a) }
37 37
38 38 Plain = Inlines:a
39   - { RDoc::Markup::Paragraph.new(*a) } # raise "$$ = a; $$->key = PLAIN;" }
  39 + { RDoc::Markup::Paragraph.new(*a) }
40 40
41 41 AtxInline = !Newline !(Sp? "#"* Sp Newline) Inline
42 42
@@ -412,11 +412,10 @@ Endline = LineBreak | TerminalEndline | NormalEndline
412 412
413 413 NormalEndline = Sp Newline !BlankLine !">" !AtxStart
414 414 !(Line ("===" "="* | "---" "-"*) Newline)
415   - { raise '$$ = mk_str("\n");
416   - $$->key = SPACE;' }
  415 + { "\n" }
417 416
418 417 TerminalEndline = Sp Newline Eof
419   - { raise " $$ = NULL; " }
  418 + { }
420 419
421 420 LineBreak = " " NormalEndline
422 421 { raise " $$ = mk_element(LINEBREAK); " }
@@ -631,7 +630,7 @@ StartList = &.
631 630 { [] }
632 631
633 632 Line = RawLine
634   - { raise " $$ = mk_str(yytext); " }
  633 + #{ a = text }
635 634 RawLine = ( < (!"\r" !"\n" .)* Newline > | < .+ > Eof )
636 635
637 636 SkipBlock = ( !BlankLine RawLine )+ BlankLine*
47 test/test_pegdown.rb
@@ -17,16 +17,55 @@ def mu_pp obj
17 17 s.force_encoding Encoding.default_external if defined? Encoding
18 18 s.chomp
19 19 end
20   -
21   - def test_parse
22   - doc = parse 'it worked'
  20 +
  21 + def test_parse_para
  22 + doc = parse "it worked\n"
  23 +
  24 + expected = @RM::Document.new(
  25 + @RM::Paragraph.new("it worked"))
  26 +
  27 + assert_equal expected, doc
  28 + end
  29 +
  30 + def test_parse_para_multiline
  31 + doc = parse "one\ntwo"
  32 +
  33 + expected = @RM::Document.new(
  34 + @RM::Paragraph.new("one\n", "two"))
  35 +
  36 + assert_equal expected, doc
  37 + end
  38 +
  39 + def test_parse_para_two
  40 + doc = parse "one\n\ntwo"
  41 +
  42 + expected = @RM::Document.new(
  43 + @RM::Paragraph.new("one"),
  44 + @RM::Paragraph.new("two"))
  45 +
  46 + assert_equal expected, doc
  47 + end
  48 +
  49 + def test_parse_plain
  50 + doc = parse "it worked"
23 51
24 52 expected = @RM::Document.new(
25   - @RM::Paragraph.new('it worked'))
  53 + @RM::Paragraph.new("it worked"))
26 54
27 55 assert_equal expected, doc
28 56 end
29 57
  58 +# def test_parse_style
  59 +# doc = parse <<-MD
  60 +#<style></style>
  61 +# MD
  62 +#
  63 +# expected = @RM::Document.new(
  64 +# @RM::Paragraph.new("it worked"))
  65 +#
  66 +# assert_equal expected, doc
  67 +# end
  68 +
30 69 def parse text
31 70 Pegdown.parse text
32 71 end

0 comments on commit d882989

Please sign in to comment.
Something went wrong with that request. Please try again.