Repository navigation
Replies: 1 comment
|
If "no wrap after a heading" means never leave a heading alone at the bottom of a page, react-pdf has a prop built for that: const styles = StyleSheet.create({
// put the spacing ABOVE blocks, not below them (explained further down)
heading: { fontSize: 16, fontWeight: 'bold', marginTop: 18 },
paragraph: { marginTop: 6, lineHeight: 1.4 },
});
// in your markdown -> react-pdf mapper
case 'heading':
return <Text style={styles.heading} minPresenceAhead={60}>{node.text}</Text>;
case 'paragraph':
return <Text style={styles.paragraph}>{node.text}</Text>;Choose the value so that it covers about two lines of your body text. The heading and the content after it should be siblings, i.e. children of the same parent, which a flat markdown-to-elements mapping gives you anyway. One trap I ran into while testing this. With the spacing written as The other common suggestion, and why I would not use it for markdown. You can wrap the heading and the first block in How I tested it: a markdown-like document with 12 sections (a heading, then three paragraphs of different lengths), with 0–39 lead-in lines before it so that the headings fall at every possible position on the page. That gives 40 layouts per variant. I counted pages whose last line was a heading using
Environment: @react-pdf/renderer 4.9.0 (@react-pdf/layout 5.2.0), React 19.3, Node 26, checked with poppler's |
Uh oh!
There was an error while loading. Please reload this page.
Hi everyone!
I'm dynamically rendering larger text files from a markdown source.
How can I force no wrap after a heading component?
All reactions