rouge-ruby / rouge

A pure Ruby code highlighter that is compatible with Pygments
https://rouge.jneen.net/
Other
3.33k stars 735 forks source link

Python: Support conversion specifiers in format strings #1801

Closed chvp closed 2 years ago

chvp commented 2 years ago

Fixes #1800. Format string syntax can be found here: https://docs.python.org/3/library/string.html#format-string-syntax

Technically only [asr] is allowed after !. If wanted, I could make the entire ![asr] punctuation (or something else entirely), but parsing the specifier as a generic Python expression (so in practice, an identifier) seems fine to me.

tancnle commented 2 years ago

@chvp Thank you for your contribution ❤️ TIL about conversion in format string syntax.

Technically only [asr] is allowed after !

It will be great to constrain the rule as you said. Would it be possible to do that in this PR? FYI, Pygments has support for conversion specifiers that we could port over to Rouge. WDYT?

chvp commented 2 years ago

I updated it so it is constrained to [asr]. I also carried over the same categories as in pygments.

chvp commented 2 years ago

@tancnle Is anything blocking this from being merged?

tancnle commented 2 years ago

@chvp Sorry for the delay. I think this is a good change.

We would have to look into extending this support for the standard string in the future.

Screen Shot 2022-05-01 at 8 31 46 pm