payload-markdown 1.8.1 → 1.9.0

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.
Files changed (94) hide show
  1. package/dist/core/plugins/remarkCompileLayouts.js.map +1 -1
  2. package/dist/core/plugins/remarkDirectiveLines.d.ts +7 -5
  3. package/dist/core/plugins/remarkDirectiveLines.js +29 -18
  4. package/dist/core/plugins/remarkDirectiveLines.js.map +1 -1
  5. package/dist/core/plugins/remarkLayoutDirectives.js +1 -1
  6. package/dist/core/plugins/remarkLayoutDirectives.js.map +1 -1
  7. package/dist/core/plugins/remarkValidateDirectiveThemes.js +7 -14
  8. package/dist/core/plugins/remarkValidateDirectiveThemes.js.map +1 -1
  9. package/dist/core/renderMarkdown.js +2 -231
  10. package/dist/core/renderMarkdown.js.map +1 -1
  11. package/dist/core/sanitizeSchema.d.ts +11 -0
  12. package/dist/core/sanitizeSchema.js +176 -0
  13. package/dist/core/sanitizeSchema.js.map +1 -0
  14. package/dist/directives/definitions/badge.d.ts +5 -2
  15. package/dist/directives/definitions/badge.js +138 -10
  16. package/dist/directives/definitions/badge.js.map +1 -1
  17. package/dist/directives/definitions/badges.d.ts +1 -2
  18. package/dist/directives/definitions/badges.js +12 -3
  19. package/dist/directives/definitions/badges.js.map +1 -1
  20. package/dist/directives/definitions/button.d.ts +6 -2
  21. package/dist/directives/definitions/button.js +202 -12
  22. package/dist/directives/definitions/button.js.map +1 -1
  23. package/dist/directives/definitions/buttons.d.ts +1 -2
  24. package/dist/directives/definitions/buttons.js +12 -3
  25. package/dist/directives/definitions/buttons.js.map +1 -1
  26. package/dist/directives/definitions/callout.d.ts +1 -2
  27. package/dist/directives/definitions/callout.js +37 -3
  28. package/dist/directives/definitions/callout.js.map +1 -1
  29. package/dist/directives/definitions/card.d.ts +6 -2
  30. package/dist/directives/definitions/card.js +51 -3
  31. package/dist/directives/definitions/card.js.map +1 -1
  32. package/dist/directives/definitions/cards.d.ts +1 -2
  33. package/dist/directives/definitions/cards.js +40 -4
  34. package/dist/directives/definitions/cards.js.map +1 -1
  35. package/dist/directives/definitions/cell.d.ts +2 -2
  36. package/dist/directives/definitions/cell.js +9 -3
  37. package/dist/directives/definitions/cell.js.map +1 -1
  38. package/dist/directives/definitions/columns.d.ts +3 -4
  39. package/dist/directives/definitions/columns.js +17 -3
  40. package/dist/directives/definitions/columns.js.map +1 -1
  41. package/dist/directives/definitions/details.d.ts +1 -2
  42. package/dist/directives/definitions/details.js +24 -3
  43. package/dist/directives/definitions/details.js.map +1 -1
  44. package/dist/directives/definitions/section.d.ts +1 -2
  45. package/dist/directives/definitions/section.js +22 -3
  46. package/dist/directives/definitions/section.js.map +1 -1
  47. package/dist/directives/definitions/steps.d.ts +1 -2
  48. package/dist/directives/definitions/steps.js +22 -3
  49. package/dist/directives/definitions/steps.js.map +1 -1
  50. package/dist/directives/definitions/tab.d.ts +8 -2
  51. package/dist/directives/definitions/tab.js +45 -3
  52. package/dist/directives/definitions/tab.js.map +1 -1
  53. package/dist/directives/definitions/tabs.d.ts +1 -1
  54. package/dist/directives/definitions/tabs.js +40 -3
  55. package/dist/directives/definitions/tabs.js.map +1 -1
  56. package/dist/directives/definitions/toc.d.ts +1 -2
  57. package/dist/directives/definitions/toc.js +32 -4
  58. package/dist/directives/definitions/toc.js.map +1 -1
  59. package/dist/directives/diagnostics.d.ts +2 -15
  60. package/dist/directives/diagnostics.js +27 -157
  61. package/dist/directives/diagnostics.js.map +1 -1
  62. package/dist/directives/lint.d.ts +11 -0
  63. package/dist/directives/lint.js +33 -0
  64. package/dist/directives/lint.js.map +1 -0
  65. package/dist/directives/registry.d.ts +23 -5
  66. package/dist/directives/registry.js +52 -40
  67. package/dist/directives/registry.js.map +1 -1
  68. package/dist/directives/spec.js +25 -51
  69. package/dist/directives/spec.js.map +1 -1
  70. package/dist/directives/themeDiagnostics.d.ts +8 -0
  71. package/dist/directives/themeDiagnostics.js +21 -0
  72. package/dist/directives/themeDiagnostics.js.map +1 -0
  73. package/dist/directives/types.d.ts +157 -14
  74. package/dist/directives/types.js +6 -1
  75. package/dist/directives/types.js.map +1 -1
  76. package/dist/editor/directives/completions.js +11 -4
  77. package/dist/editor/directives/completions.js.map +1 -1
  78. package/dist/editor/themes/payload.js +2 -1
  79. package/dist/editor/themes/payload.js.map +1 -1
  80. package/dist/version.d.ts +1 -1
  81. package/dist/version.js +1 -1
  82. package/dist/version.js.map +1 -1
  83. package/package.json +1 -1
  84. package/skills/payload-markdown/claude/skill.json +1 -1
  85. package/skills/payload-markdown/codex/skill.json +1 -1
  86. package/dist/core/plugins/directiveBadge.d.ts +0 -6
  87. package/dist/core/plugins/directiveBadge.js +0 -94
  88. package/dist/core/plugins/directiveBadge.js.map +0 -1
  89. package/dist/core/plugins/directiveButton.d.ts +0 -6
  90. package/dist/core/plugins/directiveButton.js +0 -132
  91. package/dist/core/plugins/directiveButton.js.map +0 -1
  92. package/dist/directives/buttonSyntax.d.ts +0 -7
  93. package/dist/directives/buttonSyntax.js +0 -6
  94. package/dist/directives/buttonSyntax.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/core/plugins/remarkCompileLayouts.ts"],"sourcesContent":["import type { Heading, Root, RootContent } from 'mdast'\nimport type { ContainerDirective } from 'mdast-util-directive'\nimport type { Plugin } from 'unified'\n\nimport type { LayoutName, LayoutToken } from '../../directives/types.js'\nimport type { DiagnosticPlace } from '../diagnostics.js'\n\nimport { layoutDirectiveRegistry } from '../../directives/registry.js'\nimport { reportDiagnostic } from '../diagnostics.js'\n\ntype LayoutNode = ContainerDirective | Root\n\ntype AppendableRootContent = Exclude<RootContent, LayoutToken>\n\ntype LayoutFrame = {\n cellHeadingDepth?: number\n name: 'root' | LayoutName\n node: LayoutNode\n parentHeadingDepth?: number\n place?: DiagnosticPlace\n}\n\ntype CompileWarning = {\n code: string\n place?: DiagnosticPlace\n reason: string\n}\n\nfunction isHeading(node: RootContent): node is Heading {\n return node.type === 'heading'\n}\n\nfunction isLayoutToken(node: RootContent): node is LayoutToken {\n return node.type === 'vlLayoutToken'\n}\n\nfunction isAppendableRootContent(node: RootContent): node is AppendableRootContent {\n return node.type !== 'vlLayoutToken'\n}\n\nfunction makeDirective(\n name: LayoutName,\n attributes: Record<string, boolean | string> = {},\n label?: string,\n parentHeadingDepth?: number,\n cellHeadingDepth?: number,\n place?: DiagnosticPlace,\n): ContainerDirective {\n return {\n name,\n type: 'containerDirective',\n attributes: Object.fromEntries(\n Object.entries(attributes).map(([key, value]) => [key, String(value)]),\n ),\n children: [],\n data: {\n vlCellHeadingDepth: cellHeadingDepth,\n vlDirectiveLabel: label,\n vlParentHeadingDepth: parentHeadingDepth,\n ...(place ? { vlPlace: place } : {}),\n },\n }\n}\n\nfunction getChildren(node: LayoutNode): AppendableRootContent[] {\n return node.children as AppendableRootContent[]\n}\n\nfunction top<T>(arr: T[]): T {\n return arr[arr.length - 1]\n}\n\nfunction isGridName(name: LayoutFrame['name']): name is '2col' | '3col' {\n return layoutDirectiveRegistry.isGridName(name)\n}\n\nfunction findNearestSectionIndex(stack: LayoutFrame[]): number {\n for (let i = stack.length - 1; i >= 0; --i) if (stack[i]?.name === 'section') return i\n\n return -1\n}\n\nfunction findNearestGridIndex(stack: LayoutFrame[]): number {\n for (let i = stack.length - 1; i >= 0; --i) if (isGridName(stack[i]?.name)) return i\n\n return -1\n}\n\nfunction closeTop(stack: LayoutFrame[]) {\n if (stack.length > 1) stack.pop()\n}\n\nfunction closeActiveGrid(stack: LayoutFrame[]): boolean {\n const gridIndex = findNearestGridIndex(stack)\n if (gridIndex < 0) return false\n\n while (stack.length - 1 >= gridIndex) stack.pop()\n\n return true\n}\n\nfunction closeActiveGridInsideSection(stack: LayoutFrame[]): boolean {\n const gridIndex = findNearestGridIndex(stack)\n const sectionIndex = findNearestSectionIndex(stack)\n\n if (gridIndex < 0 || sectionIndex < 0) return false\n if (gridIndex < sectionIndex) return false\n\n while (stack.length - 1 >= gridIndex) stack.pop()\n\n return true\n}\n\nfunction closeThroughSection(stack: LayoutFrame[]): boolean {\n const sectionIndex = findNearestSectionIndex(stack)\n if (sectionIndex < 0) return false\n\n while (stack.length - 1 >= sectionIndex) stack.pop()\n\n return true\n}\n\nexport const remarkCompileLayouts: Plugin<[], Root> = () => {\n return (tree, file) => {\n const input = [...tree.children]\n const rebuiltRoot: Root = { ...tree, children: [] }\n const stack: LayoutFrame[] = [{ name: 'root', node: rebuiltRoot }]\n const warnings: CompileWarning[] = []\n\n let currentHeadingDepth: number | undefined\n\n const append = (node: AppendableRootContent) => getChildren(top(stack).node).push(node)\n\n for (const node of input) {\n if (isLayoutToken(node)) {\n const place = node.data?.vlPlace\n\n if (node.action === 'open') {\n const definition = layoutDirectiveRegistry.get(node.name)\n\n if (definition?.kind === 'section') {\n const next = makeDirective('section', node.attributes, node.label, undefined, undefined, place)\n append(next)\n stack.push({ name: 'section', node: next, place })\n continue\n }\n\n if (definition?.kind === 'cell') {\n const next = makeDirective('cell', node.attributes, node.label, undefined, undefined, place)\n append(next)\n stack.push({ name: 'cell', node: next, place })\n continue\n }\n\n if (definition?.kind !== 'grid') {\n const next = makeDirective(node.name, node.attributes, node.label, undefined, undefined, place)\n append(next)\n stack.push({ name: node.name, node: next, place })\n continue\n }\n\n closeActiveGridInsideSection(stack)\n\n const parentDepth = currentHeadingDepth ?? 1\n const cellDepth = parentDepth + 1\n const next = makeDirective(\n node.name,\n node.attributes,\n node.label,\n parentDepth,\n cellDepth,\n place,\n )\n\n append(next)\n stack.push({\n name: node.name,\n cellHeadingDepth: cellDepth,\n node: next,\n parentHeadingDepth: parentDepth,\n place,\n })\n continue\n }\n\n if (node.action === 'close') {\n if (stack.length === 1) {\n warnings.push({\n code: 'stray-directive-close',\n place,\n reason: 'Encountered ::: with no open layout block.',\n })\n continue\n }\n\n closeTop(stack)\n continue\n }\n\n if (node.action === 'closeGrid') {\n if (!closeActiveGrid(stack)) {\n warnings.push({\n code: 'stray-directive-close',\n place,\n reason: 'Encountered :::endcol with no open grid.',\n })\n continue\n }\n\n continue\n }\n\n if (node.action === 'closeSection') {\n if (!closeThroughSection(stack))\n warnings.push({\n code: 'stray-directive-close',\n place,\n reason: 'Encountered :::end or :::endsection with no open section.',\n })\n\n continue\n }\n }\n\n if (isHeading(node)) {\n const currentFrame = top(stack)\n\n if (isGridName(currentFrame.name)) {\n const parentDepth = currentFrame.parentHeadingDepth\n\n if (typeof parentDepth === 'number' && node.depth < parentDepth) closeTop(stack)\n }\n\n currentHeadingDepth = node.depth\n append(node)\n continue\n }\n\n if (isAppendableRootContent(node)) append(node)\n }\n\n while (stack.length > 1) {\n warnings.push({\n code: 'unclosed-directive',\n place: top(stack).place,\n reason: `Auto-closing unclosed layout block: ${top(stack).name}`,\n })\n stack.pop()\n }\n\n tree.children = rebuiltRoot.children\n\n for (const { code, place, reason } of warnings)\n reportDiagnostic(file, reason, { code, place, source: 'directive' })\n }\n}\n"],"names":["layoutDirectiveRegistry","reportDiagnostic","isHeading","node","type","isLayoutToken","isAppendableRootContent","makeDirective","name","attributes","label","parentHeadingDepth","cellHeadingDepth","place","Object","fromEntries","entries","map","key","value","String","children","data","vlCellHeadingDepth","vlDirectiveLabel","vlParentHeadingDepth","vlPlace","getChildren","top","arr","length","isGridName","findNearestSectionIndex","stack","i","findNearestGridIndex","closeTop","pop","closeActiveGrid","gridIndex","closeActiveGridInsideSection","sectionIndex","closeThroughSection","remarkCompileLayouts","tree","file","input","rebuiltRoot","warnings","currentHeadingDepth","append","push","action","definition","get","kind","next","undefined","parentDepth","cellDepth","code","reason","currentFrame","depth","source"],"mappings":"AAOA,SAASA,uBAAuB,QAAQ,+BAA8B;AACtE,SAASC,gBAAgB,QAAQ,oBAAmB;AAoBpD,SAASC,UAAUC,IAAiB;IAClC,OAAOA,KAAKC,IAAI,KAAK;AACvB;AAEA,SAASC,cAAcF,IAAiB;IACtC,OAAOA,KAAKC,IAAI,KAAK;AACvB;AAEA,SAASE,wBAAwBH,IAAiB;IAChD,OAAOA,KAAKC,IA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4BACN/C;4BACAgD,QAAQ;wBACV;wBACA;oBACF;oBAEA;gBACF;gBAEA,IAAI1D,KAAKiD,MAAM,KAAK,gBAAgB;oBAClC,IAAI,CAACV,oBAAoBT,QACvBe,SAASG,IAAI,CAAC;wBACZS,MAAM;wBACN/C;wBACAgD,QAAQ;oBACV;oBAEF;gBACF;YACF;YAEA,IAAI3D,UAAUC,OAAO;gBACnB,MAAM2D,eAAelC,IAAIK;gBAEzB,IAAIF,WAAW+B,aAAatD,IAAI,GAAG;oBACjC,MAAMkD,cAAcI,aAAanD,kBAAkB;oBAEnD,IAAI,OAAO+C,gBAAgB,YAAYvD,KAAK4D,KAAK,GAAGL,aAAatB,SAASH;gBAC5E;gBAEAgB,sBAAsB9C,KAAK4D,KAAK;gBAChCb,OAAO/C;gBACP;YACF;YAEA,IAAIG,wBAAwBH,OAAO+C,OAAO/C;QAC5C;QAEA,MAAO8B,MAAMH,MAAM,GAAG,EAAG;YACvBkB,SAASG,IAAI,CAAC;gBACZS,MAAM;gBACN/C,OAAOe,IAAIK,OAAOpB,KAAK;gBACvBgD,QAAQ,CAAC,oCAAoC,EAAEjC,IAAIK,OAAOzB,IAAI,EAAE;YAClE;YACAyB,MAAMI,GAAG;QACX;QAEAO,KAAKvB,QAAQ,GAAG0B,YAAY1B,QAAQ;QAEpC,KAAK,MAAM,EAAEuC,IAAI,EAAE/C,KAAK,EAAEgD,MAAM,EAAE,IAAIb,SACpC/C,iBAAiB4C,MAAMgB,QAAQ;YAAED;YAAM/C;YAAOmD,QAAQ;QAAY;IACtE;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../src/core/plugins/remarkCompileLayouts.ts"],"sourcesContent":["import type { Heading, Root, RootContent } from 'mdast'\nimport type { ContainerDirective } from 'mdast-util-directive'\nimport type { Plugin } from 'unified'\n\nimport type { GridDirectiveName, LayoutName, LayoutToken } from '../../directives/types.js'\nimport type { DiagnosticPlace } from '../diagnostics.js'\n\nimport { layoutDirectiveRegistry } from '../../directives/registry.js'\nimport { reportDiagnostic } from '../diagnostics.js'\n\ntype LayoutNode = ContainerDirective | Root\n\ntype AppendableRootContent = Exclude<RootContent, LayoutToken>\n\ntype LayoutFrame = {\n cellHeadingDepth?: number\n name: 'root' | LayoutName\n node: LayoutNode\n parentHeadingDepth?: number\n place?: DiagnosticPlace\n}\n\ntype CompileWarning = {\n code: string\n place?: DiagnosticPlace\n reason: string\n}\n\nfunction isHeading(node: RootContent): node is Heading {\n return node.type === 'heading'\n}\n\nfunction isLayoutToken(node: RootContent): node is LayoutToken {\n return node.type === 'vlLayoutToken'\n}\n\nfunction isAppendableRootContent(node: RootContent): node is AppendableRootContent {\n return node.type !== 'vlLayoutToken'\n}\n\nfunction makeDirective(\n name: LayoutName,\n attributes: Record<string, boolean | string> = {},\n label?: string,\n parentHeadingDepth?: number,\n cellHeadingDepth?: number,\n place?: DiagnosticPlace,\n): ContainerDirective {\n return {\n name,\n type: 'containerDirective',\n attributes: Object.fromEntries(\n Object.entries(attributes).map(([key, value]) => [key, String(value)]),\n ),\n children: [],\n data: {\n vlCellHeadingDepth: cellHeadingDepth,\n vlDirectiveLabel: label,\n vlParentHeadingDepth: parentHeadingDepth,\n ...(place ? { vlPlace: place } : {}),\n },\n }\n}\n\nfunction getChildren(node: LayoutNode): AppendableRootContent[] {\n return node.children as AppendableRootContent[]\n}\n\nfunction top<T>(arr: T[]): T {\n return arr[arr.length - 1]\n}\n\nfunction isGridName(name: LayoutFrame['name']): name is GridDirectiveName {\n return layoutDirectiveRegistry.isGridName(name)\n}\n\nfunction findNearestSectionIndex(stack: LayoutFrame[]): number {\n for (let i = stack.length - 1; i >= 0; --i) if (stack[i]?.name === 'section') return i\n\n return -1\n}\n\nfunction findNearestGridIndex(stack: LayoutFrame[]): number {\n for (let i = stack.length - 1; i >= 0; --i) if (isGridName(stack[i]?.name)) return i\n\n return -1\n}\n\nfunction closeTop(stack: LayoutFrame[]) {\n if (stack.length > 1) stack.pop()\n}\n\nfunction closeActiveGrid(stack: LayoutFrame[]): boolean {\n const gridIndex = findNearestGridIndex(stack)\n if (gridIndex < 0) return false\n\n while (stack.length - 1 >= gridIndex) stack.pop()\n\n return true\n}\n\nfunction closeActiveGridInsideSection(stack: LayoutFrame[]): boolean {\n const gridIndex = findNearestGridIndex(stack)\n const sectionIndex = findNearestSectionIndex(stack)\n\n if (gridIndex < 0 || sectionIndex < 0) return false\n if (gridIndex < sectionIndex) return false\n\n while (stack.length - 1 >= gridIndex) stack.pop()\n\n return true\n}\n\nfunction closeThroughSection(stack: LayoutFrame[]): boolean {\n const sectionIndex = findNearestSectionIndex(stack)\n if (sectionIndex < 0) return false\n\n while (stack.length - 1 >= sectionIndex) stack.pop()\n\n return true\n}\n\nexport const remarkCompileLayouts: Plugin<[], Root> = () => {\n return (tree, file) => {\n const input = [...tree.children]\n const rebuiltRoot: Root = { ...tree, children: [] }\n const stack: LayoutFrame[] = [{ name: 'root', node: rebuiltRoot }]\n const warnings: CompileWarning[] = []\n\n let currentHeadingDepth: number | undefined\n\n const append = (node: AppendableRootContent) => getChildren(top(stack).node).push(node)\n\n for (const node of input) {\n if (isLayoutToken(node)) {\n const place = node.data?.vlPlace\n\n if (node.action === 'open') {\n const definition = layoutDirectiveRegistry.get(node.name)\n\n if (definition?.kind === 'section') {\n const next = makeDirective('section', node.attributes, node.label, undefined, undefined, place)\n append(next)\n stack.push({ name: 'section', node: next, place })\n continue\n }\n\n if (definition?.kind === 'cell') {\n const next = makeDirective('cell', node.attributes, node.label, undefined, undefined, place)\n append(next)\n stack.push({ name: 'cell', node: next, place })\n continue\n }\n\n if (definition?.kind !== 'grid') {\n const next = makeDirective(node.name, node.attributes, node.label, undefined, undefined, place)\n append(next)\n stack.push({ name: node.name, node: next, place })\n continue\n }\n\n closeActiveGridInsideSection(stack)\n\n const parentDepth = currentHeadingDepth ?? 1\n const cellDepth = parentDepth + 1\n const next = makeDirective(\n node.name,\n node.attributes,\n node.label,\n parentDepth,\n cellDepth,\n place,\n )\n\n append(next)\n stack.push({\n name: node.name,\n cellHeadingDepth: cellDepth,\n node: next,\n parentHeadingDepth: parentDepth,\n place,\n })\n continue\n }\n\n if (node.action === 'close') {\n if (stack.length === 1) {\n warnings.push({\n code: 'stray-directive-close',\n place,\n reason: 'Encountered ::: with no open layout block.',\n })\n continue\n }\n\n closeTop(stack)\n continue\n }\n\n if (node.action === 'closeGrid') {\n if (!closeActiveGrid(stack)) {\n warnings.push({\n code: 'stray-directive-close',\n place,\n reason: 'Encountered :::endcol with no open grid.',\n })\n continue\n }\n\n continue\n }\n\n if (node.action === 'closeSection') {\n if (!closeThroughSection(stack))\n warnings.push({\n code: 'stray-directive-close',\n place,\n reason: 'Encountered :::end or :::endsection with no open section.',\n })\n\n continue\n }\n }\n\n if (isHeading(node)) {\n const currentFrame = top(stack)\n\n if (isGridName(currentFrame.name)) {\n const parentDepth = currentFrame.parentHeadingDepth\n\n if (typeof parentDepth === 'number' && node.depth < parentDepth) closeTop(stack)\n }\n\n currentHeadingDepth = node.depth\n append(node)\n continue\n }\n\n if (isAppendableRootContent(node)) append(node)\n }\n\n while (stack.length > 1) {\n warnings.push({\n code: 'unclosed-directive',\n place: top(stack).place,\n reason: `Auto-closing unclosed layout block: ${top(stack).name}`,\n })\n stack.pop()\n }\n\n tree.children = rebuiltRoot.children\n\n for (const { code, place, reason } of warnings)\n reportDiagnostic(file, reason, { code, place, source: 'directive' })\n }\n}\n"],"names":["layoutDirectiveRegistry","reportDiagnostic","isHeading","node","type","isLayoutToken","isAppendableRootContent","makeDirective","name","attributes","label","parentHeadingDepth","cellHeadingDepth","place","Object","fromEntries","entries","map","key","value","String","children","data","vlCellHeadingDepth","vlDirectiveLabel","vlParentHeadingDepth","vlPlace","getChildren","top","arr","length","isGridName","findNearestSectionIndex","stack","i","findNearestGridIndex","closeTop","pop","closeActiveGrid","gridIndex","closeActiveGridInsideSection","sectionIndex","closeThroughSection","remarkCompileLayouts","tree","file","input","rebuiltRoot","warnings","currentHeadingDepth","append","push","action","definition","get","kind","next","undefined","parentDepth","cellDepth","code","reason","currentFrame","depth","source"],"mappings":"AAOA,SAASA,uBAAuB,QAAQ,+BAA8B;AACtE,SAASC,gBAAgB,QAAQ,oBAAmB;AAoBpD,SAASC,UAAUC,IAAiB;IAClC,OAAOA,KAAKC,IAAI,KAAK;AACvB;AAEA,SAASC,cAAcF,IAAiB;IACtC,OAAOA,KAAKC,IAAI,KAAK;AACvB;AAEA,SAASE,wBAAwBH,IAAiB;IAChD,OAAOA,KAAKC,IAAI,KAAK;AACvB;AAEA,SAASG,cACPC,IAAgB,EAChBC,aAA+C,CAAC,CAAC,EACjDC,KAAc,EACdC,kBAA2B,EAC3BC,gBAAyB,EACzBC,KAAuB;IAEvB,OAAO;QACLL;QACAJ,MAAM;QACNK,YAAYK,OAAOC,WAAW,CAC5BD,OAAOE,OAAO,CAACP,YAAYQ,GAAG,CAAC,CAAC,CAACC,KAAKC,MAAM,GAAK;gBAACD;gBAAKE,OAAOD;aAAO;QAEvEE,UAAU,EAAE;QACZC,MAAM;YACJC,oBAAoBX;YACpBY,kBAAkBd;YAClBe,sBAAsBd;YACtB,GAAIE,QAAQ;gBAAEa,SAASb;YAAM,IAAI,CAAC,CAAC;QACrC;IACF;AACF;AAEA,SAASc,YAAYxB,IAAgB;IACnC,OAAOA,KAAKkB,QAAQ;AACtB;AAEA,SAASO,IAAOC,GAAQ;IACtB,OAAOA,GAAG,CAACA,IAAIC,MAAM,GAAG,EAAE;AAC5B;AAEA,SAASC,WAAWvB,IAAyB;IAC3C,OAAOR,wBAAwB+B,UAAU,CAACvB;AAC5C;AAEA,SAASwB,wBAAwBC,KAAoB;IACnD,IAAK,IAAIC,IAAID,MAAMH,MAAM,GAAG,GAAGI,KAAK,GAAG,EAAEA,EAAG,IAAID,KAAK,CAACC,EAAE,EAAE1B,SAAS,WAAW,OAAO0B;IAErF,OAAO,CAAC;AACV;AAEA,SAASC,qBAAqBF,KAAoB;IAChD,IAAK,IAAIC,IAAID,MAAMH,MAAM,GA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AED;YAAM/C;YAAOmD,QAAQ;QAAY;IACtE;AACF,EAAC"}
