[TxMt] Re: Regex For Markdown Fenced Code Blocks

Allan Odgaard mailinglist at textmate.org
Wed Feb 11 04:42:13 UTC 2015


On 10 Feb 2015, at 23:40, Robert J. Rockefeller wrote:

> I still have something wrong.
>
> My injected grammar (injection selector is L:text.html.markdown) looks 
> like this:
> […]

OK, your initial hunch was correct about the end pattern being eclipsed 
by recursively matching a new raw block since this is an injection 
grammar (I thought you had simply extended the current Markdown 
grammar).

You can solve this by changing the injection scope selector.

To make it only inject at the root of the grammar, you can use:

     L:(text.html.markdown $)

However, in your example document, the here-doc is technically inside a 
paragraph. I am not sure if Markdown (that support fenced code blocks) 
will treat it as a code block or not, but if you want to support fenced 
code blocks, regardless of current context, you should use this 
injection scope selector:

     L:(text.html.markdown - markup.raw)

This will inject the grammar everywhere except markup.raw, so you will 
avoid the recursion.

Btw: The inline markdown and markdown block: You may want to swap the 
two rules, so that we always try a block first (3 backticks), and then, 
if it’s not a block, fallback on trying inline raw. Then remove the 
trailing space, and possibly add another rule (before the inline raw) to 
match escape sequences, so that \` is not mistaken as inline raw.


More information about the textmate mailing list