payload-markdown 1.8.0 → 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.
- package/README.md +16 -0
- package/dist/agent/access.d.ts +1 -1
- package/dist/agent/access.js.map +1 -1
- package/dist/agent/guide.d.ts +3 -0
- package/dist/agent/guide.js +28 -2
- package/dist/agent/guide.js.map +1 -1
- package/dist/agent/palettes.d.ts +55 -0
- package/dist/agent/palettes.js +194 -0
- package/dist/agent/palettes.js.map +1 -0
- package/dist/agent/skill.d.ts +2 -2
- package/dist/agent/skill.js +2 -2
- package/dist/agent/skill.js.map +1 -1
- package/dist/agent/validate.d.ts +1 -1
- package/dist/agent/validate.js +3 -0
- package/dist/agent/validate.js.map +1 -1
- package/dist/appearance/PaletteRowLabel.client.d.ts +2 -0
- package/dist/appearance/PaletteRowLabel.client.js +70 -0
- package/dist/appearance/PaletteRowLabel.client.js.map +1 -0
- package/dist/appearance/config.d.ts +8 -0
- package/dist/appearance/config.js +172 -0
- package/dist/appearance/config.js.map +1 -0
- package/dist/appearance/options.d.ts +11 -0
- package/dist/appearance/options.js +15 -0
- package/dist/appearance/options.js.map +1 -0
- package/dist/appearance/runtime.d.ts +25 -0
- package/dist/appearance/runtime.js +126 -0
- package/dist/appearance/runtime.js.map +1 -0
- package/dist/components/MarkdownRenderer/Component.js +4 -0
- package/dist/components/MarkdownRenderer/Component.js.map +1 -1
- package/dist/core/plugins/rehypeResolveIcons.js +10 -1
- package/dist/core/plugins/rehypeResolveIcons.js.map +1 -1
- package/dist/core/plugins/remarkCompileLayouts.js.map +1 -1
- package/dist/core/plugins/remarkDirectiveLines.d.ts +7 -5
- package/dist/core/plugins/remarkDirectiveLines.js +29 -18
- package/dist/core/plugins/remarkDirectiveLines.js.map +1 -1
- package/dist/core/plugins/remarkLayoutDirectives.js +1 -1
- package/dist/core/plugins/remarkLayoutDirectives.js.map +1 -1
- package/dist/core/plugins/remarkValidateDirectiveThemes.js +7 -14
- package/dist/core/plugins/remarkValidateDirectiveThemes.js.map +1 -1
- package/dist/core/plugins/remarkValidatePalettes.d.ts +9 -0
- package/dist/core/plugins/remarkValidatePalettes.js +51 -0
- package/dist/core/plugins/remarkValidatePalettes.js.map +1 -0
- package/dist/core/renderMarkdown.js +4 -221
- package/dist/core/renderMarkdown.js.map +1 -1
- package/dist/core/sanitizeSchema.d.ts +11 -0
- package/dist/core/sanitizeSchema.js +176 -0
- package/dist/core/sanitizeSchema.js.map +1 -0
- package/dist/directive-spec.json +60 -0
- package/dist/directives/definitions/badge.d.ts +5 -2
- package/dist/directives/definitions/badge.js +138 -10
- package/dist/directives/definitions/badge.js.map +1 -1
- package/dist/directives/definitions/badges.d.ts +1 -2
- package/dist/directives/definitions/badges.js +12 -3
- package/dist/directives/definitions/badges.js.map +1 -1
- package/dist/directives/definitions/button.d.ts +7 -3
- package/dist/directives/definitions/button.js +211 -14
- package/dist/directives/definitions/button.js.map +1 -1
- package/dist/directives/definitions/buttons.d.ts +1 -2
- package/dist/directives/definitions/buttons.js +12 -3
- package/dist/directives/definitions/buttons.js.map +1 -1
- package/dist/directives/definitions/callout.d.ts +1 -2
- package/dist/directives/definitions/callout.js +46 -5
- package/dist/directives/definitions/callout.js.map +1 -1
- package/dist/directives/definitions/card.d.ts +6 -4
- package/dist/directives/definitions/card.js +64 -11
- package/dist/directives/definitions/card.js.map +1 -1
- package/dist/directives/definitions/cards.d.ts +1 -2
- package/dist/directives/definitions/cards.js +49 -4
- package/dist/directives/definitions/cards.js.map +1 -1
- package/dist/directives/definitions/cell.d.ts +2 -2
- package/dist/directives/definitions/cell.js +9 -3
- package/dist/directives/definitions/cell.js.map +1 -1
- package/dist/directives/definitions/columns.d.ts +3 -4
- package/dist/directives/definitions/columns.js +17 -3
- package/dist/directives/definitions/columns.js.map +1 -1
- package/dist/directives/definitions/details.d.ts +1 -2
- package/dist/directives/definitions/details.js +28 -3
- package/dist/directives/definitions/details.js.map +1 -1
- package/dist/directives/definitions/section.d.ts +1 -2
- package/dist/directives/definitions/section.js +26 -3
- package/dist/directives/definitions/section.js.map +1 -1
- package/dist/directives/definitions/steps.d.ts +1 -2
- package/dist/directives/definitions/steps.js +26 -3
- package/dist/directives/definitions/steps.js.map +1 -1
- package/dist/directives/definitions/tab.d.ts +8 -2
- package/dist/directives/definitions/tab.js +45 -3
- package/dist/directives/definitions/tab.js.map +1 -1
- package/dist/directives/definitions/tabs.d.ts +1 -1
- package/dist/directives/definitions/tabs.js +44 -3
- package/dist/directives/definitions/tabs.js.map +1 -1
- package/dist/directives/definitions/toc.d.ts +1 -2
- package/dist/directives/definitions/toc.js +33 -5
- package/dist/directives/definitions/toc.js.map +1 -1
- package/dist/directives/diagnostics.d.ts +2 -10
- package/dist/directives/diagnostics.js +27 -141
- package/dist/directives/diagnostics.js.map +1 -1
- package/dist/directives/iconPlaceholder.d.ts +9 -3
- package/dist/directives/iconPlaceholder.js +8 -1
- package/dist/directives/iconPlaceholder.js.map +1 -1
- package/dist/directives/lint.d.ts +11 -0
- package/dist/directives/lint.js +33 -0
- package/dist/directives/lint.js.map +1 -0
- package/dist/directives/palette.d.ts +23 -0
- package/dist/directives/palette.js +40 -0
- package/dist/directives/palette.js.map +1 -0
- package/dist/directives/registry.d.ts +23 -5
- package/dist/directives/registry.js +52 -40
- package/dist/directives/registry.js.map +1 -1
- package/dist/directives/spec.d.ts +6 -2
- package/dist/directives/spec.js +29 -50
- package/dist/directives/spec.js.map +1 -1
- package/dist/directives/themeDiagnostics.d.ts +8 -0
- package/dist/directives/themeDiagnostics.js +21 -0
- package/dist/directives/themeDiagnostics.js.map +1 -0
- package/dist/directives/types.d.ts +157 -14
- package/dist/directives/types.js +6 -1
- package/dist/directives/types.js.map +1 -1
- package/dist/editor/directiveConfig.d.ts +15 -1
- package/dist/editor/directiveConfig.js +21 -1
- package/dist/editor/directiveConfig.js.map +1 -1
- package/dist/editor/directives/completions.d.ts +4 -2
- package/dist/editor/directives/completions.js +33 -7
- package/dist/editor/directives/completions.js.map +1 -1
- package/dist/editor/directives/diagnostics.d.ts +2 -2
- package/dist/editor/directives/diagnostics.js +10 -3
- package/dist/editor/directives/diagnostics.js.map +1 -1
- package/dist/editor/themes/payload.js +2 -1
- package/dist/editor/themes/payload.js.map +1 -1
- package/dist/exports/client.d.ts +4 -1
- package/dist/exports/client.js +5 -2
- package/dist/exports/client.js.map +1 -1
- package/dist/field/MarkdownField/Component.js +54 -3
- package/dist/field/MarkdownField/Component.js.map +1 -1
- package/dist/icons/entries.d.ts +22 -0
- package/dist/icons/entries.js +50 -0
- package/dist/icons/entries.js.map +1 -0
- package/dist/icons/resolve.d.ts +2 -1
- package/dist/icons/resolve.js +2 -2
- package/dist/icons/resolve.js.map +1 -1
- package/dist/icons/sanitizeSvg.d.ts +12 -2
- package/dist/icons/sanitizeSvg.js +104 -3
- package/dist/icons/sanitizeSvg.js.map +1 -1
- package/dist/index.d.ts +11 -4
- package/dist/index.js +34 -3
- package/dist/index.js.map +1 -1
- package/dist/mcp/index.d.ts +2 -2
- package/dist/mcp/index.js +65 -4
- package/dist/mcp/index.js.map +1 -1
- package/dist/palettes/colors.d.ts +21 -0
- package/dist/palettes/colors.js +43 -0
- package/dist/palettes/colors.js.map +1 -0
- package/dist/palettes/contrast.d.ts +7 -0
- package/dist/palettes/contrast.js +63 -0
- package/dist/palettes/contrast.js.map +1 -0
- package/dist/palettes/defaults.d.ts +8 -0
- package/dist/palettes/defaults.js +275 -0
- package/dist/palettes/defaults.js.map +1 -0
- package/dist/palettes/diagnostics.d.ts +10 -0
- package/dist/palettes/diagnostics.js +38 -0
- package/dist/palettes/diagnostics.js.map +1 -0
- package/dist/palettes/index.d.ts +61 -0
- package/dist/palettes/index.js +246 -0
- package/dist/palettes/index.js.map +1 -0
- package/dist/render/renderMarkdown.d.ts +3 -1
- package/dist/render/renderMarkdown.js +9 -1
- package/dist/render/renderMarkdown.js.map +1 -1
- package/dist/runtime/index.d.ts +12 -1
- package/dist/runtime/index.js +21 -2
- package/dist/runtime/index.js.map +1 -1
- package/dist/types/core.d.ts +43 -0
- package/dist/types/core.js.map +1 -1
- package/dist/types.d.ts +46 -2
- package/dist/types.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +1 -1
- package/skills/payload-markdown/claude/SKILL.md +1 -0
- package/skills/payload-markdown/claude/reference/directive-spec.json +60 -0
- package/skills/payload-markdown/claude/reference/mcp-content-workflow.md +7 -0
- package/skills/payload-markdown/claude/reference/payload-markdown-directives.md +22 -2
- package/skills/payload-markdown/claude/skill.json +2 -2
- package/skills/payload-markdown/codex/SKILL.md +1 -0
- package/skills/payload-markdown/codex/reference/directive-spec.json +60 -0
- package/skills/payload-markdown/codex/reference/mcp-content-workflow.md +7 -0
- package/skills/payload-markdown/codex/reference/payload-markdown-directives.md +22 -2
- package/skills/payload-markdown/codex/skill.json +2 -2
- package/dist/core/plugins/directiveBadge.d.ts +0 -6
- package/dist/core/plugins/directiveBadge.js +0 -94
- package/dist/core/plugins/directiveBadge.js.map +0 -1
- package/dist/core/plugins/directiveButton.d.ts +0 -6
- package/dist/core/plugins/directiveButton.js +0 -115
- package/dist/core/plugins/directiveButton.js.map +0 -1
- package/dist/directives/buttonSyntax.d.ts +0 -7
- package/dist/directives/buttonSyntax.js +0 -6
- package/dist/directives/buttonSyntax.js.map +0 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { visit } from 'unist-util-visit';
|
|
2
2
|
import { resolvePayloadMarkdownIcon, validatePayloadMarkdownIconsConfig } from '../../icons/resolve.js';
|
|
3
|
+
import { getPaletteRegistry, iconPaint } from '../../palettes/index.js';
|
|
3
4
|
import { reportDiagnostic } from '../diagnostics.js';
|
|
4
5
|
function isElement(node) {
|
|
5
6
|
return Boolean(node && typeof node === 'object' && 'type' in node && node.type === 'element');
|
|
@@ -14,13 +15,21 @@ export const rehypeResolveIcons = (config = {})=>{
|
|
|
14
15
|
code: 'icon-config',
|
|
15
16
|
source: 'icon'
|
|
16
17
|
});
|
|
18
|
+
const palettes = getPaletteRegistry(config.palettes);
|
|
17
19
|
visit(tree, 'element', (node, index, parent)=>{
|
|
18
20
|
if (!isElement(node)) return;
|
|
19
21
|
if (node.tagName !== 'span') return;
|
|
20
22
|
const iconRef = getStringProperty(node, 'dataPmdIconRef');
|
|
21
23
|
if (!iconRef) return;
|
|
22
24
|
const className = Array.isArray(node.properties.className) ? node.properties.className.join(' ') : typeof node.properties.className === 'string' ? node.properties.className : 'pmd-icon';
|
|
23
|
-
|
|
25
|
+
// Unknown palette names were reported when the directive was validated;
|
|
26
|
+
// the icon then renders unpainted.
|
|
27
|
+
const paletteName = getStringProperty(node, 'dataPmdIconPalette');
|
|
28
|
+
const palette = paletteName ? palettes.get(paletteName) : undefined;
|
|
29
|
+
const resolved = resolvePayloadMarkdownIcon(iconRef, config.icons, className, palette ? {
|
|
30
|
+
name: palette.name,
|
|
31
|
+
...iconPaint(palette)
|
|
32
|
+
} : undefined);
|
|
24
33
|
const start = node.position?.start;
|
|
25
34
|
const place = start ? {
|
|
26
35
|
column: start.column,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/plugins/rehypeResolveIcons.ts"],"sourcesContent":["import type { Element, Root } from 'hast'\nimport type { Plugin } from 'unified'\n\nimport { visit } from 'unist-util-visit'\n\nimport type { MarkdownRenderConfig } from '../../types/core.js'\n\nimport {\n resolvePayloadMarkdownIcon,\n validatePayloadMarkdownIconsConfig,\n} from '../../icons/resolve.js'\nimport { reportDiagnostic } from '../diagnostics.js'\n\nfunction isElement(node: unknown): node is Element {\n return Boolean(\n node && typeof node === 'object' && 'type' in node && (node as Element).type === 'element',\n )\n}\n\nfunction getStringProperty(node: Element, name: string): string | undefined {\n const value = node.properties?.[name]\n\n return typeof value === 'string' && value.trim() ? value.trim() : undefined\n}\n\nexport const rehypeResolveIcons: Plugin<[MarkdownRenderConfig?], Root> = (\n config: MarkdownRenderConfig = {},\n) => {\n return (tree, file) => {\n for (const warning of validatePayloadMarkdownIconsConfig(config.icons))\n reportDiagnostic(file, warning, { code: 'icon-config', source: 'icon' })\n\n visit(tree, 'element', (node, index, parent) => {\n if (!isElement(node)) return\n if (node.tagName !== 'span') return\n\n const iconRef = getStringProperty(node, 'dataPmdIconRef')\n if (!iconRef) return\n\n const className = Array.isArray(node.properties.className)\n ? node.properties.className.join(' ')\n : typeof node.properties.className === 'string'\n ? node.properties.className\n : 'pmd-icon'\n const resolved = resolvePayloadMarkdownIcon(iconRef
|
|
1
|
+
{"version":3,"sources":["../../../src/core/plugins/rehypeResolveIcons.ts"],"sourcesContent":["import type { Element, Root } from 'hast'\nimport type { Plugin } from 'unified'\n\nimport { visit } from 'unist-util-visit'\n\nimport type { MarkdownRenderConfig } from '../../types/core.js'\n\nimport {\n resolvePayloadMarkdownIcon,\n validatePayloadMarkdownIconsConfig,\n} from '../../icons/resolve.js'\nimport { getPaletteRegistry, iconPaint } from '../../palettes/index.js'\nimport { reportDiagnostic } from '../diagnostics.js'\n\nfunction isElement(node: unknown): node is Element {\n return Boolean(\n node && typeof node === 'object' && 'type' in node && (node as Element).type === 'element',\n )\n}\n\nfunction getStringProperty(node: Element, name: string): string | undefined {\n const value = node.properties?.[name]\n\n return typeof value === 'string' && value.trim() ? value.trim() : undefined\n}\n\nexport const rehypeResolveIcons: Plugin<[MarkdownRenderConfig?], Root> = (\n config: MarkdownRenderConfig = {},\n) => {\n return (tree, file) => {\n for (const warning of validatePayloadMarkdownIconsConfig(config.icons))\n reportDiagnostic(file, warning, { code: 'icon-config', source: 'icon' })\n\n const palettes = getPaletteRegistry(config.palettes)\n\n visit(tree, 'element', (node, index, parent) => {\n if (!isElement(node)) return\n if (node.tagName !== 'span') return\n\n const iconRef = getStringProperty(node, 'dataPmdIconRef')\n if (!iconRef) return\n\n const className = Array.isArray(node.properties.className)\n ? node.properties.className.join(' ')\n : typeof node.properties.className === 'string'\n ? node.properties.className\n : 'pmd-icon'\n // Unknown palette names were reported when the directive was validated;\n // the icon then renders unpainted.\n const paletteName = getStringProperty(node, 'dataPmdIconPalette')\n const palette = paletteName ? palettes.get(paletteName) : undefined\n const resolved = resolvePayloadMarkdownIcon(\n iconRef,\n config.icons,\n className,\n palette ? { name: palette.name, ...iconPaint(palette) } : undefined,\n )\n\n const start = node.position?.start\n const place = start ? { column: start.column, line: start.line } : undefined\n\n for (const warning of resolved.warnings) reportDiagnostic(file, warning, { place, source: 'icon' })\n\n if (!parent || typeof index !== 'number') return\n\n parent.children.splice(index, 1, ...resolved.nodes)\n })\n }\n}\n"],"names":["visit","resolvePayloadMarkdownIcon","validatePayloadMarkdownIconsConfig","getPaletteRegistry","iconPaint","reportDiagnostic","isElement","node","Boolean","type","getStringProperty","name","value","properties","trim","undefined","rehypeResolveIcons","config","tree","file","warning","icons","code","source","palettes","index","parent","tagName","iconRef","className","Array","isArray","join","paletteName","palette","get","resolved","start","position","place","column","line","warnings","children","splice","nodes"],"mappings":"AAGA,SAASA,KAAK,QAAQ,mBAAkB;AAIxC,SACEC,0BAA0B,EAC1BC,kCAAkC,QAC7B,yBAAwB;AAC/B,SAASC,kBAAkB,EAAEC,SAAS,QAAQ,0BAAyB;AACvE,SAASC,gBAAgB,QAAQ,oBAAmB;AAEpD,SAASC,UAAUC,IAAa;IAC9B,OAAOC,QACLD,QAAQ,OAAOA,SAAS,YAAY,UAAUA,QAAQ,AAACA,KAAiBE,IAAI,KAAK;AAErF;AAEA,SAASC,kBAAkBH,IAAa,EAAEI,IAAY;IACpD,MAAMC,QAAQL,KAAKM,UAAU,EAAE,CAACF,KAAK;IAErC,OAAO,OAAOC,UAAU,YAAYA,MAAME,IAAI,KAAKF,MAAME,IAAI,KAAKC;AACpE;AAEA,OAAO,MAAMC,qBAA4D,CACvEC,SAA+B,CAAC,CAAC;IAEjC,OAAO,CAACC,MAAMC;QACZ,KAAK,MAAMC,WAAWlB,mCAAmCe,OAAOI,KAAK,EACnEhB,iBAAiBc,MAAMC,SAAS;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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,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,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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,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;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"}
|
|
@@ -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 `::
|
|
7
|
-
*
|
|
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
|
-
*
|
|
11
|
-
* markers found inside lists,
|
|
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
|
-
|
|
6
|
-
|
|
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
|
-
|
|
68
|
-
|
|
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 =
|
|
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 `::
|
|
92
|
-
*
|
|
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
|
-
*
|
|
96
|
-
* markers found inside lists,
|
|
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
|
-
...
|
|
112
|
-
|
|
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,QA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,MAAM4B,uBAA8D,CACzE9B,SAA+B,CAAC,CAAC;IAEjC,OAAO,CAAC+B,MAAMC;QACZ,MAAMvC,QAAQnB,kBAAkB2D,OAAOD,KAAKE,KAAK,IAAI;QACrD,MAAMnC,WAA2B;YAAE4B,OAAO,EAAE;YAAED,QAAQ,EAAE;YAAEP,QAAQ,EAAE;QAAC;QACrE,MAAMgB,gBAAgB5D,2BAA2BwD,MAAMtC;QAEvDsC,KAAKvB,QAAQ,GAAGuB,KAAKvB,QAAQ,CAAC4B,OAAO,CAAC,CAACtC,OACrCA,KAAKS,IAAI,KAAK,cAAcV,eAAeC,MAAML,OAAOM,UAAUC,UAAU;gBAACF;aAAK;QAGpF,KAAK,MAAM,EAAEX,KAAK,EAAEE,MAAM,EAAE,IAAI;eAAIU,SAASoB,MAAM;eAAKpB,SAAS2B,MAAM;eAAK3B,SAAS4B,KAAK;SAAC,CACzF7C,iBAAiBkD,MAAM3C,QAAQ;YAAEF;YAAOkD,QAAQ;QAAY;QAE9D,KAAK,MAAMC,UAAUH,cACnBrD,iBAAiBkD,MAAMxD,mCAAmC8D,SAAS;YACjEC,MAAM;YACNpD,OAAON,QAAQyD,OAAOE,IAAI,EAAE/C,MAAME,UAAU,CAAC2C,OAAOE,IAAI,CAAC,IAAI,GAAGF,OAAO1C,IAAI;YAC3EyC,QAAQ;QACV;IACJ;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,EACjBC,mBAAmB,EACnBC,uBAAuB,QAClB,kCAAiC;AACxC,SAASC,uBAAuB,QAAQ,+BAA8B;AACtE,SAASC,OAAO,EAAEC,gBAAgB,QAAQ,oBAAmB;AAe7D,SAASC;IACP,MAAMC,OAAO,IAAIC,IAAIL,wBAAwBM,kBAAkB,CAACC,GAAG,CAAC,CAACC,OAAS;YAACA;YAAM,EAAE;SAAoB;IAC3G,MAAM,CAACC,gBAAgB,EAAE,CAAC,GAAGT,wBAAwBM,kBAAkB;IAEvE,IAAI,CAACF,KAAKM,GAAG,CAACD,gBAAgBL,KAAKO,GAAG,CAACF,eAAe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A;;;;;;;;;;CAUC,GACD,OAAO,MAAMyB,uBAA8D,CACzE3B,SAA+B,CAAC,CAAC;IAEjC,OAAO,CAAC4B,MAAMC;QACZ,MAAMpC,QAAQ7B,kBAAkBkE,OAAOD,KAAKE,KAAK,IAAI;QACrD,MAAMhC,WAAW1B;QACjB,MAAM2D,gBAAgBnE,2BAA2B+D,MAAMnC;QAEvDmC,KAAKpB,QAAQ,GAAGoB,KAAKpB,QAAQ,CAACyB,OAAO,CAAC,CAACnC,OACrCA,KAAKS,IAAI,KAAK,cAAcV,eAAeC,MAAML,OAAOM,UAAUC,UAAU;gBAACF;aAAK;QAGpF,KAAK,MAAM,EAAEX,KAAK,EAAEE,MAAM,EAAE,IAAI;eAAIU,SAASjB,MAAM;eAAK;mBAAIiB,SAASzB,IAAI,CAAC4D,MAAM;aAAG,CAACC,IAAI;SAAG,CACzF/D,iBAAiByD,MAAMxC,QAAQ;YAAEF;YAAOiD,QAAQ;QAAY;QAE9D,KAAK,MAAMC,UAAUL,cACnB5D,iBAAiByD,MAAM/D,mCAAmCuE,SAAS;YACjEC,MAAM;YACNnD,OAAOhB,QAAQkE,OAAOE,IAAI,EAAE9C,MAAME,UAAU,CAAC0C,OAAOE,IAAI,CAAC,IAAI,GAAGF,OAAOzC,IAAI;YAC3EwC,QAAQ;QACV;IACJ;AACF,EAAC"}
|
|
@@ -12,9 +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
|
|
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 {
|
|
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
|
|
11
|
-
for (const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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 {
|
|
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"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Root } from 'mdast';
|
|
2
|
+
import type { Plugin } from 'unified';
|
|
3
|
+
import type { MarkdownRenderConfig } from '../../types/core.js';
|
|
4
|
+
/**
|
|
5
|
+
* Reports palette references the render cannot resolve (`palette`,
|
|
6
|
+
* `iconPalette`, and `palette=` on icon entries) and configured palettes that
|
|
7
|
+
* were ignored because they are invalid. Unknown palettes render unpainted.
|
|
8
|
+
*/
|
|
9
|
+
export declare const remarkValidatePalettes: Plugin<[MarkdownRenderConfig?], Root>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { visit } from 'unist-util-visit';
|
|
2
|
+
import { layoutDirectiveRegistry } from '../../directives/registry.js';
|
|
3
|
+
import { getExtraIconWarnings, parseIconEntries } from '../../icons/entries.js';
|
|
4
|
+
import { collectPaletteNames, getUnknownPaletteWarning } from '../../palettes/diagnostics.js';
|
|
5
|
+
import { getPaletteRegistry } from '../../palettes/index.js';
|
|
6
|
+
import { reportDiagnostic } from '../diagnostics.js';
|
|
7
|
+
function isContainerDirective(node) {
|
|
8
|
+
return Boolean(node && typeof node === 'object' && 'type' in node && node.type === 'containerDirective');
|
|
9
|
+
}
|
|
10
|
+
function validateDirective(node, file, config) {
|
|
11
|
+
const allowed = layoutDirectiveRegistry.get(node.name)?.allowedAttributes;
|
|
12
|
+
if (!allowed) return;
|
|
13
|
+
const place = node.data?.vlPlace;
|
|
14
|
+
if (allowed.includes('icon')) {
|
|
15
|
+
const icon = node.attributes?.icon;
|
|
16
|
+
const { entries, warnings } = parseIconEntries(typeof icon === 'string' ? icon : undefined);
|
|
17
|
+
for (const warning of [
|
|
18
|
+
...warnings,
|
|
19
|
+
...getExtraIconWarnings(node.name, entries)
|
|
20
|
+
])reportDiagnostic(file, warning, {
|
|
21
|
+
code: 'icon-option',
|
|
22
|
+
place,
|
|
23
|
+
source: 'icon'
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
for (const name of collectPaletteNames(allowed, node.attributes)){
|
|
27
|
+
const warning = getUnknownPaletteWarning(name, node.name, config);
|
|
28
|
+
if (warning) reportDiagnostic(file, warning, {
|
|
29
|
+
code: 'unknown-palette',
|
|
30
|
+
place,
|
|
31
|
+
source: 'theme'
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Reports palette references the render cannot resolve (`palette`,
|
|
37
|
+
* `iconPalette`, and `palette=` on icon entries) and configured palettes that
|
|
38
|
+
* were ignored because they are invalid. Unknown palettes render unpainted.
|
|
39
|
+
*/ export const remarkValidatePalettes = (config = {})=>{
|
|
40
|
+
return (tree, file)=>{
|
|
41
|
+
for (const warning of getPaletteRegistry(config.palettes).warnings)reportDiagnostic(file, warning, {
|
|
42
|
+
code: 'palette-config',
|
|
43
|
+
source: 'theme'
|
|
44
|
+
});
|
|
45
|
+
visit(tree, (node)=>{
|
|
46
|
+
if (isContainerDirective(node)) validateDirective(node, file, config);
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=remarkValidatePalettes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/core/plugins/remarkValidatePalettes.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 { getExtraIconWarnings, parseIconEntries } from '../../icons/entries.js'\nimport { collectPaletteNames, getUnknownPaletteWarning } from '../../palettes/diagnostics.js'\nimport { getPaletteRegistry } from '../../palettes/index.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 validateDirective(node: ContainerDirective, file: DiagnosticFile, config: MarkdownRenderConfig) {\n const allowed = layoutDirectiveRegistry.get(node.name)?.allowedAttributes\n if (!allowed) return\n\n const place = node.data?.vlPlace\n\n if (allowed.includes('icon')) {\n const icon = node.attributes?.icon\n const { entries, warnings } = parseIconEntries(typeof icon === 'string' ? icon : undefined)\n\n for (const warning of [...warnings, ...getExtraIconWarnings(node.name, entries)])\n reportDiagnostic(file, warning, { code: 'icon-option', place, source: 'icon' })\n }\n\n for (const name of collectPaletteNames(allowed, node.attributes)) {\n const warning = getUnknownPaletteWarning(name, node.name, config)\n if (warning) reportDiagnostic(file, warning, { code: 'unknown-palette', place, source: 'theme' })\n }\n}\n\n/**\n * Reports palette references the render cannot resolve (`palette`,\n * `iconPalette`, and `palette=` on icon entries) and configured palettes that\n * were ignored because they are invalid. Unknown palettes render unpainted.\n */\nexport const remarkValidatePalettes: Plugin<[MarkdownRenderConfig?], Root> = (\n config: MarkdownRenderConfig = {},\n) => {\n return (tree, file) => {\n for (const warning of getPaletteRegistry(config.palettes).warnings)\n reportDiagnostic(file, warning, { code: 'palette-config', source: 'theme' })\n\n visit(tree, (node) => {\n if (isContainerDirective(node)) validateDirective(node, file, config)\n })\n }\n}\n"],"names":["visit","layoutDirectiveRegistry","getExtraIconWarnings","parseIconEntries","collectPaletteNames","getUnknownPaletteWarning","getPaletteRegistry","reportDiagnostic","isContainerDirective","node","Boolean","type","validateDirective","file","config","allowed","get","name","allowedAttributes","place","data","vlPlace","includes","icon","attributes","entries","warnings","undefined","warning","code","source","remarkValidatePalettes","tree","palettes"],"mappings":"AAIA,SAASA,KAAK,QAAQ,mBAAkB;AAIxC,SAASC,uBAAuB,QAAQ,+BAA8B;AACtE,SAASC,oBAAoB,EA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