Render soft line breaks in paragraphs with buttons (RND-12359) (#4724)

This commit is contained in:
Nolann B.
2026-10-29 08:56:09 +01:00
committed by GitHub
parent be658e1b32
commit 38f60f2633
2 changed files with 15 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"gitbook": patch
---
Render soft line breaks in paragraphs that contain buttons.
@@ -38,12 +38,21 @@ export function Text(props: { text: DocumentText }) {
{children}
</Mark>
);
}, leaf.text)}
}, withSoftBreaks(leaf.text))}
</React.Fragment>
);
});
}
// Paragraphs with buttons are flex containers, where a `\n` alone can't move the next items to a new line.
function withSoftBreaks(text: string): React.ReactNode {
const lines = text.split('\n');
// Keep `\n` in the same text node as a preceding `\r`: split apart, the HTML parser reads the lone `\r` as an extra line.
return lines.flatMap((line, index) =>
index < lines.length - 1 ? [`${line}\n`, <span key={index} className="basis-full" />] : line
);
}
const MARK_STYLES = {
bold: Bold,
italic: Italic,