diff --git a/.changeset/wild-phones-work.md b/.changeset/wild-phones-work.md new file mode 100644 index 000000000..a55eecadf --- /dev/null +++ b/.changeset/wild-phones-work.md @@ -0,0 +1,6 @@ +--- +'astro': patch +'@astrojs/markdown-remark': patch +--- + +Remove extra newlines around Markdown components diff --git a/packages/astro/test/astro-markdown.test.js b/packages/astro/test/astro-markdown.test.js index 1ef8a4b9a..dd40bc071 100644 --- a/packages/astro/test/astro-markdown.test.js +++ b/packages/astro/test/astro-markdown.test.js @@ -291,12 +291,16 @@ describe('Astro Markdown', () => { expect(slots.find('> .fragmentSlot > div').text()).to.contain('1:'); expect(slots.find('> .fragmentSlot > div + p').text()).to.contain('2:'); expect(slots.find('> .pSlot > p[title="hello"]').text()).to.contain('3:'); - expect(slots.find('> .defaultSlot').text().replace(/\s+/g, ' ')).to.equal( - ` - 4: Div in default slot - 5: Paragraph in fragment in default slot - 6: Regular text in default slot - `.replace(/\s+/g, ' ') + expect(slots.find('> .defaultSlot').html()).to.match( + new RegExp( + `
5: Paragraph in fragment in default slot
` + + // Optional whitespace due to the line breaks between components + `[\s\n]*` + + `6: Regular text in default slot` + ) ); const nestedSlots = $('article').eq(1); 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