Repository navigation
feat(code-block): {diff} fence attribute for unified-diff blocks (code-block Task 2.3) - #3034
Merged
Merged
Conversation
Introduce $isDiffFence (true whenever the {diff} attribute is present) so
that context-only {diff} fences — no + or - lines — still take the
$cleanInner highlight path and emit data-diff="true". Previously $hasDiff
stayed false for context-only blocks, falling through to the plain .Inner
branch which left the leading space gutter in the output.
Changes:
- hugo/layouts/_default/_markup/render-codeblock.html: add $isDiffFence,
use `or $hasDiff $isDiffFence` for the render branch and data-diff/
data-copy-raw attributes.
- scripts/parsers/__tests__/diff-markers.test.ts: new test verifying
context-only {diff} DOM shape passes through copyDiffFinal correctly.
4 tasks
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.
What / Why
Implements the deferred Task 2.3 from the
tutorial-code-block-enhancementsopenspec: the{diff}fence attribute for unified-diff-format code blocks.Fences tagged
{diff}now interpret their content as a standard unified-diff body — leading+= added line,-= removed line,(space) = context line. The gutter column is stripped before Chroma highlighting, and the added/removed row styling reuses the exact samediff-added/diff-removedCSS classes anddata-diffDOM shape that[!code ++]/[!code --]markers already produce. Copy behavior is automatic: the existingcopyDiffFinalpath excludes removed lines and yields the final code.Commits
de3171d63feat(code-block):{diff}fence attribute for unified-diff blocks (task 2.3)8e9e5c1d2fix(code-block): always strip{diff}gutter even for context-only fencesThe fix commit addresses a spec defect found in final review: when a
{diff}fence contains only context lines (no+/-), the original implementation left$hasDiff = falseand fell through to the plain render branch, highlighting.Inner(with gutter spaces) instead of$cleanInner(stripped). Fix introduces$isDiffFenceflag so the stripped-source render path fires whenever{diff}is present, regardless of whether add/remove lines exist.How tested
scripts/parsers/__tests__/diff-markers.test.ts(5 pre-existing + 3 for Task 2.3 + 1 for the context-only fix){diff}are byte-identical — gated by strictindex $attrs "diff"attribute-presence checkDeploy scope
Frontend/Hugo only — changes are in:
hugo/layouts/_default/_markup/render-codeblock.htmlscripts/parsers/__tests__/diff-markers.test.tsNo CAP/backend changes. No new npm packages. No TypeScript runtime changes.