highlight.js icon indicating copy to clipboard operation
highlight.js copied to clipboard

(Python) Template strings (t-strings, PEP 750) not properly highlighted

Open TethysPlex opened this issue 2 months ago • 0 comments

Describe the issue

Python 3.14 introduce template strings (t-strings) as defined in PEP 750. Template strings use the t prefix (similar to f-strings' f prefix) but are not currently recognized by Highlight.js. This results in incorrect syntax highlighting where the t prefix and the template string syntax are not properly distinguished from regular strings.

Which language seems to have the issue?

python

Are you using highlight or highlightAuto?

Both highlight and highlightAuto are affected.

Sample Code to Reproduce

from string.templatelib import Template, Interpolation

# Basic template string
name = "World"
template = t"Hello {name}"

# Template string with conversion
message = t"Hello {name!r}"

# Template string with format spec
value = 42
formatted = t"Value: {value:.2f}"

# Raw template string
trade = 'shrubberies'
raw_template = rt'Did you say "{trade}"?\n'

# Debug specifier
debug_template = t"Hello {name=}"

# Template concatenation
combined = t"Hello " + t"{name}"
implicit = t"Hello " t"{name}"

Expected behavior

The syntax highlighting should recognize:

  1. The t and T prefixes as valid string prefixes (similar to f, r, b)
  2. The combination rt and tr prefixes for raw template strings
  3. Template strings should be highlighted similarly to f-strings, with:
    • The string prefix (t, T, rt, tr) highlighted as a keyword
    • Interpolation expressions inside {...} properly highlighted
    • Support for conversion specifiers (!r, !s, !a)
    • Support for format specifiers (: followed by format spec)
    • Support for the debug specifier (=)

Additional context

  • PEP 750: https://peps.python.org/pep-0750/
  • Python version: 3.14
  • The syntax is nearly identical to f-strings

TethysPlex avatar Oct 09 '25 08:10 TethysPlex