fix: revert JSX expression hack (temporary!)
This commit is contained in:
parent
f200ddadbc
commit
b78883fca1
3 changed files with 10 additions and 14 deletions
|
@ -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}';` : ''}
|
||||
|
|
|
@ -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}</${node.tagName}>`;
|
||||
} 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 });
|
||||
|
|
|
@ -14,7 +14,10 @@ describe('expressions', () => {
|
|||
chai.expect(code).to.equal(`<Fragment>\n<Component>{a}</Component>\n</Fragment>`);
|
||||
});
|
||||
|
||||
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(`<h1 id={$$slug(\`\${frontmatter.title}\`)}>{frontmatter.title}</h1>`);
|
||||
});
|
||||
|
||||
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(`<h1 id={$$slug(\`Hello \${frontmatter.name}\`)}>Hello {frontmatter.name}</h1>`);
|
||||
});
|
||||
|
||||
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 <span>{frontmatter.name}</span>`, {});
|
||||
|
||||
chai
|
||||
|
|
Loading…
Reference in a new issue