-
-
Notifications
You must be signed in to change notification settings - Fork 61
Description
Generally the result of highlight() contains lauguage name as HTML class name.
If code is illegal syntax for the specified language,
the HTML class name is added or not (inconsistent).
option lang |
illegal syntax? | option hljs |
class name of outer <figure> |
class name of inner <code> |
|---|---|---|---|---|
java |
no | false |
highlight java |
N/A (none) |
java |
no | true |
highlight java |
hljs java |
java |
yes | false |
highlight |
N/A (none) |
java |
yes | true |
highlight |
hljs java |
| none | - | false |
highlight plain |
N/A (none) |
| none | - | true |
highlight plain |
hljs plain |
I think we have three options:
- always add laugage name even if illegal syntax.
- never add language name if illegal syntax.
- add the language name
plainif illegal syntax.
I think Option 1 might be best because users will intend to be.
Please advice!
I think this inconsistency is caused by undocumented behavior of highlight() of highlightjs package.
The API document of highlightjs package is:
https://highlightjs.readthedocs.io/en/latest/api.html#highlight-languagename-code-ignore-illegals-continuation
According to above API document, highlight() throws an exception in case of detecting illegal syntax for the language.
But actually not throw any exception (regardless ignore_illegals parameter).
Instead, illegal property of the return value is set to true and
language property of the return value does not exist.
Current code of lib/highlight.js considers the exception halfway.
And the lack of lanaguage property is not expected.
Anyway the code should be modified to keep consistency.
p.s. This issue is derived from hexojs/hexo#3984