fb84622af0
* deps: markdown-remark * wip: heading-ids function * chore: add `@astrojs/markdoc` to external * feat: `headings` support * fix: allow `render` config on headings * fix: nonexistent `userConfig` * test: headings, toc, astro component render * docs: README * chore: changeset * refactor: expose Markdoc helpers from runtime * fix: bad named exports (commonjsssss) * refactor: defaultNodes -> nodes * deps: github-slugger * fix: reset slugger cache on each render * fix: bad astroNodes import * docs: explain headingSlugger export * docs: add back double stringify comment * chore: bump to minor for internal exports change
29 lines
1 KiB
TypeScript
29 lines
1 KiB
TypeScript
import type { Config as MarkdocConfig } from '@markdoc/markdoc';
|
|
import Markdoc from '@markdoc/markdoc';
|
|
//@ts-expect-error Cannot find module 'astro:assets' or its corresponding type declarations.
|
|
import { Image } from 'astro:assets';
|
|
|
|
// Separate module to only import `astro:assets` when
|
|
// `experimental.assets` flag is set in a project.
|
|
// TODO: merge with `./runtime.ts` when `experimental.assets` is baselined.
|
|
export const experimentalAssetsConfig: MarkdocConfig = {
|
|
nodes: {
|
|
image: {
|
|
attributes: {
|
|
...Markdoc.nodes.image.attributes,
|
|
__optimizedSrc: { type: 'Object' },
|
|
},
|
|
transform(node, config) {
|
|
const attributes = node.transformAttributes(config);
|
|
const children = node.transformChildren(config);
|
|
|
|
if (node.type === 'image' && '__optimizedSrc' in node.attributes) {
|
|
const { __optimizedSrc, ...rest } = node.attributes;
|
|
return new Markdoc.Tag(Image, { ...rest, src: __optimizedSrc }, children);
|
|
} else {
|
|
return new Markdoc.Tag('img', attributes, children);
|
|
}
|
|
},
|
|
},
|
|
},
|
|
};
|