rust-lang / mdBook

Create book from markdown files. Like Gitbook but implemented in Rust
https://rust-lang.github.io/mdBook/
Mozilla Public License 2.0
18.37k stars 1.65k forks source link

Allow additional javascript attributes in the configuration #2444

Open h7kanna opened 1 month ago

h7kanna commented 1 month ago

Problem

I am not able to include a JavaScript module in the additional_js option.

Example:

<!-- Custom JS scripts -->
<script src="custom-js/index.js" type="module" async></script>

Currently, the configuration is only a list of file name strings. Also the custom head.hbs cannot be used as additional_js is only for local files.

Proposed Solution

Provide new additional-js-attributes option augmenting the existing additional-js option.

Example:

[output.html]
additional-js = ["custom-js/index.js", "custom-js/xtermjs"]
additional-js-attributes = [
  [
    { type = "module" },
    { async = true },
  ],
  [
    { type = "module" },
    { async = true },
  ],
]

Notes

Demo implementation is here https://github.com/rust-lang/mdBook/compare/master...h7kanna:mdBook:additional-js-attributes

h7kanna commented 1 month ago

@rustbot claim