[TxMt] Regex For Markdown Fenced Code Blocks

Robert J. Rockefeller bob at bobrockefeller.com
Tue Feb 10 00:07:41 UTC 2015


I’m new to TextMate 2 grammar definitions and am trying to add a Markdown regex to identify a Markdown fenced code block like this one:

```
Vagrant.configure("2") do |config|

  config.vm.box = "scotch/box"
  config.vm.network "private_network", ip: "192.168.33.10"
  config.vm.hostname = "scotchbox"
  config.vm.synced_folder ".", "/var/www", :mount_options => ["dmode=777", "fmode=666"]

end
```

I built this regex:

{	name = 'markup.raw.block.markdown';
	begin = '(^|\G)([`]{3})';
	end = '(^|\G)(^[`]{3})';
},

Which hits the starting ``` but misses the ending one. Probably because it thinks the second one is the start of a new code block rather than the end of the last one.

TextMate tangles me up some because it looks at just one line at a time for regex matches. Looked at it that way, each of the ```s is exactly the same!

What would the proper regex be?

Bob
-------------------
Robert J. Rockefeller
Richmond Hill, GA
www.bobrockefeller.com



More information about the textmate mailing list