Skip to content

syntax: add Jinja2 template syntax highlighting - #5171

Open
KuzinAndrey wants to merge 1 commit into
MidnightCommander:masterfrom
KuzinAndrey:add-syntax-jinja2
Open

KuzinAndrey wants to merge 1 commit into
MidnightCommander:masterfrom
KuzinAndrey:add-syntax-jinja2

Conversation

@KuzinAndrey

Copy link
Copy Markdown
Contributor

Proposed changes

Add jinja2.syntax for Jinja2 templates (*.j2, *.jinja, *.jinja2)

1 2 3

Checklist

  • I have referenced the issue(s) resolved by this PR (if any)
  • I have signed-off my contribution with git commit --amend -s
  • Lint and unit tests pass locally with my changes (make indent && make check)
  • I have added tests that prove my fix is effective or that my feature works
  • I have added the necessary documentation (if appropriate)

@github-actions github-actions Bot added needs triage Needs triage by maintainers prio: medium Has the potential to affect progress labels Sep 29, 2026
@github-actions github-actions Bot added this to the Future Releases milestone Sep 29, 2026
@zyv zyv added area: mcedit mcedit, the built-in text editor and removed needs triage Needs triage by maintainers labels Sep 29, 2026
@zyv zyv modified the milestones: Future Releases, 4.9.0 Sep 29, 2026

@zyv zyv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that, but I'm wondering if everybody will like that. It is often the case that the .j2 extension is used on top of YAML, HTML, Python, etc. Because our CoolEdit highlighter doesn't support composed syntaxes, these files will not be highlighted as these languages before.

On the other hand, I think right now they are simply not highlighted at all, and so this is an improvement. If the user wants to force a different highlighting, mcedit allows you to change the syntax on the fly.

Add jinja2.syntax for Jinja2 templates (*.j2, *.jinja, *.jinja2):
{% %} statement and {{ }} expression tag contexts, {# #} and #
comments, strings, numbers, operators and literals, with every builtin
filter, test and global function colored as a builtin name per
https://jinja.palletsprojects.com/en/stable/templates/.

Signed-off-by: Kuzin Andrey <kuzinandrey@yandex.ru>
@KuzinAndrey

Copy link
Copy Markdown
Contributor Author

Yes, currently there is no syntax highlighting at all for such files. However, embedded highlighting needs to be supported within other syntax files for Yaml, Html, Python.

Also improved the syntax highlighting of floating-point numbers written in exponential notation.

@zyv

zyv commented Sep 29, 2026

Copy link
Copy Markdown
Member

Yes, currently there is no syntax highlighting at all for such files. However, embedded highlighting needs to be supported within other syntax files for Yaml, Html, Python.

If by that you mean that you intend to add J2 inside other highlighters, then I don't think it's a good idea. I would rather leave it to one day in the future when we have an alternative engine.

@KuzinAndrey

KuzinAndrey commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor Author

If by that you mean that you intend to add J2 inside other highlighters, then I don't think it's a good idea. I would rather leave it to one day in the future when we have an alternative engine.

No, only what has already been done for support .j2/.jinja in that PR.

I meant that partial syntax highlighting is already supported in some files for Jinja templates (yaml for example)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: mcedit mcedit, the built-in text editor prio: medium Has the potential to affect progress

Development

Successfully merging this pull request may close these issues.

2 participants