ThisIsMissEm / jade-tmbundle

[DEPRECATED] A textmate bundle for the Jade language
http://jade-lang.com
220 stars 81 forks source link

Syntax highlighting for :markdown filter is too greedy #16

Open TrevorBurnham opened 12 years ago

TrevorBurnham commented 12 years ago

Here's a test case:

!!!5
  p
    :markdown
      This looks fine.
    p Why is this blue?

This renders as

http://cl.ly/030K0s3J1D1g3l0n1v2v

Jade correctly interprets the p as being a separate element, not part of the Markdown, so the highlighting is inaccurate.

TrevorBurnham commented 12 years ago

Here's another case where the highlighting for the :markdown filter isn't greedy enough:

!!! 5
  p
    :markdown
      This is Markdown

      This is Markdown, too

http://cl.ly/3D040O0g0E2w1y1R3a2A

TrevorBurnham commented 12 years ago

In the "not greedy enough case," the Markdown highlighting continues if and only if the blank line between the two paragraphs is indented. Jade, however, doesn't care whether it's indented or not.

enyo commented 12 years ago

Thanks TrevorBurnham for pointing out that inserting intended blank lines "fixes" this behavior. This is at least a workaround.

KelseyHigham commented 12 years ago

Apparently this is caused by Markdown's treatment of any indented text as raw <pre><code>.

Markdown's Language Grammar, lines 126~130:

    raw_block = {
        begin = '(^|\G)([ ]{4}|\t)';
        name = 'markup.raw.block.markdown';
        while = '(^|\G)([ ]{4}|\t)';
    };

(If you're not fluent in regex, what that says, as best as I can tell, is that while Markdown sees indented code (4 spaces or a literal indent character), it will keep treating text as raw <pre><code>. That's why inserting an unindented line stops the greedy parsing.)

I'm not sure why the markup.raw.block.markdown continues after the actual text.html.markdown should stop, but it implies another workaround:

  1. Go to Bundles > Edit Bundles… > Jade > Language Grammars > Jade
  2. Search for "Markdown" (or go to lines 17~21, if your file looks exactly like mine)
  3. Remove the string include = 'text.html.markdown';, or replace it with include = 'plain.text';

(TextMate will automatically create a copy of your Jade bundle at ~/Library/Application Support/("TextMate" for TM 1, "Avian" for TM 2)/Bundles/Jade.tmbundle; the original is preserved at /Pristine Copy/Bundles. So you don't need to worry about editing the bundle.)

This still doesn't restore Markdown's syntax highlighting, though.