You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Markdown backend strips the first-line indentation of code blocks #4485
The Markdown backend calls .strip() on code block content (md_backend.py, child.children.strip()), which removes the leading indentation of the first line while later lines keep theirs. The code's relative indentation changes, so the content is altered rather than just trimmed: a YAML snippet changes structure, and an indented Python snippet becomes an IndentationError.
Code blocks whose first line is not indented are unaffected, which is probably why this has gone unnoticed.
Input (fenced code)
Extracted code text
key: 1 / sub: / x: 2
key: 1 / sub: / x: 2
x = 1 / y = 2
x = 1 / y = 2
The same happens for indented (non-fenced) code blocks.
PR #3891 already fixes the equivalent problem for HTML <pre> (trimming only the leading newline and trailing whitespace instead of .strip()), but it does not touch the Markdown backend. LaTeX verbatim shows the same behaviour; I'm leaving that out of scope here.
Activity