388 Commits

Author SHA1 Message Date
Eric Huss
45e2158e84 Merge pull request #2982 from ehuss/fix-sidebar-scroll
Fix sidebar scroll position when heading nav is involved
2025-12-11 19:21:21 +00:00
Eric Huss
59017ea918 Fix sidebar scroll position when heading nav is involved
This fixes an issue where the sidebar was scrolling incorrectly when
clicking on chapters when a heading nav is currently in view. The
problem was that it was storing the scrollTop of the sidebar, but it was
not considering that when navigating to another chapter that the heading
nav of the previous chapter would disappear.

The solution is to keep of an offset instead so that it can make sure
that the vertical position of the clicked chapter stays in the same
relative position when the new page loads.

Fixes https://github.com/rust-lang/mdBook/issues/2967
2025-12-11 11:13:47 -08:00
Eric Huss
7bdea7c085 Don't rebuild preprocessor map during test
This fixes a problem where custom preprocessors were not being
registered when running tests. This was caused by the test function
rebuilding the preprocessor map.

This removes the code that was rebuilding the preprocessors and removing
the IndexPreprocessor when running tests. Skipping IndexPreprocessor was
added back in https://github.com/rust-lang/mdBook/pull/741 to fix
https://github.com/rust-lang/mdBook/issues/724 which was caused by
https://github.com/rust-lang/mdBook/pull/685 which added the
IndexPreprocessor.

Additionally, https://github.com/rust-lang/mdBook/pull/1986 added
running *all* preprocessors.

The IndexPreprocessor was removed because in the past the code was
testing against the source directly, and the path from `chapter.path` is
the converted `index.md` file, and that filename does not exist in the
source. This isn't a problem anymore because due to
https://github.com/rust-lang/mdBook/pull/891 it is not reading from the
`src` directory.

Note that this results in a minor change where the chapter path changes
from `README.md` to `index.md` in the output and the `--chapter` option.
I think I'm ok with that change, though it would be easy to switch it
back if that's an issue.
2025-12-10 13:42:15 -08:00
Eric Huss
2bcae6b0a9 Add a test with a custom preprocessor
This test illustrates that the test function is not working correctly
when there is a custom preprocessor.
2025-12-10 12:51:19 -08:00
Eric Huss
5d64d0e5f2 Merge pull request #2953 from ehuss/fix-heading-nav-level
Fix heading nav level
2025-11-20 01:13:35 +00:00
Eric Huss
718ceecfa2 Fix heading nav depth
This fixes an issue where when a heading goes from a larger to a smaller
level, it was going back too far so that subsequent headings would be at
a lower level than they should have been.

Fixes https://github.com/rust-lang/mdBook/issues/2944
2025-11-19 17:06:49 -08:00
Eric Huss
09616e31af Add a test to validate the structure of the heading nav
This checks the entire structure of the heading nav for this test. It
currently is not handling nesting properly.

Having a large inline string like this may not be the easiest to
maintain or be able to see the structure. I don't see a way to format it
in goml.
2025-11-19 16:50:35 -08:00
Eric Huss
7e7a3b495e Merge pull request #2952 from ehuss/ignore-top-env-keys
Ignore invalid top-level environment variable config keys
2025-11-20 00:45:41 +00:00
Eric Huss
d39deca76a Ignore invalid top-level environment variable config keys
This changes it so that top-level environment variable config keys like
`MDBOOK_FOO` are ignored instead of generating an error. It's just too
inconvenient since it is common for users to set environment variables
like `MDBOOK_VERSION` or whatever for their own scripts.
2025-11-19 16:38:47 -08:00
Eric Huss
4b5ea14ee1 Support new font-awesome class names
In version 6, Font Awesome changed so that the class names look like
`fa-solid fa-cat` instead of `fas fa-cat`. This updates so that it
handles this new style.
2025-11-19 16:04:34 -08:00
Eric Huss
c53379e3ac Add a test using full fontawesome type names
In version 6, Font Awesome changed so that the class names look like
`fa-solid fa-cat` instead of `fas fa-cat`. mdBook is not handling the
new style.
2025-11-19 15:56:54 -08:00
Eric Huss
2afad43bdd Add error handling to env config handling
This adds several changes to how environment variables are handled to
more closely align with how configs are handled, and to fix an issue
with replacing entire tables. The changes are:

