Highlight.js: Different styles on the same page

Created on 2 Jun 2015  路  5Comments  路  Source: highlightjs/highlight.js

Hello,

Is it possible to use different styles on the same page? I want to specify style the same way that the language is specified:

<pre><code class="html solarized_dark">...</code></pre>

Thanks!

Most helpful comment

BTW, there's a way to prefix styles if you with help of LESS:

.atelier-seaside-light {
  @import (less) 'https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.6/styles/atelier-seaside.light.min.css';
}

As a result you'll get:

.atelier-seaside-light .hljs-comment {
  color: #687d68;
}
.atelier-seaside-light .hljs-variable,
...
.atelier-seaside-light .css .hljs-pseudo {
  color: #e6193c;
}
...

That works perfectly! :)

All 5 comments

Hi!

No, it won't work like that. We don't generate inline styling in the code blocks, instead we generate markup with pre-defined class names, like <span class="hljs-keyword">, and then rely on CSS to provide actual colors and styles for those.

It may be possible though to create a Web component for highlight.js that would use a scoped stylesheets for individual code blocks.

Ok, thanks for the explanation.

BTW, it could be done like this, for example in highlight.js/src/styles/solarized_dark.css:

.hljs-comment,
.solarized-dark .hljs-comment /* to override default */ {
  color: #586e75;
}

We have some plans to generate stylesheets in uniform way, but only after #348.

Ok, that's cool :-)

BTW, there's a way to prefix styles if you with help of LESS:

.atelier-seaside-light {
  @import (less) 'https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.6/styles/atelier-seaside.light.min.css';
}

As a result you'll get:

.atelier-seaside-light .hljs-comment {
  color: #687d68;
}
.atelier-seaside-light .hljs-variable,
...
.atelier-seaside-light .css .hljs-pseudo {
  color: #e6193c;
}
...

That works perfectly! :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gskinner picture gskinner  路  4Comments

Martii picture Martii  路  7Comments

OrbintSoft picture OrbintSoft  路  8Comments

Lestoroer picture Lestoroer  路  7Comments

gka picture gka  路  7Comments