Change color of tag attributes independent from tag text

21 views
Skip to first unread message

pilkjaer

unread,
Jul 3, 2017, 7:51:22 AM7/3/17
to highlight.js
Hi!
I'm trying to make my XML code readable and my goal is to have my XML colored the way Eclipse does it.
I have noticed that both XML tag text as well XML tag attributes are sharing same CSS-classes resulting in not being able to change them separately. Is this functionality lacking or it's just me who is doing changes in the wrong place?
I have updated following classes:
.hljs,
.hljs-subst {
  color: #444;
}

Original xml:
<tag attribue="value">
  some text
</tag>

If I change color #444 to red I get the following:
<tag attribue="value">
  some text
</tag>

I want to be able to change color "attribute" without affecting color of "some text" and "<>".
Version tested 9.12.0.

Ivan Sagalaev

unread,
Jul 3, 2017, 12:56:04 PM7/3/17
to highl...@googlegroups.com
> I'm trying to make my XML code readable and my goal is to have my XML
> colored the way Eclipse does it.

In general, highlight.js does not have a goal of being able to imitate
other highlighting engines.

Although in this particular case it's quite possible to do what you're
after.

> I have noticed that both XML tag text as well XML tag attributes are
> sharing same CSS-classes resulting in not being able to change them
> separately.

That's not correct. Text between tags does not have any special markup
applied to it, the `.hljs` class is the general foreground text color.
But attribute names do get marked up with `.hljs-attr`, it's just not
highlighted by default in many of the included styles. Use this one.

pilkjaer

unread,
Jul 4, 2017, 2:23:15 AM7/4/17
to highlight.js
Thank you for the fast reply!
You mentioned that "it's just not 
highlighted by default in many of the included styles". Is there a tag attribute or some other setting in order to activate it? Or some parameters to hljs.initHighlightingOnLoad(); ?

/Anthony

Ivan Sagalaev

unread,
Jul 4, 2017, 2:33:12 AM7/4/17
to highl...@googlegroups.com
On 07/03/2017 11:23 PM, pilkjaer wrote:
> Thank you for the fast reply!
> You mentioned that /"it's just not /
> /highlighted by default in many of the included styles"./ Is there a tag
> attribute or some other setting in order to activate it? Or some
> parameters to *hljs.initHighlightingOnLoad();* ?

It's not about any sort of activation. The attribute names always have
class "hljs-attr". You can either pick a style that assigns a separate
color for that (like Solarized) or add a rule for it to your own style
sheet.
Message has been deleted

Ivan Sagalaev

unread,
Jul 4, 2017, 2:50:55 AM7/4/17
to highl...@googlegroups.com
On 07/03/2017 11:47 PM, pilkjaer wrote:
> I have tried to have 2 different styles:
>
> /* normal text in black*/
> .hljs {
> color: #444;
> }
>
> /* attribute text in red*/
> .hljs-subst {
> color: #e80b0b;
> }
>
> but both attribute and plain text were the same black color.

I'm sorry, I can't make this any clearer: you need to style the class
".hljs-attr", not these two.
Reply all
Reply to author
Forward
0 new messages