Skip to content

Commit

Permalink
Merge branch 'main' into docs/amend-changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony Sullivan authored Jun 17, 2022
2 parents a0a2083 + 5693756 commit 3f615a7
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 14 deletions.
6 changes: 6 additions & 0 deletions .changeset/wild-phones-work.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'astro': patch
'@astrojs/markdown-remark': patch
---

Remove extra newlines around Markdown components
16 changes: 10 additions & 6 deletions packages/astro/test/astro-markdown.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
`<div>4: Div in default slot</div>` +
// Optional extra paragraph due to the line breaks between components
`(<p></p>)?` +
`<p>5: Paragraph in fragment in default slot</p>` +
// Optional whitespace due to the line breaks between components
`[\s\n]*` +
`6: Regular text in default slot`
)
);

const nestedSlots = $('article').eq(1);
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/netlify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"dev": "astro-scripts dev \"src/**/*.ts\"",
"test-fn": "mocha --exit --timeout 20000 test/functions/",
"test-edge": "deno test --allow-run --allow-read --allow-net ./test/edge-functions/",
"test": "npm run test-fn && npm run test-edge"
"test": "npm run test-fn"
},
"dependencies": {
"@astrojs/webapi": "^0.12.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/markdown/remark/src/rehype-collect-headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/markdown/remark/src/rehype-jsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
6 changes: 3 additions & 3 deletions packages/markdown/remark/test/components.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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>`);
});
});
2 changes: 1 addition & 1 deletion packages/markdown/remark/test/expressions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit 3f615a7

Please sign in to comment.