Skip to content

Commit

Permalink
fix: codeblock yaml data section
Browse files Browse the repository at this point in the history
  • Loading branch information
farnabaz committed Nov 15, 2024
1 parent fcb2ff3 commit b74b764
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"dev:prepare": "nuxi prepare playground",
"generate": "nuxi generate playground",
"lint": "eslint --ext .js,.ts,.vue .",
"test": "pnpm lint && vitest run",
"test": "vitest run",
"prepack": "pnpm build",
"release": "release-it"
},
Expand Down
14 changes: 8 additions & 6 deletions src/from-markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@ export default (opts: RemarkMDCOptions = {}) => {
const canContainEols = ['textComponent']

const experimentalCodeBlockYamlProps = (node: Container) => {
const firstSection = node.children[0] as Container
if (
node.children?.length &&
node.children[0].type === 'code' &&
node.children[0].lang === 'yaml' &&
node.children[0].meta === '[props]'
firstSection &&
firstSection.children?.length &&
firstSection.children[0].type === 'code' &&
firstSection.children[0].lang === 'yaml' &&
firstSection.children[0].meta === '[props]'
) {
node.rawData = node.children[0].value as string
node.rawData = firstSection.children[0].value as string
node.mdc = node.mdc || {}
node.mdc.codeBlockProps = true
node.children!.splice(0, 1)
firstSection.children!.splice(0, 1)
}
}
const experimentalAutoUnwrap = (node: Container) => {
Expand Down
24 changes: 16 additions & 8 deletions test/__snapshots__/codeblock-props.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ exports[`basic > YamlProps 1`] = `
],
"key": "value",
},
"mdc": {
"codeBlockProps": true,
},
"name": "with-frontmatter-yaml",
"position": {
"end": {
Expand All @@ -38,8 +41,7 @@ exports[`basic > YamlProps 1`] = `
"rawData": "array:
- item
- itemKey: value
key: value
---",
key: value",
"type": "containerComponent",
},
],
Expand Down Expand Up @@ -146,6 +148,9 @@ exports[`basic > nested-component-yamlProps 1`] = `
"fmAttributes": {
"key": "value",
},
"mdc": {
"codeBlockProps": true,
},
"name": "hello",
"position": {
"end": {
Expand All @@ -159,8 +164,7 @@ exports[`basic > nested-component-yamlProps 1`] = `
"offset": 165,
},
},
"rawData": "key: value
---",
"rawData": "key: value",
"type": "containerComponent",
},
],
Expand Down Expand Up @@ -202,6 +206,9 @@ exports[`basic > nested-component-yamlProps 1`] = `
],
"key": "value",
},
"mdc": {
"codeBlockProps": true,
},
"name": "with-frontmatter-and-nested-component-yaml",
"position": {
"end": {
Expand All @@ -218,8 +225,7 @@ exports[`basic > nested-component-yamlProps 1`] = `
"rawData": "array:
- item
- itemKey: value
key: value
---",
key: value",
"type": "containerComponent",
},
],
Expand Down Expand Up @@ -521,6 +527,9 @@ exports[`basic > yamlProps1 1`] = `
"subkey2": "value",
},
},
"mdc": {
"codeBlockProps": true,
},
"name": "with-frontmatter-yaml1",
"position": {
"end": {
Expand All @@ -540,8 +549,7 @@ key2:
subkey2: value
array:
- item
- itemKey: value
---",
- itemKey: value",
"type": "containerComponent",
},
],
Expand Down

0 comments on commit b74b764

Please sign in to comment.