Repository navigation
Keep the code language when stripping CSS classes - #51
Merged
Merged
Conversation
Markdig records a fenced code block's language as class="language-xxx" on the <code> element. The cleanup regex stripped every class attribute, so the only record of the language was destroyed and a round-trip turned ```csharp back into a bare ```. The HTML to Markdown direction already reads the language-* class correctly, so the fix is limited to not throwing it away: the regex now skips class attributes whose value starts with "language-" and continues to strip everything else, which is what Loop needs. Un-skips the round-trip test that documented the bug. Two tests that asserted the old behaviour are updated: one claimed no class attribute survives at all, and the other expected the language to be lost. Non-language stripping is now covered by a custom container, which renders <div class="warning">. Fixes #34 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: b721ad5f-9add-4f55-b9c8-7e6d7b0fb3e7
This was referenced Aug 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #34
Markdig records a fenced code block's language as
class="language-xxx"on the<code>element.LoopHtmlConverterthen stripped every class attribute with a blanket regex, which destroyed the only record of the language. A round-trip turned```csharpback into a bare```.The HTML to Markdown direction already reads the
language-*class correctly (that came in with the<pre>fix for #19), so the bug was entirely in the stripping step. The regex now skips class attributes whose value starts withlanguage-and strips everything else, which is what Loop actually needs.Test changes worth a look
Un-skipping the round-trip test made two existing tests fail, both because they asserted the old buggy behaviour:
Convert_StripsCssClassesassertedclass=never appears in the output at all. Replaced with two narrower tests: one that the language class survives, one that a non-language class does not.FencedCode_SurvivesARoundTrip_ExceptTheLanguageexpected the language to be lost. Removed, sinceFencedCode_KeepsItsLanguagenow covers the same input with the correct expectation.For the "non-language classes are still stripped" case I used a custom container (
:::warning), because I wanted a class that Markdig genuinely emits rather than a guess. I verified the actual renderer output first::::warningproduces<div class="warning">before stripping and<div>after, so the assertion cannot pass vacuously.Verification
Full suite: 85 passed, 0 failed, 2 skipped. The two remaining skips are the still-open bugs #32 and #33.
Base branch
This targets
test/23-converter-tests(PR #41) because the converters live inmd2loop.Coreand the test suite only exists on that branch. It needs to merge after #41.