Commit Graph

2934 Commits

Author SHA1 Message Date
Eric Huss
83c307be3c Add job to automatically update dependencies
This adds a job to automatically update cargo dependencies once a month.
I've added this script instead of using Renovate because I couldn't get
Renovate to update versions in `Cargo.toml`. I also wanted to batch
transitive dependency updates all in one PR.
2025-09-24 16:05:14 -07:00
Eric Huss
aa96e1174e Merge pull request #2857 from ehuss/move-copy-theme
Move theme copy to the Theme type and reduce visibility
2025-09-21 01:02:42 +00:00
Eric Huss
7fcacf3386 Move theme copy to the Theme type and reduce visibility
This moves the code for copying the theme to the theme directory to the
Theme type so that the code lives closer to the data definition. This
also then reduces the public API surface of the Theme to give a little
more flexibility for updating it in the future.
2025-09-20 17:55:12 -07:00
Eric Huss
2aa2b95f0f Merge pull request #2856 from ehuss/fs-update
Clean up some fs-related utilities
2025-09-21 00:18:51 +00:00
Eric Huss
797112ef36 Clean up some fs-related utilities
This does a little cleanup around the usage of filesystem functions:

- Add `mdbook_core::utils::fs::read_to_string` as a wrapper around
  `std::fs::read_to_string` to provide better error messages. Use
  this wherever a file is read.
- Add `mdbook_core::utils::fs::create_dir_all` as a wrapper around
  `std::fs::create_dir_all` to provide better error messages. Use
  this wherever a file is read.
- Replace `mdbook_core::utils::fs::write_file` with `write` to mirror
  the `std::fs::write` API.
- Remove `mdbook_core::utils::fs::create_file`. It was generally not
  used anymore.
- Scrub the usage of `std::fs` to use the new wrappers. This doesn't
  remove it 100%, but it is now significantly reduced.
2025-09-20 17:13:31 -07:00
Eric Huss
f24221a1d7 Merge pull request #2855 from ehuss/move-get_404_output_file
Move get_404_output_file to HtmlConfig
2025-09-20 01:18:12 +00:00
Eric Huss
6223189b95 Move get_404_output_file to HtmlConfig
This function was essentially only operating on data from HtmlConfig. It
wasn't really a "filesystem" function. So this moves it to be more
logically associated with the data it works on.
2025-09-19 18:11:29 -07:00
Eric Huss
73aeed48d7 Merge pull request #2854 from ehuss/move-take-lines
Move take_lines functions to mdbook-driver and make private
2025-09-20 01:07:23 +00:00
Eric Huss
09c3e542da Move take_lines functions to mdbook-driver and make private
These functions are only used by the links preprocessor. I'm moving
these functions to put them closer to the code that they are associated
with, and to reduce the public API surface.
2025-09-19 18:01:33 -07:00
Eric Huss
9fae3c88eb Merge pull request #2853 from ehuss/markdown-outdated-comment
Remove outdated comment in mdbook-markdown
2025-09-20 00:53:05 +00:00
Eric Huss
8159dea9ea Remove outdated comment in mdbook-markdown
I missed this in https://github.com/rust-lang/mdBook/pull/2844.
2025-09-19 17:46:08 -07:00
Eric Huss
e5386f9230 Merge pull request #2852 from ehuss/add-def-list-cfg-link
Add link to `output.html.definition-lists`
2025-09-19 03:26:17 +00:00
Eric Huss
5fafc3f1f6 Add link to output.html.definition-lists
I forgot to include this link in the description of definition lists.
2025-09-18 20:20:25 -07:00
Eric Huss
39a148fc8d Merge pull request #2851 from ehuss/admonitions
Add support for admonitions
2025-09-19 03:00:27 +00:00
Eric Huss
873e4fe40f Add support for admonitions
This enables the admonitions support from pulldown-cmark. This includes
a config option in case it causes problems with existing books.

I would like to make this extensible in the future, though I'm not sure
what that would look like. There's also some concerns with how this will
affect translations like mdbook-i18n-helpers, which we may need to work
out in a different way.