@@ -3,11 +3,13 @@ import type { Plugin } from 'unified';
3
3
  import type { MarkdownRenderConfig } from '../../types/core.js';
4
4
  /**
5
5
  * Lifts directive lines out of root-level paragraphs: `:::` markers become
6
- * layout tokens for remarkCompileLayouts, and `::button` / `::badge` lines
7
- * become leaf directive nodes. Detection is source-based (see lineScanner).
6
+ * layout tokens for remarkCompileLayouts, and `::name` lines become leaf
7
+ * directive nodes built by the definition's `leaf.build`. Detection is
8
+ * source-based (see lineScanner).
8
9
  *
9
- * Warnings keep the historical order: container-line diagnostics, then
10
- * button/unknown-leaf diagnostics, then badge diagnostics, followed by
11
- * markers found inside lists, blockquotes, tables or footnotes.
10
+ * Warnings keep the historical order: container-line diagnostics, then each
11
+ * leaf directive's diagnostics in registry order (unknown leaf names with the
12
+ * first leaf directive, `button`), followed by markers found inside lists,
13
+ * blockquotes, tables or footnotes.
12
14
  */
13
15
  export declare const remarkDirectiveLines: Plugin<[MarkdownRenderConfig?], Root>;
@@ -2,8 +2,19 @@ import { getLeafDirectiveName, getLeafDirectiveProblem } from '../../directives/
2
2
  import { createSourceIndex, findNestedDirectiveMarkers, getNestedDirectiveMarkerDiagnostic, joinPhrasingLines, scanDirectiveLineAt, splitParagraphIntoLines } from '../../directives/lineScanner.js';
3
3
  import { layoutDirectiveRegistry } from '../../directives/registry.js';
4
4
  import { placeAt, reportDiagnostic } from '../diagnostics.js';
5
- import { makeBadgeDirective } from './directiveBadge.js';
6
- import { makeButtonDirective } from './directiveButton.js';
5
+ function createWarningBuckets() {
6
+ const leaf = new Map(layoutDirectiveRegistry.leafDirectiveNames.map((name)=>[
7
+ name,
8
+ []
9
+ ]));
10
+ const [firstLeafName = ''] = layoutDirectiveRegistry.leafDirectiveNames;
11
+ if (!leaf.has(firstLeafName)) leaf.set(firstLeafName, []);
12
+ return {
13
+ layout: [],
14
+ leaf,
15
+ unknownLeaf: leaf.get(firstLeafName) ?? []
16
+ };
17
+ }
7
18
  function makeSink(target, place) {
8
19
  return {
9
20
  message (reason) {
@@ -64,19 +75,20 @@ function splitParagraph(node, index, warnings, config) {
64
75
  pending.push(lines[lineIndex]);
65
76
  continue;
66
77
  }
67
- if (!layoutDirectiveRegistry.isLeafDirectiveName(leafName)) {
68
- push(warnings.button, `Unknown directive "${leafName}".`);
78
+ const leaf = layoutDirectiveRegistry.get(leafName)?.leaf;
79
+ const bucket = warnings.leaf.get(leafName);
80
+ if (!leaf || !bucket) {
81
+ push(warnings.unknownLeaf, `Unknown directive "${leafName}".`);
69
82
  pending.push(lines[lineIndex]);
70
83
  continue;
71
84
  }
72
- const bucket = leafName === 'button' ? warnings.button : warnings.badge;
73
85
  const problem = getLeafDirectiveProblem(scanned.text, leafName);
74
86
  if (problem) {
75
87
  push(bucket, problem);
76
88
  pending.push(lines[lineIndex]);
77
89
  continue;
78
90
  }
79
- const directive = leafName === 'button' ? makeButtonDirective(scanned.text, makeSink(bucket, place), config) : makeBadgeDirective(scanned.text, makeSink(bucket, place));
91
+ const directive = leaf.build(scanned.text, makeSink(bucket, place), config);
80
92
  if (directive) lineIndex = emit(directive, scanned.phrasingEnd);
81
93
  else pending.push(lines[lineIndex]);
82
94
  }
@@ -88,28 +100,27 @@ function splitParagraph(node, index, warnings, config) {
88
100
  }
89
101
  /**
90
102
  * Lifts directive lines out of root-level paragraphs: `:::` markers become
91
- * layout tokens for remarkCompileLayouts, and `::button` / `::badge` lines
92
- * become leaf directive nodes. Detection is source-based (see lineScanner).
103
+ * layout tokens for remarkCompileLayouts, and `::name` lines become leaf
104
+ * directive nodes built by the definition's `leaf.build`. Detection is
105
+ * source-based (see lineScanner).
93
106
  *
94
- * Warnings keep the historical order: container-line diagnostics, then
95
- * button/unknown-leaf diagnostics, then badge diagnostics, followed by
96
- * markers found inside lists, blockquotes, tables or footnotes.
107
+ * Warnings keep the historical order: container-line diagnostics, then each
108
+ * leaf directive's diagnostics in registry order (unknown leaf names with the
109
+ * first leaf directive, `button`), followed by markers found inside lists,
110
+ * blockquotes, tables or footnotes.
97
111
  */ export const remarkDirectiveLines = (config = {})=>{
98
112
  return (tree, file)=>{
99
113
  const index = createSourceIndex(String(file.value ?? ''));
100
- const warnings = {
101
- badge: [],
102
- button: [],
103
- layout: []
104
- };
114
+ const warnings = createWarningBuckets();
105
115
  const nestedMarkers = findNestedDirectiveMarkers(tree, index);
106
116
  tree.children = tree.children.flatMap((node)=>node.type === 'paragraph' ? splitParagraph(node, index, warnings, config) : [
107
117
  node
108
118
  ]);
109
119
  for (const { place, reason } of [
110
120
  ...warnings.layout,
111
- ...warnings.button,
112
- ...warnings.badge
121
+ ...[
122
+ ...warnings.leaf.values()
123
+ ].flat()
113
124
  ])reportDiagnostic(file, reason, {
114
125
  place,
115
126
  source: 'directive'
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/core/plugins/remarkDirectiveLines.ts"],"sourcesContent":["import type { Paragraph, Root, RootContent } from 'mdast'\nimport type { Plugin } from 'unified'\n\nimport type { PhrasingLine, ScannedDirectiveLine, SourceIndex } from '../../directives/lineScanner.js'\nimport type { MarkdownRenderConfig } from '../../types/core.js'\nimport type { DiagnosticPlace } from '../diagnostics.js'\n\nimport { getLeafDirectiveName, getLeafDirectiveProblem } from '../../directives/leafSyntax.js'\nimport {\n createSourceIndex,\n findNestedDirectiveMarkers,\n getNestedDirectiveMarkerDiagnostic,\n joinPhrasingLines,\n scanDirectiveLineAt,\n splitParagraphIntoLines,\n} from '../../directives/lineScanner.js'\nimport { layoutDirectiveRegistry } from '../../directives/registry.js'\nimport { placeAt, reportDiagnostic } from '../diagnostics.js'\nimport { makeBadgeDirective } from './directiveBadge.js'\nimport { makeButtonDirective } from './directiveButton.js'\n\ntype PlacedWarning = {\n place?: DiagnosticPlace\n reason: string\n}\n\ntype WarningBuckets = {\n badge: PlacedWarning[]\n button: PlacedWarning[]\n layout: PlacedWarning[]\n}\n\nfunction makeSink(target: PlacedWarning[], place: DiagnosticPlace | undefined) {\n return {\n message(reason: string) {\n target.push({ place, reason })\n },\n }\n}\n\nfunction getScannedPlace(scanned: ScannedDirectiveLine, index: SourceIndex): DiagnosticPlace {\n return placeAt(scanned.startLine, index.lineStarts[scanned.startLine] ?? 0, scanned.from)\n}\n\nfunction splitParagraph(\n node: Paragraph,\n index: SourceIndex,\n warnings: WarningBuckets,\n config: MarkdownRenderConfig,\n): RootContent[] {\n const lines = splitParagraphIntoLines(node)\n const out: RootContent[] = []\n let pending: PhrasingLine[] = []\n let changed = false\n\n const flush = () => {\n if (pending.length > 0) out.push({ type: 'paragraph', children: joinPhrasingLines(pending) })\n pending = []\n }\n\n const emit = (replacement: RootContent, endIndex: number) => {\n flush()\n out.push(replacement)\n changed = true\n\n return endIndex\n }\n\n for (let lineIndex = 0; lineIndex < lines.length; ++lineIndex) {\n const scanned = scanDirectiveLineAt(lines, lineIndex, index)\n\n if (!scanned) {\n pending.push(lines[lineIndex])\n continue\n }\n\n const place = getScannedPlace(scanned, index)\n const push = (bucket: PlacedWarning[], reason: string) => bucket.push({ place, reason })\n\n if (scanned.kind === 'container') {\n const result = layoutDirectiveRegistry.parseMarkdownLineDetailed(scanned.text)\n\n for (const reason of result.diagnostics) push(warnings.layout, reason)\n\n if (result.token) {\n // The open/close marker's position, for compile-stage diagnostics.\n result.token.data = { ...result.token.data, vlPlace: place }\n lineIndex = emit(result.token, scanned.phrasingEnd)\n } else pending.push(lines[lineIndex])\n\n continue\n }\n\n const leafName = getLeafDirectiveName(scanned.text)\n\n if (!leafName) {\n pending.push(lines[lineIndex])\n continue\n }\n\n if (!layoutDirectiveRegistry.isLeafDirectiveName(leafName)) {\n push(warnings.button, `Unknown directive \"${leafName}\".`)\n pending.push(lines[lineIndex])\n continue\n }\n\n const bucket = leafName === 'button' ? warnings.button : warnings.badge\n const problem = getLeafDirectiveProblem(scanned.text, leafName)\n\n if (problem) {\n push(bucket, problem)\n pending.push(lines[lineIndex])\n continue\n }\n\n const directive =\n leafName === 'button'\n ? makeButtonDirective(scanned.text, makeSink(bucket, place), config)\n : makeBadgeDirective(scanned.text, makeSink(bucket, place))\n\n if (directive) lineIndex = emit(directive as RootContent, scanned.phrasingEnd)\n else pending.push(lines[lineIndex])\n }\n\n if (!changed) return [node]\n\n flush()\n\n return out\n}\n\n/**\n * Lifts directive lines out of root-level paragraphs: `:::` markers become\n * layout tokens for remarkCompileLayouts, and `::button` / `::badge` lines\n * become leaf directive nodes. Detection is source-based (see lineScanner).\n *\n * Warnings keep the historical order: container-line diagnostics, then\n * button/unknown-leaf diagnostics, then badge diagnostics, followed by\n * markers found inside lists, blockquotes, tables or footnotes.\n */\nexport const remarkDirectiveLines: Plugin<[MarkdownRenderConfig?], Root> = (\n config: MarkdownRenderConfig = {},\n) => {\n return (tree, file) => {\n const index = createSourceIndex(String(file.value ?? ''))\n const warnings: WarningBuckets = { badge: [], button: [], layout: [] }\n const nestedMarkers = findNestedDirectiveMarkers(tree, index)\n\n tree.children = tree.children.flatMap((node): RootContent[] =>\n node.type === 'paragraph' ? splitParagraph(node, index, warnings, config) : [node],\n )\n\n for (const { place, reason } of [...warnings.layout, ...warnings.button, ...warnings.badge])\n reportDiagnostic(file, reason, { place, source: 'directive' })\n\n for (const marker of nestedMarkers)\n reportDiagnostic(file, getNestedDirectiveMarkerDiagnostic(marker), {\n code: 'nested-directive-marker',\n place: placeAt(marker.line, index.lineStarts[marker.line] ?? 0, marker.from),\n source: 'directive',\n })\n }\n}\n"],"names":["getLeafDirectiveName","getLeafDirectiveProblem","createSourceIndex","findNestedDirectiveMarkers","getNestedDirectiveMarkerDiagnostic","joinPhrasingLines","scanDirectiveLineAt","splitParagraphIntoLines","layoutDirectiveRegistry","placeAt","reportDiagnostic","makeBadgeDirective","makeButtonDirective","makeSink","target","place","message","reason","push","getScannedPlace","scanned","index","startLine","lineStarts","from","splitParagraph","node","warnings","config","lines","out","pending","changed","flush","length","type","children","emit","replacement","endIndex","lineIndex","bucket","kind","result","parseMarkdownLineDetailed","text","diagnostics","layout","token","data","vlPlace","phrasingEnd","leafName","isLeafDirectiveName","button","badge","problem","directive","remarkDirectiveLines","tree","file","String","value","nestedMarkers","flatMap","source","marker","code","line"],"mappings":"AAOA,SAASA,oBAAoB,EAAEC,uBAAuB,QAAQ,iCAAgC;AAC9F,SACEC,iBAAiB,EACjBC,0BAA0B,EAC1BC,kCAAkC,EAClCC,iBAAiB,EACjBC,mBAAmB,EACnBC,uBAAuB,QAClB,kCAAiC;AACxC,SAASC,uBAAuB,QAAQ,+BAA8B;AACtE,SAASC,OAAO,EAAEC,gBAAgB,QAAQ,oBAAmB;AAC7D,SAASC,kBAAkB,QAAQ,sBAAqB;AACxD,SAASC,mBAAmB,QAAQ,uBAAsB;AAa1D,SAASC,SAASC,MAAuB,EAAEC,KAAkC;IAC3E,OAAO;QACLC,SAAQC,MAAc;YACpBH,OAAOI,IAAI,CAAC;gBAAEH;gBAAOE;YAAO;QAC9B;IACF;AACF;AAEA,SAASE,gBAAgBC,OAA6B,EAAEC,KAAkB;IACxE,OAAOZ,QAAQW,QAAQE,SAAS,EAAED,MAAME,UAAU,CAACH,QAAQE,SAAS,CAAC,IAAI,GAAGF,QAAQI,IAAI;AAC1F;AAEA,SAASC,eACPC,IAAe,EACfL,KAAkB,EAClBM,QAAwB,EACxBC,MAA4B;IAE5B,MAAMC,QAAQtB,wBAAwBmB;IACtC,MAAMI,MAAqB,EAAE;IAC7B,IAAIC,UAA0B,EAAE;IAChC,IAAIC,UAAU;IAEd,MAAMC,QAAQ;QACZ,IAAIF,QAAQG,MAAM,GAAG,GAAGJ,IAAIZ,IAAI,CAAC;YAAEiB,MAAM;YAAaC,UAAU/B,kBAAkB0B;QAAS;QAC3FA,UAAU,EAAE;IACd;IAEA,MAAMM,OAAO,CAACC,aAA0BC;QACtCN;QACAH,IAAIZ,IAAI,CAACoB;QACTN,UAAU;QAEV,OAAOO;IACT;IAEA,IAAK,IAAIC,YAAY,GAAGA,YAAYX,MAAMK,MAAM,EAAE,EAAEM,U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ACJ;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../src/core/plugins/remarkDirectiveLines.ts"],"sourcesContent":["import type { Paragraph, Root, RootContent } from 'mdast'\nimport type { Plugin } from 'unified'\n\nimport type { PhrasingLine, ScannedDirectiveLine, SourceIndex } from '../../directives/lineScanner.js'\nimport type { MarkdownRenderConfig } from '../../types/core.js'\nimport type { DiagnosticPlace } from '../diagnostics.js'\n\nimport { getLeafDirectiveName, getLeafDirectiveProblem } from '../../directives/leafSyntax.js'\nimport {\n createSourceIndex,\n findNestedDirectiveMarkers,\n getNestedDirectiveMarkerDiagnostic,\n joinPhrasingLines,\n scanDirectiveLineAt,\n splitParagraphIntoLines,\n} from '../../directives/lineScanner.js'\nimport { layoutDirectiveRegistry } from '../../directives/registry.js'\nimport { placeAt, reportDiagnostic } from '../diagnostics.js'\n\ntype PlacedWarning = {\n place?: DiagnosticPlace\n reason: string\n}\n\ntype WarningBuckets = {\n layout: PlacedWarning[]\n /** One bucket per leaf directive, in registry order. */\n leaf: Map<string, PlacedWarning[]>\n /** Unknown `::name` lines (historically reported with the first leaf directive). */\n unknownLeaf: PlacedWarning[]\n}\n\nfunction createWarningBuckets(): WarningBuckets {\n const leaf = new Map(layoutDirectiveRegistry.leafDirectiveNames.map((name) => [name, [] as PlacedWarning[]]))\n const [firstLeafName = ''] = layoutDirectiveRegistry.leafDirectiveNames\n\n if (!leaf.has(firstLeafName)) leaf.set(firstLeafName, [])\n\n return { layout: [], leaf, unknownLeaf: leaf.get(firstLeafName) ?? [] }\n}\n\nfunction makeSink(target: PlacedWarning[], place: DiagnosticPlace | undefined) {\n return {\n message(reason: string) {\n target.push({ place, reason })\n },\n }\n}\n\nfunction getScannedPlace(scanned: ScannedDirectiveLine, index: SourceIndex): DiagnosticPlace {\n return placeAt(scanned.startLine, index.lineStarts[scanned.startLine] ?? 0, scanned.from)\n}\n\nfunction splitParagraph(\n node: Paragraph,\n index: SourceIndex,\n warnings: WarningBuckets,\n config: MarkdownRenderConfig,\n): RootContent[] {\n const lines = splitParagraphIntoLines(node)\n const out: RootContent[] = []\n let pending: PhrasingLine[] = []\n let changed = false\n\n const flush = () => {\n if (pending.length > 0) out.push({ type: 'paragraph', children: joinPhrasingLines(pending) })\n pending = []\n }\n\n const emit = (replacement: RootContent, endIndex: number) => {\n flush()\n out.push(replacement)\n changed = true\n\n return endIndex\n }\n\n for (let lineIndex = 0; lineIndex < lines.length; ++lineIndex) {\n const scanned = scanDirectiveLineAt(lines, lineIndex, index)\n\n if (!scanned) {\n pending.push(lines[lineIndex])\n continue\n }\n\n const place = getScannedPlace(scanned, index)\n const push = (bucket: PlacedWarning[], reason: string) => bucket.push({ place, reason })\n\n if (scanned.kind === 'container') {\n const result = layoutDirectiveRegistry.parseMarkdownLineDetailed(scanned.text)\n\n for (const reason of result.diagnostics) push(warnings.layout, reason)\n\n if (result.token) {\n // The open/close marker's position, for compile-stage diagnostics.\n result.token.data = { ...result.token.data, vlPlace: place }\n lineIndex = emit(result.token, scanned.phrasingEnd)\n } else pending.push(lines[lineIndex])\n\n continue\n }\n\n const leafName = getLeafDirectiveName(scanned.text)\n\n if (!leafName) {\n pending.push(lines[lineIndex])\n continue\n }\n\n const leaf = layoutDirectiveRegistry.get(leafName)?.leaf\n const bucket = warnings.leaf.get(leafName)\n\n if (!leaf || !bucket) {\n push(warnings.unknownLeaf, `Unknown directive \"${leafName}\".`)\n pending.push(lines[lineIndex])\n continue\n }\n\n const problem = getLeafDirectiveProblem(scanned.text, leafName)\n\n if (problem) {\n push(bucket, problem)\n pending.push(lines[lineIndex])\n continue\n }\n\n const directive = leaf.build(scanned.text, makeSink(bucket, place), config)\n\n if (directive) lineIndex = emit(directive as RootContent, scanned.phrasingEnd)\n else pending.push(lines[lineIndex])\n }\n\n if (!changed) return [node]\n\n flush()\n\n return out\n}\n\n/**\n * Lifts directive lines out of root-level paragraphs: `:::` markers become\n * layout tokens for remarkCompileLayouts, and `::name` lines become leaf\n * directive nodes built by the definition's `leaf.build`. Detection is\n * source-based (see lineScanner).\n *\n * Warnings keep the historical order: container-line diagnostics, then each\n * leaf directive's diagnostics in registry order (unknown leaf names with the\n * first leaf directive, `button`), followed by markers found inside lists,\n * blockquotes, tables or footnotes.\n */\nexport const remarkDirectiveLines: Plugin<[MarkdownRenderConfig?], Root> = (\n config: MarkdownRenderConfig = {},\n) => {\n return (tree, file) => {\n const index = createSourceIndex(String(file.value ?? ''))\n const warnings = createWarningBuckets()\n const nestedMarkers = findNestedDirectiveMarkers(tree, index)\n\n tree.children = tree.children.flatMap((node): RootContent[] =>\n node.type === 'paragraph' ? splitParagraph(node, index, warnings, config) : [node],\n )\n\n for (const { place, reason } of [...warnings.layout, ...[...warnings.leaf.values()].flat()])\n reportDiagnostic(file, reason, { place, source: 'directive' })\n\n for (const marker of nestedMarkers)\n reportDiagnostic(file, getNestedDirectiveMarkerDiagnostic(marker), {\n code: 'nested-directive-marker',\n place: placeAt(marker.line, index.lineStarts[marker.line] ?? 0, marker.from),\n source: 'directive',\n })\n }\n}\n"],"names":["getLeafDirectiveName","getLeafDirectiveProblem","createSourceIndex","findNestedDirectiveMarkers","getNestedDirectiveMarkerDiagnostic","joinPhrasingLines","scanDirectiveLineAt","splitParagraphIntoLines","layoutDirectiveRegistry","placeAt","reportDiagnostic","createWarningBuckets","leaf","Map","leafDirectiveNames","map","name","firstLeafName","has","set","layout","unknownLeaf","get","makeSink","target","place","message","reason","push","getScannedPlace","scanned","index","startLine","lineStarts","from","splitParagraph","node","warnings","config","lines","out","pending","changed","flush","length","type","children","emit","replacement","endIndex","lineIndex","bucket","kind","result","parseMarkdownLineDetailed","text","diagnostics","token","data","vlPlace","phrasingEnd","leafName","problem","directive","build","remarkDirectiveLines","tree","file","String","value","nestedMarkers","flatMap","values","flat","source","marker","code","line"],"mappings":"AAOA,SAASA,oBAAoB,EAAEC,uBAAuB,QAAQ,iCAAgC;AAC9F,SACEC,iBAAiB,EACjBC,0BAA0B,EAC1BC,kCAAkC,EAClCC,iBAAiB,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+12,9 @@ function isContainerDirective(node) {
12
12
  return node.type === 'containerDirective';
13
13
  }
14
14
  function transformDirective(node, file) {
15
- if (node.type === 'leafDirective' && node.name !== 'button') return;
16
15
  const definition = layoutDirectiveRegistry.get(node.name);
17
16
  if (!definition) return;
17
+ if (!layoutDirectiveRegistry.receivesLayoutMarker(definition, isContainerDirective(node) ? 'container' : 'leaf')) return;
18
18
  const renderProperties = isContainerDirective(node) ? definition.getMdastRenderProperties?.(node) : undefined;
19
19
  if (isContainerDirective(node)) {
20
20
  for (const warning of definition.validateMdast?.(node) ?? [])reportDiagnostic(file, warning, {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/core/plugins/remarkLayoutDirectives.ts"],"sourcesContent":["import type { Root } from 'mdast'\nimport type { ContainerDirective, LeafDirective } from 'mdast-util-directive'\nimport type { Plugin } from 'unified'\n\nimport { visit } from 'unist-util-visit'\n\nimport { layoutDirectiveRegistry } from '../../directives/registry.js'\nimport { setDirectiveRenderData } from '../../directives/renderData.js'\nimport { type DiagnosticFile, reportDiagnostic } from '../diagnostics.js'\n\ntype MarkdownDirectiveNode = ContainerDirective | LeafDirective\n\nfunction isMarkdownDirective(node: unknown): node is MarkdownDirectiveNode {\n return Boolean(\n node &&\n typeof node === 'object' &&\n 'type' in node &&\n ['containerDirective', 'leafDirective'].includes(\n (node as { type?: string }).type ?? '',\n ),\n )\n}\n\nfunction isContainerDirective(node: MarkdownDirectiveNode): node is ContainerDirective {\n return node.type === 'containerDirective'\n}\n\nfunction transformDirective(node: MarkdownDirectiveNode, file: DiagnosticFile) {\n if (node.type === 'leafDirective' && node.name !== 'button') return\n\n const definition = layoutDirectiveRegistry.get(node.name)\n\n if (!definition) return\n\n const renderProperties = isContainerDirective(node)\n ? definition.getMdastRenderProperties?.(node)\n : undefined\n\n if (isContainerDirective(node)) {\n for (const warning of definition.validateMdast?.(node) ?? [])\n reportDiagnostic(file, warning, { place: node.data?.vlPlace, source: 'directive' })\n\n definition.transformMdast?.(node, {\n isSupportedDirectiveName: (name) => layoutDirectiveRegistry.isSupportedDirectiveName(name),\n })\n }\n\n setDirectiveRenderData(node, definition, renderProperties)\n}\n\nexport const remarkLayoutDirectives: Plugin<[], Root> = () => {\n return (tree: Root, file) => {\n visit(tree, (node) => {\n if (!isMarkdownDirective(node)) return\n if (!layoutDirectiveRegistry.isSupportedDirectiveName(node.name)) return\n\n transformDirective(node, file)\n })\n }\n}\n"],"names":["visit","layoutDirectiveRegistry","setDirectiveRenderData","reportDiagnostic","isMarkdownDirective","node","Boolean","includes","type","isContainerDirective","transformDirective","file","name","definition","get","renderProperties","getMdastRenderProperties","undefined","warning","validateMdast","place","data","vlPlace","source","transformMdast","isSupportedDirectiveName","remarkLayoutDirectives","tree"],"mappings":"AAIA,SAASA,KAAK,QAAQ,mBAAkB;AAExC,SAASC,uBAAuB,QAAQ,+BAA8B;AACtE,SAASC,sBAAsB,QAAQ,iCAAgC;AACvE,SAA8BC,gBAAgB,QAAQ,oBAAmB;AAIzE,SAASC,oBAAoBC,IAAa;IACxC,OAAOC,QACLD,QACE,OAAOA,SAAS,YAChB,UAAUA,QACV;QAAC;QAAsB;KAAgB,CAACE,QAAQ,CAC9C,AAACF,KAA2BG,IAAI,IAAI;AAG5C;AAEA,SAASC,qBAAqBJ,IAA2B;IACvD,OAAOA,KAAKG,IAAI,KAAK;AACvB;AAEA,SAASE,mBAAmBL,IAA2B,EAAEM,IAAoB;IAC3E,IAAIN,KAAKG,IAAI,KAAK,mBAAmBH,KAAKO,IAAI,KAAK,UAAU;IAE7D,MAAMC,aAAaZ,wBAAwBa,GAAG,CAACT,KAAKO,IAAI;IAExD,IAAI,CAACC,YAAY;IAEjB,MAAME,mBAAmBN,qBAAqBJ,QAC1CQ,WAAWG,wBAAwB,GAAGX,QACtCY;IAEJ,IAAIR,qBAAqBJ,OAAO;QAC9B,KAAK,MAAMa,WAAWL,WAAWM,aAAa,GAAGd,SAAS,EAAE,CAC1DF,iBAAiBQ,MAAMO,SAAS;YAAEE,OAAOf,KAAKgB,IAAI,EAAEC;YAASC,QAAQ;QAAY;QAEnFV,WAAWW,cAAc,GAAGnB,MAAM;YAChCoB,0BAA0B,CAACb,OAASX,wBAAwBwB,wBAAwB,CAACb;QACvF;IACF;IAEAV,uBAAuBG,MAAMQ,YAAYE;AAC3C;AAEA,OAAO,MAAMW,yBAA2C;IACtD,OAAO,CAACC,MAAYhB;QAClBX,MAAM2B,MAAM,CAACtB;YACX,IAAI,CAACD,oBAAoBC,OAAO;YAChC,IAAI,CAACJ,wBAAwBwB,wBAAwB,CAACpB,KAAKO,IAAI,GAAG;YAElEF,mBAAmBL,MAAMM;QAC3B;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../src/core/plugins/remarkLayoutDirectives.ts"],"sourcesContent":["import type { Root } from 'mdast'\nimport type { ContainerDirective, LeafDirective } from 'mdast-util-directive'\nimport type { Plugin } from 'unified'\n\nimport { visit } from 'unist-util-visit'\n\nimport { layoutDirectiveRegistry } from '../../directives/registry.js'\nimport { setDirectiveRenderData } from '../../directives/renderData.js'\nimport { type DiagnosticFile, reportDiagnostic } from '../diagnostics.js'\n\ntype MarkdownDirectiveNode = ContainerDirective | LeafDirective\n\nfunction isMarkdownDirective(node: unknown): node is MarkdownDirectiveNode {\n return Boolean(\n node &&\n typeof node === 'object' &&\n 'type' in node &&\n ['containerDirective', 'leafDirective'].includes(\n (node as { type?: string }).type ?? '',\n ),\n )\n}\n\nfunction isContainerDirective(node: MarkdownDirectiveNode): node is ContainerDirective {\n return node.type === 'containerDirective'\n}\n\nfunction transformDirective(node: MarkdownDirectiveNode, file: DiagnosticFile) {\n const definition = layoutDirectiveRegistry.get(node.name)\n\n if (!definition) return\n if (!layoutDirectiveRegistry.receivesLayoutMarker(definition, isContainerDirective(node) ? 'container' : 'leaf'))\n return\n\n const renderProperties = isContainerDirective(node)\n ? definition.getMdastRenderProperties?.(node)\n : undefined\n\n if (isContainerDirective(node)) {\n for (const warning of definition.validateMdast?.(node) ?? [])\n reportDiagnostic(file, warning, { place: node.data?.vlPlace, source: 'directive' })\n\n definition.transformMdast?.(node, {\n isSupportedDirectiveName: (name) => layoutDirectiveRegistry.isSupportedDirectiveName(name),\n })\n }\n\n setDirectiveRenderData(node, definition, renderProperties)\n}\n\nexport const remarkLayoutDirectives: Plugin<[], Root> = () => {\n return (tree: Root, file) => {\n visit(tree, (node) => {\n if (!isMarkdownDirective(node)) return\n if (!layoutDirectiveRegistry.isSupportedDirectiveName(node.name)) return\n\n transformDirective(node, file)\n })\n }\n}\n"],"names":["visit","layoutDirectiveRegistry","setDirectiveRenderData","reportDiagnostic","isMarkdownDirective","node","Boolean","includes","type","isContainerDirective","transformDirective","file","definition","get","name","receivesLayoutMarker","renderProperties","getMdastRenderProperties","undefined","warning","validateMdast","place","data","vlPlace","source","transformMdast","isSupportedDirectiveName","remarkLayoutDirectives","tree"],"mappings":"AAIA,SAASA,KAAK,QAAQ,mBAAkB;AAExC,SAASC,uBAAuB,QAAQ,+BAA8B;AACtE,SAASC,sBAAsB,QAAQ,iCAAgC;AACvE,SAA8BC,gBAAgB,QAAQ,oBAAmB;AAIzE,SAASC,oBAAoBC,IAAa;IACxC,OAAOC,QACLD,QACE,OAAOA,SAAS,YAChB,UAAUA,QACV;QAAC;QAAsB;KAAgB,CAACE,QAAQ,CAC9C,AAACF,KAA2BG,IAAI,IAAI;AAG5C;AAEA,SAASC,qBAAqBJ,IAA2B;IACvD,OAAOA,KAAKG,IAAI,KAAK;AACvB;AAEA,SAASE,mBAAmBL,IAA2B,EAAEM,IAAoB;IAC3E,MAAMC,aAAaX,wBAAwBY,GAAG,CAACR,KAAKS,IAAI;IAExD,IAAI,CAACF,YAAY;IACjB,IAAI,CAACX,wBAAwBc,oBAAoB,CAACH,YAAYH,qBAAqBJ,QAAQ,cAAc,SACvG;IAEF,MAAMW,mBAAmBP,qBAAqBJ,QAC1CO,WAAWK,wBAAwB,GAAGZ,QACtCa;IAEJ,IAAIT,qBAAqBJ,OAAO;QAC9B,KAAK,MAAMc,WAAWP,WAAWQ,aAAa,GAAGf,SAAS,EAAE,CAC1DF,iBAAiBQ,MAAMQ,SAAS;YAAEE,OAAOhB,KAAKiB,IAAI,EAAEC;YAASC,QAAQ;QAAY;QAEnFZ,WAAWa,cAAc,GAAGpB,MAAM;YAChCqB,0BAA0B,CAACZ,OAASb,wBAAwByB,wBAAwB,CAACZ;QACvF;IACF;IAEAZ,uBAAuBG,MAAMO,YAAYI;AAC3C;AAEA,OAAO,MAAMW,yBAA2C;IACtD,OAAO,CAACC,MAAYjB;QAClBX,MAAM4B,MAAM,CAACvB;YACX,IAAI,CAACD,oBAAoBC,OAAO;YAChC,IAAI,CAACJ,wBAAwByB,wBAAwB,CAACrB,KAAKS,IAAI,GAAG;YAElEJ,mBAAmBL,MAAMM;QAC3B;IACF;AACF,EAAC"}
@@ -1,25 +1,18 @@
1
1
  import { visit } from 'unist-util-visit';
2
2
  import { layoutDirectiveRegistry } from '../../directives/registry.js';
3
- import { getDirectiveFallbackThemeName, hasDirectiveTheme } from '../../directives/themes.js';
3
+ import { getUnknownThemeDiagnostics } from '../../directives/themeDiagnostics.js';
4
4
  import { reportDiagnostic } from '../diagnostics.js';
5
5
  function isContainerDirective(node) {
6
6
  return Boolean(node && typeof node === 'object' && 'type' in node && node.type === 'containerDirective');
7
7
  }
8
8
  function warnUnknownThemes(node, file, config) {
9
9
  const definition = layoutDirectiveRegistry.get(node.name);
10
- if (!definition?.themeAttributes) return;
11
- for (const [attribute, groupName] of Object.entries(definition.themeAttributes)){
12
- if (!groupName) continue;
13
- const value = node.attributes?.[attribute];
14
- if (typeof value !== 'string' || !value.trim()) continue;
15
- if (hasDirectiveTheme(groupName, value, config.themes)) continue;
16
- const label = attribute === 'theme' ? 'theme' : attribute;
17
- reportDiagnostic(file, `Unknown ${label} "${value}" on "${node.name}". Falling back to "${getDirectiveFallbackThemeName(groupName, config.themes)}".`, {
18
- code: 'unknown-theme',
19
- place: node.data?.vlPlace,
20
- source: 'theme'
21
- });
22
- }
10
+ if (!definition) return;
11
+ for (const message of getUnknownThemeDiagnostics(definition, node.attributes, config.themes))reportDiagnostic(file, message, {
12
+ code: 'unknown-theme',
13
+ place: node.data?.vlPlace,
14
+ source: 'theme'
15
+ });
23
16
  }
24
17
  export const remarkValidateDirectiveThemes = (config = {})=>{
25
18
  return (tree, file)=>{
@@ -1 +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 { getDirectiveFallbackThemeName, hasDirectiveTheme } from '../../directives/themes.js'\nimport { type DiagnosticFile, reportDiagnostic } from '../diagnostics.js'\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(\n node: ContainerDirective,\n file: DiagnosticFile,\n config: MarkdownRenderConfig,\n) {\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 reportDiagnostic(\n file,\n `Unknown ${label} \"${value}\" on \"${node.name}\". Falling back to \"${getDirectiveFallbackThemeName(groupName, config.themes)}\".`,\n { code: 'unknown-theme', place: node.data?.vlPlace, source: 'theme' },\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","getDirectiveFallbackThemeName","hasDirectiveTheme","reportDiagnostic","isContainerDirective","node","Boolean","type","warnUnknownThemes","file","config","definition","get","name","themeAttributes","attribute","groupName","Object","entries","value","attributes","trim","themes","label","code","place","data","vlPlace","source","remarkValidateDirectiveThemes","tree"],"mappings":"AAIA,SAASA,KAAK,QAAQ,mBAAkB;AAIxC,SAASC,uBAAuB,QAAQ,+BAA8B;AACtE,SAASC,6BAA6B,EAAEC,iBAAiB,QAAQ,6BAA4B;AAC7F,SAA8BC,gBAAgB,QAAQ,oBAAmB;AAEzE,SAASC,qBAAqBC,IAAa;IACzC,OAAOC,QACLD,QACE,OAAOA,SAAS,YAChB,UAAUA,QACV,AAACA,KAA2BE,IAAI,KAAK;AAE3C;AAEA,SAASC,kBACPH,IAAwB,EACxBI,IAAoB,EACpBC,MAA4B;IAE5B,MAAMC,aAAaX,wBAAwBY,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,IAAInB,kBAAkBc,WAAWG,OAAOT,OAAOY,MAAM,GAAG;QAExD,MAAMC,QAAQR,cAAc,UAAU,UAAUA;QAEhDZ,iBACEM,MACA,CAAC,QAAQ,EAAEc,MAAM,EAAE,EAAEJ,MAAM,MAAM,EAAEd,KAAKQ,IAAI,CAAC,oBAAoB,EAAEZ,8BAA8Be,WAAWN,OAAOY,MAAM,EAAE,EAAE,CAAC,EAC9H;YAAEE,MAAM;YAAiBC,OAAOpB,KAAKqB,IAAI,EAAEC;YAASC,QAAQ;QAAQ;IAExE;AACF;AAEA,OAAO,MAAMC,gCAAuE,CAClFnB,SAA+B,CAAC,CAAC;IAEjC,OAAO,CAACoB,MAAMrB;QACZV,MAAM+B,MAAM,CAACzB;YACX,IAAI,CAACD,qBAAqBC,OAAO;YAEjCG,kBAAkBH,MAAMI,MAAMC;QAChC;IACF;AACF,EAAC"}
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 { getUnknownThemeDiagnostics } from '../../directives/themeDiagnostics.js'\nimport { type DiagnosticFile, reportDiagnostic } from '../diagnostics.js'\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(\n node: ContainerDirective,\n file: DiagnosticFile,\n config: MarkdownRenderConfig,\n) {\n const definition = layoutDirectiveRegistry.get(node.name)\n if (!definition) return\n\n for (const message of getUnknownThemeDiagnostics(definition, node.attributes, config.themes))\n reportDiagnostic(file, message, { code: 'unknown-theme', place: node.data?.vlPlace, source: 'theme' })\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","getUnknownThemeDiagnostics","reportDiagnostic","isContainerDirective","node","Boolean","type","warnUnknownThemes","file","config","definition","get","name","message","attributes","themes","code","place","data","vlPlace","source","remarkValidateDirectiveThemes","tree"],"mappings":"AAIA,SAASA,KAAK,QAAQ,mBAAkB;AAIxC,SAASC,uBAAuB,QAAQ,+BAA8B;AACtE,SAASC,0BAA0B,QAAQ,uCAAsC;AACjF,SAA8BC,gBAAgB,QAAQ,oBAAmB;AAEzE,SAASC,qBAAqBC,IAAa;IACzC,OAAOC,QACLD,QACE,OAAOA,SAAS,YAChB,UAAUA,QACV,AAACA,KAA2BE,IAAI,KAAK;AAE3C;AAEA,SAASC,kBACPH,IAAwB,EACxBI,IAAoB,EACpBC,MAA4B;IAE5B,MAAMC,aAAaV,wBAAwBW,GAAG,CAACP,KAAKQ,IAAI;IACxD,IAAI,CAACF,YAAY;IAEjB,KAAK,MAAMG,WAAWZ,2BAA2BS,YAAYN,KAAKU,UAAU,EAAEL,OAAOM,MAAM,EACzFb,iBAAiBM,MAAMK,SAAS;QAAEG,MAAM;QAAiBC,OAAOb,KAAKc,IAAI,EAAEC;QAASC,QAAQ;IAAQ;AACxG;AAEA,OAAO,MAAMC,gCAAuE,CAClFZ,SAA+B,CAAC,CAAC;IAEjC,OAAO,CAACa,MAAMd;QACZT,MAAMuB,MAAM,CAAClB;YACX,IAAI,CAACD,qBAAqBC,OAAO;YAEjCG,kBAAkBH,MAAMI,MAAMC;QAChC;IACF;AACF,EAAC"}
@@ -1,7 +1,7 @@
1
1
  import { fromHtml } from 'hast-util-from-html';
2
2
  import { toString } from 'hast-util-to-string';
3
3
  import rehypeRaw from 'rehype-raw';
4
- import rehypeSanitize, { defaultSchema } from 'rehype-sanitize';
4
+ import rehypeSanitize from 'rehype-sanitize';
5
5
  import rehypeStringify from 'rehype-stringify';
6
6
  import remarkGfm from 'remark-gfm';
7
7
  import remarkParse from 'remark-parse';
@@ -24,6 +24,7 @@ import { remarkLayoutDirectives } from './plugins/remarkLayoutDirectives.js';
24
24
  import { remarkValidateDirectiveThemes } from './plugins/remarkValidateDirectiveThemes.js';
25
25
  import { remarkValidatePalettes } from './plugins/remarkValidatePalettes.js';
26
26
  import { getRenderData } from './renderData.js';
27
+ import { sanitizeSchema } from './sanitizeSchema.js';
27
28
  function extractCodeLanguage(className) {
28
29
  const classes = typeof className === 'string' ? className.split(/\s+/) : Array.isArray(className) ? className : [];
29
30
  return classes.find((c)=>typeof c === 'string' && c.startsWith('language-'))?.slice(9);
@@ -89,236 +90,6 @@ function rehypeShikiCodeBlocks(options = {}) {
89
90
  }
90
91
  };
91
92
  }
92
- function getAttributeDefinitions(value) {
93
- return value ?? [];
94
- }
95
- const sanitizeSchema = {
96
- ...defaultSchema,
97
- attributes: {
98
- ...defaultSchema.attributes ?? {},
99
- a: [
100
- ...getAttributeDefinitions(defaultSchema.attributes?.a ?? []),
101
- 'ariaLabel',
102
- 'className',
103
- 'dataButton',
104
- 'dataDirective',
105
- 'dataIconPalette',
106
- 'dataPalette',
107
- 'dataDirectiveLink',
108
- 'dataIconPosition',
109
- 'dataSize',
110
- 'dataVariant',
111
- 'dataVlLayout',
112
- 'href',
113
- 'target',
114
- 'rel',
115
- 'title'
116
- ],
117
- article: [
118
- ...getAttributeDefinitions(defaultSchema.attributes?.article ?? []),
119
- 'className',
120
- 'dataDirective',
121
- 'dataIconPalette',
122
- 'dataPalette',
123
- 'dataEyebrow',
124
- 'dataHref',
125
- 'dataIcon',
126
- 'dataLinkScope',
127
- 'dataNewTab',
128
- 'dataStepCard',
129
- 'dataTabPanel',
130
- 'dataTabValue',
131
- 'dataTheme',
132
- 'dataTitle',
133
- 'dataVlLayout',
134
- 'hidden',
135
- 'id',
136
- 'role',
137
- 'tabIndex'
138
- ],
139
- button: [
140
- ...getAttributeDefinitions(defaultSchema.attributes?.button ?? []),
141
- 'ariaControls',
142
- 'ariaSelected',
143
- 'className',
144
- 'dataTabTrigger',
145
- 'dataTabValue',
146
- 'disabled',
147
- 'id',
148
- 'role',
149
- 'tabIndex',
150
- 'type'
151
- ],
152
- code: [
153
- ...getAttributeDefinitions(defaultSchema.attributes?.code ?? []),
154
- 'className',
155
- 'tabIndex'
156
- ],
157
- details: [
158
- ...getAttributeDefinitions(defaultSchema.attributes?.details ?? []),
159
- 'dataDirective',
160
- 'dataIconPalette',
161
- 'dataPalette',
162
- 'dataTheme',
163
- 'dataTitle',
164
- 'dataVlLayout',
165
- 'open'
166
- ],
167
- div: [
168
- ...getAttributeDefinitions(defaultSchema.attributes?.div ?? []),
169
- 'dataAlign',
170
- 'dataDirective',
171
- 'dataIconPalette',
172
- 'dataPalette',
173
- 'dataDirectiveBody',
174
- 'dataDirectiveTitle',
175
- 'dataEyebrow',
176
- 'dataHref',
177
- 'dataGap',
178
- 'dataCellTheme',
179
- 'dataIcon',
180
- 'dataTabsList',
181
- 'dataTabPanel',
182
- 'dataTabTrigger',
183
- 'dataTabValue',
184
- 'dataTheme',
185
- 'dataTitle',
186
- 'dataStack',
187
- 'dataVariant',
188
- 'dataVlLayout',
189
- 'dataWrap',
190
- 'dataVlCellHeadingDepth',
191
- 'hidden',
192
- 'id',
193
- 'role',
194
- 'tabIndex'
195
- ],
196
- h1: [
197
- ...getAttributeDefinitions(defaultSchema.attributes?.h1 ?? []),
198
- 'dataDirectiveTitle',
199
- 'dataHeadingAnchor',
200
- 'id'
201
- ],
202
- h2: [
203
- ...getAttributeDefinitions(defaultSchema.attributes?.h2 ?? []),
204
- 'dataDirectiveTitle',
205
- 'dataHeadingAnchor',
206
- 'id'
207
- ],
208
- h3: [
209
- ...getAttributeDefinitions(defaultSchema.attributes?.h3 ?? []),
210
- 'dataDirectiveTitle',
211
- 'dataHeadingAnchor',
212
- 'id'
213
- ],
214
- h4: [
215
- ...getAttributeDefinitions(defaultSchema.attributes?.h4 ?? []),
216
- 'dataHeadingAnchor',
217
- 'id'
218
- ],
219
- h5: [
220
- ...getAttributeDefinitions(defaultSchema.attributes?.h5 ?? []),
221
- 'dataHeadingAnchor',
222
- 'id'
223
- ],
224
- h6: [
225
- ...getAttributeDefinitions(defaultSchema.attributes?.h6 ?? []),
226
- 'dataHeadingAnchor',
227
- 'id'
228
- ],
229
- img: [
230
- ...getAttributeDefinitions(defaultSchema.attributes?.img ?? []),
231
- 'alt',
232
- 'className',
233
- 'dataDirective',
234
- 'src',
235
- 'title',
236
- 'width',
237
- 'height'
238
- ],
239
- li: [
240
- ...getAttributeDefinitions(defaultSchema.attributes?.li ?? []),
241
- 'dataStep',
242
- 'dataTocLevel'
243
- ],
244
- nav: [
245
- ...getAttributeDefinitions(defaultSchema.attributes?.nav ?? []),
246
- 'ariaLabel',
247
- 'dataDirective',
248
- 'dataTheme',
249
- 'dataTitle',
250
- 'dataVlLayout'
251
- ],
252
- p: [
253
- ...getAttributeDefinitions(defaultSchema.attributes?.p ?? []),
254
- 'className',
255
- 'dataDirectiveEyebrow'
256
- ],
257
- pre: [
258
- ...getAttributeDefinitions(defaultSchema.attributes?.pre ?? []),
259
- 'className',
260
- 'tabindex'
261
- ],
262
- section: [
263
- ...getAttributeDefinitions(defaultSchema.attributes?.section ?? []),
264
- 'dataColumns',
265
- 'dataCardTheme',
266
- 'dataCellTheme',
267
- 'dataDefault',
268
- 'dataDisabled',
269
- 'dataDirective',
270
- 'dataIconPalette',
271
- 'dataPalette',
272
- 'dataHref',
273
- 'dataLabel',
274
- 'dataLinkScope',
275
- 'dataLayout',
276
- 'dataNewTab',
277
- 'dataStack',
278
- 'dataNumbered',
279
- 'dataStepTheme',
280
- 'dataTabTheme',
281
- 'dataTabValue',
282
- 'dataTheme',
283
- 'dataVariant',
284
- 'dataValue',
285
- 'dataVlLayout',
286
- 'dataVlCellHeadingDepth',
287
- 'role'
288
- ],
289
- span: [
290
- ...getAttributeDefinitions(defaultSchema.attributes?.span ?? []),
291
- 'className',
292
- 'dataPmdIcon',
293
- 'dataPmdIconPalette',
294
- 'dataPmdIconRef',
295
- 'dataStepNumber',
296
- 'focusable',
297
- 'style'
298
- ],
299
- summary: [
300
- ...getAttributeDefinitions(defaultSchema.attributes?.summary ?? []),
301
- 'className'
302
- ]
303
- },
304
- // Clobber protection for author raw HTML is applied by rehypeTrustBoundary
305
- // (raw-HTML ids/names get the default `user-content-` prefix there), so the
306
- // pipeline's own heading, footnote and tab ids stay unprefixed.
307
- clobberPrefix: '',
308
- tagNames: [
309
- ...defaultSchema.tagNames ?? [],
310
- 'a',
311
- 'article',
312
- 'br',
313
- 'button',
314
- 'details',
315
- 'img',
316
- 'nav',
317
- 'section',
318
- 'span',
319
- 'summary'
320
- ]
321
- };
322
93
  const FAILED_RENDER_HTML = '<p>Failed to render markdown.</p>';
323
94
  /**
324
95
  * Headless renderer: compiles markdown to sanitized HTML and returns the