159 Commits

Author SHA1 Message Date
Eric Huss
94569a42da Update to 0.5.2 2025-12-11 11:40:27 -08:00
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
f857ab294c Merge pull request #2981 from ehuss/fix-rustdoc-color
Fix color for rustdoc error messages
2025-12-10 22:08:16 +00:00
Eric Huss
23724b0a6b Fix color for rustdoc error messages
Due to a change in tracing-subscriber where it escapes ANSI codes, the
output from rustdoc was changed to be escaped instead of colored. This
fixes the issue by just printing to the console directly.

This does not have a test because it is difficult to emulate a terminal
in the testsuite, and I don't feel like adding color overrides at the
moment.

Ref:
- https://github.com/rust-lang/mdBook/pull/2829 -- Switched to tracing
- https://github.com/advisories/GHSA-xwfj-jgwm-7wp5 -- CVE-2025-58160
- https://github.com/tokio-rs/tracing/issues/3378 -- Discussion of
  supporting color codes.

Eventually mdbook's primary output should migrate away from using log
messages, and instead use a structured console system. However, that's a
ways off.
2025-12-10 14:01:50 -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
eb83d080f6 Update to 0.5.1 2025-11-19 17:36:49 -08:00
Eric Huss
710ec2755d Merge pull request #2932 from vitorfloriano/scrollbar-bg-transparent
Change scrollbar background to transparent
2025-11-20 01:22:36 +00: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
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
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
262afdc2f8 Update to 0.5.0
This is the stable release of 0.5.0. No changes have been made since
0.5.0-beta.2.
2025-11-17 08:57:52 -08:00
Vitor Floriano
ef10e720a5 Change scrollbar background to transparent
Closes #2930.
2025-11-12 18:16:31 -03:00
Eric Huss
922f0d8ad4 Update to 0.5.0-beta.2.
I expect this to be the last pre-release before 0.5.
2025-11-07 18:00:52 -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
152132458e Move end tag handling to a function
This is to reduce the size of the processing function.
2025-11-06 07:25:55 -08:00
Eric Huss
bc7ca458b6 Merge pull request #2923 from LikeLakers2/hide-resize-handle-on-noscript
Hide the sidebar resize indicator when JS isn't available
2025-11-06 03:41:26 +00:00
MichiRecRoom
07fb33f5da Hide the sidebar resize handle when scripting isn't available 2025-11-05 19:11:09 -08:00
Eric Huss
f0117ec3df Add a comment about synchronizing the event stack 2025-11-05 11:45:46 -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
5905bf1d85 Factor out Token::TagToken to combat rightwards drift 2025-11-05 11:33:58 -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
051fc9f01d Add a comment about the intent of HTML id generation 2025-11-04 16:05:36 -08:00
Eric Huss
d0bde467e0 Lowercase heading IDs
This switches from ASCII lowercase to Unicode lowercase when generating
heading IDs. This brings mdbook more in line with other tools and sites
when they generate heading IDs. The generation still isn't 100% the same
as other tools and sites, but it is usually the same in most cases.

Closes https://github.com/rust-lang/mdBook/issues/1059
2025-11-04 16:05:31 -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
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
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
e2c954f693 Merge pull request #2911 from ehuss/trace-events
Add some trace logging for event processing
2025-10-30 03:42:12 +00:00
Eric Huss
8ba833feb2 Add some trace logging for event processing
This adds some trace logging to help debug markdown parsing and HTML
parsing.
2025-10-29 20:34:11 -07:00
Eric Huss
1cc4cbb202 Add Config::contains_key
This adds the method `contains_key` to assist with detecting if a key is
set in the config. There have been a few scenarios where I have needed
this when upgrading to 0.5. For now this only supports the `output` and
`preprocessor`. Checking the presence in the other tables isn't easy,
but could potentially be added if needed.
2025-10-29 20:29:46 -07:00
Eric Huss
a17c1d1b95 mdbook-compare: fix duplicate "diff" print
The "diff" arg is already in the args list.
2025-10-29 19:45:22 -07:00
Eric Huss
8a27d1b7ac Merge pull request #2904 from traviscross/TC/fix-ayu-comments
Remove italics from `ayu` quotes/comments for alignment
2025-10-28 19:50:07 +00:00
Eric Huss
68d9bcfec4 Expose "search" feature from mdbook-driver
This allows users of mdbook-driver to easily enable the search feature.
2025-10-28 11:29:48 -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
Travis Cross
49f9c9741e Remove italics from ayu quotes/comments for alignment
Comments in code examples often rely on exact column alignment,
e.g. for ASCII-art.  This alignment often relies on both code and
comment characters having exactly the same width.

Setting `font-style: italic` seems to break these invariants with
common monospace fonts used by browsers.  This may be due to font
synthesis when the monospace font does not have a native italic
variant.

E.g., see these code examples when using the `ayu` theme:

- https://doc.rust-lang.org/1.90.0/reference/types/closure.html#r-type.closure.drop-order
- https://doc.rust-lang.org/1.90.0/reference/types/impl-trait.html#r-type.impl-trait.generic-capture.precise.use

It seems more important to have correct alignment than to style these
elements in italics, so let's drop the italic styling.

One alternative would be to set `font-synthesis: none` instead.  This
would prevent font synthesis-related misalignment while still
rendering italics when a font supports italics natively.  This might
correct the alignment issue, but ASCII-art in comments often wants
vertical bars to actually be vertical, so it still seems better to
just turn off italics entirely.

A more minimal change might be to only drop this from comments and not
from `hljs-quote`, but it seems the styling for these classes are
usually kept in sync, so we preserve that here.
2025-10-27 20:26:04 +00:00
Eric Huss
ac11e00aa2 Update to 0.5.0-beta.1 2025-10-26 12:55:06 -07:00
Eric Huss
adcbd117da Fix error message for config.get deserialization error
The error message for a deserialization failure was missing a call to
`format!`.
2025-10-25 16:46:51 -07:00
Eric Huss
08d9fddfc9 Add a test for config.get deserialization error 2025-10-25 16:45:48 -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
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
a097fe6232 Merge pull request #2891 from ehuss/divide-by-zero-heading-bug
Avoid divide-by-zero in heading nav computation
2025-10-21 00:52:17 +00:00
Eric Huss
4b5004b621 Avoid divide-by-zero in heading nav computation
This particular value can go to zero when the document height and the
window height are exactly the same value. This causes a NaN which causes
the "current" heading nav bug to not update properly. This clamps the
value to 1 to avoid that.
2025-10-20 17:43:34 -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
1620858032 Improve the heading nav debug
This updates the heading nav debug code with a few changes:

- Now enabled with the `mdbookEnableThresholdDebug` function.
- Adds a table with the relevant internal variables.
2025-10-20 17:05:44 -07:00
Eric Huss
3a2705d742 Remove tabs in chrome.css
This causes awkwardness with some editors which want to replace tabs
with spaces.
2025-10-20 15:41:33 -07:00