2

I use pygments to highlight code.

And I want to add some specify style to a part of code in highlight block.

For example, I want to change "private String" color to red.

{% highlight java %}
public class A {
    <span color="red">private String</span> xx;
}
{% endhighlight %}

How can I do this?

1 Answer 1

1

A Name token is transformed by Pygments to :

<span class="n">Private</span>
<span class="n">String</span>
<span class="n">name</span>

or 

<span class="o">(</span>
<span class="n">String</span>
<span class="n">name</span>
<span class="o">){</span>

Styling .n class can be done in your highlight.css (or maybe .scss) with :

.highlight .n{ color: red; }

But you will not target the Private String specific token. If you want to do so, you will have to write you own Pygments lexer

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.