Skip to content

fix(syntax-highlighting): extend diff highlight to overflowing line content#7178

Merged
jstirnaman merged 13 commits intomasterfrom
fix/diff-fence-line-overflow
May 1, 2026
Merged

fix(syntax-highlighting): extend diff highlight to overflowing line content#7178
jstirnaman merged 13 commits intomasterfrom
fix/diff-fence-line-overflow

Conversation

@jstirnaman
Copy link
Copy Markdown
Contributor

@jstirnaman jstirnaman commented May 1, 2026

Problem

Reported on a diff fence in influxdb3/clustered/reference/release-notes/clustered/ — long + lines that horizontally overflow the visible code-block width render with the green diff highlight covering only the leftmost portion of the line (up to the right edge of the visible container). The overflowed text on the right has no highlight.

The .gi and .gd classes (Generic.Inserted / Generic.Deleted, applied to lines in ```diff fences) were styled with display: block. A block-level element sizes itself to its parent's content area — which is the visible width of the <pre> container, not the natural width of the line content. Lines longer than that visible width extend to the right but the background does not follow.

Fix

Switch from display: block to display: inline-block + min-width: 100%:

uses display: block + width: max-content

inline-block was abandoned because chroma puts a trailing \n inside the .gi span and inline-block collapsed lines onto one row.

Affects:

  • .gi (Generic.Inserted, the + lines)
  • .gd (Generic.Deleted, the - lines)

Verification

  • npx hugo --quiet builds clean
  • Manual visual check: a diff line longer than the visible code-block width should now show green tint covering the full line including the overflowed text

Test plan

…eams

Validator change:
  scripts/lib/codeblock-validators/yaml.mjs — switch yaml.load to
  yaml.loadAll so YAML streams (multiple documents separated by ---)
  parse cleanly. Kubernetes manifests, InfluxDB template manifests,
  and similar tools commonly emit multi-doc streams; rejecting them
  forced authors to relabel the fence and lose syntax highlighting.

Content fixes (yaml fence preserved):
  content/influxdb3/clustered/reference/release-notes/clustered.md
    - Line 148 fence relabeled yaml → diff (the block is a literal
      diff with + prefixes, not yaml).
    - Line 823 (now 823): replaced bare `...` ellipsis with
      `# ... fields elided ...` comment so indentation stays valid.
    - Line 1747 (now ~1747): replaced bare `....` and inner `...`
      ellipses with structured `# ... fields elided ...` comments.

  content/influxdb3/enterprise/admin/clustering.md
    - Three node-config blocks (Small / Medium / Large cluster) had
      `mode:` defined per node, producing "duplicated mapping key"
      errors because each block was one YAML document. Added `---`
      between node configs so each becomes its own document in the
      stream — matches author intent (per-node configs side by side)
      and parses cleanly.

  content/kapacitor/v1/reference/event_handlers/alerta.md
    - Genuine YAML bug: `correlate: 'event1', 'event2'` is invalid
      syntax, and the very next `correlate:` line was a duplicate
      key. Fixed to `correlate: ['event1', 'event2']` and removed
      the duplicate line that incorrectly assigned service names to
      the correlate key.

Test coverage: 59/59 lint-codeblocks tests still pass; multi-doc
support is exercised implicitly by the now-passing real content.
… comments

Per review feedback on #7160, the legacy admin-section example block
contained `- ...` and bare `...` lines used as ellipsis. While the
current YAML parser accepts them (they parse as the string '...'), they
are misleading: a copy-paste of the example would be invalid as actual
config. Replaced with explicit YAML comments that name what was elided.

Also normalized the leading comment from `## ...snip` to a properly
descriptive YAML comment for consistency.
…ontent

The .gi (and .gd) classes used `display: block`, which sizes the
highlighted span to the parent's visible width. When a diff line
horizontally overflows the code-block container, the text continues to
the right of the visible area but the green/red background does not —
the right-hand portion of the line renders without any highlight, which
is what the user reported on a clustered release-notes diff fence.

Switch to `display: inline-block` + `min-width: 100%`. inline-block
lets the element grow with content (so it covers the full overflow
width); min-width: 100% keeps the highlight at least as wide as the
visible container for short lines. The combined behavior is the
standard pattern for line-level diff highlights in pre/code blocks.
@jstirnaman jstirnaman requested a review from a team as a code owner May 1, 2026 16:05
@jstirnaman jstirnaman requested review from sanderson and removed request for a team May 1, 2026 16:05
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 1, 2026

PR Preview Action v1.4.8
🚀 Deployed preview to https://influxdata.github.io/docs-v2/pr-preview/pr-7178/
on branch gh-pages at 2026-05-01 19:51 UTC

@jstirnaman jstirnaman changed the base branch from master to fix/lint-yaml-blocking-errors May 1, 2026 16:12
@jstirnaman jstirnaman removed the request for review from sanderson May 1, 2026 16:47
@jstirnaman jstirnaman marked this pull request as draft May 1, 2026 16:47
@jstirnaman
Copy link
Copy Markdown
Contributor Author

jstirnaman commented May 1, 2026

Bug: Diff highlighting doesn't show at all.

Base automatically changed from fix/lint-yaml-blocking-errors to master May 1, 2026 17:30
… with palette

The previous `display: inline-block` on `.gi`/`.gd` swallowed the
trailing newline inside each chroma diff-line span, collapsing every
diff line onto a single inline row.

Switch to `display: block` + `width: max-content` + `min-width: 100%`:
block restores per-line stacking, max-content lets the highlight grow
with content past the visible area, and min-width keeps short lines
tinted to the right edge.

Replace the hard-coded green/red with palette variables
($gr-rainforest/$gr-viridian, $r-curacao/$r-ruby) and lower the tint
opacity for better readability against the article background.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 1, 2026

Vale Style Check Results

Metric Count
Errors 0
Warnings 0
Suggestions 1

Check passed

@jstirnaman
Copy link
Copy Markdown
Contributor Author

Adding the test-diff examples to content/example.md as a regression fixture.

Screenshot 2026-05-01 at 2 31 21 PM Screenshot 2026-05-01 at 2 34 03 PM

jstirnaman added 2 commits May 1, 2026 14:42
Add four diff fence fixtures to content/example.md (subtractive only,
subtractive with overflow, subtractive with context, mixed additions
and deletions) and matching Cypress assertions in
render-regression.cy.js.

Tests guard against the regression fixed in the prior commit:

- per-row stacking (sibling .gd spans must have distinct top offsets)
- display: block on .gd/.gi
- width: max-content (.gd offsetWidth exceeds parent clientWidth on
  overflowing lines)
- context lines remain untinted

Also extend assertHasHighlightedCodeBlock's selector to include
language-diff so the existing /example/ smoke test covers the new
fixtures.
@jstirnaman jstirnaman marked this pull request as ready for review May 1, 2026 19:46
- Apply Prettier formatting to multi-line .toArray() chain in
  render-regression.cy.js (was unstaged)
@jstirnaman
Copy link
Copy Markdown
Contributor Author

Quick self-review (low effort):

Findings: 0 P1, 0 P2, 2 P3, 2 P4

  • P3 — Stale PR description. Body says "Switch from display: block to display: inline-block," but the landed fix keeps display: block and adds width: max-content + min-width: 100%. Inline code comments on .gi/.gd correctly explain why inline-block was abandoned (chroma's trailing \n inside the span). Description should be updated for accuracy — not blocking.
  • P3 — Title scope. Second commit also migrates colors to palette vars ($gr-rainforest, $gr-viridian, $r-curacao, $r-ruby) and reduces alpha (0.35→0.12 green, 0.25→0.10 red). Covered by commit message; flagging for visibility.
  • P4 — Lighter alpha. Worth a visual gut-check post-merge; defensible as palette alignment.
  • P4 — Unstaged Prettier reformat in render-regression.cy.js — fixed in 5f9b8d3.

Verification: npx hugo --quiet builds clean. Pre-push packages-audit fails on pre-existing transitive-dep advisories (eslint→minimatch→brace-expansion, picomatch) untouched by this diff; pushed with --no-verify per repo convention for unrelated-lint cases.

@jstirnaman jstirnaman merged commit e9bc709 into master May 1, 2026
25 of 26 checks passed
github-actions Bot added a commit that referenced this pull request May 1, 2026
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