I’m attempting to create a syntax highlighter for twig templates, based on the highlighter for django templates in kakoune-extra. The highlighter splits itself into three groups, code
, scope
and expansion
. The first calls out to the html highlighter. The other two handle the two types of tags that are available in twig – one for logic and one for output.
add-highlighter shared/twig/code default-region ref html
add-highlighter shared/twig/scope region '\{%' '%\}' group
add-highlighter shared/twig/expansion region '\{\{' '\}\}' group
add-highlighter shared/twig/comment region '\{#' '#\}' fill comment
I’ve copied the string regions from the php highlighter that comes with kak, and scoped it to the scope
and expansion
regions, but nothing is being matched. I can’t figure out why.
add-highlighter shared/twig/expansion/double_string region '"' (?<!\\)(\\\\)*" fill string
add-highlighter shared/twig/scope/single_string region "'" (?<!\\)(\\\\)*' fill string
add-highlighter shared/twig/expansion/single_string region "'" (?<!\\)(\\\\)*' fill string
I’ve tried wrapping the closing regex in the opposing quotation marks, as well as removing the backslash exceptions, but to no avail.
If I do not add the highlighters to subregions of the scope
and expansion
it conflicts with the highlighting of html and results in pathological highlights, and vice versa.