mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-11-01 01:40:10 +00:00
Render soft line breaks in paragraphs with buttons (RND-12359) (#4724)
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user