Fix: Hyphens breaking Markdoc tags (#7599)
* fix: handle hyphens in tag names * test: add hyphen in test suite * chore: changeset
This commit is contained in:
parent
6fd9f4a160
commit
8df6a423c5
4 changed files with 18 additions and 6 deletions
5
.changeset/witty-pandas-behave.md
Normal file
5
.changeset/witty-pandas-behave.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@astrojs/markdoc': patch
|
||||
---
|
||||
|
||||
Fix hyphens in Markdoc tag names causing build failures
|
|
@ -225,8 +225,8 @@ function getStringifiedImports(
|
|||
let stringifiedComponentImports = '';
|
||||
for (const [key, config] of Object.entries(componentConfigMap)) {
|
||||
const importName = config.namedExport
|
||||
? `{ ${config.namedExport} as ${componentNamePrefix + key} }`
|
||||
: componentNamePrefix + key;
|
||||
? `{ ${config.namedExport} as ${componentNamePrefix + toImportName(key)} }`
|
||||
: componentNamePrefix + toImportName(key);
|
||||
const resolvedPath =
|
||||
config.type === 'local' ? new URL(config.path, root).pathname : config.path;
|
||||
|
||||
|
@ -235,6 +235,11 @@ function getStringifiedImports(
|
|||
return stringifiedComponentImports;
|
||||
}
|
||||
|
||||
function toImportName(unsafeName: string) {
|
||||
// TODO: more checks that name is a safe JS variable name
|
||||
return unsafeName.replace('-', '_');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a stringified map from tag / node name to component import name.
|
||||
* This uses the same `componentNamePrefix` used by `getStringifiedImports()`.
|
||||
|
@ -247,7 +252,9 @@ function getStringifiedMap(
|
|||
) {
|
||||
let stringifiedComponentMap = '{';
|
||||
for (const key in componentConfigMap) {
|
||||
stringifiedComponentMap += `${key}: ${componentNamePrefix + key},\n`;
|
||||
stringifiedComponentMap += `${JSON.stringify(key)}: ${
|
||||
componentNamePrefix + toImportName(key)
|
||||
},\n`;
|
||||
}
|
||||
stringifiedComponentMap += '}';
|
||||
return stringifiedComponentMap;
|
||||
|
|
|
@ -11,7 +11,7 @@ export default defineMarkdocConfig({
|
|||
},
|
||||
},
|
||||
tags: {
|
||||
mq: {
|
||||
'marquee-element': {
|
||||
render: component('./src/components/CustomMarquee.astro'),
|
||||
attributes: {
|
||||
direction: {
|
||||
|
|
|
@ -6,9 +6,9 @@ title: Post with components
|
|||
|
||||
This uses a custom marquee component with a shortcode:
|
||||
|
||||
{% mq direction="right" %}
|
||||
{% marquee-element direction="right" %}
|
||||
I'm a marquee too!
|
||||
{% /mq %}
|
||||
{% /marquee-element %}
|
||||
|
||||
And a code component for code blocks:
|
||||
|
||||
|
|
Loading…
Reference in a new issue