@elastic/isomer-sdk 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. package/NOTICE.txt +0 -286
  2. package/THIRD_PARTY_LICENSES.md +1 -885
  3. package/dist/author/authored_fields.d.ts +37 -12
  4. package/dist/author/authored_fields.d.ts.map +1 -1
  5. package/dist/author/authored_fields.js +45 -69
  6. package/dist/author/authored_fields.js.map +1 -1
  7. package/dist/author/authoring_input.d.ts.map +1 -1
  8. package/dist/author/authoring_input.js +12 -6
  9. package/dist/author/authoring_input.js.map +1 -1
  10. package/dist/author/authoring_model.d.ts +8 -2
  11. package/dist/author/authoring_model.d.ts.map +1 -1
  12. package/dist/author/authoring_model.js +67 -23
  13. package/dist/author/authoring_model.js.map +1 -1
  14. package/dist/author/declarations.d.ts.map +1 -1
  15. package/dist/author/declarations.js +45 -34
  16. package/dist/author/declarations.js.map +1 -1
  17. package/dist/author/index.d.ts +2 -1
  18. package/dist/author/index.d.ts.map +1 -1
  19. package/dist/author/index.js +2 -1
  20. package/dist/author/index.js.map +1 -1
  21. package/dist/author/jsx_shim.d.ts +49 -30
  22. package/dist/author/jsx_shim.d.ts.map +1 -1
  23. package/dist/author/jsx_shim.js +131 -40
  24. package/dist/author/jsx_shim.js.map +1 -1
  25. package/dist/author/print_jsx.d.ts +19 -0
  26. package/dist/author/print_jsx.d.ts.map +1 -0
  27. package/dist/author/print_jsx.js +372 -0
  28. package/dist/author/print_jsx.js.map +1 -0
  29. package/dist/author/prompt.d.ts +2 -2
  30. package/dist/author/prompt.d.ts.map +1 -1
  31. package/dist/author/prompt.js +7 -2
  32. package/dist/author/prompt.js.map +1 -1
  33. package/dist/author/schema_to_typescript.d.ts.map +1 -1
  34. package/dist/author/schema_to_typescript.js +6 -3
  35. package/dist/author/schema_to_typescript.js.map +1 -1
  36. package/dist/cjs/author/authored_fields.js +47 -70
  37. package/dist/cjs/author/authored_fields.js.map +1 -1
  38. package/dist/cjs/author/authoring_input.js +12 -6
  39. package/dist/cjs/author/authoring_input.js.map +1 -1
  40. package/dist/cjs/author/authoring_model.js +69 -24
  41. package/dist/cjs/author/authoring_model.js.map +1 -1
  42. package/dist/cjs/author/declarations.js +44 -33
  43. package/dist/cjs/author/declarations.js.map +1 -1
  44. package/dist/cjs/author/index.js +5 -1
  45. package/dist/cjs/author/index.js.map +1 -1
  46. package/dist/cjs/author/jsx_shim.js +130 -39
  47. package/dist/cjs/author/jsx_shim.js.map +1 -1
  48. package/dist/cjs/author/print_jsx.js +378 -0
  49. package/dist/cjs/author/print_jsx.js.map +1 -0
  50. package/dist/cjs/author/prompt.js +7 -2
  51. package/dist/cjs/author/prompt.js.map +1 -1
  52. package/dist/cjs/author/schema_to_typescript.js +6 -3
  53. package/dist/cjs/author/schema_to_typescript.js.map +1 -1
  54. package/dist/cjs/composition/error.js +1 -0
  55. package/dist/cjs/composition/error.js.map +1 -1
  56. package/dist/cjs/composition/structured_value.js.map +1 -1
  57. package/dist/cjs/define/primitive_module.js +10 -4
  58. package/dist/cjs/define/primitive_module.js.map +1 -1
  59. package/dist/cjs/entries/index.js +3 -2
  60. package/dist/cjs/entries/index.js.map +1 -1
  61. package/dist/cjs/entries/markdown.js +2 -1
  62. package/dist/cjs/entries/markdown.js.map +1 -1
  63. package/dist/cjs/pack/index.js +2 -1
  64. package/dist/cjs/pack/index.js.map +1 -1
  65. package/dist/cjs/pack/primitive_pack.js +14 -4
  66. package/dist/cjs/pack/primitive_pack.js.map +1 -1
  67. package/dist/cjs/render/format_number.js +2 -1
  68. package/dist/cjs/render/format_number.js.map +1 -1
  69. package/dist/cjs/render/html/envelope.js +12 -6
  70. package/dist/cjs/render/html/envelope.js.map +1 -1
  71. package/dist/cjs/render/markdown/builder.js +6 -2
  72. package/dist/cjs/render/markdown/builder.js.map +1 -1
  73. package/dist/cjs/render/markdown/format.js +46 -24
  74. package/dist/cjs/render/markdown/format.js.map +1 -1
  75. package/dist/cjs/render/markdown/host_tags.js +67 -0
  76. package/dist/cjs/render/markdown/host_tags.js.map +1 -0
  77. package/dist/cjs/render/markdown/index.js +3 -1
  78. package/dist/cjs/render/markdown/index.js.map +1 -1
  79. package/dist/cjs/render/markdown/split.js +325 -0
  80. package/dist/cjs/render/markdown/split.js.map +1 -0
  81. package/dist/cjs/render/react/content.js +3 -1
  82. package/dist/cjs/render/react/content.js.map +1 -1
  83. package/dist/cjs/render/slack/markdown_content.js +7 -1
  84. package/dist/cjs/render/slack/markdown_content.js.map +1 -1
  85. package/dist/cjs/validate/json_schema.js +10 -3
  86. package/dist/cjs/validate/json_schema.js.map +1 -1
  87. package/dist/cjs/validate/url.js +2 -1
  88. package/dist/cjs/validate/url.js.map +1 -1
  89. package/dist/composition/error.d.ts +1 -0
  90. package/dist/composition/error.d.ts.map +1 -1
  91. package/dist/composition/error.js +1 -0
  92. package/dist/composition/error.js.map +1 -1
  93. package/dist/composition/structured_value.d.ts +3 -3
  94. package/dist/composition/structured_value.d.ts.map +1 -1
  95. package/dist/composition/structured_value.js.map +1 -1
  96. package/dist/define/primitive_module.d.ts +7 -0
  97. package/dist/define/primitive_module.d.ts.map +1 -1
  98. package/dist/define/primitive_module.js +10 -4
  99. package/dist/define/primitive_module.js.map +1 -1
  100. package/dist/entries/index.d.ts +1 -1
  101. package/dist/entries/index.d.ts.map +1 -1
  102. package/dist/entries/index.js +1 -1
  103. package/dist/entries/index.js.map +1 -1
  104. package/dist/entries/markdown.d.ts +1 -1
  105. package/dist/entries/markdown.d.ts.map +1 -1
  106. package/dist/entries/markdown.js +1 -1
  107. package/dist/entries/markdown.js.map +1 -1
  108. package/dist/pack/index.d.ts +1 -1
  109. package/dist/pack/index.d.ts.map +1 -1
  110. package/dist/pack/index.js +1 -1
  111. package/dist/pack/index.js.map +1 -1
  112. package/dist/pack/primitive_pack.d.ts +3 -1
  113. package/dist/pack/primitive_pack.d.ts.map +1 -1
  114. package/dist/pack/primitive_pack.js +13 -3
  115. package/dist/pack/primitive_pack.js.map +1 -1
  116. package/dist/render/format_number.d.ts.map +1 -1
  117. package/dist/render/format_number.js +2 -1
  118. package/dist/render/format_number.js.map +1 -1
  119. package/dist/render/html/envelope.js +12 -6
  120. package/dist/render/html/envelope.js.map +1 -1
  121. package/dist/render/markdown/builder.d.ts +3 -0
  122. package/dist/render/markdown/builder.d.ts.map +1 -1
  123. package/dist/render/markdown/builder.js +3 -1
  124. package/dist/render/markdown/builder.js.map +1 -1
  125. package/dist/render/markdown/format.d.ts +2 -0
  126. package/dist/render/markdown/format.d.ts.map +1 -1
  127. package/dist/render/markdown/format.js +42 -22
  128. package/dist/render/markdown/format.js.map +1 -1
  129. package/dist/render/markdown/host_tags.d.ts +14 -0
  130. package/dist/render/markdown/host_tags.d.ts.map +1 -0
  131. package/dist/render/markdown/host_tags.js +63 -0
  132. package/dist/render/markdown/host_tags.js.map +1 -0
  133. package/dist/render/markdown/index.d.ts +1 -0
  134. package/dist/render/markdown/index.d.ts.map +1 -1
  135. package/dist/render/markdown/index.js +1 -0
  136. package/dist/render/markdown/index.js.map +1 -1
  137. package/dist/render/markdown/split.d.ts +32 -0
  138. package/dist/render/markdown/split.d.ts.map +1 -0
  139. package/dist/render/markdown/split.js +321 -0
  140. package/dist/render/markdown/split.js.map +1 -0
  141. package/dist/render/react/content.d.ts +1 -1
  142. package/dist/render/react/content.d.ts.map +1 -1
  143. package/dist/render/react/content.js +3 -1
  144. package/dist/render/react/content.js.map +1 -1
  145. package/dist/render/slack/markdown_content.d.ts.map +1 -1
  146. package/dist/render/slack/markdown_content.js +7 -1
  147. package/dist/render/slack/markdown_content.js.map +1 -1
  148. package/dist/validate/json_schema.d.ts.map +1 -1
  149. package/dist/validate/json_schema.js +10 -3
  150. package/dist/validate/json_schema.js.map +1 -1
  151. package/dist/validate/url.d.ts.map +1 -1
  152. package/dist/validate/url.js +2 -1
  153. package/dist/validate/url.js.map +1 -1
  154. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":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O,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AAE7D,4EAA4E;AAC5E,MAAM,cAAc,GAAG,oDAAoD,CAAC;AAC5E,MAAM,eAAe,GAAG,GAAG,CAAC;AAC5B,MAAM,mBAAmB,GACvB,sDAAsD,CAAC;AACzD,MAAM,qBAAqB,GAAG,IAAI,CAAC;AAEnC,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAEhC,MAAM,kBAAkB,GAAG,CAAC,QAAgB,EAAW,EAAE;IACvD,IAAI,QAAQ,CAAC,MAAM,GAAG,gBAAgB;QAAE,OAAO,IAAI,CAAC;IACpD,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,QAAQ,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC;QACzD,IAAI,MAAM,CAAC,MAAM,GAAG,eAAe;YAAE,OAAO,IAAI,CAAC;IACnD,CAAC;IACD,IAAI,UAAU,GAAG,CAAC,CAAC;IACnB,KAAK,MAAM,CAAC,IAAI,QAAQ,CAAC,QAAQ,CAAC,mBAAmB,CAAC,EAAE,CAAC;QACvD,IAAI,EAAE,UAAU,GAAG,qBAAqB;YAAE,OAAO,IAAI,CAAC;IACxD,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\n// Authored Markdown source made safe to print, for `md.authored`, and the GFM\n// parse it shares with the Slack fallback.\n\nimport type { Definition, Nodes, Parents, Root } from 'mdast';\nimport { fromMarkdown } from 'mdast-util-from-markdown';\nimport { gfmFromMarkdown } from 'mdast-util-gfm';\nimport { gfm } from 'micromark-extension-gfm';\n\nimport {\n BLOCKED_HREF,\n sanitizeParsedAssetUrl,\n sanitizeParsedNavigationHref,\n} from '../../validate/url';\n\n// Escapes label characters that could close a `[...]` early and smuggle in a\n// hostile destination of their own.\nconst escapeLinkLabel = (label: string): string =>\n label.replace(/[[\\]\\\\]/g, '\\\\$&');\n\n// Percent-encodes destination characters that would terminate the `(...)`\n// early or read as a link title. `encodeURIComponent` leaves `(` and `)`\n// unescaped by spec, so those two are mapped by hand.\nconst escapeLinkDestination = (href: string): string =>\n href.replace(/[()\\s\\\\]/g, (char) => {\n if (char === '(') return '%28';\n if (char === ')') return '%29';\n return encodeURIComponent(char);\n });\n\nconst escapeParsedDestination = (href: string): string =>\n escapeLinkDestination(href.replace(/&/g, '&amp;'));\n\nlet parseOptions: Parameters<typeof fromMarkdown>[1] | undefined;\n\nconst parse = (source: string): Root =>\n fromMarkdown(\n source,\n (parseOptions ??= {\n extensions: [gfm()],\n mdastExtensions: [gfmFromMarkdown()],\n })\n );\n\n/** `markdown` as flat GFM mdast blocks, typed `unknown` so no declaration names mdast; `null` past the parse budget or the parser's recursion depth. */\nexport const parseGfmBlocks = (markdown: string): readonly unknown[] | null => {\n if (exceedsParseBudget(markdown)) return null;\n try {\n return parse(markdown).children;\n } catch (error) {\n if (!(error instanceof RangeError)) throw error;\n return null;\n }\n};\n\n// Each pass can expose a new sink (an escaped HTML block reveals the Markdown\n// inside it; a blocked link's label may close an outer `](`), so passes repeat\n// until the source is stable.\nconst MAX_PASSES = 16;\n\nconst escapeTitle = (title: string): string =>\n `\"${title.replace(/[\"\\\\]/g, '\\\\$&')}\"`;\n\nconst offsets = (node: Nodes): [number, number] | undefined => {\n const start = node.position?.start.offset;\n const end = node.position?.end.offset;\n return start === undefined || end === undefined ? undefined : [start, end];\n};\n\nconst sanitizePass = (source: string): string => {\n const root = parse(source);\n const definitions = new Map<string, Definition>();\n const pending: Nodes[] = [...root.children].reverse();\n while (pending.length) {\n const node = pending.pop()!;\n if (node.type === 'definition' && !definitions.has(node.identifier)) {\n definitions.set(node.identifier, node);\n }\n if ('children' in node) pending.push(...[...node.children].reverse());\n }\n\n const slice = (node: Nodes): string => {\n const range = offsets(node);\n return range ? source.slice(...range) : '';\n };\n\n const emitChildren = (\n start: number,\n end: number,\n children: readonly Nodes[]\n ): string => {\n let out = '';\n let cursor = start;\n for (const child of children) {\n const range = offsets(child);\n if (!range) continue;\n out += source.slice(cursor, range[0]) + emit(child);\n cursor = range[1];\n }\n return out + source.slice(cursor, end);\n };\n\n const emitLabel = (node: Parents): string => {\n const first = node.children[0];\n const last = node.children[node.children.length - 1];\n const from = first && offsets(first);\n const to = last && offsets(last);\n return from && to ? emitChildren(from[0], to[1], node.children) : '';\n };\n\n const rewrite = (node: Nodes): string | undefined => {\n switch (node.type) {\n case 'html':\n return slice(node).replace(/</g, '&lt;');\n case 'definition': {\n const safe =\n sanitizeParsedNavigationHref(node.url) ??\n sanitizeParsedAssetUrl(node.url);\n if (safe === node.url) return undefined;\n const title = node.title ? ` ${escapeTitle(node.title)}` : '';\n return `[${node.label ?? node.identifier}]: ${\n safe === null ? BLOCKED_HREF : escapeParsedDestination(safe)\n }${title}`;\n }\n case 'imageReference': {\n const definition = definitions.get(node.identifier);\n return definition && sanitizeParsedAssetUrl(definition.url) === null\n ? escapeLinkLabel(node.alt ?? '')\n : undefined;\n }\n case 'linkReference': {\n const definition = definitions.get(node.identifier);\n return definition &&\n sanitizeParsedNavigationHref(definition.url) === null &&\n sanitizeParsedAssetUrl(definition.url) !== null\n ? emitLabel(node)\n : undefined;\n }\n case 'image': {\n const safe = sanitizeParsedAssetUrl(node.url);\n if (safe === null) return escapeLinkLabel(node.alt ?? '');\n if (safe === node.url) return undefined;\n const title = node.title ? ` ${escapeTitle(node.title)}` : '';\n return `![${escapeLinkLabel(node.alt ?? '')}](${escapeParsedDestination(\n safe\n )}${title})`;\n }\n case 'link': {\n const raw = slice(node);\n const safe = sanitizeParsedNavigationHref(node.url);\n if (raw.startsWith('<')) {\n return safe === null ? raw.slice(1, -1) : undefined;\n }\n // A GFM literal (`www.x.com`) is http(s) or mailto by construction.\n if (!raw.startsWith('[')) return undefined;\n if (safe === null) return emitLabel(node);\n if (safe === node.url) return undefined;\n const title = node.title ? ` ${escapeTitle(node.title)}` : '';\n return `[${emitLabel(node)}](${escapeParsedDestination(safe)}${title})`;\n }\n default:\n return undefined;\n }\n };\n\n const emit = (node: Nodes): string => {\n const replaced = rewrite(node);\n if (replaced !== undefined) return replaced;\n const range = offsets(node);\n if (!range) return '';\n return 'children' in node\n ? emitChildren(range[0], range[1], node.children)\n : source.slice(...range);\n };\n\n return emitChildren(0, source.length, root.children);\n};\n\n/** {@link sanitizeMarkdownSource}'s result, and whether it degraded to inert text. */\nexport const sanitizeAuthoredSource = (\n markdown: string\n): { markdown: string; inert: boolean } => {\n if (exceedsParseBudget(markdown)) {\n return { markdown: inert(markdown), inert: true };\n }\n let current = markdown;\n try {\n for (let pass = 0; pass < MAX_PASSES; pass++) {\n const next = sanitizePass(current);\n if (next === current) return { markdown: current, inert: false };\n current = next;\n }\n } catch (error) {\n // The parser recurses per nesting level, so inline nesting deep enough\n // to exhaust the stack lands here.\n if (!(error instanceof RangeError)) throw error;\n }\n return { markdown: inert(current), inert: true };\n};\n\n/** Sanitizes GFM destinations and HTML; excessive syntax or length degrades to inert text. */\nexport const sanitizeMarkdownSource = (markdown: string): string =>\n sanitizeAuthoredSource(markdown).markdown;\n\n// No link, image, definition, or tag can survive without `[` or `<`.\nconst inert = (markdown: string): string =>\n markdown.replace(/[[\\]\\\\]/g, '\\\\$&').replace(/</g, '&lt;');\n\n// GFM parsing is superlinear for some delimiter runs, even without nesting.\nconst LINE_PREFIX_RE = /^(?:[ \\t>]|[-*+](?=[ \\t])|\\d{1,9}[.)](?=[ \\t]))+/gm;\nconst MAX_LINE_PREFIX = 256;\nconst INLINE_DELIMITER_RE =\n /[[\\]*`~<>|\\\\]|(?<![\\p{L}\\p{N}])_|_(?![\\p{L}\\p{N}])/gu;\nconst MAX_INLINE_DELIMITERS = 2048;\n\nconst MAX_PARSE_LENGTH = 16_384;\n\nconst exceedsParseBudget = (markdown: string): boolean => {\n if (markdown.length > MAX_PARSE_LENGTH) return true;\n for (const [prefix] of markdown.matchAll(LINE_PREFIX_RE)) {\n if (prefix.length > MAX_LINE_PREFIX) return true;\n }\n let delimiters = 0;\n for (const _ of markdown.matchAll(INLINE_DELIMITER_RE)) {\n if (++delimiters > MAX_INLINE_DELIMITERS) return true;\n }\n return false;\n};\n"]}
