Repository navigation
Text fragments, port fallback, GitHub alerts and rel="external" - #139
Merged
Merged
Conversation
A link such as `page.md#:~:text=some%20words` uses a text fragment, which the browser resolves by searching the page's text. Anchor validation took the whole fragment for an element ID and warned that the anchor doesn't exist. Now only the part before `:~:` is checked, and nothing when it is empty.
`mkdocs serve` failed with "Address already in use" when another program, often another `mkdocs serve`, had port 8000. When the port is the default one, it now tries 8001 to 8010 and logs which one it uses. A port set with `--dev-addr` or `dev_addr` is still used as given. The server now binds before the first build, so the site is built for the port it is actually served on. On Windows the socket uses SO_EXCLUSIVEADDRUSE, because SO_REUSEADDR there lets two servers share a port silently.
A blockquote that starts with `[!NOTE]`, `[!TIP]`, `[!IMPORTANT]`, `[!WARNING]` or `[!CAUTION]` on its own line is how GitHub writes a callout. MkDocs showed it as a plain quote starting with `[!NOTE]`. It now becomes the same HTML as the `admonition` extension produces, which themes already style; the `mkdocs` theme gains colors for tip, important and caution. The conversion runs after other treeprocessors that handle these alerts themselves, such as Sumi's callouts, so their output is unchanged.
Themes and site CSS had no reliable way to tell a link to another site from an internal one, for example to add an icon. Markdown links to `https://`, `http://` or protocol-relative `//` URLs now get `rel="external"`. A `rel` the author set, such as with `attr_list`, is kept and `external` is added to it. Links in raw HTML are left alone, as before.
Contributor
Merging this PR will degrade performance by 16.49%1 warning
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing |
2 of 3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Four small, long-standing annoyances from the roadmap, one commit each, all for 1.11.0.
page.md#:~:text=some%20wordsis resolved by the browser by searching the page's text, but anchor validation took the whole fragment for an element ID. Now only the part before:~:is checked (page.md#heading:~:text=…still checks#heading), and nothing when it's empty.mkdocs serveuses the next free port when 8000 is busy. Instead of failing with "Address already in use" (typically a secondmkdocs serve), it tries 8001–8010 and logsPort 8000 is in use, so serving on port 8001 instead.A port set with--dev-addrordev_addris still used as given. The server now binds before the first build, so the site is built for the port it's actually served on. On Windows the socket usesSO_EXCLUSIVEADDRUSE, sinceSO_REUSEADDRthere lets two servers share a port without an error (not tested on Windows).[!NOTE],[!TIP],[!IMPORTANT],[!WARNING]or[!CAUTION]on its own line becomes<div class="admonition note">with a title, the same HTML as theadmonitionextension, so themes style it with no setup. Consecutive alerts stay separate, nested ones work,\[!NOTE]stays literal. It runs after Sumi's own callouts (treeprocessor priority 22 vs 25), so Sumi's output is unchanged; checked with mkdocs-sumi main. Themkdocstheme gets colors for tip, important and caution;readthedocsalready had them.rel="external". For Markdown links tohttps://,http://and//URLs, so themes and CSS can mark them. Arelset withattr_listis kept andexternaladded. Links in raw HTML are untouched, as before.The built-in themes with all five alerts:
Related Issue
Roadmap items 9, 14, 15 and 17 in #59.
Checklist
dev_addr, anchor validation, new "Alerts" and "External links" sections in Writing your docs, Fixed Upstream Issues pagedocs/about/release-notes.mdupdated (if applicable): new Added and Fixed sections under 1.11.0Checked locally: full unit test suite (962 tests),
hatch run integration.py3.12-default:test,mkdocs build --strictof the docs site,uvx prek run, and two realmkdocs serveprocesses (the second one moved to 8001).