- Top-level tables like `MDBOOK_BOOK` now *replace* the contents of the
  `book` table instead of merging it. This adds consistency with how all
  the other environment objects work.
- Fixed allowing top-level replacement of `MDBOOK_BOOK` and
  `MDBOOK_OUTPUT`. This was inadvertently recently broken.
- Added ability to replace top-level `MDBOOK_RUST`. I don't recall why
  that wasn't included.
- Reject invalid keys like `MDBOOK_FOO`.
- Reject unknown keys, like `MDBOOK_BOOK='{"xyz": 123}'`
- Reject invalid types, like `MDBOOK_BOOK='{"title": 123}'`
2025-11-17 14:38:58 -08:00
Eric Huss
5445458d1a Add tests for various environment config issues
These currently aren't working as expected.
2025-11-17 12:47:01 -08:00
Eric Huss
700839f77f Handle unclosed HTML tags inside a markdown element
This fixes an issue where it was panicking due to an unbalanced HTML tag
when exiting a markdown element. The problem was that the tag stack was
left non-empty when processing was finished due to `end_tag` being out
of sync with the pulldown-cmark event tags.

There really should be better validation that the stack is in sync and
balanced, but this should address the main culprit of the interplay of
raw HTML tags and pulldown-cmark events.
2025-11-06 07:31:45 -08:00
Eric Huss
054da77b6a Add test for unbalanced html in a header
This is unexpectedly panicking.
2025-11-06 07:25:53 -08:00
Eric Huss
22065ebc79 Give a warning for unclosed HTML tags
This changes the internal error message to a warning to let the user
know that the HTML tags are unbalanced. In the future this will be a
denyable lint.

This is a very primitive approach of just ignoring the end tag. Ideally
it should recover using the standard HTML parsing algorithm, since there
is a chance that there will be a cascade of errors under certain
unbalanced situations.
2025-11-05 11:42:43 -08:00
Eric Huss
1646e4923a Add a test for HTML tags out of sync 2025-11-05 11:19:42 -08:00
Eric Huss
1e190137c3 Add a check for unclosed elements on the stack
This checks for any unclosed elements when processing is finished. This
is intended to detect invalid HTML in the source, or bugs in the tree
builder. Raw HTML elements generate a warning (which in the future will
be a configurable lint). All other sync errors are internal errors as
they are not expected, and it would be helpful to know if they ever
happen.
2025-11-05 11:14:39 -08:00
Eric Huss
4417f8cb0a Add a test for unclosed HTML tags 2025-11-05 10:45:46 -08:00
Eric Huss
b3bd103742 Add a warning when a Font Awesome font is missing
With the migration to Font Awesome 6, I'm running into books where the
icon names are missing or have changed. This adds a warning to help
identify those situations.
2025-10-30 19:30:01 -07:00
Eric Huss
7e5fa3565b Add a fontawesome test for a missing icon
This is a test for when an icon is missing.
2025-10-30 19:27:40 -07:00
Eric Huss
6d9f49cbc5 Update fontawesome test to make it clear the intent
This example was intended to demonstrate that it only translates if
there are no child elements.
2025-10-30 19:24:49 -07:00
Eric Huss
005f4d648a Fix print page links for internal links to non-chapters
This fixes links on the print page that go to an internal destination
that is not a chapter. The path would have the wrong relative
destination, and would be broken. The logic for detecting this was
incorrectly only checking if a link went outside the book, or didn't
have an html extension. This doesn't work for links to HTML files that
are inside the book, but not one of the chapters.
2025-10-30 18:37:12 -07:00
Eric Huss
59343b525d Add test for print relative for page that doesn't exist
An example where this can happen is a link to a page that was renamed
and redirected, or just a normal HTML file.
2025-10-30 18:04:51 -07:00
Eric Huss
54175698d5 Don't modify headers or dt if the tag is manually written HTML
This changes it so that header and `<dt>` tags manually written as HTML
are not modified (no anchor, no id, etc.). This is to avoid mangling any
HTML that the user explicitly crafted.

