Something like the following works:
syntax region ankiHighlight matchgroup=ankiConceal start='\V<span class="highlight">' end='\V<\/span>' oneline concealends
hi ankiHighlight cterm=underline gui=underline
setlocal conceallevel=2
This creates a syntax region matching the span tags as the start and end. It sets a separate matchgroup
to highlight the tags themselves, which is required if you'd like to conceal only the tags. Then it uses the concealends
attribute to indicate that they should be concealed.
The matches for the start and end tag are quite literal (using \V
for very literal non-magic regexp mode), you can adapt the regular expressions to matches that make sense for you. I also added the oneline
attribute, which requires the whole match on a single line, and help prevent a start hit without a matching end from running through the end of the file.
See :help :syn-region
, :help :syn-concealends
, :help :syn-oneline
, :help /\V
, etc.
I highlighted the ankiHighlight
region with an underline. You can adapt that setting to use colors or whatever you like. You can also set a highlight for ankiConceal
if you want to set colors or attributes when the span tags are displayed.
I set 'conceallevel'
to 2, which is typically what you'd want to have them effectively concealed. (See :help 'conceallevel'
for options 1 and 3, also :help 'concealcursor'
for behavior when the cursor is on that line.)
Note that "conceal" might look particularly odd when you have long blocks of text concealed, as is the case here. For instance, when :set wrap
is in effect, the lines will be wrapped before the tags are concealed, so it might look that lines are wrapping much earlier than the right margin, so you might want to keep that in mind.