1
+ {"version":3,"file":"format.js","sourceRoot":"","sources":["../../../../src/render/markdown/format.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAMH,uEAAwD;AACxD,mDAAiD;AACjD,qEAA8C;AAE9C,4CAI4B;AAE5B,6EAA6E;AAC7E,oCAAoC;AACpC,MAAM,eAAe,GAAG,CAAC,KAAa,EAAU,EAAE,CAChD,KAAK,CAAC,OAAO,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;AAEpC,0EAA0E;AAC1E,yEAAyE;AACzE,sDAAsD;AACtD,MAAM,qBAAqB,GAAG,CAAC,IAAY,EAAU,EAAE,CACrD,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,EAAE;IACjC,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;QACjB,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;QACjB,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,kBAAkB,CAAC,IAAI,CAAC,CAAC;AAClC,CAAC,CAAC,CAAC;AAEL,MAAM,uBAAuB,GAAG,CAAC,IAAY,EAAU,EAAE,CACvD,qBAAqB,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;AAErD,IAAI,YAA4D,CAAC;AAEjE,MAAM,KAAK,GAAG,CAAC,MAAc,EAAQ,EAAE,CACrC,IAAA,uCAAY,EACV,MAAM,EACN,CAAC,YAAY,KAAK;IAChB,UAAU,EAAE,CAAC,IAAA,6BAAG,GAAE,CAAC;IACnB,eAAe,EAAE,CAAC,IAAA,gCAAe,GAAE,CAAC;CACrC,CAAC,CACH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CAAC,CAAC;IACnB,KAAK,MAAM,CAAC,IAAI,QAAQ,CAAC,QAAQ,CAAC,mBAAmB,CAAC,EAAE,CAAC;QACvD,IAAI,EAAE,UAAU,GAAG,qBAAqB,EAAE,CAAC;YACzC,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAhBW,QAAA,kBAAkB,sBAgB7B","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\n// Authored Markdown source made safe to print, for `md.authored`, and the GFM\n// parse it shares with the Slack fallback.\n\nimport type { Definition, Nodes, Parents, Root } from 'mdast';\nimport { fromMarkdown } from 'mdast-util-from-markdown';\nimport { gfmFromMarkdown } from 'mdast-util-gfm';\nimport { gfm } from 'micromark-extension-gfm';\n\nimport {\n BLOCKED_HREF,\n sanitizeParsedAssetUrl,\n sanitizeParsedNavigationHref,\n} from '../../validate/url';\n\n// Escapes label characters that could close a `[...]` early and smuggle in a\n// hostile destination of their own.\nconst escapeLinkLabel = (label: string): string =>\n label.replace(/[[\\]\\\\]/g, '\\\\$&');\n\n// Percent-encodes destination characters that would terminate the `(...)`\n// early or read as a link title. `encodeURIComponent` leaves `(` and `)`\n// unescaped by spec, so those two are mapped by hand.\nconst escapeLinkDestination = (href: string): string =>\n href.replace(/[()\\s\\\\]/g, (char) => {\n if (char === '(') {\n return '%28';\n }\n if (char === ')') {\n return '%29';\n }\n return encodeURIComponent(char);\n });\n\nconst escapeParsedDestination = (href: string): string =>\n escapeLinkDestination(href.replace(/&/g, '&amp;'));\n\nlet parseOptions: Parameters<typeof fromMarkdown>[1] | undefined;\n\nconst parse = (source: string): Root =>\n fromMarkdown(\n source,\n (parseOptions ??= {\n extensions: [gfm()],\n mdastExtensions: [gfmFromMarkdown()],\n })\n );\n\n/** `markdown` as flat GFM mdast blocks, typed `unknown` so no declaration names mdast; `null` past the parse budget or the parser's recursion depth. */\nexport const parseGfmBlocks = (markdown: string): readonly unknown[] | null => {\n if (exceedsParseBudget(markdown)) {\n return null;\n }\n try {\n return parse(markdown).children;\n } catch (error) {\n if (!(error instanceof RangeError)) {\n throw error;\n }\n return null;\n }\n};\n\n// Each pass can expose a new sink (an escaped HTML block reveals the Markdown\n// inside it; a blocked link's label may close an outer `](`), so passes repeat\n// until the source is stable.\nconst MAX_PASSES = 16;\n\nconst escapeTitle = (title: string): string =>\n `\"${title.replace(/[\"\\\\]/g, '\\\\$&')}\"`;\n\nconst offsets = (node: Nodes): [number, number] | undefined => {\n const start = node.position?.start.offset;\n const end = node.position?.end.offset;\n return start === undefined || end === undefined ? undefined : [start, end];\n};\n\nconst sanitizePass = (source: string): string => {\n const root = parse(source);\n const definitions = new Map<string, Definition>();\n const pending: Nodes[] = [...root.children].reverse();\n while (pending.length) {\n const node = pending.pop()!;\n if (node.type === 'definition' && !definitions.has(node.identifier)) {\n definitions.set(node.identifier, node);\n }\n if ('children' in node) {\n pending.push(...[...node.children].reverse());\n }\n }\n\n const slice = (node: Nodes): string => {\n const range = offsets(node);\n return range ? source.slice(...range) : '';\n };\n\n const emitChildren = (\n start: number,\n end: number,\n children: readonly Nodes[]\n ): string => {\n let out = '';\n let cursor = start;\n for (const child of children) {\n const range = offsets(child);\n if (!range) {\n continue;\n }\n out += source.slice(cursor, range[0]) + emit(child);\n cursor = range[1];\n }\n return out + source.slice(cursor, end);\n };\n\n const emitLabel = (node: Parents): string => {\n const first = node.children[0];\n const last = node.children[node.children.length - 1];\n const from = first && offsets(first);\n const to = last && offsets(last);\n return from && to ? emitChildren(from[0], to[1], node.children) : '';\n };\n\n const rewrite = (node: Nodes): string | undefined => {\n switch (node.type) {\n case 'html':\n return slice(node).replace(/</g, '&lt;');\n case 'definition': {\n const safe =\n sanitizeParsedNavigationHref(node.url) ??\n sanitizeParsedAssetUrl(node.url);\n if (safe === node.url) {\n return undefined;\n }\n const title = node.title ? ` ${escapeTitle(node.title)}` : '';\n return `[${node.label ?? node.identifier}]: ${\n safe === null ? BLOCKED_HREF : escapeParsedDestination(safe)\n }${title}`;\n }\n case 'imageReference': {\n const definition = definitions.get(node.identifier);\n return definition && sanitizeParsedAssetUrl(definition.url) === null\n ? escapeLinkLabel(node.alt ?? '')\n : undefined;\n }\n case 'linkReference': {\n const definition = definitions.get(node.identifier);\n return definition &&\n sanitizeParsedNavigationHref(definition.url) === null &&\n sanitizeParsedAssetUrl(definition.url) !== null\n ? emitLabel(node)\n : undefined;\n }\n case 'image': {\n const safe = sanitizeParsedAssetUrl(node.url);\n if (safe === null) {\n return escapeLinkLabel(node.alt ?? '');\n }\n if (safe === node.url) {\n return undefined;\n }\n const title = node.title ? ` ${escapeTitle(node.title)}` : '';\n return `![${escapeLinkLabel(node.alt ?? '')}](${escapeParsedDestination(\n safe\n )}${title})`;\n }\n case 'link': {\n const raw = slice(node);\n const safe = sanitizeParsedNavigationHref(node.url);\n if (raw.startsWith('<')) {\n return safe === null ? raw.slice(1, -1) : undefined;\n }\n // A GFM literal (`www.x.com`) is http(s) or mailto by construction.\n if (!raw.startsWith('[')) {\n return undefined;\n }\n if (safe === null) {\n return emitLabel(node);\n }\n if (safe === node.url) {\n return undefined;\n }\n const title = node.title ? ` ${escapeTitle(node.title)}` : '';\n return `[${emitLabel(node)}](${escapeParsedDestination(safe)}${title})`;\n }\n default:\n return undefined;\n }\n };\n\n const emit = (node: Nodes): string => {\n const replaced = rewrite(node);\n if (replaced !== undefined) {\n return replaced;\n }\n const range = offsets(node);\n if (!range) {\n return '';\n }\n return 'children' in node\n ? emitChildren(range[0], range[1], node.children)\n : source.slice(...range);\n };\n\n return emitChildren(0, source.length, root.children);\n};\n\n/** {@link sanitizeMarkdownSource}'s result, and whether it degraded to inert text. */\nexport const sanitizeAuthoredSource = (\n markdown: string\n): { markdown: string; inert: boolean } => {\n if (exceedsParseBudget(markdown)) {\n return { markdown: inert(markdown), inert: true };\n }\n let current = markdown;\n try {\n for (let pass = 0; pass < MAX_PASSES; pass++) {\n const next = sanitizePass(current);\n if (next === current) {\n return { markdown: current, inert: false };\n }\n current = next;\n }\n } catch (error) {\n // The parser recurses per nesting level, so inline nesting deep enough\n // to exhaust the stack lands here.\n if (!(error instanceof RangeError)) {\n throw error;\n }\n }\n return { markdown: inert(current), inert: true };\n};\n\n/** Sanitizes GFM destinations and HTML; excessive syntax or length degrades to inert text. */\nexport const sanitizeMarkdownSource = (markdown: string): string =>\n sanitizeAuthoredSource(markdown).markdown;\n\n// No link, image, definition, or tag can survive without `[` or `<`.\nexport const inert = (markdown: string): string =>\n markdown.replace(/[[\\]\\\\]/g, '\\\\$&').replace(/</g, '&lt;');\n\n// GFM parsing is superlinear for some delimiter runs, even without nesting.\nconst LINE_PREFIX_RE = /^(?:[ \\t>]|[-*+](?=[ \\t])|\\d{1,9}[.)](?=[ \\t]))+/gm;\nconst MAX_LINE_PREFIX = 256;\n// An escaped punctuation character opens nothing, so `\\*` counts as one.\nconst INLINE_DELIMITER_RE =\n /\\\\[!-/:-@[-`{-~]|[[\\]*`~<>|\\\\]|(?<![\\p{L}\\p{N}])_|_(?![\\p{L}\\p{N}])/gu;\nconst MAX_INLINE_DELIMITERS = 2048;\n\nconst MAX_PARSE_LENGTH = 16_384;\n\nexport const exceedsParseBudget = (markdown: string): boolean => {\n if (markdown.length > MAX_PARSE_LENGTH) {\n return true;\n }\n for (const [prefix] of markdown.matchAll(LINE_PREFIX_RE)) {\n if (prefix.length > MAX_LINE_PREFIX) {\n return true;\n }\n }\n let delimiters = 0;\n for (const _ of markdown.matchAll(INLINE_DELIMITER_RE)) {\n if (++delimiters > MAX_INLINE_DELIMITERS) {\n return true;\n }\n }\n return false;\n};\n"]}
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
4
+ * or more contributor license agreements. Licensed under the Elastic License
5
+ * 2.0; you may not use this file except in compliance with the Elastic License
6
+ * 2.0.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.findHostTags = void 0;
10
+ const NAME = String.raw `[A-Za-z_:][\w.:-]*`;
11
+ // A quoted value stays on one line and holds no backtick, so a code span
12
+ // opened before the tag still closes where CommonMark closes it.
13
+ const VALUE = String.raw `[^\s"'=<>\x60]+|'[^'\r\n\x60]*'|"[^"\r\n\x60]*"`;
14
+ const ATTRIBUTE = String.raw `[ \t]+${NAME}(?:[ \t]*=[ \t]*(?:${VALUE}))?`;
15
+ const ATTRIBUTE_RE = new RegExp(String.raw `[ \t]+(${NAME})(?:[ \t]*=[ \t]*(${VALUE}))?`, 'g');
16
+ const escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
17
+ const tagPattern = (names) => new RegExp(`<(${names.map(escapeRegExp).join('|')})((?:${ATTRIBUTE})*)[ \\t]*/?>`, 'gi');
18
+ const parseAttributes = (body) => {
19
+ const attributes = Object.create(null);
20
+ for (const [, name, value = ''] of body.matchAll(ATTRIBUTE_RE)) {
21
+ const key = name.toLowerCase();
22
+ if (!(key in attributes)) {
23
+ attributes[key] =
24
+ value.startsWith('"') || value.startsWith("'")
25
+ ? value.slice(1, -1)
26
+ : value;
27
+ }
28
+ }
29
+ return attributes;
30
+ };
31
+ // `\<` is an escaped `<`. Where a backslash is literal (code, HTML), the tag
32
+ // is literal too, so skipping it there changes nothing.
33
+ const isEscaped = (source, index) => {
34
+ let backslashes = 0;
35
+ while (source[index - backslashes - 1] === '\\') {
36
+ backslashes += 1;
37
+ }
38
+ return backslashes % 2 === 1;
39
+ };
40
+ /** Every tag named in `names` (matched case-insensitively and whole), in source order. */
41
+ const findHostTags = (source, names) => {
42
+ const canonical = new Map();
43
+ for (const name of names) {
44
+ const lower = name.toLowerCase();
45
+ if (lower !== '' && !canonical.has(lower)) {
46
+ canonical.set(lower, name);
47
+ }
48
+ }
49
+ if (canonical.size === 0) {
50
+ return [];
51
+ }
52
+ const tags = [];
53
+ for (const match of source.matchAll(tagPattern([...canonical.keys()]))) {
54
+ if (isEscaped(source, match.index)) {
55
+ continue;
56
+ }
57
+ tags.push({
58
+ index: match.index,
59
+ raw: match[0],
60
+ name: canonical.get(match[1].toLowerCase()),
61
+ attributes: parseAttributes(match[2]),
62
+ });
63
+ }
64
+ return tags;
65
+ };
66
+ exports.findHostTags = findHostTags;
67
+ //# sourceMappingURL=host_tags.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host_tags.js","sourceRoot":"","sources":["../../../../src/render/markdown/host_tags.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAoBH,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAA,oBAAoB,CAAC;AAC5C,yEAAyE;AACzE,iEAAiE;AACjE,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAA,iDAAiD,CAAC;AAC1E,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAA,SAAS,IAAI,sBAAsB,KAAK,KAAK,CAAC;AAC1E,MAAM,YAAY,GAAG,IAAI,MAAM,CAC7B,MAAM,CAAC,GAAG,CAAA,UAAU,IAAI,qBAAqB,KAAK,KAAK,EACvD,GAAG,CACJ,CAAC;AAEF,MAAM,YAAY,GAAG,CAAC,KAAa,EAAU,EAAE,CAC7C,KAAK,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;AAE/C,MAAM,UAAU,GAAG,CAAC,KAAwB,EAAU,EAAE,CACtD,IAAI,MAAM,CACR,KAAK,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,SAAS,eAAe,EACtE,IAAI,CACL,CAAC;AAEJ,MAAM,eAAe,GAAG,CAAC,IAAY,EAA0B,EAAE;IAC/D,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAA2B,CAAC;IACjE,KAAK,MAAM,CAAC,EAAE,IAAI,EA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KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,MAAM,IAAI,GAAc,EAAE,CAAC;IAC3B,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,GAAG,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACvE,IAAI,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;YACnC,SAAS;QACX,CAAC;QACD,IAAI,CAAC,IAAI,CAAC;YACR,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;YACb,IAAI,EAAE,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAE,CAAC,WAAW,EAAE,CAAE;YAC7C,UAAU,EAAE,eAAe,CAAC,KAAK,CAAC,CAAC,CAAE,CAAC;SACvC,CAAC,CAAC;IACL,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AA3BW,QAAA,YAAY,gBA2BvB","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\n// Finds a host's own tags, such as `<render_attachment id=\"…\" />`, in\n// authored Markdown. The grammar is CommonMark's raw HTML open tag (§6.6) on\n// one line, with `_` allowed in the name. One scan serves both paths of\n// `splitAuthoredMarkdown`: the parsed path swaps each tag for a sentinel\n// before parsing, and the over-budget path cuts the source at each tag.\n\n/** A tag found by {@link findHostTags}. */\nexport interface HostTag {\n /** Offset of the `<` in the source. */\n readonly index: number;\n /** The tag as written. */\n readonly raw: string;\n /** The name as listed in the options. */\n readonly name: string;\n /** Values as written, keyed by lower-cased name; a bare attribute is `''`. */\n readonly attributes: Readonly<Record<string, string>>;\n}\n\nconst NAME = String.raw`[A-Za-z_:][\\w.:-]*`;\n// A quoted value stays on one line and holds no backtick, so a code span\n// opened before the tag still closes where CommonMark closes it.\nconst VALUE = String.raw`[^\\s\"'=<>\\x60]+|'[^'\\r\\n\\x60]*'|\"[^\"\\r\\n\\x60]*\"`;\nconst ATTRIBUTE = String.raw`[ \\t]+${NAME}(?:[ \\t]*=[ \\t]*(?:${VALUE}))?`;\nconst ATTRIBUTE_RE = new RegExp(\n String.raw`[ \\t]+(${NAME})(?:[ \\t]*=[ \\t]*(${VALUE}))?`,\n 'g'\n);\n\nconst escapeRegExp = (value: string): string =>\n value.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n\nconst tagPattern = (names: readonly string[]): RegExp =>\n new RegExp(\n `<(${names.map(escapeRegExp).join('|')})((?:${ATTRIBUTE})*)[ \\\\t]*/?>`,\n 'gi'\n );\n\nconst parseAttributes = (body: string): Record<string, string> => {\n const attributes = Object.create(null) as Record<string, string>;\n for (const [, name, value = ''] of body.matchAll(ATTRIBUTE_RE)) {\n const key = name!.toLowerCase();\n if (!(key in attributes)) {\n attributes[key] =\n value.startsWith('\"') || value.startsWith(\"'\")\n ? value.slice(1, -1)\n : value;\n }\n }\n return attributes;\n};\n\n// `\\<` is an escaped `<`. Where a backslash is literal (code, HTML), the tag\n// is literal too, so skipping it there changes nothing.\nconst isEscaped = (source: string, index: number): boolean => {\n let backslashes = 0;\n while (source[index - backslashes - 1] === '\\\\') {\n backslashes += 1;\n }\n return backslashes % 2 === 1;\n};\n\n/** Every tag named in `names` (matched case-insensitively and whole), in source order. */\nexport const findHostTags = (\n source: string,\n names: readonly string[]\n): HostTag[] => {\n const canonical = new Map<string, string>();\n for (const name of names) {\n const lower = name.toLowerCase();\n if (lower !== '' && !canonical.has(lower)) {\n canonical.set(lower, name);\n }\n }\n if (canonical.size === 0) {\n return [];\n }\n const tags: HostTag[] = [];\n for (const match of source.matchAll(tagPattern([...canonical.keys()]))) {\n if (isEscaped(source, match.index)) {\n continue;\n }\n tags.push({\n index: match.index,\n raw: match[0],\n name: canonical.get(match[1]!.toLowerCase())!,\n attributes: parseAttributes(match[2]!),\n });\n }\n return tags;\n};\n"]}
@@ -6,10 +6,12 @@
6
6
  * 2.0.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.renderMarkdownEnvelope = exports.serializeMarkdown = exports.md = void 0;
