Node: doc: all <pre> tags are highlighted as JavaScript

Created on 12 May 2020  ·  3Comments  ·  Source: nodejs/node

📗 API Reference Docs Problem

  • Version: n/a
  • Platform: n/a
  • Subsystem: n/a

Location

_Section of the site where the content exists_

Affected URL(s):

Problem description

_Concise explanation of what you found to be problematic_

While looking into #32938, I discovered that currently, every single <pre> tag gets highlighted as JavaScript regardless of the info string specified (and even if left unspecified). The following line executes the code that does this.

https://github.com/nodejs/node/blob/94e5b5c77dade0d8f7358c66144b75c369679cab/doc/template.html#L56

This behavior can be observed in the C++ code blocks in the published API reference documents. The following line is the reason for this — the language has been hard-coded.

https://github.com/nodejs/node/blob/94e5b5c77dade0d8f7358c66144b75c369679cab/doc/api_assets/sh_main.js#L542


  • [x] I would like to work on this issue and submit a pull request.

^ I'm currently on summer vacation, so I would have the time to work on this.

/cc @Trott

doc

Most helpful comment

@Trott, it is my impression that this would be an excellent opportunity to switch to highlight.js for a few reasons:

  1. SHJS hasn't been updated in 6 years
  2. SHJS is GPL v3 licensed
  3. SHJS doesn't understand modern language syntax
  4. highlight.js is currently well-maintained (and popular)
  5. highlight.js is BSD licensed
  6. highlight.js is able to highlight the modern syntax of several languages
  7. we'd have syntax highlighting on par w/ the Markdown docs rendered on GitHub.com

I think there was a reason why @zeke mentioned it in passing — it's the route to go nowadays. If GitHub's syntax highlighting library (Prettylights) were OSS, we'd ideally use that, but that doesn't seem to be one of our options. I can give it a day or two before proceeding in case others want to shop around and propose a superior frontend syntax highlighting library, but this seems like the best bet as far as I can tell.

/cc @nodejs/documentation

All 3 comments

Yes, please fix this! 😀

@Trott, it is my impression that this would be an excellent opportunity to switch to highlight.js for a few reasons:

  1. SHJS hasn't been updated in 6 years
  2. SHJS is GPL v3 licensed
  3. SHJS doesn't understand modern language syntax
  4. highlight.js is currently well-maintained (and popular)
  5. highlight.js is BSD licensed
  6. highlight.js is able to highlight the modern syntax of several languages
  7. we'd have syntax highlighting on par w/ the Markdown docs rendered on GitHub.com

I think there was a reason why @zeke mentioned it in passing — it's the route to go nowadays. If GitHub's syntax highlighting library (Prettylights) were OSS, we'd ideally use that, but that doesn't seem to be one of our options. I can give it a day or two before proceeding in case others want to shop around and propose a superior frontend syntax highlighting library, but this seems like the best bet as far as I can tell.

/cc @nodejs/documentation

I think there was a reason why @zeke mentioned it in passing — it's the route to go nowadays

☝️ Yep that is why I mentioned it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

TazmanianDI picture TazmanianDI  ·  127Comments

feross picture feross  ·  208Comments

Trott picture Trott  ·  87Comments

speakeasypuncture picture speakeasypuncture  ·  152Comments

aduh95 picture aduh95  ·  104Comments