Closes https://github.com/rust-lang/mdBook/issues/2771
2025-09-18 19:54:20 -07:00
Eric Huss
604d4dd78a Merge pull request #2850 from ehuss/fix-nojs-css-vars
Fix missing css vars for no-js dark mode
2025-09-19 01:59:48 +00:00
Eric Huss
ddeb3ce54f Fix missing css vars for no-js dark mode
These various were inadvertently missing from the no-js dark mode.
2025-09-18 18:53:46 -07:00
Eric Huss
15958773d5 Merge pull request #2847 from ehuss/definition-list
Add support for definition lists
2025-09-17 23:50:16 +00:00
Eric Huss
ba4c3ed873 Add support for definition lists
This enables the definition lists support from pulldown-cmark.
This includes a config option in case it causes problems with existing
books.

Closes https://github.com/rust-lang/mdBook/issues/2770
2025-09-17 16:44:45 -07:00
Eric Huss
53d39a8654 Merge pull request #2846 from ehuss/fix-unique-id-loop
Fix ID collisions when the numeric suffix gets used
2025-09-17 21:42:08 +00:00
Eric Huss
f1731329e1 Fix ID collisions when the numeric suffix gets used
This fixes a collision with the ID generation where it a previous entry
could generate a unique ID like "foo-1", but then a header with the text
"Foo 1" would collide with it. This fixes it so that when generating the
ID for "Foo 1", it will loop unit it finds an ID that doesn't collide
(in this case, `foo-1-1`).
2025-09-17 14:36:16 -07:00
Eric Huss
51d7998ba4 Merge pull request #2845 from ehuss/script-in-block
Fix raw status ending in the HTML tokenizer
2025-09-17 21:27:14 +00:00
Eric Huss
d27a2bdd1d Fix raw status ending in the HTML tokenizer
This fixes a small mistake where the "raw" status wasn't being reset
once exiting the script or style tags. That means any text nodes that
followed would be misinterpreted as being raw.
2025-09-17 14:21:01 -07:00
Eric Huss
cd3e26fb90 Add a test for a script inside an HTML block 2025-09-17 14:19:38 -07:00
Eric Huss
1c034bdd9a Merge pull request #2844 from ehuss/html-tokenize
Add a new HTML rendering pipeline
2025-09-17 03:36:21 +00:00
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
Eric Huss
d4763d2c90 Merge pull request #2843 from ehuss/new-html-tests
Add more comprehensive tests for HTML rendering
2025-09-16 21:14:58 +00:00
Eric Huss
03443f723c Add more comprehensive tests for HTML rendering
This adds a bunch of tests to better exercise the HTML rendering and to
be able to track any changes in its behavior.

This includes a new `check_all_main_files` to more conveniently check
the HTML content of every chapter in a book.
2025-09-16 14:07:54 -07:00
Eric Huss
c3f4b8114a Merge pull request #2842 from ehuss/mdbook-compare
Add a basic utility to compare different versions of mdbook
2025-09-16 21:05:18 +00:00
Eric Huss
21e8c08827 Add a basic utility to compare different versions of mdbook
This is a very simplistic utility to compare the output of different
versions of mdbook. This is useful when making changes to compare
real-world books to see what changes actually happen.

This is a variation of scripts that I have been using for a few years.
This could definitely use some improvements, but this seems like it
could be useful as-is.
2025-09-16 13:58:20 -07:00
Eric Huss
de155f859b Merge pull request #2841 from ehuss/fix-missing-a
Fix broken a tag
2025-09-16 03:24:38 +00:00
Eric Huss
737090abf1 Fix broken a tag
This fixes the missing close `</a>` tag for the "previous" button.
2025-09-15 20:17:11 -07:00
Eric Huss
fb4fa867d1 Merge pull request #2840 from ehuss/partition-source
Rewrite partition_source to return slices
2025-09-16 01:50:14 +00:00
Eric Huss
c606a010c7 Rewrite partition_source to return slices
This changes partition_source so that instead of allocating new strings,
it just returns slices into the original string. It probably doesn't
make a big difference perf-wise, but I felt more comfortable with this,
and also felt it was a little easier to understand exactly what it was
doing.