9
+ exports.splitAuthoredMarkdown = exports.renderMarkdownEnvelope = exports.serializeMarkdown = exports.md = void 0;
10
10
  var builder_1 = require("./builder");
11
11
  Object.defineProperty(exports, "md", { enumerable: true, get: function () { return builder_1.md; } });
12
12
  Object.defineProperty(exports, "serializeMarkdown", { enumerable: true, get: function () { return builder_1.serializeMarkdown; } });
13
13
  var envelope_1 = require("./envelope");
14
14
  Object.defineProperty(exports, "renderMarkdownEnvelope", { enumerable: true, get: function () { return envelope_1.renderMarkdownEnvelope; } });
15
+ var split_1 = require("./split");
16
+ Object.defineProperty(exports, "splitAuthoredMarkdown", { enumerable: true, get: function () { return split_1.splitAuthoredMarkdown; } });
15
17
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/render/markdown/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,qCAAkD;AAAzC,6FAAA,EAAE,OAAA;AAAE,4GAAA,iBAAiB,OAAA;AAE9B,uCAIoB;AADlB,kHAAA,sBAAsB,OAAA","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nexport { md, serializeMarkdown } from './builder';\n\nexport {\n type MarkdownEnvelopeDispatcher,\n type MarkdownEnvelopeOptions,\n renderMarkdownEnvelope,\n} from './envelope';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/render/markdown/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,qCAAkD;AAAzC,6FAAA,EAAE,OAAA;AAAE,4GAAA,iBAAiB,OAAA;AAC9B,uCAIoB;AADlB,kHAAA,sBAAsB,OAAA;AAGxB,iCAIiB;AADf,8GAAA,qBAAqB,OAAA","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nexport { md, serializeMarkdown } from './builder';\nexport {\n type MarkdownEnvelopeDispatcher,\n type MarkdownEnvelopeOptions,\n renderMarkdownEnvelope,\n} from './envelope';\n\nexport {\n type AuthoredMarkdownSegment,\n type SplitAuthoredMarkdownOptions,\n splitAuthoredMarkdown,\n} from './split';\n"]}
@@ -0,0 +1,325 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
4
+ * or more contributor license agreements. Licensed under the Elastic License
5
+ * 2.0; you may not use this file except in compliance with the Elastic License
6
+ * 2.0.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.splitAuthoredMarkdown = void 0;
10
+ const builder_1 = require("./builder");
11
+ const format_1 = require("./format");
12
+ const host_tags_1 = require("./host_tags");
13
+ // A sentinel keeps the tag's own `<` and `>` as its edges, so emphasis and
14
+ // other delimiters around it read exactly as they did around the tag, and
15
+ // holds private-use characters between them, which no Markdown construct
16
+ // reads, so it parses as text wherever the tag was written. Any already in
17
+ // the source, literal or as a character reference (the only other way text
18
+ // can decode to one), are replaced first, so the parsed text holds sentinels
19
+ // only where tags were.
20
+ const SENTINEL_RE = /<\uE000(\d+)\uE001>/g;
21
+ // In a link destination the parser strips the angle brackets.
22
+ const SENTINEL_ANYWHERE_RE = /<?\uE000(\d+)\uE001>?/g;
23
+ const RESERVED_RE = /[\uE000\uE001]|&#(?:[xX]0*[eE]00[01]|0*5734[45]);/g;
24
+ const sentinel = (index) => `<\uE000${index}\uE001>`;
25
+ const withoutReserved = (source) => source.replace(RESERVED_RE, (match) => match.length === 1 ? '\uFFFD' : '&#xFFFD;');
26
+ // Tags written identically get the same sentinel, so a reference label that
27
+ // holds one still matches a definition that holds the same. Sharing by
28
+ // exact text keeps each tag's attributes and spelling its own.
29
+ const substitute = (source, tags) => {
30
+ const first = new Map();
31
+ let out = '';
32
+ let cursor = 0;
33
+ tags.forEach((tag, index) => {
34
+ if (!first.has(tag.raw)) {
35
+ first.set(tag.raw, index);
36
+ }
37
+ out += source.slice(cursor, tag.index) + sentinel(first.get(tag.raw));
38
+ cursor = tag.index + tag.raw.length;
39
+ });
40
+ return out + source.slice(cursor);
41
+ };
42
+ // The GFM serializer's cost grows steeply with nesting depth, while the
43
+ // parse budget bounds breadth, not depth. Nothing authored nests this deep.
44
+ const MAX_DEPTH = 64;
45
+ const exceedsDepth = (nodes, depth = 1) => depth > MAX_DEPTH ||
46
+ nodes.some((node) => 'children' in node && exceedsDepth(node.children, depth + 1));
47
+ // The tag's node in the tree, until it is cut out again.
48
+ const HOST = 'isomerHostElement';
49
+ const isHost = (node) => node.type === HOST;
50
+ const hostTag = (node) => node.tag;
51
+ const element = ({ name, attributes }) => ({
52
+ type: 'element',
53
+ name,
54
+ attributes,
55
+ });
56
+ const markdown = (source) => source.trim() === ''
57
+ ? []
58
+ : [{ type: 'markdown', content: builder_1.md.authored(source), source }];
59
+ // A sentinel in a text node becomes a host node between the text around it.
60
+ // In any other string (code, alt, url, title, HTML) the tag text goes back. A
61
+ // footnote prints at the end of its segment, away from where it is cited, so
62
+ // a tag inside one is literal too.
63
+ const resolve = (node, tags, literal) => {
64
+ if (node.type === 'text' && !literal) {
65
+ const parts = [];
66
+ let cursor = 0;
67
+ for (const match of node.value.matchAll(SENTINEL_RE)) {
68
+ if (match.index > cursor) {
69
+ parts.push({
70
+ type: 'text',
71
+ value: node.value.slice(cursor, match.index),
72
+ });
73
+ }
74
+ parts.push({
75
+ type: HOST,
76
+ tag: tags[Number(match[1])],
77
+ });
78
+ cursor = match.index + match[0].length;
79
+ }
80
+ if (parts.length === 0) {
81
+ return [node];
82
+ }
83
+ if (cursor < node.value.length) {
84
+ parts.push({ type: 'text', value: node.value.slice(cursor) });
85
+ }
86
+ return parts;
87
+ }
88
+ const restored = { ...node };
89
+ for (const [key, value] of Object.entries(restored)) {
90
+ if (typeof value === 'string') {
91
+ restored[key] = value.replace(SENTINEL_ANYWHERE_RE, (_, index) => tags[Number(index)].raw);
92
+ }
93
+ }
94
+ if ('children' in node) {
95
+ restored.children = node.children.flatMap((child) => resolve(child, tags, literal || node.type === 'footnoteDefinition'));
96
+ }
97
+ return [restored];
98
+ };
99
+ // Depth-first, in document order.
100
+ const walk = (node, visit) => {
101
+ visit(node);
102
+ if ('children' in node) {
103
+ node.children.forEach((child) => walk(child, visit));
104
+ }
105
+ };
106
+ const PHRASING_PARENTS = new Set([
107
+ 'delete',
108
+ 'emphasis',
109
+ 'heading',
110
+ 'link',
111
+ 'linkReference',
112
+ 'paragraph',
113
+ 'strong',
114
+ 'tableCell',
115
+ ]);
116
+ // A wrapper the tag leaves empty would print its markers alone (`****` is a
117
+ // thematic break). Containers keep their place: an empty list item keeps the
118
+ // numbering of the items after it.
119
+ const DROPPED_WHEN_EMPTY = new Set([
120
+ 'delete',
121
+ 'emphasis',
122
+ 'heading',
123
+ 'link',
124
+ 'linkReference',
125
+ 'paragraph',
126
+ 'strong',
127
+ ]);
128
+ // Text either side of a removed tag joins, with one space if either side
129
+ // had one. The run's edges are trimmed, and a hard break left at an edge is
130
+ // dropped as `md.paragraph` drops it, since it would print as a bare `\\`.
131
+ const tidyPhrasing = (children) => {
132
+ const joined = [];
133
+ for (const child of children) {
134
+ const previous = joined[joined.length - 1];
135
+ if (previous?.type === 'text' && child.type === 'text') {
136
+ const left = previous.value.replace(/\s+$/, '');
137
+ const right = child.value.replace(/^\s+/, '');
138
+ const spaced = left !== previous.value || right !== child.value;
139
+ joined[joined.length - 1] = {
140
+ type: 'text',
141
+ value: left + (spaced ? ' ' : '') + right,
142
+ };
143
+ }
144
+ else {
145
+ joined.push(child);
146
+ }
147
+ }
148
+ const isEdge = (node) => node?.type === 'break' ||
149
+ (node?.type === 'text' && node.value.trim() === '');
150
+ while (isEdge(joined[0])) {
151
+ joined.shift();
152
+ }
153
+ while (isEdge(joined[joined.length - 1])) {
154
+ joined.pop();
155
+ }
156
+ const first = joined[0];
157
+ if (first?.type === 'text') {
158
+ joined[0] = { ...first, value: first.value.trimStart() };
159
+ }
160
+ const last = joined[joined.length - 1];
161
+ if (last?.type === 'text') {
162
+ joined[joined.length - 1] = { ...last, value: last.value.trimEnd() };
163
+ }
164
+ return joined;
165
+ };
166
+ // `node` without its host nodes, which are appended to `found` in document
167
+ // order; `[]` when nothing is left of it. Only a node a tag was removed
168
+ // from is tidied, so phrasing elsewhere in the block stays as written.
169
+ const strip = (node, found) => {
170
+ if (isHost(node)) {
171
+ found.push(hostTag(node));
172
+ return [];
173
+ }
174
+ if (!('children' in node)) {
175
+ return [node];
176
+ }
177
+ const before = found.length;
178
+ const stripped = node.children.flatMap((child) => strip(child, found));
179
+ if (found.length === before) {
180
+ return [node];
181
+ }
182
+ const children = PHRASING_PARENTS.has(node.type)
183
+ ? tidyPhrasing(stripped)
184
+ : stripped;
185
+ return children.length === 0 && DROPPED_WHEN_EMPTY.has(node.type)
186
+ ? []
187
+ : [{ ...node, children }];
188
+ };
189
+ // The first definition of each identifier, anywhere in the tree, as the
190
+ // parser resolved references.
191
+ const firstDefinitions = (blocks) => {
192
+ const definitions = new Map();
193
+ for (const block of blocks) {
194
+ walk(block, (node) => {
195
+ if (node.type === 'definition' && !definitions.has(node.identifier)) {
196
+ definitions.set(node.identifier, node);
197
+ }
198
+ });
199
+ }
200
+ return definitions;
201
+ };
202
+ // Each segment is a document of its own, so a definition another segment
203
+ // holds is copied ahead of the run that references it.
204
+ const printRun = (run, definitions) => {
205
+ const present = new Set();
206
+ const needed = new Map();
207
+ for (const block of run) {
208
+ walk(block, (node) => {
209
+ present.add(node);
210
+ if (node.type === 'linkReference' || node.type === 'imageReference') {
211
+ const definition = definitions.get(node.identifier);
212
+ if (definition) {
213
+ needed.set(node.identifier, definition);
214
+ }
215
+ }
216
+ });
217
+ }
218
+ const carried = [...needed.values()].filter((node) => !present.has(node));
219
+ return (0, builder_1.printParsed)([...carried, ...run]);
220
+ };
221
+ const splitBlocks = (blocks, tags) => {
222
+ const resolved = blocks.flatMap((block) => resolve(block, tags, false));
223
+ const definitions = firstDefinitions(resolved);
224
+ const segments = [];
225
+ let run = [];
226
+ const flush = () => {
227
+ if (run.length > 0) {
228
+ segments.push(...markdown(printRun(run, definitions)));
229
+ }
230
+ run = [];
231
+ };
232
+ // `block` without its tags joins the run; each tag ends the run after it.
233
+ const push = (block) => {
234
+ const found = [];
235
+ run.push(...strip(block, found));
236
+ for (const tag of found) {
237
+ flush();
238
+ segments.push(element(tag));
239
+ }
240
+ };
241
+ for (const block of resolved) {
242
+ if (block.type === 'definition') {
243
+ // Prints nothing where it stands; it is copied where it is referenced.
244
+ continue;
245
+ }
246
+ if (block.type !== 'paragraph' || !block.children.some(isHost)) {
247
+ push(block);
248
+ continue;
249
+ }
250
+ // A tag directly in a top-level paragraph splits it in place.
251
+ let piece = [];
252
+ const pushPiece = () => {
253
+ const children = tidyPhrasing(piece);
254
+ if (children.length > 0) {
255
+ push({ ...block, children });
256
+ }
257
+ piece = [];
258
+ };
259
+ for (const child of block.children) {
260
+ if (isHost(child)) {
261
+ pushPiece();
262
+ flush();
263
+ segments.push(element(hostTag(child)));
264
+ }
265
+ else {
266
+ piece.push(child);
267
+ }
268
+ }
269
+ pushPiece();
270
+ }
271
+ flush();
272
+ return segments;
273
+ };
274
+ // Past the parse budget there is no tree to consult, so the source is cut at
275
+ // each tag and every piece degrades to inert text, as `md.authored` degrades.
276
+ const cutLinearly = (source, tags) => {
277
+ const segments = [];
278
+ const push = (piece) => {
279
+ const text = piece.trim();
280
+ if (text !== '') {
281
+ segments.push({
282
+ type: 'markdown',
283
+ content: (0, builder_1.verbatim)((0, format_1.inert)(text), text),
284
+ source: text,
285
+ });
286
+ }
287
+ };
288
+ let cursor = 0;
289
+ for (const tag of tags) {
290
+ push(source.slice(cursor, tag.index));
291
+ segments.push(element(tag));
292
+ cursor = tag.index + tag.raw.length;
293
+ }
294
+ push(source.slice(cursor));
295
+ return segments;
296
+ };
297
+ /**
298
+ * Splits authored Markdown at the host's own elements, such as
299
+ * `<render_attachment id="…" />`, so the host can replace each with content
300
+ * of its own without cutting the raw string. The source is parsed once, so a
301
+ * tag in code, a link destination or title, an image's alt text, or raw HTML
302
+ * stays text, and a list, table, quote, or emphasis around a tag stays whole.
303
+ * Each `markdown` segment is sanitized as `md.authored` sanitizes; past the
304
+ * parse budget the source is cut at each tag into inert pieces.
305
+ *
306
+ * @example
307
+ * splitAuthoredMarkdown(message, { elements: ['render_attachment'] })
308
+ */
309
+ const splitAuthoredMarkdown = (source, { elements }) => {
310
+ const cleaned = withoutReserved(source);
311
+ const tags = (0, host_tags_1.findHostTags)(cleaned, elements);
312
+ if (tags.length === 0) {
313
+ return markdown(source);
314
+ }
315
+ // The budget applies to the source as written: a long attribute value
316
+ // shrinks to a sentinel, but comes back in full wherever it is literal.
317
+ const blocks = (0, format_1.exceedsParseBudget)(cleaned)
318
+ ? null
319
+ : (0, format_1.parseGfmBlocks)(substitute(cleaned, tags));
320
+ return blocks && !exceedsDepth(blocks)
321
+ ? splitBlocks(blocks, tags)
322
+ : cutLinearly(cleaned, tags);
323
+ };
324
+ exports.splitAuthoredMarkdown = splitAuthoredMarkdown;
325
+ //# sourceMappingURL=split.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"split.js","sourceRoot":"","sources":["../../../../src/render/markdown/split.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAaH,uCAAsD;AACtD,qCAAqE;AACrE,2CAAyD;AAuBzD,2EAA2E;AAC3E,0EAA0E;AAC1E,yEAAyE;AACzE,2EAA2E;AAC3E,2EAA2E;AAC3E,6EAA6E;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G,IAAA,wBAAY,EAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAC7C,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC1B,CAAC;IACD,sEAAsE;IACtE,wEAAwE;IACxE,MAAM,MAAM,GAAG,IAAA,2BAAkB,EAAC,OAAO,CAAC;QACxC,CAAC,CAAC,IAAI;QACN,CAAC,CAAE,IAAA,uBAAc,EAAC,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,CACT,CAAC;IACrC,OAAO,MAAM,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC;QACpC,CAAC,CAAC,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC;QAC3B,CAAC,CAAC,WAAW,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AACjC,CAAC,CAAC;AAlBW,QAAA,qBAAqB,yBAkBhC","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\n// Splits authored Markdown at a host's own tags without a second grammar:\n// each tag becomes a sentinel, the stock GFM parser parses the whole source\n// once, and where the sentinel lands says what the tag is. In a `text`\n// node it is a tag; anywhere else (a code span or block, an image's alt, a\n// link destination or title, raw HTML) it is literal and the tag text goes\n// back. Blocks that held a tag are then printed from the tree.\n\nimport type { Definition, Nodes, RootContent } from 'mdast';\n\nimport type { MarkdownContent } from '../../define/markdown_content';\n\nimport { md, printParsed, verbatim } from './builder';\nimport { exceedsParseBudget, inert, parseGfmBlocks } from './format';\nimport { findHostTags, type HostTag } from './host_tags';\n\n/** A piece of authored Markdown, or one of the host's elements cut out of it. */\nexport type AuthoredMarkdownSegment =\n | {\n type: 'markdown';\n content: MarkdownContent;\n /** The text `content` was built from, for a host that stores a string and passes it to `md.authored` later. */\n source: string;\n }\n | {\n type: 'element';\n /** The name as listed in {@link SplitAuthoredMarkdownOptions.elements}. */\n name: string;\n /** Attribute values as written, keyed by lower-cased name; a bare attribute is `''`. */\n attributes: Readonly<Record<string, string>>;\n };\n\nexport interface SplitAuthoredMarkdownOptions {\n /** Tag names to cut out, matched case-insensitively and whole. */\n readonly elements: readonly string[];\n}\n\n// A sentinel keeps the tag's own `<` and `>` as its edges, so emphasis and\n// other delimiters around it read exactly as they did around the tag, and\n// holds private-use characters between them, which no Markdown construct\n// reads, so it parses as text wherever the tag was written. Any already in\n// the source, literal or as a character reference (the only other way text\n// can decode to one), are replaced first, so the parsed text holds sentinels\n// only where tags were.\nconst SENTINEL_RE = /<\\uE000(\\d+)\\uE001>/g;\n// In a link destination the parser strips the angle brackets.\nconst SENTINEL_ANYWHERE_RE = /<?\\uE000(\\d+)\\uE001>?/g;\nconst RESERVED_RE = /[\\uE000\\uE001]|&#(?:[xX]0*[eE]00[01]|0*5734[45]);/g;\nconst sentinel = (index: number): string => `<\\uE000${index}\\uE001>`;\nconst withoutReserved = (source: string): string =>\n source.replace(RESERVED_RE, (match) =>\n match.length === 1 ? '\\uFFFD' : '&#xFFFD;'\n );\n\n// Tags written identically get the same sentinel, so a reference label that\n// holds one still matches a definition that holds the same. Sharing by\n// exact text keeps each tag's attributes and spelling its own.\nconst substitute = (source: string, tags: readonly HostTag[]): string => {\n const first = new Map<string, number>();\n let out = '';\n let cursor = 0;\n tags.forEach((tag, index) => {\n if (!first.has(tag.raw)) {\n first.set(tag.raw, index);\n }\n out += source.slice(cursor, tag.index) + sentinel(first.get(tag.raw)!);\n cursor = tag.index + tag.raw.length;\n });\n return out + source.slice(cursor);\n};\n\n// The GFM serializer's cost grows steeply with nesting depth, while the\n// parse budget bounds breadth, not depth. Nothing authored nests this deep.\nconst MAX_DEPTH = 64;\n\nconst exceedsDepth = (nodes: readonly Nodes[], depth = 1): boolean =>\n depth > MAX_DEPTH ||\n nodes.some(\n (node) => 'children' in node && exceedsDepth(node.children, depth + 1)\n );\n\n// The tag's node in the tree, until it is cut out again.\nconst HOST = 'isomerHostElement';\ninterface HostNode {\n type: typeof HOST;\n tag: HostTag;\n}\n\nconst isHost = (node: Nodes): boolean => (node.type as string) === HOST;\nconst hostTag = (node: Nodes): HostTag => (node as unknown as HostNode).tag;\n\nconst element = ({ name, attributes }: HostTag): AuthoredMarkdownSegment => ({\n type: 'element',\n name,\n attributes,\n});\n\nconst markdown = (source: string): AuthoredMarkdownSegment[] =>\n source.trim() === ''\n ? []\n : [{ type: 'markdown', content: md.authored(source), source }];\n\n// A sentinel in a text node becomes a host node between the text around it.\n// In any other string (code, alt, url, title, HTML) the tag text goes back. A\n// footnote prints at the end of its segment, away from where it is cited, so\n// a tag inside one is literal too.\nconst resolve = (\n node: Nodes,\n tags: readonly HostTag[],\n literal: boolean\n): Nodes[] => {\n if (node.type === 'text' && !literal) {\n const parts: Nodes[] = [];\n let cursor = 0;\n for (const match of node.value.matchAll(SENTINEL_RE)) {\n if (match.index > cursor) {\n parts.push({\n type: 'text',\n value: node.value.slice(cursor, match.index),\n });\n }\n parts.push({\n type: HOST,\n tag: tags[Number(match[1])]!,\n } as unknown as Nodes);\n cursor = match.index + match[0].length;\n }\n if (parts.length === 0) {\n return [node];\n }\n if (cursor < node.value.length) {\n parts.push({ type: 'text', value: node.value.slice(cursor) });\n }\n return parts;\n }\n const restored = { ...node } as Record<string, unknown>;\n for (const [key, value] of Object.entries(restored)) {\n if (typeof value === 'string') {\n restored[key] = value.replace(\n SENTINEL_ANYWHERE_RE,\n (_, index: string) => tags[Number(index)]!.raw\n );\n }\n }\n if ('children' in node) {\n restored.children = node.children.flatMap((child) =>\n resolve(child, tags, literal || node.type === 'footnoteDefinition')\n );\n }\n return [restored as unknown as Nodes];\n};\n\n// Depth-first, in document order.\nconst walk = (node: Nodes, visit: (node: Nodes) => void): void => {\n visit(node);\n if ('children' in node) {\n node.children.forEach((child) => walk(child, visit));\n }\n};\n\nconst PHRASING_PARENTS = new Set([\n 'delete',\n 'emphasis',\n 'heading',\n 'link',\n 'linkReference',\n 'paragraph',\n 'strong',\n 'tableCell',\n]);\n\n// A wrapper the tag leaves empty would print its markers alone (`****` is a\n// thematic break). Containers keep their place: an empty list item keeps the\n// numbering of the items after it.\nconst DROPPED_WHEN_EMPTY = new Set([\n 'delete',\n 'emphasis',\n 'heading',\n 'link',\n 'linkReference',\n 'paragraph',\n 'strong',\n]);\n\n// Text either side of a removed tag joins, with one space if either side\n// had one. The run's edges are trimmed, and a hard break left at an edge is\n// dropped as `md.paragraph` drops it, since it would print as a bare `\\\\`.\nconst tidyPhrasing = (children: Nodes[]): Nodes[] => {\n const joined: Nodes[] = [];\n for (const child of children) {\n const previous = joined[joined.length - 1];\n if (previous?.type === 'text' && child.type === 'text') {\n const left = previous.value.replace(/\\s+$/, '');\n const right = child.value.replace(/^\\s+/, '');\n const spaced = left !== previous.value || right !== child.value;\n joined[joined.length - 1] = {\n type: 'text',\n value: left + (spaced ? ' ' : '') + right,\n };\n } else {\n joined.push(child);\n }\n }\n const isEdge = (node: Nodes | undefined): boolean =>\n node?.type === 'break' ||\n (node?.type === 'text' && node.value.trim() === '');\n while (isEdge(joined[0])) {\n joined.shift();\n }\n while (isEdge(joined[joined.length - 1])) {\n joined.pop();\n }\n const first = joined[0];\n if (first?.type === 'text') {\n joined[0] = { ...first, value: first.value.trimStart() };\n }\n const last = joined[joined.length - 1];\n if (last?.type === 'text') {\n joined[joined.length - 1] = { ...last, value: last.value.trimEnd() };\n }\n return joined;\n};\n\n// `node` without its host nodes, which are appended to `found` in document\n// order; `[]` when nothing is left of it. Only a node a tag was removed\n// from is tidied, so phrasing elsewhere in the block stays as written.\nconst strip = (node: Nodes, found: HostTag[]): Nodes[] => {\n if (isHost(node)) {\n found.push(hostTag(node));\n return [];\n }\n if (!('children' in node)) {\n return [node];\n }\n const before = found.length;\n const stripped = node.children.flatMap((child) => strip(child, found));\n if (found.length === before) {\n return [node];\n }\n const children = PHRASING_PARENTS.has(node.type)\n ? tidyPhrasing(stripped)\n : stripped;\n return children.length === 0 && DROPPED_WHEN_EMPTY.has(node.type)\n ? []\n : [{ ...node, children } as Nodes];\n};\n\n// The first definition of each identifier, anywhere in the tree, as the\n// parser resolved references.\nconst firstDefinitions = (\n blocks: readonly Nodes[]\n): ReadonlyMap<string, Definition> => {\n const definitions = new Map<string, Definition>();\n for (const block of blocks) {\n walk(block, (node) => {\n if (node.type === 'definition' && !definitions.has(node.identifier)) {\n definitions.set(node.identifier, node);\n }\n });\n }\n return definitions;\n};\n\n// Each segment is a document of its own, so a definition another segment\n// holds is copied ahead of the run that references it.\nconst printRun = (\n run: readonly Nodes[],\n definitions: ReadonlyMap<string, Definition>\n): string => {\n const present = new Set<Nodes>();\n const needed = new Map<string, Definition>();\n for (const block of run) {\n walk(block, (node) => {\n present.add(node);\n if (node.type === 'linkReference' || node.type === 'imageReference') {\n const definition = definitions.get(node.identifier);\n if (definition) {\n needed.set(node.identifier, definition);\n }\n }\n });\n }\n const carried = [...needed.values()].filter((node) => !present.has(node));\n return printParsed([...carried, ...run]);\n};\n\nconst splitBlocks = (\n blocks: readonly Nodes[],\n tags: readonly HostTag[]\n): AuthoredMarkdownSegment[] => {\n const resolved = blocks.flatMap((block) => resolve(block, tags, false));\n const definitions = firstDefinitions(resolved);\n const segments: AuthoredMarkdownSegment[] = [];\n let run: Nodes[] = [];\n const flush = (): void => {\n if (run.length > 0) {\n segments.push(...markdown(printRun(run, definitions)));\n }\n run = [];\n };\n // `block` without its tags joins the run; each tag ends the run after it.\n const push = (block: Nodes): void => {\n const found: HostTag[] = [];\n run.push(...strip(block, found));\n for (const tag of found) {\n flush();\n segments.push(element(tag));\n }\n };\n for (const block of resolved) {\n if (block.type === 'definition') {\n // Prints nothing where it stands; it is copied where it is referenced.\n continue;\n }\n if (block.type !== 'paragraph' || !block.children.some(isHost)) {\n push(block);\n continue;\n }\n // A tag directly in a top-level paragraph splits it in place.\n let piece: Nodes[] = [];\n const pushPiece = (): void => {\n const children = tidyPhrasing(piece);\n if (children.length > 0) {\n push({ ...block, children } as Nodes);\n }\n piece = [];\n };\n for (const child of block.children) {\n if (isHost(child)) {\n pushPiece();\n flush();\n segments.push(element(hostTag(child)));\n } else {\n piece.push(child);\n }\n }\n pushPiece();\n }\n flush();\n return segments;\n};\n\n// Past the parse budget there is no tree to consult, so the source is cut at\n// each tag and every piece degrades to inert text, as `md.authored` degrades.\nconst cutLinearly = (\n source: string,\n tags: readonly HostTag[]\n): AuthoredMarkdownSegment[] => {\n const segments: AuthoredMarkdownSegment[] = [];\n const push = (piece: string): void => {\n const text = piece.trim();\n if (text !== '') {\n segments.push({\n type: 'markdown',\n content: verbatim(inert(text), text),\n source: text,\n });\n }\n };\n let cursor = 0;\n for (const tag of tags) {\n push(source.slice(cursor, tag.index));\n segments.push(element(tag));\n cursor = tag.index + tag.raw.length;\n }\n push(source.slice(cursor));\n return segments;\n};\n\n/**\n * Splits authored Markdown at the host's own elements, such as\n * `<render_attachment id=\"…\" />`, so the host can replace each with content\n * of its own without cutting the raw string. The source is parsed once, so a\n * tag in code, a link destination or title, an image's alt text, or raw HTML\n * stays text, and a list, table, quote, or emphasis around a tag stays whole.\n * Each `markdown` segment is sanitized as `md.authored` sanitizes; past the\n * parse budget the source is cut at each tag into inert pieces.\n *\n * @example\n * splitAuthoredMarkdown(message, { elements: ['render_attachment'] })\n */\nexport const splitAuthoredMarkdown = (\n source: string,\n { elements }: SplitAuthoredMarkdownOptions\n): AuthoredMarkdownSegment[] => {\n const cleaned = withoutReserved(source);\n const tags = findHostTags(cleaned, elements);\n if (tags.length === 0) {\n return markdown(source);\n }\n // The budget applies to the source as written: a long attribute value\n // shrinks to a sentinel, but comes back in full wherever it is literal.\n const blocks = exceedsParseBudget(cleaned)\n ? null\n : (parseGfmBlocks(substitute(cleaned, tags)) as\n readonly RootContent[] | null);\n return blocks && !exceedsDepth(blocks)\n ? splitBlocks(blocks, tags)\n : cutLinearly(cleaned, tags);\n};\n"]}
@@ -38,7 +38,9 @@ const wrapCompositionContent = (content, composition, { framed = true, fluid = f
38
38
  .join(' '),
39
39
  role: 'group',
40
40
  'aria-label': composition.meta?.ariaLabel ?? composition.title ?? defaultAriaLabel,
41
- ...(theme === 'auto' ? {} : { 'data-theme': theme }),
41
+ ...(theme === 'auto'
42
+ ? {}
43
+ : { 'data-theme': theme, style: { colorScheme: theme } }),
42
44
  }, content);
