Skip to content

Keep a wrapped line in the paragraph it belongs to - #63

Merged
ptheofan merged 1 commit into
mainfrom
62-soft-wrapped-paragraphs
Aug 22, 2026
Merged

Keep a wrapped line in the paragraph it belongs to#63
ptheofan merged 1 commit into
mainfrom
62-soft-wrapped-paragraphs

Conversation

@ptheofan

Copy link
Copy Markdown
Owner

A pushed document came back with every paragraph styled as a heading —
bold, oversized, no bullets, no monospace. #60 clears inherited styles,
but the paragraphs never reach the code that would clear them.

Root cause. A soft-wrapped source line became a literal newline in
the model. insertText does not read that as a line break: it ends the
paragraph there and starts another, so one model element becomes two Doc
paragraphs. buildFormattingFromApiDoc matches by exact text, so neither
half matches, apiIdx stops advancing, and with a lookahead window of 10
every element after it is skipped. The text then keeps whatever
insertText gave it — the style of the character before the insertion
point, which after a heading is a heading.

Measured, not inferred: the stored .remote.md from a real push has
every paragraph prefixed ###, and the log shows only 24 formatting
requests emitted for the whole document.

Fix. A soft break renders as a space in markdown, so emit a space. A
hard break is a line break within the paragraph, which Docs spells as a
vertical tab (U+000B); emit that so the paragraph stays whole, and
reverse-convert it back to a markdown hard break so it does not read as a
difference on every later sync.

Verification

Three converter tests plus one round-trip test, all watched failing
first — including never leaves a newline in an inline element, which
covers headings, list items and body text together.

One trap worth recording: importing the constant from
MarkdownToDocsConverter into DocsToMarkdownConverter created a
circular import that silently left it undefined and broke 23 unrelated
tests. It now lives in @shared/constants.

pnpm test 1039 passed / 62 files · typecheck clean · lint clean.

Closes #62

🤖 Generated with Claude Code

@ptheofan
ptheofan force-pushed the 62-soft-wrapped-paragraphs branch from d766ce8 to 6b0c101 Compare August 22, 2026 17:42
A soft break became a literal newline in the model. insertText does not
read that as a line break -- it ends the paragraph and starts another, so
one model element became two Doc paragraphs. Formatting is matched to
paragraphs by exact text, so neither half matched, apiIdx stopped
advancing, and every element after it was skipped. Nothing was styled
from there on, leaving the text with whatever insertText gave it: the
style of the character before the insertion point, which after a heading
is a heading.

A soft break renders as a space in markdown, so emit a space. A hard
break is a line break inside the paragraph, which Docs spells as a
vertical tab; emit that and reverse-convert it back to a markdown hard
break, or it would read as a difference on every later sync.

Closes #62

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@ptheofan
ptheofan force-pushed the 62-soft-wrapped-paragraphs branch from 6b0c101 to 0e0b9f3 Compare August 22, 2026 17:46
@ptheofan
ptheofan merged commit 02e1a69 into main Aug 22, 2026
5 checks passed
@ptheofan
ptheofan deleted the 62-soft-wrapped-paragraphs branch August 22, 2026 17:49
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.

A soft-wrapped source line splits the paragraph and loses all formatting after it

1 participant