bhollis / maruku

A pure-Ruby Markdown-superset interpreter (Official Repo).
MIT License
500 stars 80 forks source link

Comment symbol (#) in code block seems to be broken #46

Closed jmmcd closed 12 years ago

jmmcd commented 12 years ago

When I use comment symbols (#) in code blocks (```), Maruku seems unable to parse my markdown. Here are two minimal test files, one with a comment and one without. As you can see, the one with the comment fails. I'm on OSX, Maruku 0.6.0.

   $ maruku --version
   Maruku 0.6.0

   $ cat test_no_comment.md

x = 5

   $ maruku test_no_comment.md
   $ cat test.md

assign 5 to x

x = 5

   $ maruku test.md

    ___________________________________________________________________________
   | Maruku tells you:
   +---------------------------------------------------------------------------
   | String finished while reading (break on []) already read: ""
   | ---------------------------------------------------------------------------
   | ```EOF
   | ---|------------------------------------------------------------------------
   |    +--- Byte 3
   | Shown bytes [0 to 3] of 3:
   | >```
   | 
   | At line 2
   |       text     |```|
   |    header3 --> |# assign 5 to x|
   |       text     |x = 5|
   |       text     |```|
   +---------------------------------------------------------------------------
   !/Library/Ruby/Gems/1.8/gems/maruku-0.6.0/lib/maruku/errors_management.rb:49:in `maruku_error'
   !/Library/Ruby/Gems/1.8/gems/maruku-0.6.0/lib/maruku/input/parse_span_better.rb:402:in `read_simple'
   !/Library/Ruby/Gems/1.8/gems/maruku-0.6.0/lib/maruku/input/parse_span_better.rb:521:in `read_inline_code'
   !/Library/Ruby/Gems/1.8/gems/maruku-0.6.0/lib/maruku/input/parse_span_better.rb:89:in `read_span'
   !/Library/Ruby/Gems/1.8/gems/maruku-0.6.0/lib/maruku/input/parse_span_better.rb:46:in `parse_span_better'
   \___________________________________________________________________________

    ___________________________________________________________________________
   | Maruku tells you:
   +---------------------------------------------------------------------------
   | I boldly continue
   | ---------------------------------------------------------------------------
   | ```EOF
   | ---|------------------------------------------------------------------------
   |    +--- Byte 3
   | Shown bytes [0 to 3] of 3:
   | >```
   | 
   | At line 2
   |       text     |```|
   |    header3 --> |# assign 5 to x|
   |       text     |x = 5|
   |       text     |```|
   +---------------------------------------------------------------------------
   !/Library/Ruby/Gems/1.8/gems/maruku-0.6.0/lib/maruku/errors_management.rb:56:in `maruku_recover'
   !/Library/Ruby/Gems/1.8/gems/maruku-0.6.0/lib/maruku/input/parse_span_better.rb:403:in `read_simple'
   !/Library/Ruby/Gems/1.8/gems/maruku-0.6.0/lib/maruku/input/parse_span_better.rb:521:in `read_inline_code'
   !/Library/Ruby/Gems/1.8/gems/maruku-0.6.0/lib/maruku/input/parse_span_better.rb:89:in `read_span'
   !/Library/Ruby/Gems/1.8/gems/maruku-0.6.0/lib/maruku/input/parse_span_better.rb:46:in `parse_span_better'
   \___________________________________________________________________________
   /Library/Ruby/Gems/1.8/gems/maruku-0.6.0/lib/maruku/input/parse_span_better.rb:528:in `read_inline_code': undefined method `[]' for nil:NilClass (NoMethodError)
    from /Library/Ruby/Gems/1.8/gems/maruku-0.6.0/lib/maruku/input/parse_span_better.rb:89:in `read_span'
    from /Library/Ruby/Gems/1.8/gems/maruku-0.6.0/lib/maruku/input/parse_span_better.rb:46:in `parse_span_better'
    from /Library/Ruby/Gems/1.8/gems/maruku-0.6.0/lib/maruku/input/parse_span_better.rb:36:in `parse_lines_as_span'
    from /Library/Ruby/Gems/1.8/gems/maruku-0.6.0/lib/maruku/input/parse_block.rb:275:in `read_paragraph'
    from /Library/Ruby/Gems/1.8/gems/maruku-0.6.0/lib/maruku/input/parse_block.rb:158:in `read_text_material'
    from /Library/Ruby/Gems/1.8/gems/maruku-0.6.0/lib/maruku/input/parse_block.rb:69:in `parse_blocks'
    from /Library/Ruby/Gems/1.8/gems/maruku-0.6.0/lib/maruku/input/parse_block.rb:41:in `parse_text_as_markdown'
    from /Library/Ruby/Gems/1.8/gems/maruku-0.6.0/lib/maruku/input/parse_doc.rb:57:in `parse_doc'
    from /Library/Ruby/Gems/1.8/gems/maruku-0.6.0/lib/maruku/maruku.rb:30:in `initialize'
    from /Library/Ruby/Gems/1.8/gems/maruku-0.6.0/bin/maruku:113:in `new'
    from /Library/Ruby/Gems/1.8/gems/maruku-0.6.0/bin/maruku:113
    from /Library/Ruby/Gems/1.8/gems/maruku-0.6.0/bin/maruku:106:in `each'
    from /Library/Ruby/Gems/1.8/gems/maruku-0.6.0/bin/maruku:106
    from /usr/bin/maruku:19:in `load'
    from /usr/bin/maruku:19
distler commented 12 years ago

Backticks (including multiple backticks) create inline code: x+5<code>x+5</code>. They do not create code blocks. Moreover, while you can include a leading and/or trailing space: `x+5`<code>x+5</code>., you cannot (neither in Maruku, nor in the original Markdown ) include a leading or trailing linebreak.

If you want code blocks in Maruku, you need to use either indented code blocks or, if you are using a version of Maruku which supports it, fenced code blocks.

jmmcd commented 12 years ago

Apologies: I now see that this is documented for Github Flavored Markdown, not in Maruku itself.