ShuLiZheng
ShuLiZheng

Reputation: 21

Jekyll - Style a part of code in highlight code block

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?

Upvotes: 2

Views: 327

Answers (1)

David Jacquel
David Jacquel

Reputation: 52809

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

Upvotes: 1

Related Questions