[TxMt] Included shell grammar until EOF

Stefan Daschek stefan at daschek.net
Fri Jul 11 09:01:54 UTC 2014


The markdown-redcarpet bundle [1] supports fenced code blocks with 
syntax highlighing, for example for shell scripts. The grammar pattern is:

   fenced_block_shell = {
     name = 'markup.raw.block.markdown.fenced';
     begin = '(^|\G)([`]{3})[ ]*(?:bash|shell|sh)$';
     end = '(^|\G)([`]{3})(\n|\z)';
     patterns = ( { include = 'source.shell'; } );
   };

This works fine, unless if have a block like:

```shell
dd bs=1m if=foo.img of=/dev/disk1
```

Here, “if” starts the scope “meta.scope.if-block.shell”, and this scope 
extends beyond the ``` the end of the fenced code block, resulting in 
incorrect highlighting for the rest of the markdown file.

Is there a way to include grammars in a way making sure the included 
grammar does not extend beyond the “end marker” in any case?

And: Could the rule for if-blocks in the shellscript bundle be more 
strict (matching only '^\s*if\b' for example)? Is this rule needed at 
all? (I haven’t found any other references to the scope “if-block” in 
the shellscript bundle.)



Stefan

[1]: https://github.com/streeter/markdown-redcarpet.tmbundle


More information about the textmate mailing list