feat(markdown/import): remove space in admonition

This commit is contained in:
Elian Doran 2025-03-15 22:39:33 +02:00
parent 40d233dccc
commit 3c93fdc202
No known key found for this signature in database
2 changed files with 4 additions and 4 deletions

View File

@ -99,7 +99,7 @@ second line 2</code></pre><ul><li>Hello</li><li>world</li></ul><ol><li>Hello</li
After`; After`;
const expected = `<p>Before</p><aside class="admonition note"><p>This is a note.</p></aside><aside class="admonition tip"><p>This is a tip.</p></aside><aside class="admonition important"><p>This is a very important information.</p></aside><aside class="admonition caution"><p>This is a caution.</p></aside><aside class="admonition warning"><h2>Title goes here</h2><p>This is a warning.</p></aside><p>After</p>`; const expected = `<p>Before</p><aside class="admonition note"><p>This is a note.</p></aside><aside class="admonition tip"><p>This is a tip.</p></aside><aside class="admonition important"><p>This is a very important information.</p></aside><aside class="admonition caution"><p>This is a caution.</p></aside><aside class="admonition warning"><h2>Title goes here</h2><p>This is a warning.</p></aside><p>After</p>`;
expect(markdownService.renderToHtml(input, "Title")).toBe(expected); expect(markdownService.renderToHtml(input, "Title")).toStrictEqual(expected);
}); });
}); });

View File

@ -43,14 +43,14 @@ class CustomMarkdownRenderer extends Renderer {
if (ADMONITION_TYPE_MAPPINGS[type]) { if (ADMONITION_TYPE_MAPPINGS[type]) {
const bodyWithoutHeader = body const bodyWithoutHeader = body
.replace(/^<p>\[\!([A-Z]+)\]/, "<p>") .replace(/^<p>\[\!([A-Z]+)\]\s*/, "<p>")
.replace(/^<p><\/p>/, ""); // Having a heading will generate an empty paragraph that we need to remove. .replace(/^<p><\/p>/, ""); // Having a heading will generate an empty paragraph that we need to remove.
return `<aside class="admonition ${type}">\n${bodyWithoutHeader}</aside>\n`; return `<aside class="admonition ${type}">${bodyWithoutHeader.trim()}</aside>`;
} }
} }
return `<blockquote>\n${body}</blockquote>\n`; return `<blockquote>${body}</blockquote>`;
} }
} }