Syntax highlighting for :markdown filter is too greedy #16

Open
TrevorBurnham opened this Issue Nov 21, 2011 · 4 comments

Comments

Projects
None yet
3 participants
@TrevorBurnham

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

This comment has been minimized.

Show comment Hide comment
@TrevorBurnham

TrevorBurnham Nov 21, 2011

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

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

This comment has been minimized.

Show comment Hide comment
@TrevorBurnham

TrevorBurnham Nov 21, 2011

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.

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

This comment has been minimized.

Show comment Hide comment
@enyo

enyo Jan 23, 2012

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

enyo commented Jan 23, 2012

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

@KelseyHigham

This comment has been minimized.

Show comment Hide comment
@KelseyHigham

KelseyHigham Jun 29, 2012

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.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment