@valkyrianlabs/payload-markdown 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +222 -0
- package/dist/blocks/MarkdownBlock/Component.d.ts +2 -0
- package/dist/blocks/MarkdownBlock/Component.js +13 -0
- package/dist/blocks/MarkdownBlock/Component.js.map +1 -0
- package/dist/blocks/MarkdownBlock/config.d.ts +2 -0
- package/dist/blocks/MarkdownBlock/config.js +20 -0
- package/dist/blocks/MarkdownBlock/config.js.map +1 -0
- package/dist/blocks/MarkdownBlock/types.d.js +3 -0
- package/dist/blocks/MarkdownBlock/types.d.js.map +1 -0
- package/dist/components/MarkdownRenderer/Component.client.d.ts +5 -0
- package/dist/components/MarkdownRenderer/Component.client.js +163 -0
- package/dist/components/MarkdownRenderer/Component.client.js.map +1 -0
- package/dist/components/MarkdownRenderer/Component.d.ts +3 -0
- package/dist/components/MarkdownRenderer/Component.js +87 -0
- package/dist/components/MarkdownRenderer/Component.js.map +1 -0
- package/dist/components/MarkdownRenderer/index.css +69 -0
- package/dist/components/MarkdownRenderer/index.module.css +45 -0
- package/dist/components/MarkdownRenderer/index.module.scss +43 -0
- package/dist/components/MarkdownRenderer/index.scss +83 -0
- package/dist/components/MarkdownRenderer/types.d.js +5 -0
- package/dist/components/MarkdownRenderer/types.d.js.map +1 -0
- package/dist/core/codeConfig.d.ts +6 -0
- package/dist/core/codeConfig.js +45 -0
- package/dist/core/codeConfig.js.map +1 -0
- package/dist/core/codeToHtml.d.ts +5 -0
- package/dist/core/codeToHtml.js +180 -0
- package/dist/core/codeToHtml.js.map +1 -0
- package/dist/core/plugins/rehypeApplyLayoutClasses.d.ts +4 -0
- package/dist/core/plugins/rehypeApplyLayoutClasses.js +72 -0
- package/dist/core/plugins/rehypeApplyLayoutClasses.js.map +1 -0
- package/dist/core/plugins/rehypeStripAuthoredInlineStyles.d.ts +3 -0
- package/dist/core/plugins/rehypeStripAuthoredInlineStyles.js +17 -0
- package/dist/core/plugins/rehypeStripAuthoredInlineStyles.js.map +1 -0
- package/dist/core/plugins/remarkCompileLayouts.d.ts +3 -0
- package/dist/core/plugins/remarkCompileLayouts.js +169 -0
- package/dist/core/plugins/remarkCompileLayouts.js.map +1 -0
- package/dist/core/plugins/remarkHeadingAnchorsAndToc.d.ts +3 -0
- package/dist/core/plugins/remarkHeadingAnchorsAndToc.js +68 -0
- package/dist/core/plugins/remarkHeadingAnchorsAndToc.js.map +1 -0
- package/dist/core/plugins/remarkLayoutDirectives.d.ts +3 -0
- package/dist/core/plugins/remarkLayoutDirectives.js +26 -0
- package/dist/core/plugins/remarkLayoutDirectives.js.map +1 -0
- package/dist/core/plugins/remarkLayoutSentinels.d.ts +3 -0
- package/dist/core/plugins/remarkLayoutSentinels.js +184 -0
- package/dist/core/plugins/remarkLayoutSentinels.js.map +1 -0
- package/dist/core/plugins/remarkLiftLayoutDirectives.d.ts +3 -0
- package/dist/core/plugins/remarkLiftLayoutDirectives.js +93 -0
- package/dist/core/plugins/remarkLiftLayoutDirectives.js.map +1 -0
- package/dist/core/plugins/remarkNormalizeLayoutSyntax.d.ts +3 -0
- package/dist/core/plugins/remarkValidateDirectiveThemes.d.ts +4 -0
- package/dist/core/plugins/remarkValidateDirectiveThemes.js +28 -0
- package/dist/core/plugins/remarkValidateDirectiveThemes.js.map +1 -0
- package/dist/core/renderMarkdown.d.ts +2 -0
- package/dist/core/renderMarkdown.js +270 -0
- package/dist/core/renderMarkdown.js.map +1 -0
- package/dist/core/types.d.js +7 -0
- package/dist/core/types.d.js.map +1 -0
- package/dist/core/types.d.ts +238 -0
- package/dist/core/types.js +5 -0
- package/dist/core/types.js.map +1 -0
- package/dist/directives/attributes.d.ts +14 -0
- package/dist/directives/attributes.js +121 -0
- package/dist/directives/attributes.js.map +1 -0
- package/dist/directives/definitions/callout.d.ts +6 -0
- package/dist/directives/definitions/callout.js +107 -0
- package/dist/directives/definitions/callout.js.map +1 -0
- package/dist/directives/definitions/card.d.ts +4 -0
- package/dist/directives/definitions/card.js +120 -0
- package/dist/directives/definitions/card.js.map +1 -0
- package/dist/directives/definitions/cards.d.ts +7 -0
- package/dist/directives/definitions/cards.js +72 -0
- package/dist/directives/definitions/cards.js.map +1 -0
- package/dist/directives/definitions/cell.d.ts +4 -0
- package/dist/directives/definitions/cell.js +44 -0
- package/dist/directives/definitions/cell.js.map +1 -0
- package/dist/directives/definitions/columns.d.ts +4 -0
- package/dist/directives/definitions/columns.js +89 -0
- package/dist/directives/definitions/columns.js.map +1 -0
- package/dist/directives/definitions/details.d.ts +2 -0
- package/dist/directives/definitions/details.js +76 -0
- package/dist/directives/definitions/details.js.map +1 -0
- package/dist/directives/definitions/section.d.ts +2 -0
- package/dist/directives/definitions/section.js +32 -0
- package/dist/directives/definitions/section.js.map +1 -0
- package/dist/directives/definitions/steps.d.ts +2 -0
- package/dist/directives/definitions/steps.js +242 -0
- package/dist/directives/definitions/steps.js.map +1 -0
- package/dist/directives/definitions/tab.d.ts +8 -0
- package/dist/directives/definitions/tab.js +59 -0
- package/dist/directives/definitions/tab.js.map +1 -0
- package/dist/directives/definitions/tabs.d.ts +2 -0
- package/dist/directives/definitions/tabs.js +197 -0
- package/dist/directives/definitions/tabs.js.map +1 -0
- package/dist/directives/definitions/toc.d.ts +7 -0
- package/dist/directives/definitions/toc.js +59 -0
- package/dist/directives/definitions/toc.js.map +1 -0
- package/dist/directives/diagnostics.d.ts +8 -0
- package/dist/directives/diagnostics.js +167 -0
- package/dist/directives/diagnostics.js.map +1 -0
- package/dist/directives/headingAnchors.d.ts +9 -0
- package/dist/directives/headingAnchors.js +54 -0
- package/dist/directives/headingAnchors.js.map +1 -0
- package/dist/directives/index.d.ts +5 -0
- package/dist/directives/index.js +6 -0
- package/dist/directives/index.js.map +1 -0
- package/dist/directives/registry.d.ts +20 -0
- package/dist/directives/registry.js +152 -0
- package/dist/directives/registry.js.map +1 -0
- package/dist/directives/renderData.d.ts +3 -0
- package/dist/directives/renderData.js +11 -0
- package/dist/directives/renderData.js.map +1 -0
- package/dist/directives/themes.d.ts +25 -0
- package/dist/directives/themes.js +274 -0
- package/dist/directives/themes.js.map +1 -0
- package/dist/directives/types.d.ts +72 -0
- package/dist/directives/types.js +3 -0
- package/dist/directives/types.js.map +1 -0
- package/dist/editor/MarkdownCodeMirror/Component.client.d.ts +8 -0
- package/dist/editor/MarkdownCodeMirror/Component.client.js +78 -0
- package/dist/editor/MarkdownCodeMirror/Component.client.js.map +1 -0
- package/dist/editor/MarkdownCodeMirror/Component.d.ts +9 -0
- package/dist/editor/MarkdownCodeMirror/Component.js +10 -0
- package/dist/editor/MarkdownCodeMirror/Component.js.map +1 -0
- package/dist/editor/MarkdownCodeMirror.d.ts +8 -0
- package/dist/editor/MarkdownCodeMirror.js +74 -0
- package/dist/editor/MarkdownCodeMirror.js.map +1 -0
- package/dist/editor/MarkdownEditor.d.ts +10 -0
- package/dist/editor/MarkdownEditor.js +22 -0
- package/dist/editor/MarkdownEditor.js.map +1 -0
- package/dist/editor/directives/completions.d.ts +5 -0
- package/dist/editor/directives/completions.js +93 -0
- package/dist/editor/directives/completions.js.map +1 -0
- package/dist/editor/directives/diagnostics.d.ts +1 -0
- package/dist/editor/directives/diagnostics.js +12 -0
- package/dist/editor/directives/diagnostics.js.map +1 -0
- package/dist/editor/themes/payload.d.ts +27 -0
- package/dist/editor/themes/payload.js +269 -0
- package/dist/editor/themes/payload.js.map +1 -0
- package/dist/editor/themes/support/highlighters.d.ts +20 -0
- package/dist/editor/themes/support/highlighters.js +1141 -0
- package/dist/editor/themes/support/highlighters.js.map +1 -0
- package/dist/editor/themes/support/lang.d.ts +40 -0
- package/dist/editor/themes/support/lang.js +201 -0
- package/dist/editor/themes/support/lang.js.map +1 -0
- package/dist/exports/advanced.d.ts +3 -0
- package/dist/exports/advanced.js +5 -0
- package/dist/exports/advanced.js.map +1 -0
- package/dist/exports/client.d.ts +1 -0
- package/dist/exports/client.js +2 -0
- package/dist/exports/client.js.map +1 -0
- package/dist/exports/server.d.ts +3 -0
- package/dist/exports/server.js +5 -0
- package/dist/exports/server.js.map +1 -0
- package/dist/field/BlocksParams/config.d.ts +7 -0
- package/dist/field/BlocksParams/config.js +149 -0
- package/dist/field/BlocksParams/config.js.map +1 -0
- package/dist/field/CodeBlock/config.d.ts +7 -0
- package/dist/field/CodeBlock/config.js +321 -0
- package/dist/field/CodeBlock/config.js.map +1 -0
- package/dist/field/CodeBlockConfig/config.d.ts +7 -0
- package/dist/field/CodeBlockConfig/config.js +306 -0
- package/dist/field/CodeBlockConfig/config.js.map +1 -0
- package/dist/field/CodeBlockParams/config.d.ts +7 -0
- package/dist/field/CodeBlockParams/config.js +321 -0
- package/dist/field/CodeBlockParams/config.js.map +1 -0
- package/dist/field/Config/config.d.ts +7 -0
- package/dist/field/Config/config.js +149 -0
- package/dist/field/Config/config.js.map +1 -0
- package/dist/field/MarkdownField/Component.d.ts +2 -0
- package/dist/field/MarkdownField/Component.js +42 -0
- package/dist/field/MarkdownField/Component.js.map +1 -0
- package/dist/field/MarkdownField/config.d.ts +3 -0
- package/dist/field/MarkdownField/config.js +20 -0
- package/dist/field/MarkdownField/config.js.map +1 -0
- package/dist/field/Tailwind/config.d.ts +9 -0
- package/dist/field/Tailwind/config.js +13 -0
- package/dist/field/Tailwind/config.js.map +1 -0
- package/dist/field/TailwindField/config.d.ts +9 -0
- package/dist/field/TailwindField/config.js +13 -0
- package/dist/field/TailwindField/config.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +91 -0
- package/dist/index.js.map +1 -0
- package/dist/runtime/index.d.ts +36 -0
- package/dist/runtime/index.js +124 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/styles/directiveSurface.d.ts +11 -0
- package/dist/styles/directiveSurface.js +38 -0
- package/dist/styles/directiveSurface.js.map +1 -0
- package/dist/types/core.d.ts +285 -0
- package/dist/types/core.js +5 -0
- package/dist/types/core.js.map +1 -0
- package/dist/types/layoutToken.d.ts +1 -0
- package/dist/types/layoutToken.js +3 -0
- package/dist/types/layoutToken.js.map +1 -0
- package/dist/types/mdast.d.js +5 -0
- package/dist/types/mdast.d.js.map +1 -0
- package/dist/types.d.js +3 -0
- package/dist/types.d.js.map +1 -0
- package/dist/types.d.ts +80 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +181 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { visit } from 'unist-util-visit';
|
|
2
|
+
import { layoutDirectiveRegistry } from '../../directives/registry.js';
|
|
3
|
+
import { hasDirectiveTheme } from '../../directives/themes.js';
|
|
4
|
+
function isContainerDirective(node) {
|
|
5
|
+
return Boolean(node && typeof node === 'object' && 'type' in node && node.type === 'containerDirective');
|
|
6
|
+
}
|
|
7
|
+
function warnUnknownThemes(node, file, config) {
|
|
8
|
+
const definition = layoutDirectiveRegistry.get(node.name);
|
|
9
|
+
if (!definition?.themeAttributes) return;
|
|
10
|
+
for (const [attribute, groupName] of Object.entries(definition.themeAttributes)){
|
|
11
|
+
if (!groupName) continue;
|
|
12
|
+
const value = node.attributes?.[attribute];
|
|
13
|
+
if (typeof value !== 'string' || !value.trim()) continue;
|
|
14
|
+
if (hasDirectiveTheme(groupName, value, config.themes)) continue;
|
|
15
|
+
const label = attribute === 'theme' ? 'theme' : attribute;
|
|
16
|
+
file.message(`Unknown ${label} "${value}" on "${node.name}". Falling back to "default".`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export const remarkValidateDirectiveThemes = (config = {})=>{
|
|
20
|
+
return (tree, file)=>{
|
|
21
|
+
visit(tree, (node)=>{
|
|
22
|
+
if (!isContainerDirective(node)) return;
|
|
23
|
+
warnUnknownThemes(node, file, config);
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=remarkValidateDirectiveThemes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/core/plugins/remarkValidateDirectiveThemes.ts"],"sourcesContent":["import type { Root } from 'mdast'\nimport type { ContainerDirective } from 'mdast-util-directive'\nimport type { Plugin } from 'unified'\n\nimport { visit } from 'unist-util-visit'\n\nimport type { MarkdownRenderConfig } from '../../types/core.js'\n\nimport { layoutDirectiveRegistry } from '../../directives/registry.js'\nimport { hasDirectiveTheme } from '../../directives/themes.js'\n\ntype MessageFile = {\n message: (reason: string) => unknown\n}\n\nfunction isContainerDirective(node: unknown): node is ContainerDirective {\n return Boolean(\n node &&\n typeof node === 'object' &&\n 'type' in node &&\n (node as { type?: string }).type === 'containerDirective',\n )\n}\n\nfunction warnUnknownThemes(node: ContainerDirective, file: MessageFile, config: MarkdownRenderConfig) {\n const definition = layoutDirectiveRegistry.get(node.name)\n if (!definition?.themeAttributes) return\n\n for (const [attribute, groupName] of Object.entries(definition.themeAttributes)) {\n if (!groupName) continue\n\n const value = node.attributes?.[attribute]\n if (typeof value !== 'string' || !value.trim()) continue\n if (hasDirectiveTheme(groupName, value, config.themes)) continue\n\n const label = attribute === 'theme' ? 'theme' : attribute\n\n file.message(\n `Unknown ${label} \"${value}\" on \"${node.name}\". Falling back to \"default\".`,\n )\n }\n}\n\nexport const remarkValidateDirectiveThemes: Plugin<[MarkdownRenderConfig?], Root> = (\n config: MarkdownRenderConfig = {},\n) => {\n return (tree, file) => {\n visit(tree, (node) => {\n if (!isContainerDirective(node)) return\n\n warnUnknownThemes(node, file, config)\n })\n }\n}\n"],"names":["visit","layoutDirectiveRegistry","hasDirectiveTheme","isContainerDirective","node","Boolean","type","warnUnknownThemes","file","config","definition","get","name","themeAttributes","attribute","groupName","Object","entries","value","attributes","trim","themes","label","message","remarkValidateDirectiveThemes","tree"],"mappings":"AAIA,SAASA,KAAK,QAAQ,mBAAkB;AAIxC,SAASC,uBAAuB,QAAQ,+BAA8B;AACtE,SAASC,iBAAiB,QAAQ,6BAA4B;AAM9D,SAASC,qBAAqBC,IAAa;IACzC,OAAOC,QACLD,QACE,OAAOA,SAAS,YAChB,UAAUA,QACV,AAACA,KAA2BE,IAAI,KAAK;AAE3C;AAEA,SAASC,kBAAkBH,IAAwB,EAAEI,IAAiB,EAAEC,MAA4B;IAClG,MAAMC,aAAaT,wBAAwBU,GAAG,CAACP,KAAKQ,IAAI;IACxD,IAAI,CAACF,YAAYG,iBAAiB;IAElC,KAAK,MAAM,CAACC,WAAWC,UAAU,IAAIC,OAAOC,OAAO,CAACP,WAAWG,eAAe,EAAG;QAC/E,IAAI,CAACE,WAAW;QAEhB,MAAMG,QAAQd,KAAKe,UAAU,EAAE,CAACL,UAAU;QAC1C,IAAI,OAAOI,UAAU,YAAY,CAACA,MAAME,IAAI,IAAI;QAChD,IAAIlB,kBAAkBa,WAAWG,OAAOT,OAAOY,MAAM,GAAG;QAExD,MAAMC,QAAQR,cAAc,UAAU,UAAUA;QAEhDN,KAAKe,OAAO,CACV,CAAC,QAAQ,EAAED,MAAM,EAAE,EAAEJ,MAAM,MAAM,EAAEd,KAAKQ,IAAI,CAAC,6BAA6B,CAAC;IAE/E;AACF;AAEA,OAAO,MAAMY,gCAAuE,CAClFf,SAA+B,CAAC,CAAC;IAEjC,OAAO,CAACgB,MAAMjB;QACZR,MAAMyB,MAAM,CAACrB;YACX,IAAI,CAACD,qBAAqBC,OAAO;YAEjCG,kBAAkBH,MAAMI,MAAMC;QAChC;IACF;AACF,EAAC"}
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { fromHtml } from 'hast-util-from-html';
|
|
2
|
+
import { toString } from 'hast-util-to-string';
|
|
3
|
+
import rehypeRaw from 'rehype-raw';
|
|
4
|
+
import rehypeSanitize, { defaultSchema } from 'rehype-sanitize';
|
|
5
|
+
import rehypeStringify from 'rehype-stringify';
|
|
6
|
+
import remarkGfm from 'remark-gfm';
|
|
7
|
+
import remarkParse from 'remark-parse';
|
|
8
|
+
import remarkRehype from 'remark-rehype';
|
|
9
|
+
import { unified } from 'unified';
|
|
10
|
+
import { visit } from 'unist-util-visit';
|
|
11
|
+
import { resolveRenderMarkdownOptions } from './codeConfig.js';
|
|
12
|
+
import { codeToHtml } from './codeToHtml.js';
|
|
13
|
+
import { rehypeApplyLayoutClasses } from './plugins/rehypeApplyLayoutClasses.js';
|
|
14
|
+
import { rehypeStripAuthoredInlineStyles } from './plugins/rehypeStripAuthoredInlineStyles.js';
|
|
15
|
+
import { remarkCompileLayouts } from './plugins/remarkCompileLayouts.js';
|
|
16
|
+
import { remarkHeadingAnchorsAndToc } from './plugins/remarkHeadingAnchorsAndToc.js';
|
|
17
|
+
import { remarkLayoutDirectives } from './plugins/remarkLayoutDirectives.js';
|
|
18
|
+
import { remarkLiftLayoutDirectives } from './plugins/remarkLiftLayoutDirectives.js';
|
|
19
|
+
import { remarkValidateDirectiveThemes } from './plugins/remarkValidateDirectiveThemes.js';
|
|
20
|
+
function extractCodeLanguage(className) {
|
|
21
|
+
const classes = typeof className === 'string' ? className.split(/\s+/) : Array.isArray(className) ? className : [];
|
|
22
|
+
return classes.find((c)=>typeof c === 'string' && c.startsWith('language-'))?.slice(9);
|
|
23
|
+
}
|
|
24
|
+
function isElement(node) {
|
|
25
|
+
return node.type === 'element';
|
|
26
|
+
}
|
|
27
|
+
function isPreElement(node) {
|
|
28
|
+
return isElement(node) && node.tagName === 'pre';
|
|
29
|
+
}
|
|
30
|
+
function hasChildren(node) {
|
|
31
|
+
return Boolean(node && typeof node === 'object' && 'children' in node);
|
|
32
|
+
}
|
|
33
|
+
function findCodeChild(node) {
|
|
34
|
+
return node.children.find((child)=>child.type === 'element' && child.tagName === 'code');
|
|
35
|
+
}
|
|
36
|
+
function parseHtmlFragment(html) {
|
|
37
|
+
const fragment = fromHtml(html, {
|
|
38
|
+
fragment: true
|
|
39
|
+
});
|
|
40
|
+
return fragment.children;
|
|
41
|
+
}
|
|
42
|
+
function rehypeShikiCodeBlocks(options = {}) {
|
|
43
|
+
return async function transformer(tree) {
|
|
44
|
+
const work = [];
|
|
45
|
+
visit(tree, 'element', (node, index, parent)=>{
|
|
46
|
+
if (typeof index !== 'number' || !hasChildren(parent) || !isPreElement(node)) return;
|
|
47
|
+
const codeNode = findCodeChild(node);
|
|
48
|
+
if (!codeNode) return;
|
|
49
|
+
const code = toString(codeNode);
|
|
50
|
+
const lang = extractCodeLanguage(codeNode.properties?.className);
|
|
51
|
+
work.push((async ()=>{
|
|
52
|
+
const highlighted = await codeToHtml(code, {
|
|
53
|
+
...options,
|
|
54
|
+
lang
|
|
55
|
+
});
|
|
56
|
+
const replacementNodes = parseHtmlFragment(highlighted);
|
|
57
|
+
parent.children.splice(index, 1, ...replacementNodes);
|
|
58
|
+
})());
|
|
59
|
+
});
|
|
60
|
+
await Promise.all(work);
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function getAttributeDefinitions(value) {
|
|
64
|
+
return value ?? [];
|
|
65
|
+
}
|
|
66
|
+
const sanitizeSchema = {
|
|
67
|
+
...defaultSchema,
|
|
68
|
+
attributes: {
|
|
69
|
+
...defaultSchema.attributes ?? {},
|
|
70
|
+
a: [
|
|
71
|
+
...getAttributeDefinitions(defaultSchema.attributes?.a ?? []),
|
|
72
|
+
'href',
|
|
73
|
+
'target',
|
|
74
|
+
'rel',
|
|
75
|
+
'title'
|
|
76
|
+
],
|
|
77
|
+
article: [
|
|
78
|
+
...getAttributeDefinitions(defaultSchema.attributes?.article ?? []),
|
|
79
|
+
'className',
|
|
80
|
+
'dataDirective',
|
|
81
|
+
'dataEyebrow',
|
|
82
|
+
'dataHref',
|
|
83
|
+
'dataStepCard',
|
|
84
|
+
'dataTabPanel',
|
|
85
|
+
'dataTabValue',
|
|
86
|
+
'dataTheme',
|
|
87
|
+
'dataTitle',
|
|
88
|
+
'dataVlLayout',
|
|
89
|
+
'hidden',
|
|
90
|
+
'id',
|
|
91
|
+
'role',
|
|
92
|
+
'tabIndex'
|
|
93
|
+
],
|
|
94
|
+
button: [
|
|
95
|
+
...getAttributeDefinitions(defaultSchema.attributes?.button ?? []),
|
|
96
|
+
'ariaControls',
|
|
97
|
+
'ariaSelected',
|
|
98
|
+
'className',
|
|
99
|
+
'dataTabTrigger',
|
|
100
|
+
'dataTabValue',
|
|
101
|
+
'disabled',
|
|
102
|
+
'id',
|
|
103
|
+
'role',
|
|
104
|
+
'tabIndex',
|
|
105
|
+
'type'
|
|
106
|
+
],
|
|
107
|
+
code: [
|
|
108
|
+
...getAttributeDefinitions(defaultSchema.attributes?.code ?? []),
|
|
109
|
+
'className'
|
|
110
|
+
],
|
|
111
|
+
details: [
|
|
112
|
+
...getAttributeDefinitions(defaultSchema.attributes?.details ?? []),
|
|
113
|
+
'dataDirective',
|
|
114
|
+
'dataTheme',
|
|
115
|
+
'dataTitle',
|
|
116
|
+
'dataVlLayout',
|
|
117
|
+
'open'
|
|
118
|
+
],
|
|
119
|
+
div: [
|
|
120
|
+
...getAttributeDefinitions(defaultSchema.attributes?.div ?? []),
|
|
121
|
+
'dataDirective',
|
|
122
|
+
'dataDirectiveBody',
|
|
123
|
+
'dataDirectiveTitle',
|
|
124
|
+
'dataEyebrow',
|
|
125
|
+
'dataHref',
|
|
126
|
+
'dataCellTheme',
|
|
127
|
+
'dataTabsList',
|
|
128
|
+
'dataTabPanel',
|
|
129
|
+
'dataTabTrigger',
|
|
130
|
+
'dataTabValue',
|
|
131
|
+
'dataTheme',
|
|
132
|
+
'dataTitle',
|
|
133
|
+
'dataVariant',
|
|
134
|
+
'dataVlLayout',
|
|
135
|
+
'dataVlCellHeadingDepth',
|
|
136
|
+
'hidden',
|
|
137
|
+
'id',
|
|
138
|
+
'role',
|
|
139
|
+
'tabIndex'
|
|
140
|
+
],
|
|
141
|
+
h1: [
|
|
142
|
+
...getAttributeDefinitions(defaultSchema.attributes?.h1 ?? []),
|
|
143
|
+
'dataDirectiveTitle',
|
|
144
|
+
'dataHeadingAnchor',
|
|
145
|
+
'id'
|
|
146
|
+
],
|
|
147
|
+
h2: [
|
|
148
|
+
...getAttributeDefinitions(defaultSchema.attributes?.h2 ?? []),
|
|
149
|
+
'dataDirectiveTitle',
|
|
150
|
+
'dataHeadingAnchor',
|
|
151
|
+
'id'
|
|
152
|
+
],
|
|
153
|
+
h3: [
|
|
154
|
+
...getAttributeDefinitions(defaultSchema.attributes?.h3 ?? []),
|
|
155
|
+
'dataDirectiveTitle',
|
|
156
|
+
'dataHeadingAnchor',
|
|
157
|
+
'id'
|
|
158
|
+
],
|
|
159
|
+
h4: [
|
|
160
|
+
...getAttributeDefinitions(defaultSchema.attributes?.h4 ?? []),
|
|
161
|
+
'dataHeadingAnchor',
|
|
162
|
+
'id'
|
|
163
|
+
],
|
|
164
|
+
h5: [
|
|
165
|
+
...getAttributeDefinitions(defaultSchema.attributes?.h5 ?? []),
|
|
166
|
+
'dataHeadingAnchor',
|
|
167
|
+
'id'
|
|
168
|
+
],
|
|
169
|
+
h6: [
|
|
170
|
+
...getAttributeDefinitions(defaultSchema.attributes?.h6 ?? []),
|
|
171
|
+
'dataHeadingAnchor',
|
|
172
|
+
'id'
|
|
173
|
+
],
|
|
174
|
+
img: [
|
|
175
|
+
...getAttributeDefinitions(defaultSchema.attributes?.img ?? []),
|
|
176
|
+
'src',
|
|
177
|
+
'alt',
|
|
178
|
+
'title',
|
|
179
|
+
'width',
|
|
180
|
+
'height'
|
|
181
|
+
],
|
|
182
|
+
li: [
|
|
183
|
+
...getAttributeDefinitions(defaultSchema.attributes?.li ?? []),
|
|
184
|
+
'dataStep'
|
|
185
|
+
],
|
|
186
|
+
nav: [
|
|
187
|
+
...getAttributeDefinitions(defaultSchema.attributes?.nav ?? []),
|
|
188
|
+
'ariaLabel',
|
|
189
|
+
'dataDirective',
|
|
190
|
+
'dataTheme',
|
|
191
|
+
'dataTitle',
|
|
192
|
+
'dataVlLayout'
|
|
193
|
+
],
|
|
194
|
+
p: [
|
|
195
|
+
...getAttributeDefinitions(defaultSchema.attributes?.p ?? []),
|
|
196
|
+
'className',
|
|
197
|
+
'dataDirectiveEyebrow'
|
|
198
|
+
],
|
|
199
|
+
pre: [
|
|
200
|
+
...getAttributeDefinitions(defaultSchema.attributes?.pre ?? []),
|
|
201
|
+
'className',
|
|
202
|
+
'tabindex'
|
|
203
|
+
],
|
|
204
|
+
section: [
|
|
205
|
+
...getAttributeDefinitions(defaultSchema.attributes?.section ?? []),
|
|
206
|
+
'dataColumns',
|
|
207
|
+
'dataCardTheme',
|
|
208
|
+
'dataCellTheme',
|
|
209
|
+
'dataDefault',
|
|
210
|
+
'dataDisabled',
|
|
211
|
+
'dataDirective',
|
|
212
|
+
'dataLabel',
|
|
213
|
+
'dataLayout',
|
|
214
|
+
'dataNumbered',
|
|
215
|
+
'dataStepTheme',
|
|
216
|
+
'dataTabTheme',
|
|
217
|
+
'dataTabValue',
|
|
218
|
+
'dataTheme',
|
|
219
|
+
'dataVariant',
|
|
220
|
+
'dataValue',
|
|
221
|
+
'dataVlLayout',
|
|
222
|
+
'dataVlCellHeadingDepth',
|
|
223
|
+
'role'
|
|
224
|
+
],
|
|
225
|
+
span: [
|
|
226
|
+
...getAttributeDefinitions(defaultSchema.attributes?.span ?? []),
|
|
227
|
+
'className',
|
|
228
|
+
'dataStepNumber',
|
|
229
|
+
'style'
|
|
230
|
+
],
|
|
231
|
+
summary: [
|
|
232
|
+
...getAttributeDefinitions(defaultSchema.attributes?.summary ?? []),
|
|
233
|
+
'className'
|
|
234
|
+
]
|
|
235
|
+
},
|
|
236
|
+
clobberPrefix: '',
|
|
237
|
+
tagNames: [
|
|
238
|
+
...defaultSchema.tagNames ?? [],
|
|
239
|
+
'a',
|
|
240
|
+
'article',
|
|
241
|
+
'br',
|
|
242
|
+
'button',
|
|
243
|
+
'details',
|
|
244
|
+
'img',
|
|
245
|
+
'nav',
|
|
246
|
+
'section',
|
|
247
|
+
'span',
|
|
248
|
+
'summary'
|
|
249
|
+
]
|
|
250
|
+
};
|
|
251
|
+
export async function compileMarkdown(markdown, config = {}) {
|
|
252
|
+
const warnings = [];
|
|
253
|
+
try {
|
|
254
|
+
const file = await unified().use(remarkParse).use(remarkGfm).use(remarkLiftLayoutDirectives).use(remarkCompileLayouts).use(remarkLayoutDirectives).use(remarkValidateDirectiveThemes, config).use(remarkHeadingAnchorsAndToc).use(remarkRehype, {
|
|
255
|
+
allowDangerousHtml: true
|
|
256
|
+
}).use(rehypeRaw).use(rehypeStripAuthoredInlineStyles).use(rehypeShikiCodeBlocks, resolveRenderMarkdownOptions(config)).use(rehypeSanitize, sanitizeSchema).use(rehypeApplyLayoutClasses, config).use(rehypeStringify).process(markdown);
|
|
257
|
+
return {
|
|
258
|
+
html: String(file),
|
|
259
|
+
warnings: file.messages.map((message)=>message.reason)
|
|
260
|
+
};
|
|
261
|
+
} catch (error) {
|
|
262
|
+
warnings.push(error instanceof Error ? error.message : 'Failed to render markdown.');
|
|
263
|
+
return {
|
|
264
|
+
html: '<p>Failed to render markdown.</p>',
|
|
265
|
+
warnings
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
//# sourceMappingURL=renderMarkdown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/core/renderMarkdown.ts"],"sourcesContent":["import type { Element, Parent, Root, RootContent } from 'hast'\nimport type { Schema } from 'hast-util-sanitize'\n\nimport { fromHtml } from 'hast-util-from-html'\nimport { toString } from 'hast-util-to-string'\nimport rehypeRaw from 'rehype-raw'\nimport rehypeSanitize, { defaultSchema } from 'rehype-sanitize'\nimport rehypeStringify from 'rehype-stringify'\nimport remarkGfm from 'remark-gfm'\nimport remarkParse from 'remark-parse'\nimport remarkRehype from 'remark-rehype'\nimport { unified } from 'unified'\nimport { visit } from 'unist-util-visit'\n\nimport type { MarkdownRenderConfig, RenderMarkdownOptions, RenderMarkdownResult } from '../types/core.js'\n\nimport { resolveRenderMarkdownOptions } from './codeConfig.js'\nimport { codeToHtml } from './codeToHtml.js'\nimport { rehypeApplyLayoutClasses } from './plugins/rehypeApplyLayoutClasses.js'\nimport { rehypeStripAuthoredInlineStyles } from './plugins/rehypeStripAuthoredInlineStyles.js'\nimport { remarkCompileLayouts } from './plugins/remarkCompileLayouts.js'\nimport { remarkHeadingAnchorsAndToc } from './plugins/remarkHeadingAnchorsAndToc.js'\nimport { remarkLayoutDirectives } from './plugins/remarkLayoutDirectives.js'\nimport { remarkLiftLayoutDirectives } from './plugins/remarkLiftLayoutDirectives.js'\nimport { remarkValidateDirectiveThemes } from './plugins/remarkValidateDirectiveThemes.js'\n\nfunction extractCodeLanguage(\n className?: Array<number | string> | boolean | null | number | string ,\n): string | undefined {\n const classes =\n typeof className === 'string'\n ? className.split(/\\s+/)\n : Array.isArray(className)\n ? className\n : []\n\n return classes\n .find((c): c is string => typeof c === 'string' && c.startsWith('language-'))\n ?.slice(9)\n}\n\nfunction isElement(node: RootContent): node is Element {\n return node.type === 'element'\n}\n\nfunction isPreElement(node: RootContent): node is Element {\n return isElement(node) && node.tagName === 'pre'\n}\n\nfunction hasChildren(node: unknown): node is Parent {\n return Boolean(node && typeof node === 'object' && 'children' in node)\n}\n\nfunction findCodeChild(node: Element): Element | undefined {\n return node.children.find(\n (child): child is Element => child.type === 'element' && child.tagName === 'code',\n )\n}\n\nfunction parseHtmlFragment(html: string): RootContent[] {\n const fragment = fromHtml(html, { fragment: true })\n return fragment.children\n}\n\nfunction rehypeShikiCodeBlocks(options: RenderMarkdownOptions = {}) {\n return async function transformer(tree: Root): Promise<void> {\n const work: Array<Promise<void>> = []\n\n visit(tree, 'element', (node, index, parent) => {\n if (typeof index !== 'number' || !hasChildren(parent) || !isPreElement(node)) return\n\n const codeNode = findCodeChild(node)\n if (!codeNode) return\n\n const code = toString(codeNode)\n const lang = extractCodeLanguage(codeNode.properties?.className)\n\n work.push(\n (async () => {\n const highlighted = await codeToHtml(code, {\n ...options,\n lang\n })\n\n const replacementNodes = parseHtmlFragment(highlighted)\n parent.children.splice(index, 1, ...replacementNodes)\n })(),\n )\n })\n\n await Promise.all(work)\n }\n}\n\ntype SanitizeAttributeValue = boolean | null | number | RegExp | string | undefined\ntype SanitizeAttributeDefinition = [string, ...SanitizeAttributeValue[]] | string\n\nfunction getAttributeDefinitions(\n value: Schema['attributes'] extends infer A\n ? A extends Record<string, infer V>\n ? V\n : never\n : never,\n): SanitizeAttributeDefinition[] {\n return (value as SanitizeAttributeDefinition[] | undefined) ?? []\n}\n\nconst sanitizeSchema: Schema = {\n ...defaultSchema,\n attributes: {\n ...(defaultSchema.attributes ?? {}),\n a: [\n ...getAttributeDefinitions(defaultSchema.attributes?.a ?? []),\n 'href',\n 'target',\n 'rel',\n 'title',\n ],\n article: [\n ...getAttributeDefinitions(defaultSchema.attributes?.article ?? []),\n 'className',\n 'dataDirective',\n 'dataEyebrow',\n 'dataHref',\n 'dataStepCard',\n 'dataTabPanel',\n 'dataTabValue',\n 'dataTheme',\n 'dataTitle',\n 'dataVlLayout',\n 'hidden',\n 'id',\n 'role',\n 'tabIndex',\n ],\n button: [\n ...getAttributeDefinitions(defaultSchema.attributes?.button ?? []),\n 'ariaControls',\n 'ariaSelected',\n 'className',\n 'dataTabTrigger',\n 'dataTabValue',\n 'disabled',\n 'id',\n 'role',\n 'tabIndex',\n 'type',\n ],\n code: [...getAttributeDefinitions(defaultSchema.attributes?.code ?? []), 'className'],\n details: [\n ...getAttributeDefinitions(defaultSchema.attributes?.details ?? []),\n 'dataDirective',\n 'dataTheme',\n 'dataTitle',\n 'dataVlLayout',\n 'open',\n ],\n div: [\n ...getAttributeDefinitions(defaultSchema.attributes?.div ?? []),\n 'dataDirective',\n 'dataDirectiveBody',\n 'dataDirectiveTitle',\n 'dataEyebrow',\n 'dataHref',\n 'dataCellTheme',\n 'dataTabsList',\n 'dataTabPanel',\n 'dataTabTrigger',\n 'dataTabValue',\n 'dataTheme',\n 'dataTitle',\n 'dataVariant',\n 'dataVlLayout',\n 'dataVlCellHeadingDepth',\n 'hidden',\n 'id',\n 'role',\n 'tabIndex',\n ],\n h1: [\n ...getAttributeDefinitions(defaultSchema.attributes?.h1 ?? []),\n 'dataDirectiveTitle',\n 'dataHeadingAnchor',\n 'id',\n ],\n h2: [\n ...getAttributeDefinitions(defaultSchema.attributes?.h2 ?? []),\n 'dataDirectiveTitle',\n 'dataHeadingAnchor',\n 'id',\n ],\n h3: [\n ...getAttributeDefinitions(defaultSchema.attributes?.h3 ?? []),\n 'dataDirectiveTitle',\n 'dataHeadingAnchor',\n 'id',\n ],\n h4: [...getAttributeDefinitions(defaultSchema.attributes?.h4 ?? []), 'dataHeadingAnchor', 'id'],\n h5: [...getAttributeDefinitions(defaultSchema.attributes?.h5 ?? []), 'dataHeadingAnchor', 'id'],\n h6: [...getAttributeDefinitions(defaultSchema.attributes?.h6 ?? []), 'dataHeadingAnchor', 'id'],\n img: [\n ...getAttributeDefinitions(defaultSchema.attributes?.img ?? []),\n 'src',\n 'alt',\n 'title',\n 'width',\n 'height',\n ],\n li: [...getAttributeDefinitions(defaultSchema.attributes?.li ?? []), 'dataStep'],\n nav: [\n ...getAttributeDefinitions(defaultSchema.attributes?.nav ?? []),\n 'ariaLabel',\n 'dataDirective',\n 'dataTheme',\n 'dataTitle',\n 'dataVlLayout',\n ],\n p: [\n ...getAttributeDefinitions(defaultSchema.attributes?.p ?? []),\n 'className',\n 'dataDirectiveEyebrow',\n ],\n pre: [\n ...getAttributeDefinitions(defaultSchema.attributes?.pre ?? []),\n 'className',\n 'tabindex',\n ],\n section: [\n ...getAttributeDefinitions(defaultSchema.attributes?.section ?? []),\n 'dataColumns',\n 'dataCardTheme',\n 'dataCellTheme',\n 'dataDefault',\n 'dataDisabled',\n 'dataDirective',\n 'dataLabel',\n 'dataLayout',\n 'dataNumbered',\n 'dataStepTheme',\n 'dataTabTheme',\n 'dataTabValue',\n 'dataTheme',\n 'dataVariant',\n 'dataValue',\n 'dataVlLayout',\n 'dataVlCellHeadingDepth',\n 'role',\n ],\n span: [\n ...getAttributeDefinitions(defaultSchema.attributes?.span ?? []),\n 'className',\n 'dataStepNumber',\n 'style',\n ],\n summary: [...getAttributeDefinitions(defaultSchema.attributes?.summary ?? []), 'className'],\n },\n clobberPrefix: '',\n tagNames: [\n ...(defaultSchema.tagNames ?? []),\n 'a',\n 'article',\n 'br',\n 'button',\n 'details',\n 'img',\n 'nav',\n 'section',\n 'span',\n 'summary',\n ],\n}\n\nexport async function compileMarkdown(\n markdown: string,\n config: MarkdownRenderConfig = {},\n): Promise<RenderMarkdownResult> {\n const warnings: string[] = []\n\n try {\n const file = await unified()\n .use(remarkParse)\n .use(remarkGfm)\n .use(remarkLiftLayoutDirectives)\n .use(remarkCompileLayouts)\n .use(remarkLayoutDirectives)\n .use(remarkValidateDirectiveThemes, config)\n .use(remarkHeadingAnchorsAndToc)\n .use(remarkRehype, { allowDangerousHtml: true })\n .use(rehypeRaw)\n .use(rehypeStripAuthoredInlineStyles)\n .use(rehypeShikiCodeBlocks, resolveRenderMarkdownOptions(config))\n .use(rehypeSanitize, sanitizeSchema)\n .use(rehypeApplyLayoutClasses, config)\n .use(rehypeStringify)\n .process(markdown)\n\n return {\n html: String(file),\n warnings: file.messages.map((message) => message.reason),\n }\n } catch (error) {\n warnings.push(error instanceof Error ? error.message : 'Failed to render markdown.')\n\n return {\n html: '<p>Failed to render markdown.</p>',\n warnings,\n }\n }\n}\n"],"names":["fromHtml","toString","rehypeRaw","rehypeSanitize","defaultSchema","rehypeStringify","remarkGfm","remarkParse","remarkRehype","unified","visit","resolveRenderMarkdownOptions","codeToHtml","rehypeApplyLayoutClasses","rehypeStripAuthoredInlineStyles","remarkCompileLayouts","remarkHeadingAnchorsAndToc","remarkLayoutDirectives","remarkLiftLayoutDirectives","remarkValidateDirectiveThemes","extractCodeLanguage","className","classes","split","Array","isArray","find","c","startsWith","slice","isElement","node","type","isPreElement","tagName","hasChildren","Boolean","findCodeChild","children","child","parseHtmlFragment","html","fragment","rehypeShikiCodeBlocks","options","transformer","tree","work","index","parent","codeNode","code","lang","properties","push","highlighted","replacementNodes","splice","Promise","all","getAttributeDefinitions","value","sanitizeSchema","attributes","a","article","button","details","div","h1","h2","h3","h4","h5","h6","img","li","nav","p","pre","section","span","summary","clobberPrefix","tagNames","compileMarkdown","markdown","config","warnings","file","use","allowDangerousHtml","process","String","messages","map","message","reason","error","Error"],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/core/types.d.ts"],"sourcesContent":["/**\n * @import {} from 'mdast-util-directive'\n */\n\nimport type { JSX, ReactNode } from 'react'\n\nexport type MarkdownRendererScope = 'blocks' | 'field'\n\n/**\n * Options that control how fenced code blocks are rendered inside markdown content.\n *\n * By default, code blocks use the plugin's enhanced rendering mode:\n * - `highlightLines` defaults to `false`\n * - `lineNumbers` defaults to `true`\n * - `prettyCodeBlocks` defaults to `true`\n * - `theme` defaults to `'github-dark'`\n *\n * These options are passed through the markdown rendering pipeline and primarily\n * affect Shiki-rendered code fences.\n */\nexport type RenderMarkdownOptions = {\n /**\n * Whether to preserve Shiki-provided per-line background highlighting.\n *\n * Defaults to `false`.\n *\n * When disabled, background styles are stripped from highlighted lines and token\n * spans so code blocks integrate more cleanly with the surrounding site design.\n */\n highlightLines?: boolean\n\n /**\n * Whether to show line numbers for fenced code blocks.\n *\n * Defaults to `true`.\n */\n lineNumbers?: boolean\n\n /**\n * Whether to apply the plugin's enhanced code block formatting.\n *\n * Defaults to `true`.\n *\n * When enabled, the renderer normalizes Shiki output for better integration with\n * markdown prose styling. This includes adjustments such as background removal,\n * spacing cleanup, line layout normalization, and other structural fixes needed\n * for features like line numbers and consistent empty-line rendering.\n *\n * Set this to `false` if you want to preserve raw Shiki block styling as much as\n * possible.\n */\n prettyCodeBlocks?: boolean\n\n /**\n * The Shiki theme to use for syntax highlighting.\n *\n * Defaults to `'github-dark'`.\n *\n * Note that this plugin is optimized around themes that still look good when block\n * backgrounds are removed or reduced. Some light themes may require additional\n * customization to maintain good contrast and readability.\n */\n theme?: string\n}\n\n/**\n * The result of compiling markdown into sanitized HTML.\n */\nexport type RenderMarkdownResult = {\n /**\n * The rendered HTML output.\n */\n html: string\n\n /**\n * Non-fatal warnings produced during rendering.\n */\n warnings: string[]\n}\n\n/**\n * Preset visual styles for rendered markdown content.\n */\nexport type MarkdownVariant = 'blog' | 'compact' | 'docs' | 'unstyled'\n\n/**\n * Preset typography sizes for rendered markdown content.\n */\nexport type MarkdownSize = 'lg' | 'md' | 'sm'\n\n/**\n * Core markdown presentation configuration.\n *\n * This type represents the configurable styling and behavior layer that can be\n * sourced from plugin defaults, globals, collection defaults, or block-level\n * overrides. It intentionally excludes runtime-only renderer props such as\n * `markdown`, `as`, and fallback nodes.\n */\nexport type MarkdownConfig = {\n /**\n * Whether to center the rendered markdown container within its wrapper.\n *\n * Defaults to `false`.\n */\n centered?: boolean\n\n /**\n * Additional classes applied to the rendered markdown element itself.\n */\n className?: string\n\n /**\n * Additional classes applied to column elements within the rendered markdown, if applicable.\n */\n columnClassName?: string\n\n /**\n * Whether to apply horizontal gutter padding to the outer wrapper.\n *\n * Defaults to `false`.\n */\n enableGutter?: boolean\n\n /**\n * Whether fenced code blocks should extend beyond the normal content width\n * on larger screens.\n *\n * Defaults to `false`.\n */\n fullBleedCode?: boolean\n\n /**\n * Optional content rendered above the markdown body.\n */\n lead?: ReactNode\n\n /**\n * Whether heading colors should be slightly muted.\n *\n * Defaults to `false`.\n */\n mutedHeadings?: boolean\n\n /**\n * Options that control fenced code block rendering.\n */\n options?: RenderMarkdownOptions\n\n /**\n * Additional classes applied to section elements within the rendered markdown, if applicable.\n */\n sectionClassName?: string\n\n /**\n * Typography size preset for the rendered markdown.\n *\n * Defaults to `'lg'`.\n */\n size?: MarkdownSize\n\n /**\n * Visual style preset for the rendered markdown.\n *\n * Defaults to `'blog'`.\n */\n variant?: MarkdownVariant\n\n /**\n * Additional classes applied to the outer wrapper element.\n */\n wrapperClassName?: string\n}\n\n/**\n * Runtime-only props shared by markdown renderer components.\n */\nexport type BaseMarkdownRendererProps = {\n /**\n * The HTML tag used for the rendered markdown container.\n *\n * Defaults to `'article'`.\n */\n as?: keyof JSX.IntrinsicElements\n\n /**\n * Content rendered when the markdown input is empty or missing.\n */\n emptyFallback?: ReactNode\n\n /**\n * Content rendered when markdown compilation fails and a fallback is desired.\n */\n errorFallback?: ReactNode\n\n /**\n * The markdown source string to render.\n */\n markdown?: null | string\n}\n\n/**\n * Props for the main markdown renderer component.\n *\n * This merges persisted/configurable markdown presentation settings with the\n * runtime-only rendering props required by the component itself.\n */\nexport type MarkdownRendererProps = {\n collectionSlug?: string\n scope?: MarkdownRendererScope\n } & BaseMarkdownRendererProps & MarkdownConfig\n\n/**\n * Options available while rendering an individual fenced code block.\n */\nexport interface CodeBlockOptions extends RenderMarkdownOptions {\n /**\n * The parsed language identifier for the fenced code block, if present.\n */\n lang?: string\n}\n\n/**\n * Stored Payload block data for a markdown block instance.\n */\nexport interface MarkdownBlockData {\n /**\n * Optional block display name assigned by Payload.\n */\n blockName?: null | string\n\n /**\n * The Payload block slug.\n */\n blockType: '@valkyrianlabs/markdown-block'\n\n /**\n * Markdown source content for this block.\n */\n content: string\n\n /**\n * Optional Payload-generated block identifier.\n */\n id?: null | string\n}\n\n/**\n * Props for the markdown block component wrapper.\n */\nexport interface MarkdownBlockProps {\n /**\n * Stored block data from Payload.\n */\n block: MarkdownBlockData\n\n /**\n * The slug of the collection this block is rendered within, if applicable.\n */\n collectionSlug?: string\n\n /**\n * Default markdown configuration, typically sourced from global or collection-level settings.\n */\n defaults?: MarkdownConfig\n\n /**\n * Block-specific markdown configuration overrides.\n */\n overrides?: MarkdownConfig\n}\n"],"names":[],"mappings":"AAAA;;CAEC,GAoPD;;CAEC,GACD,WAoBC"}
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import {} from 'mdast-util-directive'
|
|
3
|
+
*/
|
|
4
|
+
import type { JSX, ReactNode } from 'react';
|
|
5
|
+
import 'mdast-util-directive';
|
|
6
|
+
declare module 'mdast-util-directive' {
|
|
7
|
+
interface ContainerDirectiveData {
|
|
8
|
+
vlCellHeadingDepth?: number;
|
|
9
|
+
vlParentHeadingDepth?: number;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export type MarkdownRendererScope = 'blocks' | 'field';
|
|
13
|
+
/**
|
|
14
|
+
* Options that control how fenced code blocks are rendered inside markdown content.
|
|
15
|
+
*
|
|
16
|
+
* By default, code blocks use the plugin's enhanced rendering mode:
|
|
17
|
+
* - `enhancedCodeBlocks` defaults to `true`
|
|
18
|
+
* - `lineNumbers` defaults to `true`
|
|
19
|
+
* - `theme` defaults to `'github-dark'`
|
|
20
|
+
*
|
|
21
|
+
* When enhanced rendering is enabled, the plugin applies its normalized code block
|
|
22
|
+
* pipeline on top of Shiki output. This includes layout cleanup, background
|
|
23
|
+
* normalization, and support for features like line numbers.
|
|
24
|
+
*
|
|
25
|
+
* When enhanced rendering is disabled, code blocks are rendered closer to raw
|
|
26
|
+
* Shiki output and plugin-specific enhancements are bypassed.
|
|
27
|
+
*
|
|
28
|
+
* These options are passed through the markdown rendering pipeline and primarily
|
|
29
|
+
* affect Shiki-rendered code fences.
|
|
30
|
+
*/
|
|
31
|
+
export type RenderMarkdownOptions = {
|
|
32
|
+
/**
|
|
33
|
+
* Whether to apply the plugin's enhanced code block rendering pipeline.
|
|
34
|
+
*
|
|
35
|
+
* Defaults to `true`.
|
|
36
|
+
*
|
|
37
|
+
* When enabled, the renderer performs structural and visual normalization on
|
|
38
|
+
* Shiki output to produce a consistent, content-focused appearance.
|
|
39
|
+
*
|
|
40
|
+
* When disabled, code blocks are rendered closer to raw Shiki output.
|
|
41
|
+
*/
|
|
42
|
+
enhancedCodeBlocks?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* An optional list of language identifiers to load for Shiki syntax highlighting.
|
|
45
|
+
*
|
|
46
|
+
* By default, the plugin loads a core set of popular languages. You can replace
|
|
47
|
+
* that set entirely or extend it using spread syntax:
|
|
48
|
+
*
|
|
49
|
+
* ```ts
|
|
50
|
+
* options: {
|
|
51
|
+
* langs: [...DEFAULT_CODE_LANGS, 'latex']
|
|
52
|
+
* }
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
langs?: string[];
|
|
56
|
+
/**
|
|
57
|
+
* Whether to show line numbers for fenced code blocks.
|
|
58
|
+
*
|
|
59
|
+
* Defaults to `true` when `enhancedCodeBlocks` is enabled.
|
|
60
|
+
*
|
|
61
|
+
* Line numbers require the enhanced rendering pipeline and are automatically
|
|
62
|
+
* disabled when `enhancedCodeBlocks` is set to `false`.
|
|
63
|
+
*/
|
|
64
|
+
lineNumbers?: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* The Shiki theme to use for syntax highlighting.
|
|
67
|
+
*
|
|
68
|
+
* Defaults to `'github-dark'`.
|
|
69
|
+
*
|
|
70
|
+
* The plugin's enhanced renderer is tuned around its default theme. When using a
|
|
71
|
+
* non-default theme:
|
|
72
|
+
*
|
|
73
|
+
* - `enhancedCodeBlocks: true` opts into the plugin's normalized rendering pipeline
|
|
74
|
+
* - `enhancedCodeBlocks: false` preserves the theme's native appearance more closely
|
|
75
|
+
*
|
|
76
|
+
* This allows you to choose between a more controlled presentation and a more
|
|
77
|
+
* theme-faithful rendering mode.
|
|
78
|
+
*/
|
|
79
|
+
theme?: string;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* The result of compiling markdown into sanitized HTML.
|
|
83
|
+
*/
|
|
84
|
+
export type RenderMarkdownResult = {
|
|
85
|
+
/**
|
|
86
|
+
* The rendered HTML output.
|
|
87
|
+
*/
|
|
88
|
+
html: string;
|
|
89
|
+
/**
|
|
90
|
+
* Non-fatal warnings produced during rendering.
|
|
91
|
+
*/
|
|
92
|
+
warnings: string[];
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Preset visual styles for rendered markdown content.
|
|
96
|
+
*/
|
|
97
|
+
export type MarkdownVariant = 'blog' | 'compact' | 'docs' | 'unstyled';
|
|
98
|
+
/**
|
|
99
|
+
* Preset typography sizes for rendered markdown content.
|
|
100
|
+
*/
|
|
101
|
+
export type MarkdownSize = 'lg' | 'md' | 'sm';
|
|
102
|
+
/**
|
|
103
|
+
* Core markdown presentation configuration.
|
|
104
|
+
*
|
|
105
|
+
* This type represents the configurable styling and behavior layer that can be
|
|
106
|
+
* sourced from plugin defaults, globals, collection defaults, or block-level
|
|
107
|
+
* overrides. It intentionally excludes runtime-only renderer props such as
|
|
108
|
+
* `markdown`, `as`, and fallback nodes.
|
|
109
|
+
*/
|
|
110
|
+
export type MarkdownConfig = {
|
|
111
|
+
/**
|
|
112
|
+
* Additional classes applied to the rendered markdown element itself.
|
|
113
|
+
*/
|
|
114
|
+
className?: string;
|
|
115
|
+
/**
|
|
116
|
+
* Additional classes applied to column elements within the rendered markdown, if applicable.
|
|
117
|
+
*/
|
|
118
|
+
columnClassName?: string;
|
|
119
|
+
/**
|
|
120
|
+
* Whether to apply horizontal gutter padding to the outer wrapper.
|
|
121
|
+
*
|
|
122
|
+
* Defaults to `false`.
|
|
123
|
+
*/
|
|
124
|
+
enableGutter?: boolean;
|
|
125
|
+
/**
|
|
126
|
+
* Whether fenced code blocks should extend beyond the normal content width
|
|
127
|
+
* on larger screens.
|
|
128
|
+
*
|
|
129
|
+
* Defaults to `false`.
|
|
130
|
+
*/
|
|
131
|
+
fullBleedCode?: boolean;
|
|
132
|
+
/**
|
|
133
|
+
* Optional content rendered above the markdown body.
|
|
134
|
+
*/
|
|
135
|
+
lead?: ReactNode;
|
|
136
|
+
/**
|
|
137
|
+
* Whether heading colors should be slightly muted.
|
|
138
|
+
*
|
|
139
|
+
* Defaults to `false`.
|
|
140
|
+
*/
|
|
141
|
+
mutedHeadings?: boolean;
|
|
142
|
+
/**
|
|
143
|
+
* Options that control fenced code block rendering.
|
|
144
|
+
*/
|
|
145
|
+
options?: RenderMarkdownOptions;
|
|
146
|
+
/**
|
|
147
|
+
* Additional classes applied to section elements within the rendered markdown, if applicable.
|
|
148
|
+
*/
|
|
149
|
+
sectionClassName?: string;
|
|
150
|
+
/**
|
|
151
|
+
* Typography size preset for the rendered markdown.
|
|
152
|
+
*
|
|
153
|
+
* Defaults to `'lg'`.
|
|
154
|
+
*/
|
|
155
|
+
size?: MarkdownSize;
|
|
156
|
+
/**
|
|
157
|
+
* Visual style preset for the rendered markdown.
|
|
158
|
+
*
|
|
159
|
+
* Defaults to `'blog'`.
|
|
160
|
+
*/
|
|
161
|
+
variant?: MarkdownVariant;
|
|
162
|
+
/**
|
|
163
|
+
* Additional classes applied to the outer wrapper element.
|
|
164
|
+
*/
|
|
165
|
+
wrapperClassName?: string;
|
|
166
|
+
};
|
|
167
|
+
/**
|
|
168
|
+
* Runtime-only props shared by markdown renderer components.
|
|
169
|
+
*/
|
|
170
|
+
export type BaseMarkdownRendererProps = {
|
|
171
|
+
/**
|
|
172
|
+
* The HTML tag used for the rendered markdown container.
|
|
173
|
+
*
|
|
174
|
+
* Defaults to `'article'`.
|
|
175
|
+
*/
|
|
176
|
+
as?: keyof JSX.IntrinsicElements;
|
|
177
|
+
/**
|
|
178
|
+
* Content rendered when the markdown input is empty or missing.
|
|
179
|
+
*/
|
|
180
|
+
emptyFallback?: ReactNode;
|
|
181
|
+
/**
|
|
182
|
+
* Content rendered when markdown compilation fails and a fallback is desired.
|
|
183
|
+
*/
|
|
184
|
+
errorFallback?: ReactNode;
|
|
185
|
+
/**
|
|
186
|
+
* The markdown source string to render.
|
|
187
|
+
*/
|
|
188
|
+
markdown?: null | string;
|
|
189
|
+
};
|
|
190
|
+
/**
|
|
191
|
+
* Props for the main markdown renderer component.
|
|
192
|
+
*
|
|
193
|
+
* This merges persisted/configurable markdown presentation settings with the
|
|
194
|
+
* runtime-only rendering props required by the component itself.
|
|
195
|
+
*/
|
|
196
|
+
export type MarkdownRendererProps = {
|
|
197
|
+
collectionSlug?: string;
|
|
198
|
+
scope?: MarkdownRendererScope;
|
|
199
|
+
} & BaseMarkdownRendererProps & MarkdownConfig;
|
|
200
|
+
/**
|
|
201
|
+
* Options available while rendering an individual fenced code block.
|
|
202
|
+
*/
|
|
203
|
+
export interface CodeBlockOptions extends RenderMarkdownOptions {
|
|
204
|
+
/**
|
|
205
|
+
* The parsed language identifier for the fenced code block, if present.
|
|
206
|
+
*/
|
|
207
|
+
lang?: string;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Stored Payload block data for a markdown block instance.
|
|
211
|
+
*/
|
|
212
|
+
export interface MarkdownBlockData {
|
|
213
|
+
/**
|
|
214
|
+
* Optional block display name assigned by Payload.
|
|
215
|
+
*/
|
|
216
|
+
blockName?: null | string;
|
|
217
|
+
/**
|
|
218
|
+
* The Payload block slug.
|
|
219
|
+
*/
|
|
220
|
+
blockType: 'vlMdBlock';
|
|
221
|
+
/**
|
|
222
|
+
* Markdown source content for this block.
|
|
223
|
+
*/
|
|
224
|
+
content: string;
|
|
225
|
+
/**
|
|
226
|
+
* Optional Payload-generated block identifier.
|
|
227
|
+
*/
|
|
228
|
+
id?: null | string;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Props for the markdown block component wrapper.
|
|
232
|
+
*/
|
|
233
|
+
export interface MarkdownBlockProps extends MarkdownBlockData {
|
|
234
|
+
/**
|
|
235
|
+
* The slug of the collection this block is rendered within, if applicable.
|
|
236
|
+
*/
|
|
237
|
+
collectionSlug?: string;
|
|
238
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/core/types.ts"],"sourcesContent":["/**\n * @import {} from 'mdast-util-directive'\n */\n\nimport type { JSX, ReactNode } from 'react'\n\nimport 'mdast-util-directive'\n\ndeclare module 'mdast-util-directive' {\n interface ContainerDirectiveData {\n vlCellHeadingDepth?: number\n vlParentHeadingDepth?: number\n }\n}\n\nexport type MarkdownRendererScope = 'blocks' | 'field'\n\n/**\n * Options that control how fenced code blocks are rendered inside markdown content.\n *\n * By default, code blocks use the plugin's enhanced rendering mode:\n * - `enhancedCodeBlocks` defaults to `true`\n * - `lineNumbers` defaults to `true`\n * - `theme` defaults to `'github-dark'`\n *\n * When enhanced rendering is enabled, the plugin applies its normalized code block\n * pipeline on top of Shiki output. This includes layout cleanup, background\n * normalization, and support for features like line numbers.\n *\n * When enhanced rendering is disabled, code blocks are rendered closer to raw\n * Shiki output and plugin-specific enhancements are bypassed.\n *\n * These options are passed through the markdown rendering pipeline and primarily\n * affect Shiki-rendered code fences.\n */\nexport type RenderMarkdownOptions = {\n /**\n * Whether to apply the plugin's enhanced code block rendering pipeline.\n *\n * Defaults to `true`.\n *\n * When enabled, the renderer performs structural and visual normalization on\n * Shiki output to produce a consistent, content-focused appearance.\n *\n * When disabled, code blocks are rendered closer to raw Shiki output.\n */\n enhancedCodeBlocks?: boolean\n\n /**\n * An optional list of language identifiers to load for Shiki syntax highlighting.\n *\n * By default, the plugin loads a core set of popular languages. You can replace\n * that set entirely or extend it using spread syntax:\n *\n * ```ts\n * options: {\n * langs: [...DEFAULT_CODE_LANGS, 'latex']\n * }\n * ```\n */\n langs?: string[]\n\n /**\n * Whether to show line numbers for fenced code blocks.\n *\n * Defaults to `true` when `enhancedCodeBlocks` is enabled.\n *\n * Line numbers require the enhanced rendering pipeline and are automatically\n * disabled when `enhancedCodeBlocks` is set to `false`.\n */\n lineNumbers?: boolean\n\n /**\n * The Shiki theme to use for syntax highlighting.\n *\n * Defaults to `'github-dark'`.\n *\n * The plugin's enhanced renderer is tuned around its default theme. When using a\n * non-default theme:\n *\n * - `enhancedCodeBlocks: true` opts into the plugin's normalized rendering pipeline\n * - `enhancedCodeBlocks: false` preserves the theme's native appearance more closely\n *\n * This allows you to choose between a more controlled presentation and a more\n * theme-faithful rendering mode.\n */\n theme?: string\n}\n\n/**\n * The result of compiling markdown into sanitized HTML.\n */\nexport type RenderMarkdownResult = {\n /**\n * The rendered HTML output.\n */\n html: string\n\n /**\n * Non-fatal warnings produced during rendering.\n */\n warnings: string[]\n}\n\n/**\n * Preset visual styles for rendered markdown content.\n */\nexport type MarkdownVariant = 'blog' | 'compact' | 'docs' | 'unstyled'\n\n/**\n * Preset typography sizes for rendered markdown content.\n */\nexport type MarkdownSize = 'lg' | 'md' | 'sm'\n\n/**\n * Core markdown presentation configuration.\n *\n * This type represents the configurable styling and behavior layer that can be\n * sourced from plugin defaults, globals, collection defaults, or block-level\n * overrides. It intentionally excludes runtime-only renderer props such as\n * `markdown`, `as`, and fallback nodes.\n */\nexport type MarkdownConfig = {\n /**\n * Additional classes applied to the rendered markdown element itself.\n */\n className?: string\n\n /**\n * Additional classes applied to column elements within the rendered markdown, if applicable.\n */\n columnClassName?: string\n\n /**\n * Whether to apply horizontal gutter padding to the outer wrapper.\n *\n * Defaults to `false`.\n */\n enableGutter?: boolean\n\n /**\n * Whether fenced code blocks should extend beyond the normal content width\n * on larger screens.\n *\n * Defaults to `false`.\n */\n fullBleedCode?: boolean\n\n /**\n * Optional content rendered above the markdown body.\n */\n lead?: ReactNode\n\n /**\n * Whether heading colors should be slightly muted.\n *\n * Defaults to `false`.\n */\n mutedHeadings?: boolean\n\n /**\n * Options that control fenced code block rendering.\n */\n options?: RenderMarkdownOptions\n\n /**\n * Additional classes applied to section elements within the rendered markdown, if applicable.\n */\n sectionClassName?: string\n\n /**\n * Typography size preset for the rendered markdown.\n *\n * Defaults to `'lg'`.\n */\n size?: MarkdownSize\n\n /**\n * Visual style preset for the rendered markdown.\n *\n * Defaults to `'blog'`.\n */\n variant?: MarkdownVariant\n\n /**\n * Additional classes applied to the outer wrapper element.\n */\n wrapperClassName?: string\n}\n\n/**\n * Runtime-only props shared by markdown renderer components.\n */\nexport type BaseMarkdownRendererProps = {\n /**\n * The HTML tag used for the rendered markdown container.\n *\n * Defaults to `'article'`.\n */\n as?: keyof JSX.IntrinsicElements\n\n /**\n * Content rendered when the markdown input is empty or missing.\n */\n emptyFallback?: ReactNode\n\n /**\n * Content rendered when markdown compilation fails and a fallback is desired.\n */\n errorFallback?: ReactNode\n\n /**\n * The markdown source string to render.\n */\n markdown?: null | string\n}\n\n/**\n * Props for the main markdown renderer component.\n *\n * This merges persisted/configurable markdown presentation settings with the\n * runtime-only rendering props required by the component itself.\n */\nexport type MarkdownRendererProps = {\n collectionSlug?: string\n scope?: MarkdownRendererScope\n } & BaseMarkdownRendererProps & MarkdownConfig\n\n/**\n * Options available while rendering an individual fenced code block.\n */\nexport interface CodeBlockOptions extends RenderMarkdownOptions {\n /**\n * The parsed language identifier for the fenced code block, if present.\n */\n lang?: string\n}\n\n/**\n * Stored Payload block data for a markdown block instance.\n */\nexport interface MarkdownBlockData {\n /**\n * Optional block display name assigned by Payload.\n */\n blockName?: null | string\n\n /**\n * The Payload block slug.\n */\n blockType: 'vlMdBlock'\n\n /**\n * Markdown source content for this block.\n */\n content: string\n\n /**\n * Optional Payload-generated block identifier.\n */\n id?: null | string\n}\n\n/**\n * Props for the markdown block component wrapper.\n */\nexport interface MarkdownBlockProps extends MarkdownBlockData {\n /**\n * The slug of the collection this block is rendered within, if applicable.\n */\n collectionSlug?: string\n}\n"],"names":[],"mappings":"AAAA;;CAEC,GAID,OAAO,uBAAsB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type DirectiveAttributeValue = boolean | string;
|
|
2
|
+
export type DirectiveAttributes = Record<string, DirectiveAttributeValue>;
|
|
3
|
+
export type ParsedDirectiveLine = {
|
|
4
|
+
attributes: DirectiveAttributes;
|
|
5
|
+
name: string;
|
|
6
|
+
rawAttributes?: string;
|
|
7
|
+
warnings: string[];
|
|
8
|
+
};
|
|
9
|
+
export declare function parseDirectiveAttributesDetailed(value?: string): {
|
|
10
|
+
attributes: DirectiveAttributes;
|
|
11
|
+
warnings: string[];
|
|
12
|
+
};
|
|
13
|
+
export declare function parseDirectiveAttributes(value?: string): DirectiveAttributes;
|
|
14
|
+
export declare function parseDirectiveLine(text: string): null | ParsedDirectiveLine;
|