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

Lazy loading in highlight.js may break some languages highlighting #25

Closed
microdog opened this issue May 9, 2017 · 3 comments · Fixed by #192
Closed

Lazy loading in highlight.js may break some languages highlighting #25

microdog opened this issue May 9, 2017 · 3 comments · Fixed by #192

Comments

@microdog
Copy link

microdog commented May 9, 2017

Hello,
The lazy loading behavior in lib/highlight.js introduced in 7f6469e may break some languages highlighting such as shell.

The shell language highlighting relies on the bash language, if bash language is not registered yet, you will get an unexpected highlighting result.

Input:

var str = '$ echo "Hello World"';

Expected result:

'<span class="meta">$</span><span class="bash"> <span class="built_in">echo</span> <span class="string">"Hello World"</span></span>'

Only shell is registered:

'<span class="meta">$</span> echo "Hello World"'
@alxbl
Copy link
Contributor

alxbl commented Dec 11, 2017

I'm able to reproduce this behavior as well.

When testing, make sure to use hexo server -s combined with hexo generate to serve the static content, otherwise it looks like loadAllLanguages is called and the issue does not happen.

That being said, I doubt that there's much that hexo can do besides systematically load all languages.

The workaround right now would be to leave out the language from the code block and set highlight.autoDetect: true in your config file.

Another possible workaround could be to have a hidden/draft post that has an empty code block for each language that you will use. This should force the generator to require those languages, and then you shouldn't have any problems in the actual post.

Cheers,

@curbengh
Copy link
Contributor

Is this a sublanguage highlight issue? Is it fixed by #37?

@stevenjoezhang
Copy link
Member

Fixed by #192
Please enable highlight.auto_detect in Hexo _config.yml

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

Successfully merging a pull request may close this issue.

6 participants