This is generally equivalent except for the possibility of not having a
newline at the end. In practice that doesn't matter because markdown
code blocks always have a newline. However, to be defensive, the caller
will check for this.
2025-09-15 18:42:43 -07:00
Eric Huss
09f05e8a86 Add a test for partition_source 2025-09-15 18:08:25 -07:00
Eric Huss
1daa650d61 Merge pull request #2839 from ehuss/to_url_path
Add ToUrlPath helper trait
2025-09-15 14:50:47 +00:00
Eric Huss
2474ae799b Add ToUrlPath helper trait
This adds the `ToUrlPath` helper trait to convert a Path to a path
suitable for use in HTML (replacing `normalize_path`).

This also fixes a minor bug where on Windows the next/prev links were
using a double forward slash. I don't think this is possible, since
chapter links are derived from the summary, but I'm noting just in case.
It's also not too much of an issue since double slashes are normally
just treated as a single.
2025-09-15 07:44:10 -07:00
Eric Huss
f393e22896 Merge pull request #2838 from ehuss/chapters-iterator
Add an iterator over chapters
2025-09-15 14:18:39 +00:00
Eric Huss
3629e2c051 Add an iterator over chapters
This adds the `Book::chapters` iterator (and `for_each_chapter_mut`) to
iterate over non-draft chapters. This is a common pattern I keep
encountering, and I figure it might simplify things. It runs a little
risk that callers may not be properly handling every item type, but I
think it should be ok.
2025-09-15 07:11:19 -07:00
Eric Huss
e7b15274b5 Merge pull request #2837 from ehuss/remove-chrono
Remove chrono
2025-09-15 13:58:28 +00:00
Eric Huss
d15a40123c Remove chrono
I accidentally missed this in https://github.com/rust-lang/mdBook/pull/2829.
2025-09-15 06:50:50 -07:00
Eric Huss
166a972e9a Merge pull request #2833 from ehuss/static-regex
Add a helper for defining a regex
2025-09-12 13:57:30 +00:00
Eric Huss
f2db034587 Merge pull request #2832 from ehuss/remove-clap-macro_use
Remove clap macro_use
2025-09-12 13:55:51 +00:00
Eric Huss
a4140ba535 Remove clap macro_use
This removes the macro_use for clap just because I'm not a big fan of
glob-style imports like this. I think being a little more explicit here
makes it a little clearer where these macros come from.
2025-09-12 06:49:54 -07:00
Eric Huss
e3bb655663 Add a helper for defining a regex
This adds the `static_regex` macro to help with defining a regex.
2025-09-12 06:48:50 -07:00
Eric Huss
8bb9a7ff42 Merge pull request #2829 from ehuss/log-to-tracing
Switch from log to tracing
2025-09-12 13:20:49 +00:00
Eric Huss
3e673ce424 Switch from log to tracing
This switches to using the tracing crate instead of log. Tracing
provides a lot of nice features which we can take advantage of moving
forward.

This also adjusts the output fairly significantly. This includes:

- Switched the environment variable from RUST_LOG to MDBOOK_LOG.
- Dropped the timestamp. I experimented with various different time
  displays, but ultimately decided to omit it for now. I don't think
  I've ever found it to be useful, and it takes up a very significant
  amount of space. It could potentially be useful for basic profiling,
  but I think there are other, better mechanisms for that. We could
  consider leveraging tracing itself for doing some basic profiling
  (like using something like tracing-chrome).
- Dropped the target unless MDBOOK_LOG is set. The target tends to be
  pretty noisy, and doesn't really convey much information unless you
  are debugging or otherwise trying to adjust the log output.
- Added color.
- Slightly reworked the way the error cause trace is displayed.
- Slightly changed the way html5ever filtering is done, as well as add
  handlebars to the list since they both are very noisy. You can
  override this now by explicitly listing them as targets.

I still expect that mdbook will eventually change how it displays things
to the console, possibly switching away from tracing and printing things
itself. However, that is a larger project for the future.
2025-09-12 06:13:45 -07:00
Eric Huss
787882069e Merge pull request #2828 from GuillaumeGomez/simplify-gui
Simplify GUI tests runner
2025-09-08 17:35:25 +00:00
Guillaume Gomez
e6fffcf9ec Simplify GUI tests runner 2025-09-08 17:30:48 +02:00
Guillaume Gomez
c78d463864 Update browser-ui-test version to 0.22.1 2025-09-08 17:25:08 +02:00