I'm not sure what the fallout from the headers might be, since I'm not
100% sure there aren't uses where the user wanted mdbook to modify
manual HTML. However, I don't see any in rust-lang's use.
2025-10-30 11:47:43 -07:00
Eric Huss
07ed00e8f7 Add a test for manually written header tags 2025-10-30 11:40:46 -07:00
Eric Huss
ab8a4dfa5a Add a test for definition lists with manual HTML tags 2025-10-30 10:02:27 -07:00
Eric Huss
ddf02e0c0c Fix rust fenced code blocks with an indent
This fixes a bug in the Rust code block partitioning that was
incorrectly removing the whitespace from the beginning of a code block.
2025-10-27 18:38:27 -07:00
Eric Huss
3992bc18f5 Add a test for a fenced code block with an indent 2025-10-27 18:35:39 -07:00
Eric Huss
118c1096ea Merge pull request #2899 from ehuss/filtered-headings
Filter mark tags from sidebar heading nav
2025-10-22 00:24:37 +00:00
Eric Huss
18813516e1 Fix avoiding the mark header in the sidebar nav
This makes sure that the sidebar headings don't have the `<mark>` tag.
When these are created, the Marker is unable to remove them from the
sidebar (and we don't want them there in the first place).

I suspect we'll want more filtering in the future, but I'm not sure
exactly what to filter. Alternatively, it could have an allow list of
tags, and filter all others out.
2025-10-21 17:19:00 -07:00
Eric Huss
a6944683e6 Add a test that shows heading nav conflict with search mark
The search marker is getting copied into the sidebar, but it cannot be
dismissed.
2025-10-21 17:17:25 -07:00
Eric Huss
58af25384d Rework the look of the header navigation
This updates the header navigation so that:

- Added a colored bar to break it apart from the chapter navigation.
- Removed the colored circle and just use link color to make it
  look cleaner.
2025-10-21 16:06:17 -07:00
Eric Huss
5282083dec Fix heading nav with folded chapters
This fixes an issue when folding is enabled. The folding was not
properly hiding the sub-chapters because it was assuming it could hide
the next list element. However, the heading nav was the next list
element, so the remaining chapters remained visible.

The solution required some deeper changes to how the chapters were
organized in the sidebar. Instead of nested chapters being a list
element *sibling*, the nested chapter's `ol` is now a *child* of its
parent chapter. This makes it much easier to just hide everything
without regard of the exact sibling order.

This required wrapping the chapter title and the toggle chevron inside a
span so that the flex layout could be localized to just those elements,
and allow the following `ol` elements to lay out regularly.

Closes https://github.com/rust-lang/mdBook/issues/2880
2025-10-20 17:31:40 -07:00
Eric Huss
d5406c8dff Simplify GUI runner
It didn't click that this was in the same project, and thus can access
the exe directly.
2025-10-15 14:05:23 -07:00
Eric Huss
5fe7e9531d Remove test_book
This is no longer used, as individual books have been added to support
different GUI tests. If there is anything here that we later decide we
need to keep for whatever reason, the needed content can be brought back
as new GUI test books. Otherwise, the guide and other books should cover
most things here.
2025-10-15 07:00:35 -07:00
Eric Huss
f958a0e8cf Add a syntax-highlighting GUI test
This adds a test specific to highlight.js syntax highlighting.
2025-10-15 07:00:35 -07:00
Eric Huss
dbad189b26 Add a gui test book for search
This isolates the search test with its own test book.
2025-10-15 07:00:35 -07:00
Eric Huss
4a06e067c5 Add a general-purpose summary GUI book
This adds the all-summary GUI test book which can be used for general
purpose tests that need a few pages to exercise all the different kinds
of items.
2025-10-15 07:00:35 -07:00
Eric Huss
98a093a0ff Move redirect gui tests to its own book 2025-10-15 07:00:35 -07:00
Eric Huss
9b5c57bf48 Add a basic book for GUI tests
This is the default book with a single chapter.
2025-10-15 07:00:35 -07:00
Eric Huss
87e9cc0ac3 Move heading-nav gui tests to a dedicated book 2025-10-15 07:00:35 -07:00
Eric Huss
e37e5314f8 Support multiple books in the GUI tests
This adds the ability to use multiple books for the GUI tests. This is
helpful since some tests need special configuration, and sharing the
same book can make it difficult or impossible to test different
configurations. It also makes it difficult to make changes to the
test_book since it can affect other tests.

This works by placing the books in the tests/gui/books directory. The
test runner will automatically build all the books. The gui tests can
then just access the DOC_PATH with the name of the book.

Books are now saved in a temp directory to make it easier to use the
DOC_PATH variable, instead of being tests/gui/books/book_name/book which
is a little awkward.

Following commits will restructure the existing book. This is just a
mechanical move.
2025-10-15 07:00:33 -07: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
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
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
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