-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Provide the ability to add additional-js
files above book.js
in index.html
(to support custom language highlights)
#1870
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
Comments
If you just want to support a different set of languages for
|
Ahhh, don't know how I missed that |
Following suggestions in this thread leads to highlight.js warning to the console that it cannot find the language, but highlighting works.
highlighting works, but because highlight.js runs before applying the dirty hack. How to solve this elegantly? |
I guess the difference between your and my situation is that you want to register a custom language while I only needed to enable one of the languages supported by upstream You could try to incorporate your code into your custom |
* New docs * fixes * New docs * Add custom.css * fix preview adjustment when layout is UD * Test load config * Only run on master push * fixes * docs * Merge vint jobs * Support vim syntax highlight ref rust-lang/mdBook#1870 (comment)
At the current moment, one can add additional js files to be added to the generated
index.html
using thebook.toml
configuration (issue that inspired this):The provided js files are placed at the bottom of the
index.html
:However, I am having an issue using
highlight.js
's ability to add custom languages due to the placement of these custom js scripts.hljs.registerLanguage
works too late by running afterbook.js
, because by that point (from what I can gather), it has already attempted to generate a code block using my language's id. This creates an error withhighlight.js
since the language has not been defined, so it defaults to plain text color. Simply placing thecustom.js
script above thebook.js
script makes everything work perfectly.This isn't that big of a deal, as I can simply modify the
index.html
post build, but it would be nice if I could see color while developing usingserve
. Especially since using mdBook to document new programming languages (I would imagine) could be a pretty big use-case due to how amazing it looks with Rust, I feel adding a solution to this problem would be nice.An alternative solution could be the ability to provide a custom version of
highlight.js
? Maybe this is already possible, but I haven't been able to find it. That would allow one to simply append the extra language registers to the bottom of the file and use it over the one mdBook provides.The text was updated successfully, but these errors were encountered: