Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

highlight() is inconsistent when code is illegal syntax #164

Closed
seaoak opened this issue Dec 21, 2019 · 1 comment · Fixed by #246
Closed

highlight() is inconsistent when code is illegal syntax #164

seaoak opened this issue Dec 21, 2019 · 1 comment · Fixed by #246

Comments

@seaoak
Copy link
Member

seaoak commented Dec 21, 2019

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:

  1. always add laugage name even if illegal syntax.
  2. never add language name if illegal syntax.
  3. add the language name plain if 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

@stevenjoezhang stevenjoezhang linked a pull request Mar 25, 2021 that will close this issue
@stevenjoezhang
Copy link
Member

@seaoak I agree that option 1 might be the best choice. Can you help test whether this pull request meets your expectations? #246

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants