admin管理员组文章数量:1327665
I use redcarpet2 markdown in my site hosted by Github pages. I switch the syntax highlighter from pygments to highlight.js.
I specified the language for each code block by
```r
(some r code)
```
So I don't need the auto language detection by highlight.js, actually if I don't specify the language it will always mis-recognize my R code to php or perl code.
The problem is: the HTML tag for <code>
is somehow mixed.
Without rendering, the markdown correctly translate the code block with <code class="r language-r" data-lang="r"></code>
which should be rendered as R code. But when I load highlight.js and run <script>hljs.initHighlightingOnLoad();</script>
, the auto detect also works and makes the code tags mixed like <code class="r language-r hljs php" data-lang="r"></code>
where php
should be eliminated.
How can I fix the problem?
I use redcarpet2 markdown in my site hosted by Github pages. I switch the syntax highlighter from pygments to highlight.js.
I specified the language for each code block by
```r
(some r code)
```
So I don't need the auto language detection by highlight.js, actually if I don't specify the language it will always mis-recognize my R code to php or perl code.
The problem is: the HTML tag for <code>
is somehow mixed.
Without rendering, the markdown correctly translate the code block with <code class="r language-r" data-lang="r"></code>
which should be rendered as R code. But when I load highlight.js and run <script>hljs.initHighlightingOnLoad();</script>
, the auto detect also works and makes the code tags mixed like <code class="r language-r hljs php" data-lang="r"></code>
where php
should be eliminated.
How can I fix the problem?
Share Improve this question asked Feb 16, 2014 at 7:02 Kun RenKun Ren 5,0334 gold badges39 silver badges50 bronze badges2 Answers
Reset to default 5Probably your highlight.pack.js
does not include R language, you can download it here just tick the appropriate checkboxes. When HighlightJS sees unknown class for code
tag it tries to guess automatically right language.
It's possible to disable highlight.js auto language detection with hljs.configure({languages:[]})
. It will still hightlight code blocks with a language explicitly specified.
<script>hljs.configure({languages:[]});hljs.initHighlightingOnLoad();</script>
版权声明:本文标题:javascript - How can I turn off auto language detection in highlight.js and render all blocks? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742226751a2436462.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论