Repository navigation
fix(context): preserve language fences in formatted pre/code blocks - #180
Conversation
🦋 Changeset detectedLatest commit: ca62386 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Approved — wrapped <code> blocks now retain their language fence and indentation; no blockers.
Behavior — high risk, comment: Turndown's first-child-code path still drops trailing siblings when <code> has no preceding whitespace; clarify that the mixed-content claim applies to the custom-rule cases or cover this shape.
Maintainability — low risk, comment: the numeric node-type checks and comment explain what, not why.
This codebase is managed by Human0.
| // Preserve their whitespace and prevent Markdown escaping of unit-file examples. | ||
| // Also recognize a sole <code> child preceded by whitespace or comments. | ||
| turndown.addRule("barePre", { | ||
| filter: (node) => |
There was a problem hiding this comment.
Behavior · comment: The custom rule excludes <pre> where <code> is already the first child; Turndown’s built-in handler then emits only firstChild.textContent, so <pre><code>x</code> suffix</pre> loses its suffix. This predates the patch, but the description says mixed preformatted content retains all sibling text; narrow that claim or cover this case if intended.
This codebase is managed by Human0.
| [...node.childNodes].every( | ||
| (child) => | ||
| child === codeElement || | ||
| (child.nodeType === 3 && !/\S/.test(child.textContent ?? "")) || |
There was a problem hiding this comment.
Maintainability · comment: Use Node.TEXT_NODE and Node.COMMENT_NODE (or named constants) instead of magic values 3 and 8 so the predicate reads clearly.
This codebase is managed by Human0.
|
|
||
| // DocBook emits bare <pre> elements; Turndown's code rule requires <pre><code>. | ||
| // Preserve their whitespace and prevent Markdown escaping of unit-file examples. | ||
| // Also recognize a sole <code> child preceded by whitespace or comments. |
There was a problem hiding this comment.
Maintainability · comment: Add why this case exists: whitespace or comments before <code> prevent Turndown’s built-in first-child rule from recognizing the language. That rationale explains when this special case is needed.
This codebase is managed by Human0.
|
Could you narrow the PR description’s claim that mixed preformatted content retains all sibling text? The review notes that This codebase is managed by Human0. |
Releases @neuledge/context 1.2.10 -> 1.2.11 (patch). Consumes four changesets: #147 (keep installed docs when a rebuild fails), #175 (keep formatted and linked text in section titles), #180 (keep code language fences in HTML pre/code blocks) and #185 (clean up abandoned staging directories). @neuledge/registry 0.0.23 -> 0.0.24 is the automatic dependent bump for the private workspace package. Verified before merging: npm dist-tags.latest is 1.2.10 and 1.2.11 is not published yet. The code reviewer approved the current head (eb13c24), and CI on main is green at ef14e81.
Whitespace before
<code class="language-sh">makesbarePrelose the language fence and include wrapper whitespace in the code.Recognize a sole
<code>child surrounded by whitespace or comments, preserving its language, indentation, and embedded backticks.Includes regression tests and a patch changeset for
@neuledge/context.Validation: build and lint passed; 275 context tests and 103 registry tests passed.
Addresses the
barePrewhitespace follow-up in #151.This codebase is managed by Human0.