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.
- 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/renderMarkdown.js +2 -231
- 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/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 +6 -2
- package/dist/directives/definitions/button.js +202 -12
- 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 +37 -3
- package/dist/directives/definitions/callout.js.map +1 -1
- package/dist/directives/definitions/card.d.ts +6 -2
- package/dist/directives/definitions/card.js +51 -3
- package/dist/directives/definitions/card.js.map +1 -1
- package/dist/directives/definitions/cards.d.ts +1 -2
- package/dist/directives/definitions/cards.js +40 -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 +24 -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 +22 -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 +22 -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 +40 -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 +32 -4
- package/dist/directives/definitions/toc.js.map +1 -1
- package/dist/directives/diagnostics.d.ts +2 -15
- package/dist/directives/diagnostics.js +27 -157
- package/dist/directives/diagnostics.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/registry.d.ts +23 -5
- package/dist/directives/registry.js +52 -40
- package/dist/directives/registry.js.map +1 -1
- package/dist/directives/spec.js +25 -51
- 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/directives/completions.js +11 -4
- package/dist/editor/directives/completions.js.map +1 -1
- package/dist/editor/themes/payload.js +2 -1
- package/dist/editor/themes/payload.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.json +1 -1
- package/skills/payload-markdown/codex/skill.json +1 -1
- 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 -132
- 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 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/renderMarkdown.ts"],"sourcesContent":["import type { Element, Parent, Root, RootContent } from 'hast'\nimport type { Schema } from 'hast-util-sanitize'\n\nimport { fromHtml } from 'hast-util-from-html'\nimport { toString } from 'hast-util-to-string'\nimport rehypeRaw from 'rehype-raw'\nimport rehypeSanitize, { defaultSchema } from 'rehype-sanitize'\nimport rehypeStringify from 'rehype-stringify'\nimport remarkGfm from 'remark-gfm'\nimport remarkParse from 'remark-parse'\nimport remarkRehype from 'remark-rehype'\nimport { unified } from 'unified'\nimport { visit } from 'unist-util-visit'\n\nimport type { HeadingAnchor } from '../directives/headingAnchors.js'\nimport type { MarkdownRenderConfig, RenderMarkdownOptions, RenderMarkdownResult } from '../types/core.js'\nimport type { DiagnosticFile, DiagnosticPlace, RenderDiagnostic } from './diagnostics.js'\nimport type { MarkdownLink } from './renderData.js'\n\nimport { resolveRenderMarkdownOptions } from './codeConfig.js'\nimport { highlightCode } from './codeToHtml.js'\nimport { reportDiagnostic, toRenderDiagnostic } from './diagnostics.js'\nimport { rehypeApplyLayoutClasses } from './plugins/rehypeApplyLayoutClasses.js'\nimport { rehypeContentLayout } from './plugins/rehypeContentLayout.js'\nimport { rehypeResolveIcons } from './plugins/rehypeResolveIcons.js'\nimport { rehypeStripAuthoredInlineStyles } from './plugins/rehypeStripAuthoredInlineStyles.js'\nimport {\n createPipelineNonce,\n rehypeMarkPipelineElements,\n rehypeTrustBoundary,\n} from './plugins/rehypeTrustBoundary.js'\nimport { remarkCollectRenderData } from './plugins/remarkCollectRenderData.js'\nimport { remarkCompileLayouts } from './plugins/remarkCompileLayouts.js'\nimport { remarkDirectiveLines } from './plugins/remarkDirectiveLines.js'\nimport { remarkHeadingAnchorsAndToc } from './plugins/remarkHeadingAnchorsAndToc.js'\nimport { remarkLayoutDirectives } from './plugins/remarkLayoutDirectives.js'\nimport { remarkValidateDirectiveThemes } from './plugins/remarkValidateDirectiveThemes.js'\nimport { remarkValidatePalettes } from './plugins/remarkValidatePalettes.js'\nimport { getRenderData } from './renderData.js'\n\nfunction extractCodeLanguage(\n className?: Array<number | string> | boolean | null | number | string ,\n): string | undefined {\n const classes =\n typeof className === 'string'\n ? className.split(/\\s+/)\n : Array.isArray(className)\n ? className\n : []\n\n return classes\n .find((c): c is string => typeof c === 'string' && c.startsWith('language-'))\n ?.slice(9)\n}\n\nfunction isElement(node: RootContent): node is Element {\n return node.type === 'element'\n}\n\nfunction isPreElement(node: RootContent): node is Element {\n return isElement(node) && node.tagName === 'pre'\n}\n\nfunction hasChildren(node: unknown): node is Parent {\n return Boolean(node && typeof node === 'object' && 'children' in node)\n}\n\nfunction findCodeChild(node: Element): Element | undefined {\n return node.children.find(\n (child): child is Element => child.type === 'element' && child.tagName === 'code',\n )\n}\n\nfunction parseHtmlFragment(html: string): RootContent[] {\n const fragment = fromHtml(html, { fragment: true })\n return fragment.children\n}\n\ntype CodeDiagnostic = {\n place?: DiagnosticPlace\n reason: string\n severity: 'info' | 'warning'\n}\n\nfunction rehypeShikiCodeBlocks(options: RenderMarkdownOptions = {}) {\n return async function transformer(tree: Root, file: DiagnosticFile): Promise<void> {\n const work: Array<Promise<CodeDiagnostic[]>> = []\n\n visit(tree, 'element', (node, index, parent) => {\n if (typeof index !== 'number' || !hasChildren(parent) || !isPreElement(node)) return\n\n const codeNode = findCodeChild(node)\n if (!codeNode) return\n\n const code = toString(codeNode)\n const lang = extractCodeLanguage(codeNode.properties?.className)\n const start = node.position?.start\n const place = start ? { column: start.column, line: start.line } : undefined\n\n work.push(\n (async () => {\n const highlighted = await highlightCode(code, {\n ...options,\n lang\n })\n\n const replacementNodes = parseHtmlFragment(highlighted.html)\n parent.children.splice(index, 1, ...replacementNodes)\n\n const info = new Set(highlighted.info ?? [])\n\n return highlighted.warnings.map((reason) => ({\n place,\n reason,\n severity: info.has(reason) ? ('info' as const) : ('warning' as const),\n }))\n })(),\n )\n })\n\n // Report each distinct diagnostic once per render, in document order (the\n // first occurrence's position is kept).\n const seen = new Set<string>()\n\n for (const diagnostic of (await Promise.all(work)).flat()) {\n if (seen.has(diagnostic.reason)) continue\n seen.add(diagnostic.reason)\n\n reportDiagnostic(file, diagnostic.reason, {\n place: diagnostic.place,\n severity: diagnostic.severity,\n source: 'code',\n })\n }\n }\n}\n\ntype SanitizeAttributeValue = boolean | null | number | RegExp | string | undefined\ntype SanitizeAttributeDefinition = [string, ...SanitizeAttributeValue[]] | string\n\nfunction getAttributeDefinitions(\n value: Schema['attributes'] extends infer A\n ? A extends Record<string, infer V>\n ? V\n : never\n : never,\n): SanitizeAttributeDefinition[] {\n return (value as SanitizeAttributeDefinition[] | undefined) ?? []\n}\n\nconst sanitizeSchema: Schema = {\n ...defaultSchema,\n attributes: {\n ...(defaultSchema.attributes ?? {}),\n a: [\n ...getAttributeDefinitions(defaultSchema.attributes?.a ?? []),\n 'ariaLabel',\n 'className',\n 'dataButton',\n 'dataDirective',\n 'dataIconPalette',\n 'dataPalette',\n 'dataDirectiveLink',\n 'dataIconPosition',\n 'dataSize',\n 'dataVariant',\n 'dataVlLayout',\n 'href',\n 'target',\n 'rel',\n 'title',\n ],\n article: [\n ...getAttributeDefinitions(defaultSchema.attributes?.article ?? []),\n 'className',\n 'dataDirective',\n 'dataIconPalette',\n 'dataPalette',\n 'dataEyebrow',\n 'dataHref',\n 'dataIcon',\n 'dataLinkScope',\n 'dataNewTab',\n 'dataStepCard',\n 'dataTabPanel',\n 'dataTabValue',\n 'dataTheme',\n 'dataTitle',\n 'dataVlLayout',\n 'hidden',\n 'id',\n 'role',\n 'tabIndex',\n ],\n button: [\n ...getAttributeDefinitions(defaultSchema.attributes?.button ?? []),\n 'ariaControls',\n 'ariaSelected',\n 'className',\n 'dataTabTrigger',\n 'dataTabValue',\n 'disabled',\n 'id',\n 'role',\n 'tabIndex',\n 'type',\n ],\n code: [...getAttributeDefinitions(defaultSchema.attributes?.code ?? []), 'className', 'tabIndex'],\n details: [\n ...getAttributeDefinitions(defaultSchema.attributes?.details ?? []),\n 'dataDirective',\n 'dataIconPalette',\n 'dataPalette',\n 'dataTheme',\n 'dataTitle',\n 'dataVlLayout',\n 'open',\n ],\n div: [\n ...getAttributeDefinitions(defaultSchema.attributes?.div ?? []),\n 'dataAlign',\n 'dataDirective',\n 'dataIconPalette',\n 'dataPalette',\n 'dataDirectiveBody',\n 'dataDirectiveTitle',\n 'dataEyebrow',\n 'dataHref',\n 'dataGap',\n 'dataCellTheme',\n 'dataIcon',\n 'dataTabsList',\n 'dataTabPanel',\n 'dataTabTrigger',\n 'dataTabValue',\n 'dataTheme',\n 'dataTitle',\n 'dataStack',\n 'dataVariant',\n 'dataVlLayout',\n 'dataWrap',\n 'dataVlCellHeadingDepth',\n 'hidden',\n 'id',\n 'role',\n 'tabIndex',\n ],\n h1: [\n ...getAttributeDefinitions(defaultSchema.attributes?.h1 ?? []),\n 'dataDirectiveTitle',\n 'dataHeadingAnchor',\n 'id',\n ],\n h2: [\n ...getAttributeDefinitions(defaultSchema.attributes?.h2 ?? []),\n 'dataDirectiveTitle',\n 'dataHeadingAnchor',\n 'id',\n ],\n h3: [\n ...getAttributeDefinitions(defaultSchema.attributes?.h3 ?? []),\n 'dataDirectiveTitle',\n 'dataHeadingAnchor',\n 'id',\n ],\n h4: [...getAttributeDefinitions(defaultSchema.attributes?.h4 ?? []), 'dataHeadingAnchor', 'id'],\n h5: [...getAttributeDefinitions(defaultSchema.attributes?.h5 ?? []), 'dataHeadingAnchor', 'id'],\n h6: [...getAttributeDefinitions(defaultSchema.attributes?.h6 ?? []), 'dataHeadingAnchor', 'id'],\n img: [\n ...getAttributeDefinitions(defaultSchema.attributes?.img ?? []),\n 'alt',\n 'className',\n 'dataDirective',\n 'src',\n 'title',\n 'width',\n 'height',\n ],\n li: [...getAttributeDefinitions(defaultSchema.attributes?.li ?? []), 'dataStep', 'dataTocLevel'],\n nav: [\n ...getAttributeDefinitions(defaultSchema.attributes?.nav ?? []),\n 'ariaLabel',\n 'dataDirective',\n 'dataTheme',\n 'dataTitle',\n 'dataVlLayout',\n ],\n p: [\n ...getAttributeDefinitions(defaultSchema.attributes?.p ?? []),\n 'className',\n 'dataDirectiveEyebrow',\n ],\n pre: [\n ...getAttributeDefinitions(defaultSchema.attributes?.pre ?? []),\n 'className',\n 'tabindex',\n ],\n section: [\n ...getAttributeDefinitions(defaultSchema.attributes?.section ?? []),\n 'dataColumns',\n 'dataCardTheme',\n 'dataCellTheme',\n 'dataDefault',\n 'dataDisabled',\n 'dataDirective',\n 'dataIconPalette',\n 'dataPalette',\n 'dataHref',\n 'dataLabel',\n 'dataLinkScope',\n 'dataLayout',\n 'dataNewTab',\n 'dataStack',\n 'dataNumbered',\n 'dataStepTheme',\n 'dataTabTheme',\n 'dataTabValue',\n 'dataTheme',\n 'dataVariant',\n 'dataValue',\n 'dataVlLayout',\n 'dataVlCellHeadingDepth',\n 'role',\n ],\n span: [\n ...getAttributeDefinitions(defaultSchema.attributes?.span ?? []),\n 'className',\n 'dataPmdIcon',\n 'dataPmdIconPalette',\n 'dataPmdIconRef',\n 'dataStepNumber',\n 'focusable',\n 'style',\n ],\n summary: [...getAttributeDefinitions(defaultSchema.attributes?.summary ?? []), 'className'],\n },\n // Clobber protection for author raw HTML is applied by rehypeTrustBoundary\n // (raw-HTML ids/names get the default `user-content-` prefix there), so the\n // pipeline's own heading, footnote and tab ids stay unprefixed.\n clobberPrefix: '',\n tagNames: [\n ...(defaultSchema.tagNames ?? []),\n 'a',\n 'article',\n 'br',\n 'button',\n 'details',\n 'img',\n 'nav',\n 'section',\n 'span',\n 'summary',\n ],\n}\n\nconst FAILED_RENDER_HTML = '<p>Failed to render markdown.</p>'\n\n/**\n * Structured result of `renderMarkdown`.\n */\nexport type RenderedMarkdown = {\n /** Every diagnostic, in report order, with a source and (when known) a position. */\n diagnostics: RenderDiagnostic[]\n /** Fatal compilation errors; when non-empty, `html` is the failure placeholder. */\n errors: string[]\n /** Heading anchors in document order; `id` is the exact id emitted in `html`. */\n headings: HeadingAnchor[]\n html: string\n /** Authored URLs in document order. */\n links: MarkdownLink[]\n /** Plain text of the document without directive markup or raw HTML. */\n text: string\n /** `diagnostics` messages (kept for compatibility; includes errors). */\n warnings: string[]\n}\n\n/**\n * Headless renderer: compiles markdown to sanitized HTML and returns the\n * structured data the pipeline collects. Pure server code (no CSS, no React);\n * `MarkdownRenderer` is a thin wrapper around it.\n */\nexport async function renderMarkdownDocument(\n markdown: string,\n config: MarkdownRenderConfig = {},\n): Promise<RenderedMarkdown> {\n const pipelineNonce = createPipelineNonce()\n\n try {\n const file = await unified()\n .use(remarkParse)\n .use(remarkGfm)\n .use(remarkDirectiveLines, config)\n .use(remarkCompileLayouts)\n .use(remarkLayoutDirectives)\n .use(remarkValidateDirectiveThemes, config)\n .use(remarkValidatePalettes, config)\n .use(remarkCollectRenderData)\n .use(remarkHeadingAnchorsAndToc)\n .use(remarkRehype, { allowDangerousHtml: true })\n .use(rehypeMarkPipelineElements, pipelineNonce)\n .use(rehypeRaw)\n .use(rehypeTrustBoundary, pipelineNonce)\n .use(rehypeStripAuthoredInlineStyles)\n .use(rehypeShikiCodeBlocks, resolveRenderMarkdownOptions(config))\n .use(rehypeSanitize, sanitizeSchema)\n .use(rehypeApplyLayoutClasses, config)\n .use(rehypeResolveIcons, config)\n .use(rehypeContentLayout)\n .use(rehypeStringify)\n .process(markdown)\n\n const data = getRenderData(file)\n const diagnostics = file.messages.map(toRenderDiagnostic)\n\n return {\n diagnostics,\n errors: [],\n headings: data.headings ?? [],\n html: String(file),\n links: data.links ?? [],\n text: data.text ?? '',\n warnings: diagnostics.map((diagnostic) => diagnostic.message),\n }\n } catch (error) {\n const message = error instanceof Error ? error.message : 'Failed to render markdown.'\n\n // Real compile failures were previously swallowed; log them server-side.\n // eslint-disable-next-line no-console\n console.error('[payload-markdown] Failed to render markdown:', error)\n\n return {\n diagnostics: [{ code: 'render-failed', message, severity: 'error', source: 'render' }],\n errors: [message],\n headings: [],\n html: FAILED_RENDER_HTML,\n links: [],\n text: '',\n warnings: [message],\n }\n }\n}\n\n/**\n * Compiles markdown to sanitized HTML. Same pipeline as `renderMarkdownDocument`,\n * returning only `{ html, warnings, errors }`.\n */\nexport async function compileMarkdown(\n markdown: string,\n config: MarkdownRenderConfig = {},\n): Promise<RenderMarkdownResult> {\n const { errors, html, warnings } = await renderMarkdownDocument(markdown, config)\n\n return { errors, html, warnings }\n}\n"],"names":["fromHtml","toString","rehypeRaw","rehypeSanitize","defaultSchema","rehypeStringify","remarkGfm","remarkParse","remarkRehype","unified","visit","resolveRenderMarkdownOptions","highlightCode","reportDiagnostic","toRenderDiagnostic","rehypeApplyLayoutClasses","rehypeContentLayout","rehypeResolveIcons","rehypeStripAuthoredInlineStyles","createPipelineNonce","rehypeMarkPipelineElements","rehypeTrustBoundary","remarkCollectRenderData","remarkCompileLayouts","remarkDirectiveLines","remarkHeadingAnchorsAndToc","remarkLayoutDirectives","remarkValidateDirectiveThemes","remarkValidatePalettes","getRenderData","extractCodeLanguage","className","classes","split","Array","isArray","find","c","startsWith","slice","isElement","node","type","isPreElement","tagName","hasChildren","Boolean","findCodeChild","children","child","parseHtmlFragment","html","fragment","rehypeShikiCodeBlocks","options","transformer","tree","file","work","index","parent","codeNode","code","lang","properties","start","position","place","column","line","undefined","push","highlighted","replacementNodes","splice","info","Set","warnings","map","reason","severity","has","seen","diagnostic","Promise","all","flat","add","source","getAttributeDefinitions","value","sanitizeSchema","attributes","a","article","button","details","div","h1","h2","h3","h4","h5","h6","img","li","nav","p","pre","section","span","summary","clobberPrefix","tagNames","FAILED_RENDER_HTML","renderMarkdownDocument","markdown","config","pipelineNonce","use","allowDangerousHtml","process","data","diagnostics","messages","errors","headings","String","links","text","message","error","Error","console","compileMarkdown"],"mappings":"AAGA,SAASA,QAAQ,QAAQ,sBAAqB;AAC9C,SAASC,QAAQ,QAAQ,sBAAqB;AAC9C,OAAOC,eAAe,aAAY;AAClC,OAAOC,kBAAkBC,aAAa,QAAQ,kBAAiB;AAC/D,OAAOC,qBAAqB,mBAAkB;AAC9C,OAAOC,eAAe,aAAY;AAClC,OAAOC,iBAAiB,eAAc;AACtC,OAAOC,kBAAkB,gBAAe;AACxC,SAASC,OAAO,QAAQ,UAAS;AACjC,SAASC,KAAK,QAAQ,mBAAkB;AAOxC,SAASC,4BAA4B,QAAQ,kBAAiB;AAC9D,SAASC,aAAa,QAAQ,kBAAiB;AAC/C,SAASC,gBAAgB,EAAEC,kBAAkB,QAAQ,mBAAkB;AACvE,SAASC,wBAAwB,QAAQ,wCAAuC;AAChF,SAASC,mBAAmB,QAAQ,mCAAkC;AACtE,SAASC,kBAAkB,QAAQ,kCAAiC;AACpE,SAASC,+BAA+B,QAAQ,+CAA8C;AAC9F,SACEC,mBAAmB,EACnBC,0BAA0B,EAC1BC,mBAAmB,QACd,mCAAkC;AACzC,SAASC,uBAAuB,QAAQ,uCAAsC;AAC9E,SAASC,oBAAoB,QAAQ,oCAAmC;AACxE,SAASC,oBAAoB,QAAQ,oCAAmC;AACxE,SAASC,0BAA0B,QAAQ,0CAAyC;AACpF,SAASC,sBAAsB,QAAQ,sCAAqC;AAC5E,SAASC,6BAA6B,QAAQ,6CAA4C;AAC1F,SAASC,sBAAsB,QAAQ,sCAAqC;AAC5E,SAASC,aAAa,QAAQ,kBAAiB;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,EAAE0B,QAAQ,EAAE,GAAG,MAAMsC,uBAAuBC,UAAUC;IAE1E,OAAO;QAAEQ;QAAQ1E;QAAM0B;IAAS;AAClC"}
|
|
1
|
+
{"version":3,"sources":["../../src/core/renderMarkdown.ts"],"sourcesContent":["import type { Element, Parent, Root, RootContent } from 'hast'\n\nimport { fromHtml } from 'hast-util-from-html'\nimport { toString } from 'hast-util-to-string'\nimport rehypeRaw from 'rehype-raw'\nimport rehypeSanitize from 'rehype-sanitize'\nimport rehypeStringify from 'rehype-stringify'\nimport remarkGfm from 'remark-gfm'\nimport remarkParse from 'remark-parse'\nimport remarkRehype from 'remark-rehype'\nimport { unified } from 'unified'\nimport { visit } from 'unist-util-visit'\n\nimport type { HeadingAnchor } from '../directives/headingAnchors.js'\nimport type { MarkdownRenderConfig, RenderMarkdownOptions, RenderMarkdownResult } from '../types/core.js'\nimport type { DiagnosticFile, DiagnosticPlace, RenderDiagnostic } from './diagnostics.js'\nimport type { MarkdownLink } from './renderData.js'\n\nimport { resolveRenderMarkdownOptions } from './codeConfig.js'\nimport { highlightCode } from './codeToHtml.js'\nimport { reportDiagnostic, toRenderDiagnostic } from './diagnostics.js'\nimport { rehypeApplyLayoutClasses } from './plugins/rehypeApplyLayoutClasses.js'\nimport { rehypeContentLayout } from './plugins/rehypeContentLayout.js'\nimport { rehypeResolveIcons } from './plugins/rehypeResolveIcons.js'\nimport { rehypeStripAuthoredInlineStyles } from './plugins/rehypeStripAuthoredInlineStyles.js'\nimport {\n createPipelineNonce,\n rehypeMarkPipelineElements,\n rehypeTrustBoundary,\n} from './plugins/rehypeTrustBoundary.js'\nimport { remarkCollectRenderData } from './plugins/remarkCollectRenderData.js'\nimport { remarkCompileLayouts } from './plugins/remarkCompileLayouts.js'\nimport { remarkDirectiveLines } from './plugins/remarkDirectiveLines.js'\nimport { remarkHeadingAnchorsAndToc } from './plugins/remarkHeadingAnchorsAndToc.js'\nimport { remarkLayoutDirectives } from './plugins/remarkLayoutDirectives.js'\nimport { remarkValidateDirectiveThemes } from './plugins/remarkValidateDirectiveThemes.js'\nimport { remarkValidatePalettes } from './plugins/remarkValidatePalettes.js'\nimport { getRenderData } from './renderData.js'\nimport { sanitizeSchema } from './sanitizeSchema.js'\n\nfunction extractCodeLanguage(\n className?: Array<number | string> | boolean | null | number | string ,\n): string | undefined {\n const classes =\n typeof className === 'string'\n ? className.split(/\\s+/)\n : Array.isArray(className)\n ? className\n : []\n\n return classes\n .find((c): c is string => typeof c === 'string' && c.startsWith('language-'))\n ?.slice(9)\n}\n\nfunction isElement(node: RootContent): node is Element {\n return node.type === 'element'\n}\n\nfunction isPreElement(node: RootContent): node is Element {\n return isElement(node) && node.tagName === 'pre'\n}\n\nfunction hasChildren(node: unknown): node is Parent {\n return Boolean(node && typeof node === 'object' && 'children' in node)\n}\n\nfunction findCodeChild(node: Element): Element | undefined {\n return node.children.find(\n (child): child is Element => child.type === 'element' && child.tagName === 'code',\n )\n}\n\nfunction parseHtmlFragment(html: string): RootContent[] {\n const fragment = fromHtml(html, { fragment: true })\n return fragment.children\n}\n\ntype CodeDiagnostic = {\n place?: DiagnosticPlace\n reason: string\n severity: 'info' | 'warning'\n}\n\nfunction rehypeShikiCodeBlocks(options: RenderMarkdownOptions = {}) {\n return async function transformer(tree: Root, file: DiagnosticFile): Promise<void> {\n const work: Array<Promise<CodeDiagnostic[]>> = []\n\n visit(tree, 'element', (node, index, parent) => {\n if (typeof index !== 'number' || !hasChildren(parent) || !isPreElement(node)) return\n\n const codeNode = findCodeChild(node)\n if (!codeNode) return\n\n const code = toString(codeNode)\n const lang = extractCodeLanguage(codeNode.properties?.className)\n const start = node.position?.start\n const place = start ? { column: start.column, line: start.line } : undefined\n\n work.push(\n (async () => {\n const highlighted = await highlightCode(code, {\n ...options,\n lang\n })\n\n const replacementNodes = parseHtmlFragment(highlighted.html)\n parent.children.splice(index, 1, ...replacementNodes)\n\n const info = new Set(highlighted.info ?? [])\n\n return highlighted.warnings.map((reason) => ({\n place,\n reason,\n severity: info.has(reason) ? ('info' as const) : ('warning' as const),\n }))\n })(),\n )\n })\n\n // Report each distinct diagnostic once per render, in document order (the\n // first occurrence's position is kept).\n const seen = new Set<string>()\n\n for (const diagnostic of (await Promise.all(work)).flat()) {\n if (seen.has(diagnostic.reason)) continue\n seen.add(diagnostic.reason)\n\n reportDiagnostic(file, diagnostic.reason, {\n place: diagnostic.place,\n severity: diagnostic.severity,\n source: 'code',\n })\n }\n }\n}\n\nconst FAILED_RENDER_HTML = '<p>Failed to render markdown.</p>'\n\n/**\n * Structured result of `renderMarkdown`.\n */\nexport type RenderedMarkdown = {\n /** Every diagnostic, in report order, with a source and (when known) a position. */\n diagnostics: RenderDiagnostic[]\n /** Fatal compilation errors; when non-empty, `html` is the failure placeholder. */\n errors: string[]\n /** Heading anchors in document order; `id` is the exact id emitted in `html`. */\n headings: HeadingAnchor[]\n html: string\n /** Authored URLs in document order. */\n links: MarkdownLink[]\n /** Plain text of the document without directive markup or raw HTML. */\n text: string\n /** `diagnostics` messages (kept for compatibility; includes errors). */\n warnings: string[]\n}\n\n/**\n * Headless renderer: compiles markdown to sanitized HTML and returns the\n * structured data the pipeline collects. Pure server code (no CSS, no React);\n * `MarkdownRenderer` is a thin wrapper around it.\n */\nexport async function renderMarkdownDocument(\n markdown: string,\n config: MarkdownRenderConfig = {},\n): Promise<RenderedMarkdown> {\n const pipelineNonce = createPipelineNonce()\n\n try {\n const file = await unified()\n .use(remarkParse)\n .use(remarkGfm)\n .use(remarkDirectiveLines, config)\n .use(remarkCompileLayouts)\n .use(remarkLayoutDirectives)\n .use(remarkValidateDirectiveThemes, config)\n .use(remarkValidatePalettes, config)\n .use(remarkCollectRenderData)\n .use(remarkHeadingAnchorsAndToc)\n .use(remarkRehype, { allowDangerousHtml: true })\n .use(rehypeMarkPipelineElements, pipelineNonce)\n .use(rehypeRaw)\n .use(rehypeTrustBoundary, pipelineNonce)\n .use(rehypeStripAuthoredInlineStyles)\n .use(rehypeShikiCodeBlocks, resolveRenderMarkdownOptions(config))\n .use(rehypeSanitize, sanitizeSchema)\n .use(rehypeApplyLayoutClasses, config)\n .use(rehypeResolveIcons, config)\n .use(rehypeContentLayout)\n .use(rehypeStringify)\n .process(markdown)\n\n const data = getRenderData(file)\n const diagnostics = file.messages.map(toRenderDiagnostic)\n\n return {\n diagnostics,\n errors: [],\n headings: data.headings ?? [],\n html: String(file),\n links: data.links ?? [],\n text: data.text ?? '',\n warnings: diagnostics.map((diagnostic) => diagnostic.message),\n }\n } catch (error) {\n const message = error instanceof Error ? error.message : 'Failed to render markdown.'\n\n // Real compile failures were previously swallowed; log them server-side.\n // eslint-disable-next-line no-console\n console.error('[payload-markdown] Failed to render markdown:', error)\n\n return {\n diagnostics: [{ code: 'render-failed', message, severity: 'error', source: 'render' }],\n errors: [message],\n headings: [],\n html: FAILED_RENDER_HTML,\n links: [],\n text: '',\n warnings: [message],\n }\n }\n}\n\n/**\n * Compiles markdown to sanitized HTML. Same pipeline as `renderMarkdownDocument`,\n * returning only `{ html, warnings, errors }`.\n */\nexport async function compileMarkdown(\n markdown: string,\n config: MarkdownRenderConfig = {},\n): Promise<RenderMarkdownResult> {\n const { errors, html, warnings } = await renderMarkdownDocument(markdown, config)\n\n return { errors, html, warnings }\n}\n"],"names":["fromHtml","toString","rehypeRaw","rehypeSanitize","rehypeStringify","remarkGfm","remarkParse","remarkRehype","unified","visit","resolveRenderMarkdownOptions","highlightCode","reportDiagnostic","toRenderDiagnostic","rehypeApplyLayoutClasses","rehypeContentLayout","rehypeResolveIcons","rehypeStripAuthoredInlineStyles","createPipelineNonce","rehypeMarkPipelineElements","rehypeTrustBoundary","remarkCollectRenderData","remarkCompileLayouts","remarkDirectiveLines","remarkHeadingAnchorsAndToc","remarkLayoutDirectives","remarkValidateDirectiveThemes","remarkValidatePalettes","getRenderData","sanitizeSchema","extractCodeLanguage","className","classes","split","Array","isArray","find","c","startsWith","slice","isElement","node","type","isPreElement","tagName","hasChildren","Boolean","findCodeChild","children","child","parseHtmlFragment","html","fragment","rehypeShikiCodeBlocks","options","transformer","tree","file","work","index","parent","codeNode","code","lang","properties","start","position","place","column","line","undefined","push","highlighted","replacementNodes","splice","info","Set","warnings","map","reason","severity","has","seen","diagnostic","Promise","all","flat","add","source","FAILED_RENDER_HTML","renderMarkdownDocument","markdown","config","pipelineNonce","use","allowDangerousHtml","process","data","diagnostics","messages","errors","headings","String","links","text","message","error","Error","console","compileMarkdown"],"mappings":"AAEA,SAASA,QAAQ,QAAQ,sBAAqB;AAC9C,SAASC,QAAQ,QAAQ,sBAAqB;AAC9C,OAAOC,eAAe,aAAY;AAClC,OAAOC,oBAAoB,kBAAiB;AAC5C,OAAOC,qBAAqB,mBAAkB;AAC9C,OAAOC,eAAe,aAAY;AAClC,OAAOC,iBAAiB,eAAc;AACtC,OAAOC,kBAAkB,gBAAe;AACxC,SAASC,OAAO,QAAQ,UAAS;AACjC,SAASC,KAAK,QAAQ,mBAAkB;AAOxC,SAASC,4BAA4B,QAAQ,kBAAiB;AAC9D,SAASC,aAAa,QAAQ,kBAAiB;AAC/C,SAASC,gBAAgB,EAAEC,kBAAkB,QAAQ,mBAAkB;AACvE,SAASC,wBAAwB,QAAQ,wCAAuC;AAChF,SAASC,mBAAmB,QAAQ,mCAAkC;AACtE,SAASC,kBAAkB,QAAQ,kCAAiC;AACpE,SAASC,+BAA+B,QAAQ,+CAA8C;AAC9F,SACEC,mBAAmB,EACnBC,0BAA0B,EAC1BC,mBAAmB,QACd,mCAAkC;AACzC,SAASC,uBAAuB,QAAQ,uCAAsC;AAC9E,SAASC,oBAAoB,QAAQ,oCAAmC;AACxE,SAASC,oBAAoB,QAAQ,oCAAmC;AACxE,SAASC,0BAA0B,QAAQ,0CAAyC;AACpF,SAASC,sBAAsB,QAAQ,sCAAqC;AAC5E,SAASC,6BAA6B,QAAQ,6CAA4C;AAC1F,SAASC,sBAAsB,QAAQ,sCAAqC;AAC5E,SAASC,aAAa,QAAQ,kBAAiB;AAC/C,SAASC,cAAc,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,EAAEjD,IAAI,EAAE0B,QAAQ,EAAE,GAAG,MAAMa,uBAAuBC,UAAUC;IAE1E,OAAO;QAAEQ;QAAQjD;QAAM0B;IAAS;AAClC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Schema } from 'hast-util-sanitize';
|
|
2
|
+
import type { LayoutDirectiveDefinition } from '../directives/types.js';
|
|
3
|
+
/**
|
|
4
|
+
* The rehype-sanitize schema: the defaults, then the base allowlist, then
|
|
5
|
+
* what each directive declares. A directive's element gets `dataVlLayout`
|
|
6
|
+
* when it carries the layout marker. Default entries come first because the
|
|
7
|
+
* first definition of a property wins (`['className', 'data-footnote-backref']`
|
|
8
|
+
* on `a` keeps restricting link classes).
|
|
9
|
+
*/
|
|
10
|
+
export declare function createSanitizeSchema(definitions: readonly LayoutDirectiveDefinition[]): Schema;
|
|
11
|
+
export declare const sanitizeSchema: Schema;
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { defaultSchema } from 'rehype-sanitize';
|
|
2
|
+
import { layoutDirectiveRegistry } from '../directives/registry.js';
|
|
3
|
+
/**
|
|
4
|
+
* Properties the pipeline keeps beyond rehype-sanitize's defaults that no
|
|
5
|
+
* directive definition declares: heading anchors, footnotes, Shiki output,
|
|
6
|
+
* and hooks of elements that directives build after sanitizing (and that raw
|
|
7
|
+
* HTML may therefore also carry). Directive-specific properties live on the
|
|
8
|
+
* definitions (`sanitize`), see `createSanitizeSchema`.
|
|
9
|
+
*/ const BASE_ATTRIBUTES = {
|
|
10
|
+
a: [
|
|
11
|
+
'dataDirectiveLink',
|
|
12
|
+
'title'
|
|
13
|
+
],
|
|
14
|
+
article: [
|
|
15
|
+
'className',
|
|
16
|
+
'dataStepCard',
|
|
17
|
+
'dataTabPanel',
|
|
18
|
+
'dataTabValue',
|
|
19
|
+
'hidden',
|
|
20
|
+
'id',
|
|
21
|
+
'role',
|
|
22
|
+
'tabIndex'
|
|
23
|
+
],
|
|
24
|
+
button: [
|
|
25
|
+
'ariaControls',
|
|
26
|
+
'ariaSelected',
|
|
27
|
+
'className',
|
|
28
|
+
'dataTabTrigger',
|
|
29
|
+
'dataTabValue',
|
|
30
|
+
'disabled',
|
|
31
|
+
'id',
|
|
32
|
+
'role',
|
|
33
|
+
'tabIndex',
|
|
34
|
+
'type'
|
|
35
|
+
],
|
|
36
|
+
code: [
|
|
37
|
+
'className',
|
|
38
|
+
'tabIndex'
|
|
39
|
+
],
|
|
40
|
+
div: [
|
|
41
|
+
'dataDirectiveBody',
|
|
42
|
+
'dataDirectiveTitle',
|
|
43
|
+
'dataEyebrow',
|
|
44
|
+
'dataHref',
|
|
45
|
+
'dataTabsList',
|
|
46
|
+
'dataTabPanel',
|
|
47
|
+
'dataTabTrigger',
|
|
48
|
+
'dataTabValue',
|
|
49
|
+
'hidden',
|
|
50
|
+
'id',
|
|
51
|
+
'role',
|
|
52
|
+
'tabIndex'
|
|
53
|
+
],
|
|
54
|
+
h1: [
|
|
55
|
+
'dataDirectiveTitle',
|
|
56
|
+
'dataHeadingAnchor',
|
|
57
|
+
'id'
|
|
58
|
+
],
|
|
59
|
+
h2: [
|
|
60
|
+
'dataDirectiveTitle',
|
|
61
|
+
'dataHeadingAnchor',
|
|
62
|
+
'id'
|
|
63
|
+
],
|
|
64
|
+
h3: [
|
|
65
|
+
'dataDirectiveTitle',
|
|
66
|
+
'dataHeadingAnchor',
|
|
67
|
+
'id'
|
|
68
|
+
],
|
|
69
|
+
h4: [
|
|
70
|
+
'dataHeadingAnchor',
|
|
71
|
+
'id'
|
|
72
|
+
],
|
|
73
|
+
h5: [
|
|
74
|
+
'dataHeadingAnchor',
|
|
75
|
+
'id'
|
|
76
|
+
],
|
|
77
|
+
h6: [
|
|
78
|
+
'dataHeadingAnchor',
|
|
79
|
+
'id'
|
|
80
|
+
],
|
|
81
|
+
img: [
|
|
82
|
+
'title',
|
|
83
|
+
'width',
|
|
84
|
+
'height'
|
|
85
|
+
],
|
|
86
|
+
li: [
|
|
87
|
+
'dataStep'
|
|
88
|
+
],
|
|
89
|
+
p: [
|
|
90
|
+
'className',
|
|
91
|
+
'dataDirectiveEyebrow'
|
|
92
|
+
],
|
|
93
|
+
pre: [
|
|
94
|
+
'className',
|
|
95
|
+
'tabindex'
|
|
96
|
+
],
|
|
97
|
+
section: [
|
|
98
|
+
'dataCellTheme',
|
|
99
|
+
'dataStack',
|
|
100
|
+
'dataTabValue',
|
|
101
|
+
'dataVlCellHeadingDepth',
|
|
102
|
+
'role'
|
|
103
|
+
],
|
|
104
|
+
span: [
|
|
105
|
+
'className',
|
|
106
|
+
'dataStepNumber',
|
|
107
|
+
'style'
|
|
108
|
+
],
|
|
109
|
+
summary: [
|
|
110
|
+
'className'
|
|
111
|
+
]
|
|
112
|
+
};
|
|
113
|
+
/** Tag names allowed beyond the defaults that no definition brings in. */ const BASE_TAG_NAMES = [
|
|
114
|
+
'br',
|
|
115
|
+
'button',
|
|
116
|
+
'span',
|
|
117
|
+
'summary'
|
|
118
|
+
];
|
|
119
|
+
function getDefaultAttributeDefinitions(tagName) {
|
|
120
|
+
return defaultSchema.attributes?.[tagName] ?? [];
|
|
121
|
+
}
|
|
122
|
+
function addAll(target, tagName, names) {
|
|
123
|
+
const list = target.get(tagName) ?? [];
|
|
124
|
+
for (const name of names)if (!list.includes(name)) list.push(name);
|
|
125
|
+
target.set(tagName, list);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* The rehype-sanitize schema: the defaults, then the base allowlist, then
|
|
129
|
+
* what each directive declares. A directive's element gets `dataVlLayout`
|
|
130
|
+
* when it carries the layout marker. Default entries come first because the
|
|
131
|
+
* first definition of a property wins (`['className', 'data-footnote-backref']`
|
|
132
|
+
* on `a` keeps restricting link classes).
|
|
133
|
+
*/ export function createSanitizeSchema(definitions) {
|
|
134
|
+
const extra = new Map();
|
|
135
|
+
const tagNames = [
|
|
136
|
+
...BASE_TAG_NAMES
|
|
137
|
+
];
|
|
138
|
+
for (const [tagName, names] of Object.entries(BASE_ATTRIBUTES))addAll(extra, tagName, names);
|
|
139
|
+
for (const definition of definitions){
|
|
140
|
+
if (layoutDirectiveRegistry.receivesLayoutMarker(definition, 'container') || layoutDirectiveRegistry.receivesLayoutMarker(definition, 'leaf')) {
|
|
141
|
+
addAll(extra, definition.tagName, [
|
|
142
|
+
'dataVlLayout'
|
|
143
|
+
]);
|
|
144
|
+
tagNames.push(definition.tagName);
|
|
145
|
+
}
|
|
146
|
+
for (const [tagName, names] of Object.entries(definition.sanitize ?? {})){
|
|
147
|
+
if (!names) continue;
|
|
148
|
+
addAll(extra, tagName, names);
|
|
149
|
+
tagNames.push(tagName);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
const attributes = {
|
|
153
|
+
...defaultSchema.attributes ?? {}
|
|
154
|
+
};
|
|
155
|
+
for (const [tagName, names] of extra)attributes[tagName] = [
|
|
156
|
+
...getDefaultAttributeDefinitions(tagName),
|
|
157
|
+
...names
|
|
158
|
+
];
|
|
159
|
+
return {
|
|
160
|
+
...defaultSchema,
|
|
161
|
+
attributes,
|
|
162
|
+
// Clobber protection for author raw HTML is applied by rehypeTrustBoundary
|
|
163
|
+
// (raw-HTML ids/names get the default `user-content-` prefix there), so the
|
|
164
|
+
// pipeline's own heading, footnote and tab ids stay unprefixed.
|
|
165
|
+
clobberPrefix: '',
|
|
166
|
+
tagNames: [
|
|
167
|
+
...new Set([
|
|
168
|
+
...defaultSchema.tagNames ?? [],
|
|
169
|
+
...tagNames
|
|
170
|
+
])
|
|
171
|
+
]
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
export const sanitizeSchema = createSanitizeSchema(layoutDirectiveRegistry.all);
|
|
175
|
+
|
|
176
|
+
//# sourceMappingURL=sanitizeSchema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/core/sanitizeSchema.ts"],"sourcesContent":["import type { Schema } from 'hast-util-sanitize'\n\nimport { defaultSchema } from 'rehype-sanitize'\n\nimport type { LayoutDirectiveDefinition } from '../directives/types.js'\n\nimport { layoutDirectiveRegistry } from '../directives/registry.js'\n\ntype SanitizeAttributeValue = boolean | null | number | RegExp | string | undefined\ntype SanitizeAttributeDefinition = [string, ...SanitizeAttributeValue[]] | string\n\n/**\n * Properties the pipeline keeps beyond rehype-sanitize's defaults that no\n * directive definition declares: heading anchors, footnotes, Shiki output,\n * and hooks of elements that directives build after sanitizing (and that raw\n * HTML may therefore also carry). Directive-specific properties live on the\n * definitions (`sanitize`), see `createSanitizeSchema`.\n */\nconst BASE_ATTRIBUTES: Readonly<Record<string, readonly string[]>> = {\n a: ['dataDirectiveLink', 'title'],\n article: [\n 'className',\n 'dataStepCard',\n 'dataTabPanel',\n 'dataTabValue',\n 'hidden',\n 'id',\n 'role',\n 'tabIndex',\n ],\n button: [\n 'ariaControls',\n 'ariaSelected',\n 'className',\n 'dataTabTrigger',\n 'dataTabValue',\n 'disabled',\n 'id',\n 'role',\n 'tabIndex',\n 'type',\n ],\n code: ['className', 'tabIndex'],\n div: [\n 'dataDirectiveBody',\n 'dataDirectiveTitle',\n 'dataEyebrow',\n 'dataHref',\n 'dataTabsList',\n 'dataTabPanel',\n 'dataTabTrigger',\n 'dataTabValue',\n 'hidden',\n 'id',\n 'role',\n 'tabIndex',\n ],\n h1: ['dataDirectiveTitle', 'dataHeadingAnchor', 'id'],\n h2: ['dataDirectiveTitle', 'dataHeadingAnchor', 'id'],\n h3: ['dataDirectiveTitle', 'dataHeadingAnchor', 'id'],\n h4: ['dataHeadingAnchor', 'id'],\n h5: ['dataHeadingAnchor', 'id'],\n h6: ['dataHeadingAnchor', 'id'],\n img: ['title', 'width', 'height'],\n li: ['dataStep'],\n p: ['className', 'dataDirectiveEyebrow'],\n pre: ['className', 'tabindex'],\n section: ['dataCellTheme', 'dataStack', 'dataTabValue', 'dataVlCellHeadingDepth', 'role'],\n span: ['className', 'dataStepNumber', 'style'],\n summary: ['className'],\n}\n\n/** Tag names allowed beyond the defaults that no definition brings in. */\nconst BASE_TAG_NAMES: readonly string[] = ['br', 'button', 'span', 'summary']\n\nfunction getDefaultAttributeDefinitions(tagName: string): SanitizeAttributeDefinition[] {\n return (defaultSchema.attributes?.[tagName] as SanitizeAttributeDefinition[] | undefined) ?? []\n}\n\nfunction addAll(target: Map<string, string[]>, tagName: string, names: readonly string[]) {\n const list = target.get(tagName) ?? []\n\n for (const name of names) if (!list.includes(name)) list.push(name)\n target.set(tagName, list)\n}\n\n/**\n * The rehype-sanitize schema: the defaults, then the base allowlist, then\n * what each directive declares. A directive's element gets `dataVlLayout`\n * when it carries the layout marker. Default entries come first because the\n * first definition of a property wins (`['className', 'data-footnote-backref']`\n * on `a` keeps restricting link classes).\n */\nexport function createSanitizeSchema(definitions: readonly LayoutDirectiveDefinition[]): Schema {\n const extra = new Map<string, string[]>()\n const tagNames: string[] = [...BASE_TAG_NAMES]\n\n for (const [tagName, names] of Object.entries(BASE_ATTRIBUTES)) addAll(extra, tagName, names)\n\n for (const definition of definitions) {\n if (\n layoutDirectiveRegistry.receivesLayoutMarker(definition, 'container') ||\n layoutDirectiveRegistry.receivesLayoutMarker(definition, 'leaf')\n ) {\n addAll(extra, definition.tagName, ['dataVlLayout'])\n tagNames.push(definition.tagName)\n }\n\n for (const [tagName, names] of Object.entries(definition.sanitize ?? {})) {\n if (!names) continue\n\n addAll(extra, tagName, names)\n tagNames.push(tagName)\n }\n }\n\n const attributes: NonNullable<Schema['attributes']> = { ...(defaultSchema.attributes ?? {}) }\n\n for (const [tagName, names] of extra)\n attributes[tagName] = [...getDefaultAttributeDefinitions(tagName), ...names]\n\n return {\n ...defaultSchema,\n attributes,\n // Clobber protection for author raw HTML is applied by rehypeTrustBoundary\n // (raw-HTML ids/names get the default `user-content-` prefix there), so the\n // pipeline's own heading, footnote and tab ids stay unprefixed.\n clobberPrefix: '',\n tagNames: [...new Set([...(defaultSchema.tagNames ?? []), ...tagNames])],\n }\n}\n\nexport const sanitizeSchema: Schema = createSanitizeSchema(layoutDirectiveRegistry.all)\n"],"names":["defaultSchema","layoutDirectiveRegistry","BASE_ATTRIBUTES","a","article","button","code","div","h1","h2","h3","h4","h5","h6","img","li","p","pre","section","span","summary","BASE_TAG_NAMES","getDefaultAttributeDefinitions","tagName","attributes","addAll","target","names","list","get","name","includes","push","set","createSanitizeSchema","definitions","extra","Map","tagNames","Object","entries","definition","receivesLayoutMarker","sanitize","clobberPrefix","Set","sanitizeSchema","all"],"mappings":"AAEA,SAASA,aAAa,QAAQ,kBAAiB;AAI/C,SAASC,uBAAuB,QAAQ,4BAA2B;AAKnE;;;;;;CAMC,GACD,MAAMC,kBAA+D;IACnEC,GAAG;QAAC;QAAqB;KAAQ;IACjCC,SAAS;QACP;QACA;QACA;QACA;QACA;QACA;QACA;QACA;KACD;IACDC,QAAQ;QACN;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;KACD;IACDC,MAAM;QAAC;QAAa;KAAW;IAC/BC,KAAK;QACH;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;KACD;IACDC,IAAI;QAAC;QAAsB;QAAqB;KAAK;IACrDC,IAAI;QAAC;QAAsB;QAAqB;KAAK;IACrDC,IAAI;QAAC;QAAsB;QAAqB;KAAK;IACrDC,IAAI;QAAC;QAAqB;KAAK;IAC/BC,IAAI;QAAC;QAAqB;KAAK;IAC/BC,IAAI;QAAC;QAAqB;KAAK;IAC/BC,KAAK;QAAC;QAAS;QAAS;KAAS;IACjCC,IAAI;QAAC;KAAW;IAChBC,GAAG;QAAC;QAAa;KAAuB;IACxCC,KAAK;QAAC;QAAa;KAAW;IAC9BC,SAAS;QAAC;QAAiB;QAAa;QAAgB;QAA0B;KAAO;IACzFC,MAAM;QAAC;QAAa;QAAkB;KAAQ;IAC9CC,SAAS;QAAC;KAAY;AACxB;AAEA,wEAAwE,GACxE,MAAMC,iBAAoC;IAAC;IAAM;IAAU;IAAQ;CAAU;AAE7E,SAASC,+BAA+BC,OAAe;IACrD,OAAO,AAACvB,cA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AcsC,QAAQ,IAAI,EAAE;mBAAMA;aAAS;SAAE;IAC1E;AACF;AAEA,OAAO,MAAMQ,iBAAyBZ,qBAAqBjC,wBAAwB8C,GAAG,EAAC"}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LeafDirective } from 'mdast-util-directive';
|
|
2
|
+
import type { DirectiveMessageSink } from '../types.js';
|
|
2
3
|
export declare const BADGE_TYPES: readonly ["static", "npm", "github", "debian", "apt"];
|
|
3
4
|
export declare const BADGE_TARGETS: readonly ["version", "downloads", "license", "workflow", "release", "stars"];
|
|
4
5
|
export declare const BADGE_INTERVALS: readonly ["dw", "dm", "dy", "dt"];
|
|
5
6
|
export declare const BADGE_STYLES: readonly ["flat", "flat-square", "plastic", "for-the-badge", "social"];
|
|
6
7
|
export declare const BADGE_ALLOWED_ATTRIBUTES: readonly ["alt", "href", "interval", "message", "newTab", "package", "path", "repo", "src", "target", "type", "workflow", "style", "logo", "logoColor", "logoSize", "label", "labelColor", "color", "cacheSeconds"];
|
|
7
|
-
|
|
8
|
+
/** Builds the `::badge` leaf (the renderer side of `leaf.build`). */
|
|
9
|
+
export declare function makeBadgeDirective(line: string, file: DirectiveMessageSink): LeafDirective | undefined;
|
|
10
|
+
export declare const badgeDirective: import("../types.js").LayoutDirectiveDefinition<"badge", "badge">;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { getUnknownAttributeWarnings } from '../attributeDiagnostics.js';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { parseLeafDirectiveLine } from '../leafSyntax.js';
|
|
3
|
+
import { resolveShieldsBadge, SHIELDS_BADGE_QUERY_ATTRIBUTES } from '../shields.js';
|
|
4
|
+
import { defineDirective } from '../types.js';
|
|
5
|
+
import { getSafeHref, getUnsafeHrefWarnings } from '../urls.js';
|
|
4
6
|
export const BADGE_TYPES = [
|
|
5
7
|
'static',
|
|
6
8
|
'npm',
|
|
@@ -44,9 +46,120 @@ export const BADGE_ALLOWED_ATTRIBUTES = [
|
|
|
44
46
|
'workflow',
|
|
45
47
|
...SHIELDS_BADGE_QUERY_ATTRIBUTES
|
|
46
48
|
];
|
|
47
|
-
|
|
49
|
+
function validateBadgeAttributes(attributes) {
|
|
50
|
+
return [
|
|
51
|
+
...getUnknownAttributeWarnings('badge', BADGE_ALLOWED_ATTRIBUTES, attributes),
|
|
52
|
+
...getUnsafeHrefWarnings('badge', attributes)
|
|
53
|
+
];
|
|
54
|
+
}
|
|
55
|
+
function getAttribute(attributes, name) {
|
|
56
|
+
const value = attributes[name];
|
|
57
|
+
return typeof value === 'string' && value.trim() ? value.trim() : undefined;
|
|
58
|
+
}
|
|
59
|
+
function getBooleanAttribute(attributes, name) {
|
|
60
|
+
const value = attributes[name];
|
|
61
|
+
if (value === true) return true;
|
|
62
|
+
if (typeof value !== 'string') return false;
|
|
63
|
+
return value === 'true';
|
|
64
|
+
}
|
|
65
|
+
function stringifyAttributes(attributes) {
|
|
66
|
+
return Object.fromEntries(Object.entries(attributes).map(([key, value])=>[
|
|
67
|
+
key,
|
|
68
|
+
String(value)
|
|
69
|
+
]));
|
|
70
|
+
}
|
|
71
|
+
function makeBadgeImageProperties(src, alt, includeDirective) {
|
|
72
|
+
return {
|
|
73
|
+
alt,
|
|
74
|
+
// Badge images opt out of Typography's image margins and rounding.
|
|
75
|
+
className: [
|
|
76
|
+
'not-prose',
|
|
77
|
+
'pmd-badge'
|
|
78
|
+
],
|
|
79
|
+
...includeDirective ? {
|
|
80
|
+
dataDirective: 'badge'
|
|
81
|
+
} : {},
|
|
82
|
+
src
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/** Builds the `::badge` leaf (the renderer side of `leaf.build`). */ export function makeBadgeDirective(line, file) {
|
|
86
|
+
const parsed = parseLeafDirectiveLine(line, 'badge');
|
|
87
|
+
if (!parsed) return undefined;
|
|
88
|
+
const attributes = parsed.attributes;
|
|
89
|
+
const label = parsed.label.trim();
|
|
90
|
+
const href = getSafeHref(getAttribute(attributes, 'href'));
|
|
91
|
+
const newTab = getBooleanAttribute(attributes, 'newTab');
|
|
92
|
+
const alt = getAttribute(attributes, 'alt') ?? label;
|
|
93
|
+
for (const warning of parsed.warnings)file.message(warning);
|
|
94
|
+
for (const warning of validateBadgeAttributes(attributes))file.message(warning);
|
|
95
|
+
const resolved = resolveShieldsBadge(attributes);
|
|
96
|
+
for (const warning of resolved.warnings)file.message(warning);
|
|
97
|
+
if (!resolved.src) return undefined;
|
|
98
|
+
const imgProperties = makeBadgeImageProperties(resolved.src, alt, !href);
|
|
99
|
+
return {
|
|
100
|
+
name: 'badge',
|
|
101
|
+
type: 'leafDirective',
|
|
102
|
+
attributes: stringifyAttributes(attributes),
|
|
103
|
+
children: label ? [
|
|
104
|
+
{
|
|
105
|
+
type: 'text',
|
|
106
|
+
value: label
|
|
107
|
+
}
|
|
108
|
+
] : [],
|
|
109
|
+
data: href ? {
|
|
110
|
+
hChildren: [
|
|
111
|
+
{
|
|
112
|
+
type: 'element',
|
|
113
|
+
children: [],
|
|
114
|
+
properties: imgProperties,
|
|
115
|
+
tagName: 'img'
|
|
116
|
+
}
|
|
117
|
+
],
|
|
118
|
+
hName: 'a',
|
|
119
|
+
hProperties: {
|
|
120
|
+
className: [
|
|
121
|
+
'pmd-badge-link'
|
|
122
|
+
],
|
|
123
|
+
dataDirective: 'badge',
|
|
124
|
+
href,
|
|
125
|
+
...newTab ? {
|
|
126
|
+
rel: 'noopener noreferrer',
|
|
127
|
+
target: '_blank'
|
|
128
|
+
} : {}
|
|
129
|
+
}
|
|
130
|
+
} : {
|
|
131
|
+
// <img> is void: the [label] is the alt text and must not also be
|
|
132
|
+
// emitted as visible text after the image.
|
|
133
|
+
hChildren: [],
|
|
134
|
+
hName: 'img',
|
|
135
|
+
hProperties: imgProperties
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/** Editor diagnostics for a `::badge` line (the editor side of `leaf.lint`). */ function lintBadgeLine(text) {
|
|
140
|
+
const parsed = parseLeafDirectiveLine(text, 'badge');
|
|
141
|
+
if (!parsed) return [];
|
|
142
|
+
return [
|
|
143
|
+
...parsed.warnings,
|
|
144
|
+
...validateBadgeAttributes(parsed.attributes),
|
|
145
|
+
...resolveShieldsBadge(parsed.attributes).warnings
|
|
146
|
+
];
|
|
147
|
+
}
|
|
148
|
+
export const badgeDirective = defineDirective({
|
|
48
149
|
name: 'badge',
|
|
49
150
|
allowedAttributes: BADGE_ALLOWED_ATTRIBUTES,
|
|
151
|
+
attributeTypes: {
|
|
152
|
+
cacheSeconds: {
|
|
153
|
+
type: 'number',
|
|
154
|
+
min: 0
|
|
155
|
+
},
|
|
156
|
+
href: {
|
|
157
|
+
type: 'url'
|
|
158
|
+
},
|
|
159
|
+
src: {
|
|
160
|
+
type: 'url'
|
|
161
|
+
}
|
|
162
|
+
},
|
|
50
163
|
attributeValues: {
|
|
51
164
|
type: BADGE_TYPES,
|
|
52
165
|
interval: BADGE_INTERVALS,
|
|
@@ -67,15 +180,30 @@ export const badgeDirective = {
|
|
|
67
180
|
snippet: '::badge[${npm version}]{\n type="${npm}"\n target="${version}"\n package="${package-name}"\n}\n${}'
|
|
68
181
|
},
|
|
69
182
|
kind: 'badge',
|
|
183
|
+
// No marker: the builder emits the final <img> (or <a><img></a>).
|
|
184
|
+
leaf: {
|
|
185
|
+
build: (line, sink)=>makeBadgeDirective(line, sink),
|
|
186
|
+
lint: (line)=>lintBadgeLine(line)
|
|
187
|
+
},
|
|
70
188
|
public: true,
|
|
189
|
+
sanitize: {
|
|
190
|
+
a: [
|
|
191
|
+
'className',
|
|
192
|
+
'dataDirective',
|
|
193
|
+
'href',
|
|
194
|
+
'rel',
|
|
195
|
+
'target'
|
|
196
|
+
],
|
|
197
|
+
img: [
|
|
198
|
+
'alt',
|
|
199
|
+
'className',
|
|
200
|
+
'dataDirective',
|
|
201
|
+
'src'
|
|
202
|
+
]
|
|
203
|
+
},
|
|
71
204
|
supportsAttributes: true,
|
|
72
205
|
tagName: 'img',
|
|
73
|
-
validateAttributes ({ attributes })
|
|
74
|
-
|
|
75
|
-
...getUnknownAttributeWarnings('badge', BADGE_ALLOWED_ATTRIBUTES, attributes),
|
|
76
|
-
...getUnsafeHrefWarnings('badge', attributes)
|
|
77
|
-
];
|
|
78
|
-
}
|
|
79
|
-
};
|
|
206
|
+
validateAttributes: ({ attributes })=>validateBadgeAttributes(attributes)
|
|
207
|
+
});
|
|
80
208
|
|
|
81
209
|
//# sourceMappingURL=badge.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/directives/definitions/badge.ts"],"sourcesContent":["import type { LayoutDirectiveDefinition } from '../types.js'\n\nimport { getUnknownAttributeWarnings } from '../attributeDiagnostics.js'\nimport { SHIELDS_BADGE_QUERY_ATTRIBUTES } from '../shields.js'\nimport { getUnsafeHrefWarnings } from '../urls.js'\n\nexport const BADGE_TYPES = ['static', 'npm', 'github', 'debian', 'apt'] as const\nexport const BADGE_TARGETS = [\n 'version',\n 'downloads',\n 'license',\n 'workflow',\n 'release',\n 'stars',\n] as const\nexport const BADGE_INTERVALS = ['dw', 'dm', 'dy', 'dt'] as const\nexport const BADGE_STYLES = ['flat', 'flat-square', 'plastic', 'for-the-badge', 'social'] as const\nexport const BADGE_ALLOWED_ATTRIBUTES = [\n 'alt',\n 'href',\n 'interval',\n 'message',\n 'newTab',\n 'package',\n 'path',\n 'repo',\n 'src',\n 'target',\n 'type',\n 'workflow',\n ...SHIELDS_BADGE_QUERY_ATTRIBUTES,\n] as const\n\nexport const badgeDirective: LayoutDirectiveDefinition = {\n name: 'badge',\n allowedAttributes: BADGE_ALLOWED_ATTRIBUTES,\n attributeValues: {\n type: BADGE_TYPES,\n interval: BADGE_INTERVALS,\n newTab: ['true', 'false'],\n style: BADGE_STYLES,\n target: BADGE_TARGETS,\n },\n defaultAttributes: {\n newTab: 'false',\n },\n description: 'img.shields.io badge with curated resolvers and strict Shields escape hatches.',\n editor: {\n detail: 'Shields badge leaf directive',\n label: '::badge',\n snippet:\n '::badge[${npm version}]{\\n type=\"${npm}\"\\n target=\"${version}\"\\n package=\"${package-name}\"\\n}\\n${}',\n },\n kind: 'badge',\n public: true,\n supportsAttributes: true,\n tagName: 'img',\n validateAttributes({ attributes }) {\n return [\n ...getUnknownAttributeWarnings('badge', BADGE_ALLOWED_ATTRIBUTES, attributes),\n ...getUnsafeHrefWarnings('badge', attributes),\n ]\n },\n}\n"],"names":["getUnknownAttributeWarnings","SHIELDS_BADGE_QUERY_ATTRIBUTES","getUnsafeHrefWarnings","BADGE_TYPES","BADGE_TARGETS","BADGE_INTERVALS","BADGE_STYLES","BADGE_ALLOWED_ATTRIBUTES","badgeDirective","name","allowedAttributes","attributeValues","type","interval","newTab","style","target","defaultAttributes","description","editor","detail","label","snippet","kind","public","supportsAttributes","tagName","validateAttributes","attributes"],"mappings":"AAEA,SAASA,2BAA2B,QAAQ,6BAA4B;AACxE,SAASC,8BAA8B,QAAQ,gBAAe;AAC9D,SAASC,qBAAqB,QAAQ,aAAY;AAElD,OAAO,MAAMC,cAAc;IAAC;IAAU;IAAO;IAAU;IAAU;CAAM,CAAS;AAChF,OAAO,MAAMC,gBAAgB;IAC3B;IACA;IACA;IACA;IACA;IACA;CACD,CAAS;AACV,OAAO,MAAMC,kBAAkB;IAAC;IAAM;IAAM;IAAM;CAAK,CAAS;AAChE,OAAO,MAAMC,eAAe;IAAC;IAAQ;IAAe;IAAW;IAAiB;CAAS,CAAS;AAClG,OAAO,MAAMC,2BAA2B;IACtC;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;OACGN;CACJ,CAAS;AAEV,OAAO,MAAMO,iBAA4C;IACvDC,MAAM;IACNC,mBAAmBH;IACnBI,iBAAiB;QACfC,MAAMT;QACNU,UAAUR;QACVS,QAAQ;YAAC;YAAQ;SAAQ;QACzBC,OAAOT;QACPU,QAAQZ;IACV;IACAa,mBAAmB;QACjBH,QAAQ;IACV;IACAI,aAAa;IACbC,QAAQ;QACNC,QAAQ;QACRC,OAAO;QACPC,SACE;IACJ;IACAC,MAAM;IACNC,QAAQ;IACRC,oBAAoB;IACpBC,SAAS;IACTC,oBAAmB,EAAEC,UAAU,EAAE;QAC/B,OAAO;eACF5B,4BAA4B,SAASO,0BAA0BqB;eAC/D1B,sBAAsB,SAAS0B;SACnC;IACH;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/directives/definitions/badge.ts"],"sourcesContent":["import type { LeafDirective } from 'mdast-util-directive'\n\nimport type { DirectiveAttributes } from '../attributes.js'\nimport type { DirectiveMessageSink } from '../types.js'\n\nimport { getUnknownAttributeWarnings } from '../attributeDiagnostics.js'\nimport { parseLeafDirectiveLine } from '../leafSyntax.js'\nimport { resolveShieldsBadge, SHIELDS_BADGE_QUERY_ATTRIBUTES } from '../shields.js'\nimport { defineDirective } from '../types.js'\nimport { getSafeHref, getUnsafeHrefWarnings } from '../urls.js'\n\nexport const BADGE_TYPES = ['static', 'npm', 'github', 'debian', 'apt'] as const\nexport const BADGE_TARGETS = [\n 'version',\n 'downloads',\n 'license',\n 'workflow',\n 'release',\n 'stars',\n] as const\nexport const BADGE_INTERVALS = ['dw', 'dm', 'dy', 'dt'] as const\nexport const BADGE_STYLES = ['flat', 'flat-square', 'plastic', 'for-the-badge', 'social'] as const\nexport const BADGE_ALLOWED_ATTRIBUTES = [\n 'alt',\n 'href',\n 'interval',\n 'message',\n 'newTab',\n 'package',\n 'path',\n 'repo',\n 'src',\n 'target',\n 'type',\n 'workflow',\n ...SHIELDS_BADGE_QUERY_ATTRIBUTES,\n] as const\n\nfunction validateBadgeAttributes(attributes: DirectiveAttributes): string[] {\n return [\n ...getUnknownAttributeWarnings('badge', BADGE_ALLOWED_ATTRIBUTES, attributes),\n ...getUnsafeHrefWarnings('badge', attributes),\n ]\n}\n\nfunction getAttribute(attributes: Record<string, boolean | string>, name: string): string | undefined {\n const value = attributes[name]\n\n return typeof value === 'string' && value.trim() ? value.trim() : undefined\n}\n\nfunction getBooleanAttribute(attributes: Record<string, boolean | string>, name: string): boolean {\n const value = attributes[name]\n\n if (value === true) return true\n if (typeof value !== 'string') return false\n\n return value === 'true'\n}\n\nfunction stringifyAttributes(attributes: Record<string, boolean | string>): Record<string, string> {\n return Object.fromEntries(Object.entries(attributes).map(([key, value]) => [key, String(value)]))\n}\n\nfunction makeBadgeImageProperties(src: string, alt: string, includeDirective: boolean) {\n return {\n alt,\n // Badge images opt out of Typography's image margins and rounding.\n className: ['not-prose', 'pmd-badge'],\n ...(includeDirective ? { dataDirective: 'badge' } : {}),\n src,\n }\n}\n\n/** Builds the `::badge` leaf (the renderer side of `leaf.build`). */\nexport function makeBadgeDirective(line: string, file: DirectiveMessageSink): LeafDirective | undefined {\n const parsed = parseLeafDirectiveLine(line, 'badge')\n if (!parsed) return undefined\n\n const attributes = parsed.attributes\n const label = parsed.label.trim()\n const href = getSafeHref(getAttribute(attributes, 'href'))\n const newTab = getBooleanAttribute(attributes, 'newTab')\n const alt = getAttribute(attributes, 'alt') ?? label\n\n for (const warning of parsed.warnings) file.message(warning)\n for (const warning of validateBadgeAttributes(attributes)) file.message(warning)\n\n const resolved = resolveShieldsBadge(attributes)\n\n for (const warning of resolved.warnings) file.message(warning)\n if (!resolved.src) return undefined\n\n const imgProperties = makeBadgeImageProperties(resolved.src, alt, !href)\n\n return {\n name: 'badge',\n type: 'leafDirective',\n attributes: stringifyAttributes(attributes),\n children: label ? [{ type: 'text', value: label }] : [],\n data: href\n ? {\n hChildren: [\n {\n type: 'element' as const,\n children: [],\n properties: imgProperties,\n tagName: 'img',\n },\n ],\n hName: 'a',\n hProperties: {\n className: ['pmd-badge-link'],\n dataDirective: 'badge',\n href,\n ...(newTab\n ? {\n rel: 'noopener noreferrer',\n target: '_blank',\n }\n : {}),\n },\n }\n : {\n // <img> is void: the [label] is the alt text and must not also be\n // emitted as visible text after the image.\n hChildren: [],\n hName: 'img',\n hProperties: imgProperties,\n },\n }\n}\n\n/** Editor diagnostics for a `::badge` line (the editor side of `leaf.lint`). */\nfunction lintBadgeLine(text: string): string[] {\n const parsed = parseLeafDirectiveLine(text, 'badge')\n if (!parsed) return []\n\n return [\n ...parsed.warnings,\n ...validateBadgeAttributes(parsed.attributes),\n ...resolveShieldsBadge(parsed.attributes).warnings,\n ]\n}\n\nexport const badgeDirective = defineDirective({\n name: 'badge',\n allowedAttributes: BADGE_ALLOWED_ATTRIBUTES,\n attributeTypes: {\n cacheSeconds: { type: 'number', min: 0 },\n href: { type: 'url' },\n src: { type: 'url' },\n },\n attributeValues: {\n type: BADGE_TYPES,\n interval: BADGE_INTERVALS,\n newTab: ['true', 'false'],\n style: BADGE_STYLES,\n target: BADGE_TARGETS,\n },\n defaultAttributes: {\n newTab: 'false',\n },\n description: 'img.shields.io badge with curated resolvers and strict Shields escape hatches.',\n editor: {\n detail: 'Shields badge leaf directive',\n label: '::badge',\n snippet:\n '::badge[${npm version}]{\\n type=\"${npm}\"\\n target=\"${version}\"\\n package=\"${package-name}\"\\n}\\n${}',\n },\n kind: 'badge',\n // No marker: the builder emits the final <img> (or <a><img></a>).\n leaf: {\n build: (line, sink) => makeBadgeDirective(line, sink),\n lint: (line) => lintBadgeLine(line),\n },\n public: true,\n sanitize: {\n a: ['className', 'dataDirective', 'href', 'rel', 'target'],\n img: ['alt', 'className', 'dataDirective', 'src'],\n },\n supportsAttributes: true,\n tagName: 'img',\n validateAttributes: ({ attributes }) => validateBadgeAttributes(attributes),\n})\n"],"names":["getUnknownAttributeWarnings","parseLeafDirectiveLine","resolveShieldsBadge","SHIELDS_BADGE_QUERY_ATTRIBUTES","defineDirective","getSafeHref","getUnsafeHrefWarnings","BADGE_TYPES","BADGE_TARGETS","BADGE_INTERVALS","BADGE_STYLES","BADGE_ALLOWED_ATTRIBUTES","validateBadgeAttributes","attributes","getAttribute","name","value","trim","undefined","getBooleanAttribute","stringifyAttributes","Object","fromEntries","entries","map","key","String","makeBadgeImageProperties","src","alt","includeDirective","className","dataDirective","makeBadgeDirective","line","file","parsed","label","href","newTab","warning","warnings","message","resolved","imgProperties","type","children","data","hChildren","properties","tagName","hName","hProperties","rel","target","lintBadgeLine","text","badgeDirective","allowedAttributes","attributeTypes","cacheSeconds","min","attributeValues","interval","style","defaultAttributes","description","editor","detail","snippet","kind","leaf","build","sink","lint","public","sanitize","a","img","supportsAttributes","validateAttributes"],"mappings":"AAKA,SAASA,2BAA2B,QAAQ,6BAA4B;AACxE,SAASC,sBAAsB,QAAQ,mBAAkB;AACzD,SAASC,mBAAmB,EAAEC,8BAA8B,QAAQ,gBAAe;AACnF,SAASC,eAAe,QAAQ,cAAa;AAC7C,SAASC,WAAW,EAAEC,qBAAqB,QAAQ,aAAY;AAE/D,OAAO,MAAMC,cAAc;IAAC;IAAU;IAAO;IAAU;IAAU;CAAM,CAAS;AAChF,OAAO,MAAMC,gBAAgB;IAC3B;IACA;IACA;IACA;IACA;IACA;CACD,CAAS;AACV,OAAO,MAAMC,kBAAkB;IAAC;IAAM;IAAM;IAAM;CAAK,CAAS;AAChE,OAAO,MAAMC,eAAe;IAAC;IAAQ;IAAe;IAAW;IAAiB;CAAS,CAAS;AAClG,OAAO,MAAMC,2BAA2B;IACtC;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;OACGR;CACJ,CAAS;AAEV,SAASS,wBAAwBC,UAA+B;IAC9D,OAAO;WACFb,4BAA4B,SAASW,0BAA0BE;WAC/DP,sBAAsB,SAASO;KACnC;AACH;AAEA,SAASC,aAAaD,UAA4C,EAAEE,IAAY;IAC9E,MAAMC,QAAQH,UAAU,CAACE,KAAK;IAE9B,OAAO,OAAOC,UAAU,YAAYA,MAAMC,IAAI,KAAKD,MAAMC,IAAI,KAAKC;AACpE;AAEA,SAASC,oBAAoBN,UAA4C,EAAEE,IAAY;IACrF,MAAMC,QAAQH,UAAU,CAACE,KAAK;IAE9B,IAAIC,UAAU,MAAM,OAAO;IAC3B,IAAI,OAAOA,UAAU,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B;YAAQ;YAAO;SAAS;QAC1DC,KAAK;YAAC;YAAO;YAAa;YAAiB;SAAM;IACnD;IACAC,oBAAoB;IACpB7B,SAAS;IACT8B,oBAAoB,CAAC,EAAEnE,UAAU,EAAE,GAAKD,wBAAwBC;AAClE,GAAE"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type { LayoutDirectiveDefinition } from '../types.js';
|
|
2
1
|
export declare const BADGES_ALIGNS: readonly ["left", "center", "right"];
|
|
3
2
|
export declare const BADGES_GAPS: readonly ["sm", "md", "lg"];
|
|
4
3
|
export declare const BADGES_WRAPS: readonly ["true", "false"];
|
|
5
4
|
export declare const DEFAULT_BADGES_ALIGN = "left";
|
|
6
5
|
export declare const DEFAULT_BADGES_GAP = "md";
|
|
7
6
|
export declare const DEFAULT_BADGES_WRAP = "true";
|
|
8
|
-
export declare const badgesDirective: LayoutDirectiveDefinition
|
|
7
|
+
export declare const badgesDirective: import("../types.js").LayoutDirectiveDefinition<"badges", "badges">;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { defineDirective } from '../types.js';
|
|
1
2
|
export const BADGES_ALIGNS = [
|
|
2
3
|
'left',
|
|
3
4
|
'center',
|
|
@@ -24,7 +25,7 @@ function isBadgesGap(value) {
|
|
|
24
25
|
function isBadgesWrap(value) {
|
|
25
26
|
return typeof value === 'string' && BADGES_WRAPS.includes(value);
|
|
26
27
|
}
|
|
27
|
-
export const badgesDirective = {
|
|
28
|
+
export const badgesDirective = defineDirective({
|
|
28
29
|
name: 'badges',
|
|
29
30
|
allowedAttributes: [
|
|
30
31
|
'align',
|
|
@@ -45,6 +46,7 @@ export const badgesDirective = {
|
|
|
45
46
|
gap: BADGES_GAPS,
|
|
46
47
|
wrap: BADGES_WRAPS
|
|
47
48
|
},
|
|
49
|
+
container: {},
|
|
48
50
|
defaultAttributes: {
|
|
49
51
|
align: DEFAULT_BADGES_ALIGN,
|
|
50
52
|
gap: DEFAULT_BADGES_GAP,
|
|
@@ -65,8 +67,15 @@ export const badgesDirective = {
|
|
|
65
67
|
};
|
|
66
68
|
},
|
|
67
69
|
kind: 'badges',
|
|
68
|
-
openMarker: ':::badges',
|
|
69
70
|
public: true,
|
|
71
|
+
sanitize: {
|
|
72
|
+
div: [
|
|
73
|
+
'dataAlign',
|
|
74
|
+
'dataDirective',
|
|
75
|
+
'dataGap',
|
|
76
|
+
'dataWrap'
|
|
77
|
+
]
|
|
78
|
+
},
|
|
70
79
|
supportsAttributes: true,
|
|
71
80
|
tagName: 'div',
|
|
72
81
|
validateAttributes ({ attributes }) {
|
|
@@ -76,6 +85,6 @@ export const badgesDirective = {
|
|
|
76
85
|
if (typeof attributes.wrap === 'string' && !isBadgesWrap(attributes.wrap)) warnings.push(`Invalid badges wrap "${attributes.wrap}". Falling back to "${DEFAULT_BADGES_WRAP}".`);
|
|
77
86
|
return warnings;
|
|
78
87
|
}
|
|
79
|
-
};
|
|
88
|
+
});
|
|
80
89
|
|
|
81
90
|
//# sourceMappingURL=badges.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/directives/definitions/badges.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../../src/directives/definitions/badges.ts"],"sourcesContent":["import { defineDirective } from '../types.js'\n\nexport const BADGES_ALIGNS = ['left', 'center', 'right'] as const\nexport const BADGES_GAPS = ['sm', 'md', 'lg'] as const\nexport const BADGES_WRAPS = ['true', 'false'] as const\n\nexport const DEFAULT_BADGES_ALIGN = 'left'\nexport const DEFAULT_BADGES_GAP = 'md'\nexport const DEFAULT_BADGES_WRAP = 'true'\n\ntype BadgesAlign = (typeof BADGES_ALIGNS)[number]\ntype BadgesGap = (typeof BADGES_GAPS)[number]\ntype BadgesWrap = (typeof BADGES_WRAPS)[number]\n\nfunction isBadgesAlign(value: unknown): value is BadgesAlign {\n return typeof value === 'string' && BADGES_ALIGNS.includes(value as BadgesAlign)\n}\n\nfunction isBadgesGap(value: unknown): value is BadgesGap {\n return typeof value === 'string' && BADGES_GAPS.includes(value as BadgesGap)\n}\n\nfunction isBadgesWrap(value: unknown): value is BadgesWrap {\n return typeof value === 'string' && BADGES_WRAPS.includes(value as BadgesWrap)\n}\n\nexport const badgesDirective = defineDirective({\n name: 'badges',\n allowedAttributes: ['align', 'gap', 'wrap'],\n applyHast(node, _config, { mergeClassNames }) {\n const align =\n typeof node.properties.dataAlign === 'string' && isBadgesAlign(node.properties.dataAlign)\n ? node.properties.dataAlign\n : DEFAULT_BADGES_ALIGN\n const gap =\n typeof node.properties.dataGap === 'string' && isBadgesGap(node.properties.dataGap)\n ? node.properties.dataGap\n : DEFAULT_BADGES_GAP\n const wrap =\n typeof node.properties.dataWrap === 'string' && isBadgesWrap(node.properties.dataWrap)\n ? node.properties.dataWrap\n : DEFAULT_BADGES_WRAP\n\n node.properties.dataAlign = align\n node.properties.dataGap = gap\n node.properties.dataWrap = wrap\n node.properties.className = mergeClassNames(\n 'not-prose',\n 'pmd-badges',\n `pmd-badges--align-${align}`,\n `pmd-badges--gap-${gap}`,\n `pmd-badges--wrap-${wrap}`,\n )\n },\n attributeValues: {\n align: BADGES_ALIGNS,\n gap: BADGES_GAPS,\n wrap: BADGES_WRAPS,\n },\n container: {},\n defaultAttributes: {\n align: DEFAULT_BADGES_ALIGN,\n gap: DEFAULT_BADGES_GAP,\n wrap: DEFAULT_BADGES_WRAP,\n },\n description: 'Badge group wrapper for one or more Shields badge directives.',\n editor: {\n detail: 'Badge group directive',\n label: 'Badges',\n snippet:\n ':::badges{\\n align=\"${left}\"\\n gap=\"${md}\"\\n wrap=${true}\\n}\\n::badge[${npm version}]{\\n type=\"${npm}\"\\n target=\"${version}\"\\n package=\"${package-name}\"\\n}\\n:::\\n${}',\n },\n getMdastRenderProperties(node) {\n return {\n dataAlign: typeof node.attributes?.align === 'string' ? node.attributes.align : DEFAULT_BADGES_ALIGN,\n dataDirective: 'badges',\n dataGap: typeof node.attributes?.gap === 'string' ? node.attributes.gap : DEFAULT_BADGES_GAP,\n dataWrap: typeof node.attributes?.wrap === 'string' ? node.attributes.wrap : DEFAULT_BADGES_WRAP,\n }\n },\n kind: 'badges',\n public: true,\n sanitize: {\n div: ['dataAlign', 'dataDirective', 'dataGap', 'dataWrap'],\n },\n supportsAttributes: true,\n tagName: 'div',\n validateAttributes({ attributes }) {\n const warnings: string[] = []\n\n if (typeof attributes.align === 'string' && !isBadgesAlign(attributes.align))\n warnings.push(\n `Invalid badges align \"${attributes.align}\". Falling back to \"${DEFAULT_BADGES_ALIGN}\".`,\n )\n\n if (typeof attributes.gap === 'string' && !isBadgesGap(attributes.gap))\n warnings.push(\n `Invalid badges gap \"${attributes.gap}\". Falling back to \"${DEFAULT_BADGES_GAP}\".`,\n )\n\n if (typeof attributes.wrap === 'string' && !isBadgesWrap(attributes.wrap))\n warnings.push(\n `Invalid badges wrap \"${attributes.wrap}\". Falling back to \"${DEFAULT_BADGES_WRAP}\".`,\n )\n\n return warnings\n },\n})\n"],"names":["defineDirective","BADGES_ALIGNS","BADGES_GAPS","BADGES_WRAPS","DEFAULT_BADGES_ALIGN","DEFAULT_BADGES_GAP","DEFAULT_BADGES_WRAP","isBadgesAlign","value","includes","isBadgesGap","isBadgesWrap","badgesDirective","name","allowedAttributes","applyHast","node","_config","mergeClassNames","align","properties","dataAlign","gap","dataGap","wrap","dataWrap","className","attributeValues","container","defaultAttributes","description","editor","detail","label","snippet","getMdastRenderProperties","attributes","dataDirective","kind","public","sanitize","div","supportsAttributes","tagName","validateAttributes","warnings","push"],"mappings":"AAAA,SAASA,eAAe,QAAQ,cAAa;AAE7C,OAAO,MAAMC,gBAAgB;IAAC;IAAQ;IAAU;CAAQ,CAAS;AACjE,OAAO,MAAMC,cAAc;IAAC;IAAM;IAAM;CAAK,CAAS;AACtD,OAAO,MAAMC,eAAe;IAAC;IAAQ;CAAQ,CAAS;AAEtD,OAAO,MAAMC,uBAAuB,OAAM;AAC1C,OAAO,MAAMC,qBAAqB,KAAI;AACtC,OAAO,MAAMC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