43
45
  exports.wrapCompositionContent = wrapCompositionContent;
44
46
  //# sourceMappingURL=content.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"content.js","sourceRoot":"","sources":["../../../../src/render/react/content.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,iCAKe;AAyBf;;;GAGG;AACI,MAAM,wBAAwB,GAAG,CAItC,WAA+B,EAC/B,UAAmD,EACnD,OAAiB,EACjB,EAAE,OAAO,GAAG,IAAI,KAA0B,EAAE,EACjC,EAAE,CACb,IAAA,qBAAa,EACX,gBAAQ,EACR,IAAI,EACJ,GAAG;IACD,OAAO,IAAI,WAAW,CAAC,KAAK;QAC1B,CAAC,CAAC,IAAA,qBAAa,EAAC,IAAI,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,WAAW,CAAC,KAAK,CAAC;QAC1D,CAAC,CAAC,IAAI;IACR,OAAO,IAAI,WAAW,CAAC,QAAQ;QAC7B,CAAC,CAAC,IAAA,qBAAa,EACX,GAAG,EACH,EAAE,GAAG,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,EACrC,WAAW,CAAC,QAAQ,CACrB;QACH,CAAC,CAAC,IAAI;IACR,GAAG,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CACtC,IAAA,qBAAa,EAAC,CAAA,uBAAwC,CAAA,EAAE;QACtD,GAAG,EAAE,QAAQ,KAAK,EAAE;QACpB,IAAI;QACJ,OAAO;QACP,UAAU;KACX,CAAC,CACH;CACF,CAAC,MAAM,CAAC,OAAO,CAAC,CAClB,CAAC;AAhCS,QAAA,wBAAwB,4BAgCjC;AAWJ,MAAM,uBAAuB,GAAG,CAAwC,EACtE,IAAI,EACJ,OAAO,EACP,UAAU,GACoC,EAAa,EAAE,CAC7D,UAAU,CAAC,WAAW,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAcxC;;;GAGG;AACI,MAAM,sBAAsB,GAAG,CACpC,OAAkB,EAClB,WAA+B,EAC/B,EACE,MAAM,GAAG,IAAI,EACb,KAAK,GAAG,KAAK,EACb,KAAK,GAAG,WAAW,CAAC,KAAK,IAAI,MAAM,EACnC,gBAAgB,GAAG,MAAM,MACI,EAAE,EACnB,EAAE,CAChB,IAAA,qBAAa,EACX,SAAS,EACT;IACE,SAAS,EAAE,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;SAChE,MAAM,CAAC,OAAO,CAAC;SACf,IAAI,CAAC,GAAG,CAAC;IACZ,IAAI,EAAE,OAAO;IACb,YAAY,EACV,WAAW,CAAC,IAAI,EAAE,SAAS,IAAI,WAAW,CAAC,KAAK,IAAI,gBAAgB;IACtE,GAAG,CAAC,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC;CACrD,EACD,OAAO,CACR,CAAC;AAtBS,QAAA,sBAAsB,0BAsB/B","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nimport {\n createElement,\n Fragment,\n type ReactElement,\n type ReactNode,\n} from 'react';\n\nimport type { Composition } from '../../composition';\nimport type { RenderTheme } from '../../composition/named_color';\nimport type { PrimitiveNode, PrimitiveRenderContext } from '../../define';\n\n/** A pack's React renderer for one node of its own type. */\nexport interface ReactContentDispatcher<\n TNode extends PrimitiveNode,\n TContext = PrimitiveRenderContext,\n> {\n /** Must be side-effect free: the HTML surface calls it twice, once to collect styles and once to render. */\n renderReact(node: TNode, context?: TContext): ReactNode;\n}\n\n/** Options for {@link renderCompositionContent}. */\nexport interface ReactContentOptions {\n /**\n * Renders the composition's title and subtitle as the leading `h2` / `p.sub`.\n * Defaults to `true`. Pass `false` when the host already shows the title\n * itself; the title still backs the wrapper's `aria-label`.\n */\n heading?: boolean;\n}\n\n/**\n * A composition's heading and body as React nodes, without the surrounding\n * document or wrapper element.\n */\nexport const renderCompositionContent = <\n TNode extends PrimitiveNode,\n TContext = PrimitiveRenderContext,\n>(\n composition: Composition<TNode>,\n dispatcher: ReactContentDispatcher<TNode, TContext>,\n context: TContext,\n { heading = true }: ReactContentOptions = {}\n): ReactNode =>\n createElement(\n Fragment,\n null,\n ...[\n heading && composition.title\n ? createElement('h2', { key: 'title' }, composition.title)\n : null,\n heading && composition.subtitle\n ? createElement(\n 'p',\n { key: 'subtitle', className: 'sub' },\n composition.subtitle\n )\n : null,\n ...composition.body.map((node, index) =>\n createElement(RenderedCompositionNode<TNode, TContext>, {\n key: `body-${index}`,\n node,\n context,\n dispatcher,\n })\n ),\n ].filter(Boolean)\n );\n\ninterface RenderedCompositionNodeProps<\n TNode extends PrimitiveNode,\n TContext = PrimitiveRenderContext,\n> {\n node: TNode;\n context: TContext;\n dispatcher: ReactContentDispatcher<TNode, TContext>;\n}\n\nconst RenderedCompositionNode = <TNode extends PrimitiveNode, TContext>({\n node,\n context,\n dispatcher,\n}: RenderedCompositionNodeProps<TNode, TContext>): ReactNode =>\n dispatcher.renderReact(node, context);\n\n/** Options for {@link wrapCompositionContent}. */\nexport interface CompositionWrapperOptions {\n /** Adds the `framed` class. Defaults to `true`. */\n framed?: boolean;\n /** Adds the `fluid` class. */\n fluid?: boolean;\n /** Sets `data-theme`; defaults to the composition's `theme`, and `auto` sets nothing so the page's scheme applies. */\n theme?: RenderTheme;\n /** Used only when the composition has neither `meta.ariaLabel` nor a `title`. Defaults to `'View'`. */\n defaultAriaLabel?: string;\n}\n\n/**\n * The one `.isomer[.framed][.fluid]` `section` every surface wraps rendered\n * content in: the `html` surface's document wrapper and a React host's.\n */\nexport const wrapCompositionContent = <TNode extends PrimitiveNode>(\n content: ReactNode,\n composition: Composition<TNode>,\n {\n framed = true,\n fluid = false,\n theme = composition.theme ?? 'auto',\n defaultAriaLabel = 'View',\n }: CompositionWrapperOptions = {}\n): ReactElement =>\n createElement(\n 'section',\n {\n className: ['isomer', framed ? 'framed' : '', fluid ? 'fluid' : '']\n .filter(Boolean)\n .join(' '),\n role: 'group',\n 'aria-label':\n composition.meta?.ariaLabel ?? composition.title ?? defaultAriaLabel,\n ...(theme === 'auto' ? {} : { 'data-theme': theme }),\n },\n content\n );\n"]}
