No description
Find a file
Eric Huss 2b242494b0 Add a new HTML rendering pipeline
This rewrites the HTML rendering pipeline to use a tree data structure,
and implements a custom HTML serializer. The intent is to make it easier
to make changes and to manipulate the output. This should make some
future changes much easier.

This is a large change, but I'll try to briefly summarize what's
changing:

- All of the HTML rendering support has been moved out of
  mdbook-markdown into mdbook-html. For now, all of the API surface is
  private, though we may consider ways to safely expose it in the
  future.
- Instead of using pulldown-cmark's html serializer, this takes the
  pulldown-cmark events and translates them into a tree data structure
  (using the ego-tree crate to define the tree). See `tree.rs`.
- HTML in the markdown document is parsed using html5ever, and then
  lives inside the same tree data structure. See `tokenizer.rs`.
- Transformations are then applied to the tree data structure. For
  example, adding header links or hiding code lines.
- Serialization is a simple process of writing out the nodes to a
  string. See `serialize.rs`.
- The search indexer works on the tree structure instead of re-rendering
  every chapter twice. See `html_handlebars/search.rs`.
- The print page now takes a very different approach of taking the
  same tree structure built for rendering the chapters, and applies
  transformations to it. This avoid re-parsing everything again. See
  `print.rs`.
    - I changed the linking behavior so that links on the print page
      link to items on the print page instead of outside the print page.
- There are a variety of small changes to how it serializes as can be
  seen in the changes to the tests. Some highlights:
	- Code blocks no longer have a second layer of `<pre>` tags wrapping
      it.
    - Fixed a minor issue where a rust code block with a specific
      edition was having the wrong classes when there was a default
      edition.
- Drops the ammonia dependency, which significantly reduces the number
  of dependencies. It was only being used for a very minor task, and
  we can handle it much more easily now.
- Drops `pretty_assertions`, they are no longer used (mostly being
  migrated to the testsuite).

There's obviously a lot of risk trying to parse everything to such a low
level, but I think the benefits are worth it. Also, the API isn't super
ergonomic compared to say javascript (there are no selectors), but it
works well enough so far.

I have not run this through rigorous benchmarking, but it does have a
very noticeable performance improvement, especially in a debug build.

I expect in the future that we'll want to expose some kind of
integration with extensions so they have access to this tree structure
(or some kind of tree structure).

Closes https://github.com/rust-lang/mdBook/issues/1736
2025-09-16 20:26:35 -07:00
.github Add a new HTML rendering pipeline 2025-09-16 20:26:35 -07:00
ci Support publishing a pre-release version of the guide 2025-09-04 17:08:49 -07:00
crates Add a new HTML rendering pipeline 2025-09-16 20:26:35 -07:00
examples Add an iterator over chapters 2025-09-15 07:11:19 -07:00
guide Add a new HTML rendering pipeline 2025-09-16 20:26:35 -07:00
src Remove clap macro_use 2025-09-12 06:49:54 -07:00
test_book Add sidebar heading navigation 2025-08-27 14:44:12 -07:00
tests Add a new HTML rendering pipeline 2025-09-16 20:26:35 -07:00
.git-blame-ignore-revs Add .git-blame-ignore-revs 2025-07-23 17:29:53 -07:00
.gitattributes Mark more font files as binary 2025-04-05 20:41:36 -04:00
.gitignore Add testsuite book directories to ignore list 2025-04-22 21:11:54 -07:00
Cargo.lock Add a new HTML rendering pipeline 2025-09-16 20:26:35 -07:00
Cargo.toml Add a new HTML rendering pipeline 2025-09-16 20:26:35 -07:00
CHANGELOG.md Update to 0.4.52 2025-07-14 15:45:55 -07:00
CODE_OF_CONDUCT.md add explicit code of conduct, copying other rust-lang repos 2021-07-26 11:52:24 -07:00
CONTRIBUTING.md Use consistent sentence case for section headers 2025-08-16 14:59:05 -07:00
eslint.config.mjs Lint HBS JS templates 2025-08-25 15:15:47 -07:00
LICENSE Create LICENSE 2015-07-29 01:11:30 +02:00
package.json Update browser-ui-test version to 0.22.1 2025-09-08 17:25:08 +02:00
README.md README.md: update workflow status badge 2025-02-13 11:01:08 -05:00
rustfmt.toml Add rustfmt.toml 2025-07-23 17:29:55 -07:00
triagebot.toml Add more triagebot features 2025-03-23 13:04:10 -07:00

mdBook

CI Status crates.io LICENSE

mdBook is a utility to create modern online books from Markdown files.

Check out the User Guide for a list of features and installation and usage information. The User Guide also serves as a demonstration to showcase what a book looks like.

If you are interested in contributing to the development of mdBook, check out the Contribution Guide.

License

All the code in this repository is released under the Mozilla Public License v2.0, for more information take a look at the LICENSE file.