mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-28 07:03:17 +08:00
fix: Handle spaces after newline
This commit is contained in:
parent
644199d0d0
commit
d71fe28a35
@ -295,5 +295,15 @@ test('markdownToHTML - no auto wrapping', () => {
|
|||||||
you do?`,
|
you do?`,
|
||||||
{ markdownAutoWrap: false }
|
{ markdownAutoWrap: false }
|
||||||
)
|
)
|
||||||
).toMatchInlineSnapshot(`"<p>Hello, how do<br/> you do?</p>"`);
|
).toMatchInlineSnapshot(`"<p>Hello, how do<br/>you do?</p>"`);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('markdownToHTML - auto wrapping', () => {
|
||||||
|
expect(
|
||||||
|
markdownToHTML(
|
||||||
|
`Hello, how do
|
||||||
|
you do?`,
|
||||||
|
{ markdownAutoWrap: true }
|
||||||
|
)
|
||||||
|
).toMatchInlineSnapshot(`"<p>Hello, how do<br/>you do?</p>"`);
|
||||||
});
|
});
|
||||||
|
@ -66,9 +66,9 @@ export function markdownToHTML(markdown: string, { markdownAutoWrap }: MermaidCo
|
|||||||
function output(node: Token): string {
|
function output(node: Token): string {
|
||||||
if (node.type === 'text') {
|
if (node.type === 'text') {
|
||||||
if (markdownAutoWrap === false) {
|
if (markdownAutoWrap === false) {
|
||||||
return node.text.replace(/\n/g, '<br/>').replace(/ /g, ' ');
|
return node.text.replace(/\n */g, '<br/>').replace(/ /g, ' ');
|
||||||
}
|
}
|
||||||
return node.text.replace(/\n/g, '<br/>');
|
return node.text.replace(/\n */g, '<br/>');
|
||||||
} else if (node.type === 'strong') {
|
} else if (node.type === 'strong') {
|
||||||
return `<strong>${node.tokens?.map(output).join('')}</strong>`;
|
return `<strong>${node.tokens?.map(output).join('')}</strong>`;
|
||||||
} else if (node.type === 'em') {
|
} else if (node.type === 'em') {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user