Skip to content

A caret line inside an open caption is caption text, not a second caption - #274

Merged
dereuromark merged 1 commit into
masterfrom
fix/caption-continuation-caret
Aug 15, 2026
Merged

A caret line inside an open caption is caption text, not a second caption#274
dereuromark merged 1 commit into
masterfrom
fix/caption-continuation-caret

Conversation

@dereuromark

Copy link
Copy Markdown
Contributor

A table caption silently discards its own text.

| A | B |
|---|---|
| 1 | 2 |
^ First
^ Second

On master the caption reads Second. First is gone - not moved, not rendered elsewhere, dropped.

The cause is the caption collector: it gathers continuation lines until a blank line or a new block, and a line starting with the caption marker counts as a new block. So the first caption ends there, the second parses as another caption, and on a table the second overwrites the first.

What decides the fix

djot.js (checked at 596e7fc) keeps the text, because an adjacent caret line is an ordinary continuation line of the open caption and its caret is literal:

<table>
<caption>First
^ Second</caption>

This library tracks djot.js, so parity decides it rather than taste. (The sibling project Carve rules the same input differently - the second line stays a paragraph - but that is an explicit divergence in a different language, not a candidate here.)

The change is one condition in the collector: a line whose only claim to being a new block is the caption marker no longer ends the caption.

Unchanged, and now pinned by tests

Each of these already matched djot.js and still does:

  • A blank line between the two caret lines: the second caption replaces the first.
  • A plain continuation line after a caption: two-line caption.
  • Two captioned tables in one document: one caption each.
  • The documented blank line between an element and its caption.

Deliberate consequence on the other caption targets

The collector is shared, so an image and a block quote caption now swallow an adjacent caret line as well:

> q
^ First
^ Second

Before: a figure captioned First, plus a separate paragraph ^ Second. After: the caption reads First\n^ Second.

A caption is one block and its continuation rule should not depend on what it attaches to, so this is consistency rather than collateral. Neither target was losing text before, so nothing is rescued here either - say the word and I will narrow the condition to the table path, which is a one-line difference.

The caption collector gathered continuation lines until a blank line or
a new block, and a line starting with the caption marker counted as a
new block. So the first caption ended there and the second parsed as
another caption, which on a table REPLACED the first - its text was
discarded with nothing to show for it.

djot.js keeps it: an adjacent caret line is an ordinary continuation
line of the open caption, and its caret is literal text. This library
tracks djot.js, so parity decides it.

Before, the caption read `Second`. Now it reads `First\n^ Second`.

Everything else is unchanged and now has a test: a blank line between
the two caret lines still means the second caption replaces the first,
a plain continuation line still continues the caption, and two
captioned tables in one document still keep their own captions.

The collector is shared, so an image and a block quote caption swallow
an adjacent caret line too. That is deliberate: a caption is one block,
and its continuation rule cannot depend on what it attaches to. Neither
target lost text before, so this only makes them consistent.
@codecov

codecov Bot commented Aug 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.42%. Comparing base (72442e7) to head (16ca8a5).

Additional details and impacted files
@@            Coverage Diff            @@
##             master     #274   +/-   ##
=========================================
  Coverage     92.42%   92.42%           
- Complexity     3682     3683    +1     
=========================================
  Files           109      109           
  Lines         10440    10440           
=========================================
  Hits           9649     9649           
  Misses          791      791           

☔ View full report in Codecov by Harness.
📢 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 merged commit 992165a into master Aug 15, 2026
6 checks passed
@dereuromark
dereuromark deleted the fix/caption-continuation-caret branch August 15, 2026 17:57
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