Install & Compatibility
Where this runs
tested against v1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 26.9MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 2.3s · import 0.000s · 27MB
25MB installed
● package 25MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
FluentLexer
✓ from fluent_pygments import FluentLexer
✗ from fluent.lexer import FluentLexer
This example demonstrates how to use the `FluentLexer` with Pygments to highlight Fluent (FTL) code. It shows how to output the highlighted code both as a complete HTML document and as colored text for a 256-color terminal. The HTML output typically requires a separate CSS stylesheet for proper rendering, which can be generated using `pygmentize -S <style_name> -f html > style.css`.
from pygments import highlight
from pygments.formatters import HtmlFormatter, Terminal256Formatter
from fluent_pygments.lexer import FluentLexer
ftl_code = """
### A resource comment for the whole file
my-key = Localize { -brand-name }
-brand-name = Fluent
# $num is the number of strings to localize
plurals = { $num ->
[one] One string
*[other] {$num} strings
}
"""
# Highlight to HTML
html_formatter = HtmlFormatter(full=True, style='default')
highlighted_html = highlight(ftl_code, FluentLexer(), html_formatter)
# To see output, you might write to a file or print the raw HTML
# print(highlighted_html)
# Highlight to terminal with 256 colors
terminal_formatter = Terminal256Formatter(style='monokai')
highlighted_terminal = highlight(ftl_code, FluentLexer(), terminal_formatter)
print("\n--- HTML Output Snippet (not runnable directly) ---\n")
print(highlighted_html[:500] + "...") # Print a snippet for brevity
print("\n--- Terminal Output ---\n")
print(highlighted_terminal)
Debug
Known issues
gotchaPygments' `HtmlFormatter` (by default) generates HTML with CSS classes, but does not embed the actual CSS styles. For fully styled output, a separate CSS file must be generated and linked, or inline styles must be explicitly enabled (though not recommended for larger outputs).fixGenerate a stylesheet using `pygmentize -S <style_name> -f html > style.css` and include it in your HTML, or initialize `HtmlFormatter(noclasses=True)` for inline styles.
affects: All Pygments versions
gotchaProcessing untrusted or very large Fluent (FTL) input with Pygments can lead to performance issues or potential Denial-of-Service (DoS) attacks if not properly constrained, due to the complexity of regular expression matching in lexers.fixImplement strict input size limits and/or apply timeouts to the Pygments highlighting process when handling user-provided content. Limit the number of concurrent highlighting processes.
affects: All Pygments versions, including fluent-pygments 1.0
deprecatedThe broader `python-fluent` ecosystem, of which `fluent-pygments` is a part, has dropped support for older Python versions (e.g., Python 2.7 and 3.5 in `fluent.runtime` and `fluent.syntax` releases after `fluent-pygments` 1.0). While `fluent-pygments` 1.0 itself requires Python >=3.6, ensure your environment aligns with the latest `fluent.*` components if using them together.fixUpgrade to Python 3.6 or newer. For best compatibility with the `python-fluent` ecosystem, use Python 3.8+.
affects: fluent-pygments 1.0 used with older Python versions, especially <3.6
Upgrade
Version history
1.0latest on PyPI · released May 20, 2020
Audit
Dependencies
PygmentsrequiredProvides the core syntax highlighting framework that fluent-pygments extends.