diff --git a/examples/with-markdoc/src/components/Marquee.astro b/examples/with-markdoc/src/components/Marquee.astro new file mode 100644 index 000000000000..3e35d1566192 --- /dev/null +++ b/examples/with-markdoc/src/components/Marquee.astro @@ -0,0 +1,7 @@ + + + diff --git a/examples/with-markdoc/src/components/test.mdoc b/examples/with-markdoc/src/components/test.mdoc index 33ab897d26d3..60e77b1c4e29 100644 --- a/examples/with-markdoc/src/components/test.mdoc +++ b/examples/with-markdoc/src/components/test.mdoc @@ -1,6 +1,6 @@ # Hey there -This is a test file? +Look at this table! Built-in to Markdoc, neat. {% table %} * Heading 1 @@ -15,14 +15,12 @@ This is a test file? {% if $shouldMarquee %} {% mq direction="right" %} -Testing! +Im a marquee! {% /mq %} {% /if %} {% link href=$href %}Link{% /link %} -Some `inline code` should help - ```js const testing = true; function further() { diff --git a/examples/with-markdoc/src/markdoc.config.ts b/examples/with-markdoc/src/markdoc.config.ts new file mode 100644 index 000000000000..2d6e3d6cb099 --- /dev/null +++ b/examples/with-markdoc/src/markdoc.config.ts @@ -0,0 +1,30 @@ +export default { + transform: { + variables: { + shouldMarquee: true, + href: 'https://astro.build', + }, + tags: { + mq: { + render: 'marquee', + attributes: { + direction: { + type: String, + default: 'left', + matches: ['left', 'right', 'up', 'down'], + errorLevel: 'critical', + }, + }, + }, + link: { + render: 'a', + attributes: { + href: { + type: String, + required: true, + }, + }, + }, + }, + }, +}; diff --git a/examples/with-markdoc/src/pages/index.astro b/examples/with-markdoc/src/pages/index.astro index 59a5ef7bc463..6b423317c66b 100644 --- a/examples/with-markdoc/src/pages/index.astro +++ b/examples/with-markdoc/src/pages/index.astro @@ -1,52 +1,10 @@ --- -import { body } from '../components/test.mdoc'; import { Markdoc } from '@astrojs/markdoc'; import RenderMarkdoc from '../renderer/RenderMarkdoc.astro'; -import RedP from '../components/RedP.astro'; -import { Code } from 'astro/components'; -import { Tag } from '@markdoc/markdoc'; -import { ComponentRenderer } from '../renderer/astroNode'; - -const parsed = Markdoc.parse(body); -const content = Markdoc.transform(parsed, { - variables: { - shouldMarquee: true, - href: 'https://astro.build', - }, - tags: { - mq: { - render: 'marquee', - attributes: { - direction: { - type: String, - default: 'left', - matches: ['left', 'right', 'up', 'down'], - errorLevel: 'critical', - }, - }, - }, - link: { - render: 'a', - attributes: { - href: { - type: String, - required: true, - }, - }, - }, - }, -}); -const code: ComponentRenderer = { - component: Code, - props({ attributes, getTreeNode }) { - return { - ...attributes, - lang: attributes.lang ?? attributes['data-language'], - code: attributes.code ?? Markdoc.renderers.html(getTreeNode().children), - }; - }, -}; +import { getTransformed } from '../components/test.mdoc'; +import { Code } from 'astro/components'; +import Marquee from '../components/Marquee.astro'; --- @@ -61,11 +19,19 @@ const code: ComponentRenderer = {