From b78883fca14dabca870af39879af3079b76b0ecb Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Wed, 25 May 2022 18:28:16 -0400 Subject: [PATCH] fix: revert JSX expression hack (temporary!) --- packages/astro/src/vite-plugin-markdown/index.ts | 1 - .../markdown/remark/src/rehype-collect-headers.ts | 14 ++++---------- packages/markdown/remark/test/expressions.test.js | 9 ++++++--- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/packages/astro/src/vite-plugin-markdown/index.ts b/packages/astro/src/vite-plugin-markdown/index.ts index b3c916bcd..716af14fd 100644 --- a/packages/astro/src/vite-plugin-markdown/index.ts +++ b/packages/astro/src/vite-plugin-markdown/index.ts @@ -138,7 +138,6 @@ export default function markdown({ config }: AstroPluginOptions): Plugin { const { layout = '', components = '', setup = '', ...content } = frontmatter; content.astro = metadata; const prelude = `--- -import { slug as $$slug } from '@astrojs/markdown-remark'; ${layout ? `import Layout from '${layout}';` : ''} ${components ? `import * from '${components}';` : ''} ${hasInjectedScript ? `import '${PAGE_SSR_SCRIPT_ID}';` : ''} diff --git a/packages/markdown/remark/src/rehype-collect-headers.ts b/packages/markdown/remark/src/rehype-collect-headers.ts index 426b782a3..f8c071c8b 100644 --- a/packages/markdown/remark/src/rehype-collect-headers.ts +++ b/packages/markdown/remark/src/rehype-collect-headers.ts @@ -40,16 +40,10 @@ export default function createCollectHeaders() { node.properties = node.properties || {}; if (typeof node.properties.id !== 'string') { - if (isJSX) { - // HACK: for ids that have JSX content, use $$slug helper to generate slug at runtime - node.properties.id = `$$slug(\`${text.replace(/\{/g, '${')}\`)`; - (node as any).type = 'raw'; - ( - node as any - ).value = `<${node.tagName} id={${node.properties.id}}>${raw}`; - } else { - node.properties.id = slugger.slug(text); - } + node.properties.id = slugger.slug(text); + // TODO: restore fix for IDs from JSX expressions + // Reverted due to https://github.com/withastro/astro/issues/3443 + // See https://github.com/withastro/astro/pull/3410/files#diff-f0cc828ac662d9b8d48cbb9cb147883e319cdd8fa24f24ef401960520f1436caR44-R51 } headers.push({ depth, slug: node.properties.id, text }); diff --git a/packages/markdown/remark/test/expressions.test.js b/packages/markdown/remark/test/expressions.test.js index 17674c543..ba32b0c7d 100644 --- a/packages/markdown/remark/test/expressions.test.js +++ b/packages/markdown/remark/test/expressions.test.js @@ -14,7 +14,10 @@ describe('expressions', () => { chai.expect(code).to.equal(`\n{a}\n`); }); - it('should be able to serialize expression inside markdown', async () => { + // TODO: remove skips when IDs-by-JSX-expressions are restored + // Reverted due to https://github.com/withastro/astro/issues/3443 + // See https://github.com/withastro/astro/pull/3410/files#diff-f0cc828ac662d9b8d48cbb9cb147883e319cdd8fa24f24ef401960520f1436caR44-R51 + it.skip('should be able to serialize expression inside markdown', async () => { const { code } = await renderMarkdown(`# {frontmatter.title}`, {}); chai @@ -22,7 +25,7 @@ describe('expressions', () => { .to.equal(`

{frontmatter.title}

`); }); - it('should be able to serialize complex expression inside markdown', async () => { + it.skip('should be able to serialize complex expression inside markdown', async () => { const { code } = await renderMarkdown(`# Hello {frontmatter.name}`, {}); chai @@ -30,7 +33,7 @@ describe('expressions', () => { .to.equal(`

Hello {frontmatter.name}

`); }); - it('should be able to serialize complex expression with markup inside markdown', async () => { + it.skip('should be able to serialize complex expression with markup inside markdown', async () => { const { code } = await renderMarkdown(`# Hello {frontmatter.name}`, {}); chai