macdown icon indicating copy to clipboard operation
macdown copied to clipboard

Wrap text for code rendering

Open AlexHuang2 opened this issue 7 months ago • 2 comments

Noticed that code renderings do not wrap text and when exported to PDF, cuts off.

AlexHuang2 avatar Aug 09 '25 20:08 AlexHuang2

Some people may not want code blocks to wrap, or at least, not every time a document is printed.

I think there should be an option on each print job to allow the user to control whether it wraps or not, with a preference to set the default value of this option.

kg4zow avatar Aug 12 '25 10:08 kg4zow

This issue has been addressed in MacDown 3000.

The fix implements @media print CSS that forces code blocks to wrap in PDF exports:

  • white-space: pre-wrap for <pre> and <code> elements
  • overflow-wrap: break-word to prevent overflow
  • Special handling for tables containing code

Based on the approach from PR #1349 by @falkorichter.

schuyler avatar Nov 28 '25 02:11 schuyler