Repository navigation
📚 DOCS: Runnable usage example, dollarmath rendering contract, RTD on Python 3.13 - #166
Merged
Merged
Conversation
On Python 3.10 the `rtd` extra resolves markdown-it-py 3.0.0, myst-parser 4.0.1 and Sphinx 8.1, because myst-parser 5 needs Python 3.11 or later. On 3.13 it resolves markdown-it-py 4.2.0, myst-parser 5.1.0 and Sphinx 9.2, so the published docs are built against the current stack. Also move the build image to ubuntu-24.04.
The example imported `plugin1, plugin2` from `mdit_py_plugins`, which do not exist: each plugin lives in its own submodule. Show real imports, a chain of `use` calls and a keyword option, and say where the options are documented.
State the HTML each dollarmath token renders to and the `display_mode` its renderer receives: the tag (`div` or `span`) says how to display the math, and the class (`inline` or `block`) says where it was written, as in markdown-it-dollarmath. So inline `$$x$$` is a `<div class="math inline">`. Add a "Rendering dollarmath output" section with the two usual workflows: a `renderer=` that adds MathJax/KaTeX delimiters (escaping the content, which a custom renderer must do itself), and a browser script that typesets the elements with KaTeX, taking the display mode from the tag. Also say how to change the label anchor and the tags or classes. No rendered output changes.
The renderer docstring now says a custom renderer is responsible for escaping, matching the docs, which allow trusted or fully typeset output. The docs also note that browsers close the paragraph before an inline $$ div.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #166 +/- ##
==========================================
+ Coverage 92.80% 93.30% +0.49%
==========================================
Files 31 40 +9
Lines 1835 2285 +450
==========================================
+ Hits 1703 2132 +429
- Misses 132 153 +21
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This was referenced Nov 10, 2026
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.
What and why
Three docs-only changes, one commit each, plus a small wording follow-up:
The "mdit-py-plugins package" section imported
plugin1, plugin2frommdit_py_plugins, which do not exist:each plugin lives in its own submodule and the package only exports
__version__.It now shows real imports (
front_matter,footnote,tasklists), a chain ofusecalls,a keyword option (
tasklists_plugin, enabled=True), and says where each plugin's options are documented.The
dollarmath_plugindocstring now lists the HTML each token renders to and thedisplay_modeits renderer gets:math_inlineis<span class="math inline">(False);math_inline_doubleis<div class="math inline">(True);math_blockis<div class="math block">(True);math_block_labelis<div id="..." class="math block">with the anchor first (True).The tag carries the display mode and the class records where the math was written, as in markdown-it-dollarmath.
The
rendererparameter now says its return value goes into the element as is,so a custom renderer is responsible for escaping it (the default renderer does).
A new "Rendering dollarmath output" section in
docs/index.mdshows the two usual workflows:a
renderer=that adds\(...\)/\[...\]delimiters for MathJax or KaTeX auto-render (escaping withescapeHtml),and a browser script that typesets the elements with KaTeX, taking
displayModefromel.tagName === "DIV"and keeping a labelled block's anchor out of the math.
It notes that a browser closes the
<p>before an inline$$<div>, so the text after it falls outside the paragraph,and points at
label_renderer=andmd.add_render_rulefor changing the anchor, tags or classes.This answers Document the rendering workflow with dollarmath #111 with documentation instead of changing the class of inline
$$(the approach of fix: inline double dollar to be rendered with class math block #124),which would break parity with markdown-it-dollarmath and make inline
$$indistinguishable from block math.To keep the Math section readable, the
amsmathautodoc now comes beforedollarmath, so the new subsection sits under the plugin it describes..readthedocs.ymlmoves from ubuntu-22.04 / Python 3.10 to ubuntu-24.04 / Python 3.13.On 3.10 the
rtdextra resolves markdown-it-py 3.0.0, myst-parser 4.0.1 and Sphinx 8.1.3(myst-parser 5 needs Python 3.11+), so the published docs were built against an old stack.
On 3.13 it resolves markdown-it-py 4.2.0, myst-parser 5.1.0, Sphinx 9.2.0 and docutils 0.22.4.
No rendered output changes; the only code-file change is the
dollarmath_plugindocstring.How it was tested
sphinx-build -nW --keep-going -b html docs/ <out>(thetox -e docs-cleancommand) on Python 3.13 with.[rtd]:green on master before the change, and green on the branch head.
pythonblock indocs/index.mdexecuted as written (a small extractor script, fresh namespace per block),on Python 3.13 (markdown-it-py 4.2.0) and Python 3.10 (markdown-it-py 3.0.0): all pass.
On master the usage block fails with
ImportError: cannot import name 'plugin1' from 'mdit_py_plugins'.htmlblock in the new section is byte-identical to what therenderer=example renders.<p>and<div>was checked with html5lib (an HTML5 spec parser):it closes the
<p>before the<div>and leaves " in a paragraph." outside it.for
$a<b$, inline$$x^2$$(withdouble_inline=True), a$$block and a labelled block:the span typesets inline, all three divs typeset in display mode, and the label anchor is kept.
The delimiter workflow was checked the same way with KaTeX's auto-render extension and its default delimiters: same result.
md.add_render_rule("math_inline", ...)afteruse(dollarmath_plugin)overrides the default rule (checked).pytest: 511 passed (Python 3.13, markdown-it-py 4.2.0).pre-commit run --all-files: all hooks pass.Closes #44
Closes #111
Notes for the reviewer
renderer=example here; it is not auto-closed by this PR.amsmath/dollarmathautodoc order swap is the only reordering in the page.