chroma icon indicating copy to clipboard operation
chroma copied to clipboard

Multi-Language highlighting based on filename

Open silverwind opened this issue 2 years ago • 2 comments

What problem does this feature solve?

Template languages like Jinja are languages in languages and they would benefit from highlighting twice: Once for the templated syntax, and once for the template language itself. Requirement for this to work would be the presence of multiple file extensions like nginx.conf.j2.

What feature do you propose?

  • nginx.conf - First pass, strip the .j2 suffix, highlight as nginx
  • nginx.conf.j2 - Second pass, highlight as Jinja, retain nginx highlighting

silverwind avatar Apr 07 '23 09:04 silverwind

Chroma already supports this in the same way as Pygments does, via a delegating lexer. But I assume what you're proposing is some mechanism by which nested file extensions could be used to do this automatically?

alecthomas avatar Apr 07 '23 13:04 alecthomas

Yes, automatic detection based on filename would be my request in this case.

I suppose not all languages mix well together, so it should only be enabled for known template languages like jinja, handlebars, go template etc.

silverwind avatar Apr 07 '23 14:04 silverwind