mirror of
https://github.com/turnstonelabs/turnstone.git
synced 2026-08-12 23:12:23 -06:00
fix(renderer): drop the indent an indented fence close drags into code content
Copilot review on PR #804:
- An indented closing fence line (" ```") left its leading spaces as a
trailing whitespace-only line inside the rendered code block: the content
capture runs up to the backtick run and the close-line indent precedes it, so
it was captured as content. Strip a trailing newline PLUS any trailing indent
(/\n[ \t]*$/ instead of /\n$/); a column-0 close is unaffected. Red-green
pinned (content is exactly " x = 1", no trailing whitespace line).
- Correct a stale test docstring claiming the fence open anchor allows "up to 3
spaces" of indent — it allows arbitrary indent (the 4-space case is pinned
separately).
(cherry picked from commit e5e48a788a)
This commit is contained in:
@@ -1710,15 +1710,28 @@ def test_blockquoted_fence_renders_as_code() -> None:
|
||||
|
||||
|
||||
def test_indented_fence_still_renders_as_code() -> None:
|
||||
"""The open anchor allows up to 3 spaces of indentation (CommonMark), so a
|
||||
legitimately indented fence (e.g. under a list item) still renders as code
|
||||
rather than as a paragraph of literal backticks. A bare ``^`` anchor
|
||||
would have dropped it."""
|
||||
"""The open anchor allows arbitrary leading indent, so a legitimately
|
||||
indented fence (e.g. under a list item) still renders as code rather than a
|
||||
paragraph of literal backticks. (A bare ``^`` anchor would drop it; the
|
||||
deeper 4-space-indent case is pinned separately.)"""
|
||||
out = _render(" ```py\n x = 1\n ```")
|
||||
assert "<pre><code" in out, "indented fence dropped (not rendered as code):\n" + out
|
||||
assert "x = 1" in out
|
||||
|
||||
|
||||
def test_indented_fence_close_leaves_no_trailing_whitespace_line() -> None:
|
||||
"""An indented closing line's leading spaces must NOT survive as a trailing
|
||||
whitespace-only line inside the code block: the content strip removes a
|
||||
trailing newline PLUS any indent the close dragged into the capture (a
|
||||
`` ``` `` closed at column 0 is unaffected). Copilot review, PR #804."""
|
||||
out = _render(" ```py\n x = 1\n ```")
|
||||
m = re.search(r"<code[^>]*>(.*?)</code>", out, re.S)
|
||||
assert m, "no <code> block:\n" + out
|
||||
assert m.group(1) == " x = 1", "indented fence close left a trailing whitespace line: " + repr(
|
||||
m.group(1)
|
||||
)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Fix 4 — <details> open anchored to line start (B5). The details pass ran
|
||||
# with an unanchored open, so a `<details>` mentioned mid-line inside inline
|
||||
|
||||
@@ -381,7 +381,10 @@ function _renderMarkdownBody(text) {
|
||||
"<pre><code" +
|
||||
(cssLang ? ' class="language-' + escapeHtml(cssLang) + '"' : "") +
|
||||
">" +
|
||||
escapeHtml(code.replace(/\n$/, "")) +
|
||||
// Strip the trailing newline plus any whitespace an indented close
|
||||
// dragged into the content (a ` ```` close would otherwise leave a
|
||||
// whitespace-only last line in the code block).
|
||||
escapeHtml(code.replace(/\n[ \t]*$/, "")) +
|
||||
"</code></pre>",
|
||||
);
|
||||
// Store the fence source WITHOUT the re-emitted indent/marker prefix so
|
||||
|
||||
Reference in New Issue
Block a user