- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
typeset plugin reads headings in code blocks #5446
Comments
Here's a suggestion (probably naive as well): headings = []
in_code_block = False
for line in page.markdown.split("\n"):
if line.startswith("```"):
if in_code_block:
end_ticks = len(line) - len(line.lstrip("`"))
if end_ticks == start_ticks:
in_code_block = False
else:
start_ticks = len(line) - len(line.lstrip("`"))
in_code_block = True
elif line.startswith("#") and not in_code_block:
headings.append(line)
html = self.markdown.convert("\n".join(headings)) |
Thanks for reporting and providing a possible solution! The reported problem should be fixed in |
Ah, that's great! Some extensions/plugins generate headings and these would not have been caught by the previous version of the code. Working on HTML allows to pick up every headings, static or generated 👍 I'll try the fix and report back 🙂 Thanks! |
The issue is resolved, as discussed on Gitter with @pawamoy. |
Released as part of 9.1.12-insiders-4.34.0. |
Context
I'm writing some docs for mkdocstrings where we show how you can inject documentation for an object directly in a heading line:
## ::: path.to.object
Bug description
The typeset plugin naively picks up Markdown lines starting with
#
without checking if they're part of a fenced code block. It then converts those lines using the extension configured in mkdocs.yml, in this case mkdocstrings, which triggers all the code scanning + HTML rendering machinery, causing issues.Related links
https://github.com/squidfunk/mkdocs-material-insiders/blob/d82bb8e0a5ef39bed97e6a8849b8146dfd7afbb1/material/plugins/typeset/plugin.py#L74-L77
Reproduction
example.zip
Steps to reproduce
Browser
No response
Before submitting
The text was updated successfully, but these errors were encountered: