Mako: add *.mako as a file extension by adarshsm · Pull Request #3400 · pygments/pygments · GitHub
Skip to content

Mako: add *.mako as a file extension - #3400

Draft
adarshsm wants to merge 1 commit into
pygments:masterfrom
adarshsm:fix/1047-mako-extension
Draft

adarshsm wants to merge 1 commit into
pygments:masterfrom
adarshsm:fix/1047-mako-extension

Conversation

@adarshsm

Copy link
Copy Markdown

Fixes #1047.

MakoLexer is only registered for *.mao. Most Mako templates in the wild use .mako: Pyramid's pyramid_mako templates, Alembic's script.py.mako, and GitHub Linguist lists both .mako and .mao for Mako. So filename-based lookup fails for them:

>>> from pygments.lexers import get_lexer_for_filename
>>> get_lexer_for_filename('index.mako')
pygments.util.ClassNotFound: no lexer for filename 'index.mako' found

Fix: I added *.mako to MakoLexer.filenames and kept *.mao, then regenerated _mapping.py with scripts/gen_mapfiles.py. Only the Mako line changed. No other lexer claims *.mako. This follows the other template families, where the base lexer owns the base extension (CheetahLexer has *.tmpl, MyghtyLexer has *.myt, VelocityLexer has *.vm).

Tests: I added test_mako_filenames to tests/test_templates.py for index.mako, script.py.mako and test.mao. The two .mako cases fail on master and pass with the fix. The full suite passes (pytest tests --ignore=tests/contrast: 5332 passed, 16 skipped). I skipped tests/contrast because wcag_contrast_ratio isn't installed in my environment.

🤖 Generated with Claude Code

MakoLexer was only registered for *.mao, so get_lexer_for_filename()
and pygmentize failed on the far more common .mako extension (Pyramid
templates, Alembic's script.py.mako). *.mao is kept.

Fixes pygments#1047.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mako lexer reported wrong extension

1 participant