Skip to main content

How to find the Pygments token type for a short name

Look at the source code of pygments.token.

When I use Pygments or Rouge to apply syntax highlighting to some code, for example this Python snippet:

print("hello world")

they produce some HTML where each token type is identified by a short name, like nf or p or sh:

<span class="nf">print</span><span class="p">(</span><span class="sh">"</span><span class="s">hello world</span><span class="sh">"</span><span class="p">)</span>

If I find a short name I don’t recognise, I can look it up in the pygments.token source code, which includes the mapping from tokens to short names:

# Map standard token types to short names, used in CSS class naming.
# If you add a new item, please be sure to run this file to perform
# a consistency check for duplicate values.

STANDARD_TYPES = {
    Token:                         '',

    Text:                          '',
    Whitespace:                    'w',
    Error:                         'err',
    Other:                         'x',