I've written regexes for markdown for emphasis and bold as follows:
syntax match PandocEmphasisMarker "\v(^|\s+)\zs_[^\n\t_ ]+([^_\n]|(\S_\S)|(\s_\S)|(\s+_\s+))+[^\n\t_ ]+_\ze($|\s+)" contains=PandocEmphasis syntax match PandocEmphasis "\v\zs[^\n\t_ ]+([^_\n]|(\S_\S)|(\s_\S)|(\s+_\s+))+[^\n\t_ ]+\ze" contained syntax match PandocStrongMarker "\v\zs\*[^\n*]+\*\ze" contains=PandocStrong syntax match PandocStrong "\v\zs[^\n*]+\ze" contained
This yields the following (in my opinion correct) highlighting:
However, in Markdown there could be emphasis inside strong and strong inside emphasis as well. Since I already have the regexes so far, I'd like to allow them to mutually include each other.
I've tried with clusters as follows:
syntax cluster PandocEmphasisCluster contains=PandocEmphasis,PandocStrongMarker syntax cluster PandocStrongCluster contains=PandocStrong,PandocEmphasisMarker
And then referenced those clusters from the "Marker" expressions using
contains, but that did not work, it messed up the strong highlighting in my test file and the strong part inside an emphasized part was not made bold.
How can / should I make them contain each other?
This is also important for other things like
` inside emphasized or strong. Maybe I should use
- emphasis inside strong should still be strong, but also become emphasized.
- strong inside emphasis should still be emphasized, but also become strong
- effects should add up, that's what I want to achieve