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

Add additional-hljs-packages option #2156

Closed

Conversation

Evian-Zhang
Copy link
Contributor

As a syntax highlighting tool, highlight.js supports 3rd party languages (see instructions here) since they don't currently merge new grammars into core. This can be done by placing additional JavaScript files alongside hightlight.js's js file, and then call the syntax highlighting functions provided by hljs, such as hightlightBlock used in our book.js.

However, this can't be done currently in mdbook, since the additional-js field is designed for js files called after the main book.js, while placing the highlight.js 3rd packages there leads to highlightBlock called before those packages loaded. On the other hand, moving js files specified in additional-js field above the book.js may lead to unexpected behaviors, since it is supposed to be executed after the book.js is executed.

So adding another field, additional-hljs-packages, could solve this problem, which will place those js files between the highlight.js's js file and book.js.

@rustbot rustbot added the S-waiting-on-review Status: waiting on a review label Aug 5, 2023
Copy link
Contributor

@KFearsoff KFearsoff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution!

Your use case is definitely valid, but I feel like the approach is maybe a little too heavy-handed this time. It is not documented as well as it probably should be, but you can actually just edit the HTML template that the pages get rendered on!

First, you would init mdbook with --init flag, and then you would edit index.hbs - index.hbs is basically an HTML file with very little bits of Handlebars templating. So you would be able to just add all of the necessary JS script includes directly to your HTML!

@rustbot label +C-question +S-waiting-on-author

@rustbot rustbot added C-question Category: A question on how to do something S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author. labels Dec 3, 2023
@Evian-Zhang
Copy link
Contributor Author

Oh yes, I forgot this way. Thank you!

@Evian-Zhang Evian-Zhang closed this Dec 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-question Category: A question on how to do something S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author. S-waiting-on-review Status: waiting on a review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants