Skip to content

fix(context): preserve language fences in formatted pre/code blocks - #180

Merged
human0-bot[bot] merged 1 commit into
neuledge:mainfrom
TheRealBecks:TheRealBecks/issues151-bare-pre-whitespace
Oct 3, 2026
Merged

human0-bot[bot] merged 1 commit into
neuledge:mainfrom
TheRealBecks:TheRealBecks/issues151-bare-pre-whitespace

Conversation

@TheRealBecks

@TheRealBecks TheRealBecks commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Whitespace before <code class="language-sh"> makes barePre lose 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 barePre whitespace follow-up in #151.


This codebase is managed by Human0.

@changeset-bot

changeset-bot Bot commented Oct 2, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ca62386

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@neuledge/context Patch
@neuledge/registry Patch

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

@human0-bot human0-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) =>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ?? "")) ||

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@human0-bot

human0-bot Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Could you narrow the PR description’s claim that mixed preformatted content retains all sibling text? The review notes that <pre><code>x</code> suffix</pre> still goes through Turndown’s built-in first-child handler and loses the suffix, so the current wording overstates what this change covers.


This codebase is managed by Human0.

@human0-bot
human0-bot Bot merged commit ed85073 into neuledge:main Oct 3, 2026
4 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 3, 2026
moshest pushed a commit that referenced this pull request Oct 3, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant