highlightjs / highlight.js

JavaScript syntax highlighter with language auto-detection and zero dependencies.
https://highlightjs.org/
BSD 3-Clause "New" or "Revised" License
23.3k stars 3.52k forks source link

[Request] Conversion/usage of Pygments theme to `higlightjs` #4041

Closed vadimkantorov closed 2 months ago

vadimkantorov commented 2 months ago

Jekyll used to use pygments and later on rouge (can consume pygments themes) for code highlighting.

E.g. https://github.com/jekyll/minima theme produces the following code highlighting CSS for the light theme.

Is there a way to reuse these themes or these CSS classes for highlightjs browser-side code highlighting?

The usecase would be to continue using minima highlighting pygments themes / CSS, but without jekyll SSG preprocessing (e.g. I'm using minima css in my own handrolled client-side Markdown renderer, so I'd like to use highlightjs)

.highlight .c {
  color: #998;
  font-style: italic;
}
.highlight .err {
  color: #a61717;
  background-color: #e3d2d2;
}
.highlight .k {
  font-weight: bold;
}
.highlight .o {
  font-weight: bold;
}
.highlight .cm {
  color: #998;
  font-style: italic;
}
.highlight .cp {
  color: #999;
  font-weight: bold;
}
.highlight .c1 {
  color: #998;
  font-style: italic;
}
.highlight .cs {
  color: #999;
  font-weight: bold;
  font-style: italic;
}
.highlight .gd {
  color: #000;
  background-color: #fdd;
}
.highlight .gd .x {
  color: #000;
  background-color: #faa;
}
.highlight .ge {
  font-style: italic;
}
.highlight .gr {
  color: #a00;
}
.highlight .gh {
  color: #999;
}
.highlight .gi {
  color: #000;
  background-color: #dfd;
}
.highlight .gi .x {
  color: #000;
  background-color: #afa;
}
.highlight .go {
  color: #888;
}
.highlight .gp {
  color: #555;
}
.highlight .gs {
  font-weight: bold;
}
.highlight .gu {
  color: #aaa;
}
.highlight .gt {
  color: #a00;
}
.highlight .kc {
  font-weight: bold;
}
.highlight .kd {
  font-weight: bold;
}
.highlight .kp {
  font-weight: bold;
}
.highlight .kr {
  font-weight: bold;
}
.highlight .kt {
  color: #458;
  font-weight: bold;
}
.highlight .m {
  color: #099;
}
.highlight .s {
  color: #d14;
}
.highlight .na {
  color: #008080;
}
.highlight .nb {
  color: #0086B3;
}
.highlight .nc {
  color: #458;
  font-weight: bold;
}
.highlight .no {
  color: #008080;
}
.highlight .ni {
  color: #800080;
}
.highlight .ne {
  color: #900;
  font-weight: bold;
}
.highlight .nf {
  color: #900;
  font-weight: bold;
}
.highlight .nn {
  color: #555;
}
.highlight .nt {
  color: #000080;
}
.highlight .nv {
  color: #008080;
}
.highlight .ow {
  font-weight: bold;
}
.highlight .w {
  color: #bbb;
}
.highlight .mf {
  color: #099;
}
.highlight .mh {
  color: #099;
}
.highlight .mi {
  color: #099;
}
.highlight .mo {
  color: #099;
}
.highlight .sb {
  color: #d14;
}
.highlight .sc {
  color: #d14;
}
.highlight .sd {
  color: #d14;
}
.highlight .s2 {
  color: #d14;
}
.highlight .se {
  color: #d14;
}
.highlight .sh {
  color: #d14;
}
.highlight .si {
  color: #d14;
}
.highlight .sx {
  color: #d14;
}
.highlight .sr {
  color: #009926;
}
.highlight .s1 {
  color: #d14;
}
.highlight .ss {
  color: #990073;
}
.highlight .bp {
  color: #999;
}
.highlight .vc {
  color: #008080;
}
.highlight .vg {
  color: #008080;
}
.highlight .vi {
  color: #008080;
}
.highlight .il {
  color: #099;
}
joshgoebel commented 2 months ago

Our scopes are documented if you wanted to do a conversion - or write a tool to do so. (port your CSS scopes to our CSS scopes)

https://highlightjs.readthedocs.io/en/latest/css-classes-reference.html

Or if you just want to try and convert the generated HTML to use your own class names, that's just string manipulation - something that could also be automated.

I'm not aware of anyone already doing this work.

vadimkantorov commented 2 months ago

Thank you for your response!

Yeah, I wonder if it's possible to pass directly to highlighjs the CSS classes to use in place of its standard class names? As a workaround, as you say, I can post-process the Pygments CSS and rename its class names to match hljs class names, but if it's possible to simply configure hljs to use custom class names, it would be cleaner

joshgoebel commented 2 months ago

Yeah, I wonder if it's possible to pass directly to highlighjs the CSS classes to use in place of its standard class names?

No. But as I said string substitution in JS is pretty simple to do...