Skip to Content
  • Website
Codsen
  • Home
  • Open Source
  • Articles
  • About

prevOpen Source→regex-jinja-specificnext

regex-jinja-specific4.2.0

Regular expression for detecting Python-specific Jinja code

Downloads per monthChangelogMIT Licenselibera manifesto
  • the top
  • Installation
  • Quick Take
  • Examples
  • PURPOSE
  • API — ISJINJASPECIFI…
  • API — VERSION
  • Changelog

Installation

Quick Take

Examples

  • Detect Jinja's inline conditional ordering
  • Detect Jinja namespace assignment syntax
  • Detect Jinja's Python-style number formatting filter

Purpose

Nunjucks and Jinja templating languages’ syntax is mostly the same. There are certain code patterns which are Jinja-specific, mostly coming from Python functionality. This program, a regex, matches those patterns.

  • Namespaces

    {% set x = namespace(blablabla) %}

  • Backwards pattern

    {{'oodles' if crambles else 'brambles'}}

  • Python digit formatting

    '%.2f'|format(...

Often Python-specific features can be patched to make code render in Nunjucks.

This is not a definite detection tool but rather a minimal, anecdotal attempt to programmatically distinguish between the two languages.

API — isJinjaSpecific()

The main function isJinjaSpecific() is imported like this:

It’s a function which returns a RegExp object, /.../g, which you can use everywhere, for example, in RegExp.prototype.exec() or String.prototype.match().

API — version

You can import version:

Changelog

Open Changelog
↑ back to top
prev next

Copyright

All rights reserved © Roy Revelt 2026
All our open source packages are under MIT licenceopens in a new tab

Activities

🐛 See a bug? Raise an issueopens in a new tab
💘 Check out the Indiewebopens in a new tab and Libera manifestoopens in a new tab