Skip to content

Fix export to pdf#161

Open
roniaxe wants to merge 2 commits into
alecdotdev:masterfrom
roniaxe:fix_export_to_pdf
Open

Fix export to pdf#161
roniaxe wants to merge 2 commits into
alecdotdev:masterfrom
roniaxe:fix_export_to_pdf

Conversation

@roniaxe
Copy link
Copy Markdown

@roniaxe roniaxe commented May 21, 2026

Fixes #158

Summary

  • Hide top-fade mask, TOC overlay/toggle, and find bar during print so
    they no longer appear in the exported PDF or mask leading characters.
  • Reset overflow on .viewer-content so wide code blocks aren't clipped.
  • Replace invalid word-break: break-word with overflow-wrap: anywhere.
  • Add orphans/widows and break-inside: avoid rules so paragraphs,
    headings, code blocks, and other block elements don't break across
    pages in ugly ways.

Test plan

  • Export a markdown doc with TOC open → no TOC or find bar in PDF.
  • First line of body text starts cleanly with no masked characters.
  • Long code lines wrap onto next line instead of being clipped.
  • Headings don't end up alone at the bottom of a page.
  • Browser print-dialog "Headers and footers" can be unchecked.

Roni Axelrad added 2 commits May 21, 2026 08:54
The exported PDF previously had three issues:
- The first few characters of the first line were hidden behind the
  top-fade-mask gradient overlay.
- The TOC overlay, TOC toggle button, and find bar (if open) were
  visible in the exported PDF.
- Long lines inside code blocks were trimmed at the right edge because
  .viewer-content kept overflow: hidden during print, and the invalid
  `word-break: break-word` did not actually wrap long tokens.

Extend the @media print block in styles.css to hide the overlays,
release overflow on .viewer-content, and replace the bad word-break
rule with overflow-wrap: anywhere on pre / pre code.
Reduce content getting split unnaturally across pages in the exported
PDF:
- Headings get `break-after: avoid` so they no longer get stranded at
  the bottom of a page with their content on the next.
- Code blocks, blockquotes, tables, figures, images, mermaid diagrams,
  and KaTeX displays get `break-inside: avoid` so they stay on one
  page when they fit.
- Paragraphs and list items use `orphans: 3; widows: 3;` so prose can
  still split across pages but never with only one or two stranded
  lines at the top or bottom.

Note: blocks taller than a single page will still split (the browser
ignores break-inside in that case), but this fixes the common
"first line of a paragraph alone at the bottom" pattern.
@alecdotdev
Copy link
Copy Markdown
Owner

looks good! is it ready to merge/did all the tests pass?

@roniaxe
Copy link
Copy Markdown
Author

roniaxe commented May 24, 2026

@alecdotdev yes, it's ready and tests passes. it's all css changes.

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.

export as pdf doesnt work as intended

2 participants