Skip to content

Pad code-span content symmetrically in HtmlToDjot#203

Merged
dereuromark merged 1 commit into
masterfrom
fix/htmltodjot-code-span-spacing
Jun 2, 2026
Merged

Pad code-span content symmetrically in HtmlToDjot#203
dereuromark merged 1 commit into
masterfrom
fix/htmltodjot-code-span-spacing

Conversation

@dereuromark
Copy link
Copy Markdown
Contributor

Problem

HtmlToDjot corrupted inline code whose content begins or ends with a backtick. It added the fence-separating space to only the affected end:

<code>`a</code>   ->  `` `a``     ->  <code> `a</code>   (gained a leading space)
<code>a`</code>   ->  ``a` ``     ->  <code>a` </code>   (gained a trailing space)

Djot removes a single leading and trailing space from a code span only when both ends have one and the span is not all spaces. A lone pad space therefore survives as content and changes the value on the next parse.

Fix

When the content needs separating from the fence (it starts or ends with a backtick and not already a space), pad both ends. The strip rule then removes both and restores the exact content:

<code>`a</code>   ->  `` `a ``    ->  <code>`a</code>
<code>a`</code>   ->  `` a` ``    ->  <code>a`</code>

Content that already starts or ends with a real space is untouched (the existing space already separates the fence, so no extra padding is added and the significant space is preserved). All-space content and the symmetric case (`a`) were already correct and stay correct.

When inline code content begins or ends with a backtick, HtmlToDjot
added a separating space to only that end. Djot strips a leading and
trailing space from a code span only when both ends have one (and the
span is not all spaces), so a lone pad space was kept as content: a
`<code>` of `` `a `` round-tripped to `` `a `` with an extra leading
space.

Pad both ends when separation is needed, so the strip rule restores the
exact content. Content that already starts or ends with a real space is
unaffected (no extra padding is added there).
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.80%. Comparing base (5c9e2f0) to head (951618e).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #203      +/-   ##
============================================
- Coverage     91.80%   91.80%   -0.01%     
+ Complexity     3452     3450       -2     
============================================
  Files           104      104              
  Lines          9788     9786       -2     
============================================
- Hits           8986     8984       -2     
  Misses          802      802              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dereuromark dereuromark marked this pull request as ready for review June 2, 2026 01:39
@dereuromark dereuromark merged commit f8b5407 into master Jun 2, 2026
6 checks passed
@dereuromark dereuromark deleted the fix/htmltodjot-code-span-spacing branch June 2, 2026 01:40
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