Skip to content

Port upstream 4844: keep soft line breaks on export via CSS#160

Open
Renakoni wants to merge 1 commit into
mainfrom
sync/upstream-4844-soft-break-export
Open

Port upstream 4844: keep soft line breaks on export via CSS#160
Renakoni wants to merge 1 commit into
mainfrom
sync/upstream-4844-soft-break-export

Conversation

@Renakoni

Copy link
Copy Markdown
Owner

Fixes #143 β€” redoes the stale port from closed #66 against current main, matching the final upstream fix (marktext#4844, merged) exactly.

What changes

The editor shows a soft line break (a bare \n inside a paragraph) as a line break because .mu-content is white-space: pre-wrap, but HTML/PDF export collapsed it to a space β€” the two lines ran together.

Instead of forcing marked to emit <br> (which CommonMark reserves for hard breaks β€” the exported HTML would become non-conformant), the export keeps the conformant \n and renders it the way the editor does: white-space: pre-wrap on .markdown-body p and on tight list items (li:not(:has(> p))). Loose items are deliberately excluded β€” they wrap content in <p> (already covered), and li-level pre-wrap would expose marked's pretty-printing newline between </p> and </li> as a stray blank line.

The Android export path flows through the same vendored file: pdfExportHtml.ts β†’ MarkdownToHtml.generate() β†’ <article class="markdown-body"> with exportStyle.css inlined, so the one CSS rule covers both HTML and PDF export.

Verification

  • New softBreakExportHtml.spec.ts (ported from upstream): paragraph soft break stays a newline and never becomes <br>; tight-item soft break likewise; a real hard break (two trailing spaces) still renders <br>.
  • Muya app-gate suite: 1446/1446.
  • Root unit tests (incl. the vendor-sync contract): 577/577; node_modules/@muyajs/core resynced.
  • The rendered result of this exact rule (including the :has() loose-item exclusion) was verified in real Chromium upstream before marktext#4844 merged; the Android WebView shares the engine.

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.

Soft line breaks are lost in HTML/PDF export

1 participant