diff --git a/README.md b/README.md index 4058f2a..8173dd6 100644 --- a/README.md +++ b/README.md @@ -36,9 +36,9 @@ This plugin implements all the syntaxes documented in [Comark Syntax](https://co - [x] [Block Component](https://comark.dev/syntax/markdown#block-components) - [x] [Nesting](https://comark.dev/syntax/markdown#nested-components) - - [x] [YAML Props](https://comark.dev/syntax/markdown#yaml-props) - - [x] [Slots](https://comark.dev/syntax/markdown#component-slots) -- [x] [Inline Components](https://comark.dev/syntax/markdown#inline-components) + - [x] [YAML Props](https://comark.dev/syntax/components#yaml-props-use-cases) + - [x] [Slots](https://comark.dev/syntax/components#component-slots) +- [x] [Inline Components](https://comark.dev/syntax/components#inline-components) - [x] [Inline Props](https://comark.dev/syntax/markdown#attributes) - [x] [Span](https://comark.dev/syntax/markdown#span-text) - ~~Frontmatter~~. Frontmatter is not built-in in this plugin, we recommend using [`@mdit-vue/plugin-frontmatter`](https://github.com/mdit-vue/mdit-vue/tree/main/packages/plugin-frontmatter) if you want to use this plugin outside of Comark package, diff --git a/src/syntax/block.ts b/src/syntax/block.ts index 757a444..f8e05ca 100644 --- a/src/syntax/block.ts +++ b/src/syntax/block.ts @@ -7,6 +7,13 @@ export const MarkdownItMdcBlock: MarkdownIt.PluginSimple = (md) => { const min_markers = 2 const marker_str = ':' const marker_char = marker_str.charCodeAt(0) + const blockYamlLines: Record = { + '---': '---', + '```yaml [props]': '```', + '~~~yaml [props]': '~~~', + '```yml [props]': '```', + '~~~yml [props]': '~~~', + } md.block.ruler.before( 'fence', @@ -290,7 +297,10 @@ export const MarkdownItMdcBlock: MarkdownIt.PluginSimple = (md) => { const start = state.bMarks[startLine] + state.tShift[startLine] const end = state.eMarks[startLine] - if (state.src.slice(start, end) !== '---') + const line = state.src.slice(start, end) + const blockAttributesClosingFence = blockYamlLines[line] || '' + + if (!blockAttributesClosingFence) return false let lineEnd = startLine + 1 @@ -298,7 +308,7 @@ export const MarkdownItMdcBlock: MarkdownIt.PluginSimple = (md) => { let found = false while (lineEnd < endLine) { const line = state.src.slice(state.bMarks[lineEnd] + state.tShift[startLine], state.eMarks[lineEnd]) - if (line === '---') { + if (line === blockAttributesClosingFence) { found = true break } diff --git a/test/input/10.blocks-yaml.md b/test/input/10.blocks-yaml.md index cfa63ea..554cc60 100644 --- a/test/input/10.blocks-yaml.md +++ b/test/input/10.blocks-yaml.md @@ -17,3 +17,51 @@ Foo Hello **World** :: + +::icon-card +```yaml [props] +icon: IconNuxt +description: Harness the full power of Nuxt and the Nuxt ecosystem. +title: Nuxt Architecture. +:items: '[1, 2, []]' +:data: + foo: bar + baz: qux +``` + +Foo + +#slot + +Hello **World** +:: + +::icon-card + +```yaml [props] +icon: IconNuxt +description: Harness the full power of Nuxt and the Nuxt ecosystem. +title: Nuxt Architecture. +:items: '[1, 2, []]' +:data: + foo: bar + baz: qux +``` + +Foo + +#slot + +Hello **World** +:: + +::landing-hero +~~~yml [props] +demoMarkdown: |- + ```ts [example.ts] + import { parse } from 'comark' + + const tree = await parse('# Hello **World**') + ``` +~~~ +:: diff --git a/test/output/10.blocks-yaml.html b/test/output/10.blocks-yaml.html index b31a4ee..6165ccb 100644 --- a/test/output/10.blocks-yaml.html +++ b/test/output/10.blocks-yaml.html @@ -11,3 +11,34 @@

Hello World

Hello World

+ +

Foo

+ +
+ +

Foo

+ +
+