Sublime Forum

XML + Markdown syntax highlighting

#1

Hi all,

I have an XML file that contains some markdown in CDATA sections - I’d quite like to be able to syntax highlight the markdown, so I’ve been looking at creating a little syntax highlighting definition for this:

[code]# [PackageDev] target_format: plist, ext: tmLanguage

name: XML Markdown
scopeName: text.xmlmd
fileTypes: [xml]
uuid: 997f9221-cd9f-4544-9058-edc6952bb3d0

patterns:

  • name: markdown.raw.block.xmlmd
    begin: <(content|summary|description)>
    captures:
    ‘1’: {name: variable.language}
    end: </(\1)>
    patterns:

    • include: text.html.markdown
  • include: text.xml
    …[/code]

The problem I am having is with the end block. It is picked up correctly if there are 0-3 spaces before the end tag (</summary> for example), but not if there are more or a tab. I’ve tried using \s* in the end pattern as well, but that doesn’t help.

Any idea why the end pattern wouldn’t be matched based on the whitespace before it?

Thanks,
Allan

0 Likes

#2

I could be wrong, but shouldn’t that be beginCaptures? captures isn’t listed as part of a begin…end rule on this site:
http://docs.sublimetext.info/en/latest/reference/syntaxdefs.html#the-patterns-array.

Also, can you reference a capture group from the begin regex in the end regex? That’s awesome if you can, but I tried it and it didn’t work for me.

Finally, if you’re writing a new syntax highlighter, I strongly recommend checking out the new syntax highlighting system that’s coming to Sublime Text 3 (http://www.sublimetext.com/docs/3/syntax.html). The new system is currently only available in the dev builds. I have no idea when it will land in the beta channel. Writing a syntax definition is a big undertaking. I would think twice about writing a new one in the soon-to-be-obsolete TextMate (.tmLanguage) format.

0 Likes