1
+ {"version":3,"file":"content.js","sourceRoot":"","sources":["../../../../src/render/react/content.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,iCAKe;AAyBf;;;GAGG;AACI,MAAM,wBAAwB,GAAG,CAItC,WAA+B,EAC/B,UAAmD,EACnD,OAAiB,EACjB,EAAE,OAAO,GAAG,IAAI,KAA0B,EAAE,EACjC,EAAE,CACb,IAAA,qBAAa,EACX,gBAAQ,EACR,IAAI,EACJ,GAAG;IACD,OAAO,IAAI,WAAW,CAAC,KAAK;QAC1B,CAAC,CAAC,IAAA,qBAAa,EAAC,IAAI,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,WAAW,CAAC,KAAK,CAAC;QAC1D,CAAC,CAAC,IAAI;IACR,OAAO,IAAI,WAAW,CAAC,QAAQ;QAC7B,CAAC,CAAC,IAAA,qBAAa,EACX,GAAG,EACH,EAAE,GAAG,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,EACrC,WAAW,CAAC,QAAQ,CACrB;QACH,CAAC,CAAC,IAAI;IACR,GAAG,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,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.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nimport {\n createElement,\n Fragment,\n type ReactElement,\n type ReactNode,\n} from 'react';\n\nimport type { Composition } from '../../composition';\nimport type { RenderTheme } from '../../composition/named_color';\nimport type { PrimitiveNode, PrimitiveRenderContext } from '../../define';\n\n/** A pack's React renderer for one node of its own type. */\nexport interface ReactContentDispatcher<\n TNode extends PrimitiveNode,\n TContext = PrimitiveRenderContext,\n> {\n /** Must be side-effect free: the HTML surface calls it twice, once to collect styles and once to render. */\n renderReact(node: TNode, context?: TContext): ReactNode;\n}\n\n/** Options for {@link renderCompositionContent}. */\nexport interface ReactContentOptions {\n /**\n * Renders the composition's title and subtitle as the leading `h2` / `p.sub`.\n * Defaults to `true`. Pass `false` when the host already shows the title\n * itself; the title still backs the wrapper's `aria-label`.\n */\n heading?: boolean;\n}\n\n/**\n * A composition's heading and body as React nodes, without the surrounding\n * document or wrapper element.\n */\nexport const renderCompositionContent = <\n TNode extends PrimitiveNode,\n TContext = PrimitiveRenderContext,\n>(\n composition: Composition<TNode>,\n dispatcher: ReactContentDispatcher<TNode, TContext>,\n context: TContext,\n { heading = true }: ReactContentOptions = {}\n): ReactNode =>\n createElement(\n Fragment,\n null,\n ...[\n heading && composition.title\n ? createElement('h2', { key: 'title' }, composition.title)\n : null,\n heading && composition.subtitle\n ? createElement(\n 'p',\n { key: 'subtitle', className: 'sub' },\n composition.subtitle\n )\n : null,\n ...composition.body.map((node, index) =>\n createElement(RenderedCompositionNode<TNode, TContext>, {\n key: `body-${index}`,\n node,\n context,\n dispatcher,\n })\n ),\n ].filter(Boolean)\n );\n\ninterface RenderedCompositionNodeProps<\n TNode extends PrimitiveNode,\n TContext = PrimitiveRenderContext,\n> {\n node: TNode;\n context: TContext;\n dispatcher: ReactContentDispatcher<TNode, TContext>;\n}\n\nconst RenderedCompositionNode = <TNode extends PrimitiveNode, TContext>({\n node,\n context,\n dispatcher,\n}: RenderedCompositionNodeProps<TNode, TContext>): ReactNode =>\n dispatcher.renderReact(node, context);\n\n/** Options for {@link wrapCompositionContent}. */\nexport interface CompositionWrapperOptions {\n /** Adds the `framed` class. Defaults to `true`. */\n framed?: boolean;\n /** Adds the `fluid` class. */\n fluid?: boolean;\n /** Sets `data-theme` and `color-scheme`, which `light-dark()` resolves against; defaults to the composition's `theme`, and `auto` sets nothing so the page's scheme applies. */\n theme?: RenderTheme;\n /** Used only when the composition has neither `meta.ariaLabel` nor a `title`. Defaults to `'View'`. */\n defaultAriaLabel?: string;\n}\n\n/**\n * The one `.isomer[.framed][.fluid]` `section` every surface wraps rendered\n * content in: the `html` surface's document wrapper and a React host's.\n */\nexport const wrapCompositionContent = <TNode extends PrimitiveNode>(\n content: ReactNode,\n composition: Composition<TNode>,\n {\n framed = true,\n fluid = false,\n theme = composition.theme ?? 'auto',\n defaultAriaLabel = 'View',\n }: CompositionWrapperOptions = {}\n): ReactElement =>\n createElement(\n 'section',\n {\n className: ['isomer', framed ? 'framed' : '', fluid ? 'fluid' : '']\n .filter(Boolean)\n .join(' '),\n role: 'group',\n 'aria-label':\n composition.meta?.ariaLabel ?? composition.title ?? defaultAriaLabel,\n ...(theme === 'auto'\n ? {}\n : { 'data-theme': theme, style: { colorScheme: theme } }),\n },\n content\n );\n"]}
@@ -110,7 +110,8 @@ const unquoted = (node) => node.type === 'blockquote' ? node.children.flatMap(un
110
110
  // nested list follows at the next indent; any other block, such as a table,
111
111
  // follows on its own; what the item holds after either follows unbulleted,
112
112
  // since a Slack list item cannot resume; and the list resumes at its next
113
- // number. A task item's first line leads with its box.
113
+ // number. An empty item keeps its number, so the list resumes past it. A task
114
+ // item's first line leads with its box.
114
115
  const listPieces = (list, indent) => {
115
116
  const style = list.ordered ? 'ordered' : 'bullet';
116
117
  const out = [];
@@ -170,6 +171,11 @@ const listPieces = (list, indent) => {
170
171
  }
171
172
  }
172
173
  emit();
174
+ if (item.children.length === 0) {
175
+ flush();
176
+ number += 1;
177
+ offset = number - 1;
178
+ }
173
179
  }
174
180
  flush();
175
181
  return out;