diff options
author | 2022-06-17 18:52:37 +0200 | |
---|---|---|
committer | 2022-06-17 11:52:37 -0500 | |
commit | 05aa72442cd4512b94abdb39623e8caa2c1839b0 (patch) | |
tree | 4960b1a5afff0b5cd9a9a2670bf4056ea52bf7d4 /packages/markdown | |
parent | 1a2f321e3483a417671ad13e168928bb4e4a6230 (diff) | |
download | astro-05aa72442cd4512b94abdb39623e8caa2c1839b0.tar.gz astro-05aa72442cd4512b94abdb39623e8caa2c1839b0.tar.zst astro-05aa72442cd4512b94abdb39623e8caa2c1839b0.zip |
Remove extra newlines around Markdown components (#3620)
Diffstat (limited to 'packages/markdown')
4 files changed, 7 insertions, 7 deletions
diff --git a/packages/markdown/remark/src/rehype-collect-headers.ts b/packages/markdown/remark/src/rehype-collect-headers.ts index 9a64d59c8..76cb5740c 100644 --- a/packages/markdown/remark/src/rehype-collect-headers.ts +++ b/packages/markdown/remark/src/rehype-collect-headers.ts @@ -25,7 +25,7 @@ export default function createCollectHeaders() { return; } if (child.type === 'raw') { - if (child.value.startsWith('\n<') || child.value.endsWith('>\n')) { + if (child.value.match(/^\n?<.*>\n?$/)) { return; } } diff --git a/packages/markdown/remark/src/rehype-jsx.ts b/packages/markdown/remark/src/rehype-jsx.ts index a6761124c..7082997e2 100644 --- a/packages/markdown/remark/src/rehype-jsx.ts +++ b/packages/markdown/remark/src/rehype-jsx.ts @@ -53,11 +53,11 @@ export default function rehypeJsx(): ReturnType<RehypePlugin> { // wrapped by raw opening and closing tags const openingTag = { type: 'raw', - value: `\n<${node.name}${attrs}>`, + value: `<${node.name}${attrs}>`, }; const closingTag = { type: 'raw', - value: `</${node.name}>\n`, + value: `</${node.name}>`, }; parent.children.splice(index, 1, openingTag, ...node.children, closingTag); }); diff --git a/packages/markdown/remark/test/components.test.js b/packages/markdown/remark/test/components.test.js index ca0a3fdb4..4e06d7301 100644 --- a/packages/markdown/remark/test/components.test.js +++ b/packages/markdown/remark/test/components.test.js @@ -49,7 +49,7 @@ describe('components', () => { it('should normalize children', async () => { const { code } = await renderMarkdown(`<Component bool={true}>Hello world!</Component>`, {}); - chai.expect(code).to.equal(`\n<Component bool={true}>Hello world!</Component>\n`); + chai.expect(code).to.equal(`<Component bool={true}>Hello world!</Component>`); }); it('should be able to nest components', async () => { @@ -60,7 +60,7 @@ describe('components', () => { chai .expect(code) - .to.equal(`\n<Component bool={true}>\n<Component>Hello world!</Component>\n</Component>\n`); + .to.equal(`<Component bool={true}><Component>Hello world!</Component></Component>`); }); it('should allow markdown without many spaces', async () => { @@ -71,6 +71,6 @@ describe('components', () => { {} ); - chai.expect(code).to.equal(`\n<Component><h1 id="hello-world">Hello world!</h1></Component>\n`); + chai.expect(code).to.equal(`<Component><h1 id="hello-world">Hello world!</h1></Component>`); }); }); diff --git a/packages/markdown/remark/test/expressions.test.js b/packages/markdown/remark/test/expressions.test.js index ba28d9c8e..2963ff7f1 100644 --- a/packages/markdown/remark/test/expressions.test.js +++ b/packages/markdown/remark/test/expressions.test.js @@ -11,7 +11,7 @@ describe('expressions', () => { it('should be able to serialize expression inside component', async () => { const { code } = await renderMarkdown(`<Component>{a}</Component>`, {}); - chai.expect(code).to.equal(`\n<Component>{a}</Component>\n`); + chai.expect(code).to.equal(`<Component>{a}</Component>`); }); it('should be able to serialize expression inside markdown', async () => { |