@promptctl/rich-js 0.10.0 → 0.11.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/LICENSE +21 -0
- package/README.md +20 -110
- package/THIRD-PARTY-NOTICES +81 -0
- package/dist/core/box.d.ts +0 -1
- package/dist/core/box.js +0 -1
- package/dist/core/cells.d.ts +0 -1
- package/dist/core/cells.js +0 -1
- package/dist/core/color.d.ts +6 -1
- package/dist/core/color.js +6 -1
- package/dist/core/console.d.ts +13 -4
- package/dist/core/console.js +78 -87
- package/dist/core/emoji.d.ts +0 -1
- package/dist/core/emoji.js +0 -1
- package/dist/core/export-html.d.ts +24 -0
- package/dist/core/export-html.js +106 -0
- package/dist/core/export-lines.d.ts +121 -0
- package/dist/core/export-lines.js +141 -0
- package/dist/core/highlighter.d.ts +0 -1
- package/dist/core/highlighter.js +0 -1
- package/dist/core/json.d.ts +0 -1
- package/dist/core/json.js +0 -1
- package/dist/core/markup.d.ts +33 -2
- package/dist/core/markup.js +128 -16
- package/dist/core/measure.d.ts +0 -1
- package/dist/core/measure.js +0 -1
- package/dist/core/oklch.d.ts +0 -1
- package/dist/core/oklch.js +0 -1
- package/dist/core/osc8.d.ts +68 -0
- package/dist/core/osc8.js +90 -0
- package/dist/core/pretty.d.ts +21 -2
- package/dist/core/pretty.js +90 -16
- package/dist/core/protocol.d.ts +18 -2
- package/dist/core/protocol.js +0 -1
- package/dist/core/render.d.ts +0 -1
- package/dist/core/render.js +3 -10
- package/dist/core/segment.d.ts +0 -1
- package/dist/core/segment.js +0 -1
- package/dist/core/spinnerData.d.ts +0 -1
- package/dist/core/spinnerData.js +0 -1
- package/dist/core/strip.d.ts +0 -1
- package/dist/core/strip.js +12 -1
- package/dist/core/style.d.ts +1 -7
- package/dist/core/style.js +84 -67
- package/dist/core/subscription.d.ts +0 -1
- package/dist/core/subscription.js +0 -1
- package/dist/core/text.d.ts +1 -8
- package/dist/core/text.js +25 -29
- package/dist/core/wrap.d.ts +0 -1
- package/dist/core/wrap.js +0 -1
- package/dist/host/host-stream.d.ts +0 -1
- package/dist/host/host-stream.js +0 -1
- package/dist/host/index.d.ts +0 -1
- package/dist/host/index.js +0 -1
- package/dist/host/terminal-host.d.ts +0 -1
- package/dist/host/terminal-host.js +0 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.js +3 -2
- package/dist/node/prompt.d.ts +0 -1
- package/dist/node/prompt.js +0 -1
- package/dist/node/save.d.ts +2 -7
- package/dist/node/save.js +0 -1
- package/dist/node/terminal-host.d.ts +0 -1
- package/dist/node/terminal-host.js +0 -1
- package/dist/node/traceback.d.ts +0 -1
- package/dist/node/traceback.js +0 -1
- package/dist/renderables/align.d.ts +0 -1
- package/dist/renderables/align.js +0 -1
- package/dist/renderables/columns.d.ts +12 -1
- package/dist/renderables/columns.js +29 -5
- package/dist/renderables/constrain.d.ts +0 -1
- package/dist/renderables/constrain.js +0 -1
- package/dist/renderables/flexStrip.d.ts +0 -1
- package/dist/renderables/flexStrip.js +0 -1
- package/dist/renderables/group.d.ts +0 -1
- package/dist/renderables/group.js +0 -1
- package/dist/renderables/layout.d.ts +0 -1
- package/dist/renderables/layout.js +20 -7
- package/dist/renderables/live.d.ts +0 -1
- package/dist/renderables/live.js +0 -1
- package/dist/renderables/markdown.d.ts +0 -1
- package/dist/renderables/markdown.js +0 -1
- package/dist/renderables/padding.d.ts +0 -1
- package/dist/renderables/padding.js +0 -1
- package/dist/renderables/panel.d.ts +0 -1
- package/dist/renderables/panel.js +12 -4
- package/dist/renderables/progress.d.ts +0 -1
- package/dist/renderables/progress.js +7 -2
- package/dist/renderables/progressBar.d.ts +0 -1
- package/dist/renderables/progressBar.js +0 -1
- package/dist/renderables/prompt.d.ts +0 -1
- package/dist/renderables/prompt.js +0 -1
- package/dist/renderables/rule.d.ts +0 -1
- package/dist/renderables/rule.js +0 -1
- package/dist/renderables/spinner.d.ts +0 -1
- package/dist/renderables/spinner.js +0 -1
- package/dist/renderables/status.d.ts +0 -1
- package/dist/renderables/status.js +0 -1
- package/dist/renderables/syntax.d.ts +0 -1
- package/dist/renderables/syntax.js +0 -1
- package/dist/renderables/table.d.ts +0 -1
- package/dist/renderables/table.js +8 -3
- package/dist/renderables/traceback.d.ts +8 -7
- package/dist/renderables/traceback.js +14 -10
- package/dist/renderables/tree.d.ts +0 -1
- package/dist/renderables/tree.js +0 -1
- package/dist/template-bindings/color-funcs.d.ts +0 -1
- package/dist/template-bindings/color-funcs.js +0 -1
- package/dist/template-bindings/helpers.d.ts +0 -1
- package/dist/template-bindings/helpers.js +0 -1
- package/dist/template-bindings/index.d.ts +0 -1
- package/dist/template-bindings/index.js +0 -1
- package/dist/template-bindings/palette-funcs.d.ts +0 -1
- package/dist/template-bindings/palette-funcs.js +0 -1
- package/dist/template-bindings/style-funcs.d.ts +0 -1
- package/dist/template-bindings/style-funcs.js +0 -1
- package/dist/themes/buildPalette.d.ts +0 -1
- package/dist/themes/buildPalette.js +0 -1
- package/dist/themes/colorMath.d.ts +0 -1
- package/dist/themes/colorMath.js +0 -1
- package/dist/themes/colorRef.d.ts +0 -1
- package/dist/themes/colorRef.js +0 -1
- package/dist/themes/data/atom-one-dark.d.ts +0 -1
- package/dist/themes/data/atom-one-dark.js +0 -1
- package/dist/themes/data/atom-one-light.d.ts +0 -1
- package/dist/themes/data/atom-one-light.js +0 -1
- package/dist/themes/data/catppuccin-frappe.d.ts +0 -1
- package/dist/themes/data/catppuccin-frappe.js +0 -1
- package/dist/themes/data/catppuccin-latte.d.ts +0 -1
- package/dist/themes/data/catppuccin-latte.js +0 -1
- package/dist/themes/data/catppuccin-macchiato.d.ts +0 -1
- package/dist/themes/data/catppuccin-macchiato.js +0 -1
- package/dist/themes/data/catppuccin-mocha.d.ts +0 -1
- package/dist/themes/data/catppuccin-mocha.js +0 -1
- package/dist/themes/data/cyberpunk.d.ts +0 -1
- package/dist/themes/data/cyberpunk.js +0 -1
- package/dist/themes/data/default.d.ts +0 -1
- package/dist/themes/data/default.js +0 -1
- package/dist/themes/data/dracula.d.ts +0 -1
- package/dist/themes/data/dracula.js +0 -1
- package/dist/themes/data/flexoki.d.ts +0 -1
- package/dist/themes/data/flexoki.js +0 -1
- package/dist/themes/data/gruvbox.d.ts +0 -1
- package/dist/themes/data/gruvbox.js +0 -1
- package/dist/themes/data/index.d.ts +0 -1
- package/dist/themes/data/index.js +0 -1
- package/dist/themes/data/monokai.d.ts +0 -1
- package/dist/themes/data/monokai.js +0 -1
- package/dist/themes/data/nord.d.ts +0 -1
- package/dist/themes/data/nord.js +0 -1
- package/dist/themes/data/rose-pine-dawn.d.ts +0 -1
- package/dist/themes/data/rose-pine-dawn.js +0 -1
- package/dist/themes/data/rose-pine-moon.d.ts +0 -1
- package/dist/themes/data/rose-pine-moon.js +0 -1
- package/dist/themes/data/rose-pine.d.ts +0 -1
- package/dist/themes/data/rose-pine.js +0 -1
- package/dist/themes/data/solarized-dark.d.ts +0 -1
- package/dist/themes/data/solarized-dark.js +0 -1
- package/dist/themes/data/solarized-light.d.ts +0 -1
- package/dist/themes/data/solarized-light.js +0 -1
- package/dist/themes/data/svg-export.d.ts +0 -1
- package/dist/themes/data/svg-export.js +0 -1
- package/dist/themes/data/textual-ansi.d.ts +0 -1
- package/dist/themes/data/textual-ansi.js +0 -1
- package/dist/themes/data/textual-dark.d.ts +0 -1
- package/dist/themes/data/textual-dark.js +0 -1
- package/dist/themes/data/textual-light.d.ts +0 -1
- package/dist/themes/data/textual-light.js +0 -1
- package/dist/themes/data/tokyo-night.d.ts +0 -1
- package/dist/themes/data/tokyo-night.js +0 -1
- package/dist/themes/data/types.d.ts +0 -1
- package/dist/themes/data/types.js +0 -1
- package/dist/themes/palette.d.ts +0 -1
- package/dist/themes/palette.js +0 -1
- package/dist/themes/ramp.d.ts +0 -1
- package/dist/themes/ramp.js +0 -1
- package/dist/themes/registry.d.ts +0 -1
- package/dist/themes/registry.js +0 -1
- package/dist/themes/terminalThemes.d.ts +0 -1
- package/dist/themes/terminalThemes.js +0 -1
- package/dist/themes/transpose.d.ts +0 -1
- package/dist/themes/transpose.js +0 -1
- package/dist/widgets/button.d.ts +0 -1
- package/dist/widgets/button.js +0 -1
- package/dist/widgets/checkbox.d.ts +0 -1
- package/dist/widgets/checkbox.js +0 -1
- package/dist/widgets/dropdown.d.ts +0 -1
- package/dist/widgets/dropdown.js +0 -1
- package/dist/widgets/event-router.d.ts +0 -1
- package/dist/widgets/event-router.js +0 -1
- package/dist/widgets/focus-manager.d.ts +0 -1
- package/dist/widgets/focus-manager.js +0 -1
- package/dist/widgets/index.d.ts +0 -1
- package/dist/widgets/index.js +0 -1
- package/dist/widgets/screen.d.ts +0 -1
- package/dist/widgets/screen.js +0 -1
- package/dist/widgets/slider.d.ts +0 -1
- package/dist/widgets/slider.js +0 -1
- package/dist/widgets/static-item.d.ts +0 -1
- package/dist/widgets/static-item.js +0 -1
- package/dist/widgets/text-input.d.ts +0 -1
- package/dist/widgets/text-input.js +0 -1
- package/dist/widgets/toggle.d.ts +0 -1
- package/dist/widgets/toggle.js +0 -1
- package/dist/widgets/types.d.ts +0 -1
- package/dist/widgets/types.js +0 -1
- package/dist/widgets/widget-base.d.ts +0 -1
- package/dist/widgets/widget-base.js +0 -1
- package/package.json +4 -3
- package/dist/core/box.d.ts.map +0 -1
- package/dist/core/box.js.map +0 -1
- package/dist/core/cells.d.ts.map +0 -1
- package/dist/core/cells.js.map +0 -1
- package/dist/core/color.d.ts.map +0 -1
- package/dist/core/color.js.map +0 -1
- package/dist/core/console.d.ts.map +0 -1
- package/dist/core/console.js.map +0 -1
- package/dist/core/emoji.d.ts.map +0 -1
- package/dist/core/emoji.js.map +0 -1
- package/dist/core/highlighter.d.ts.map +0 -1
- package/dist/core/highlighter.js.map +0 -1
- package/dist/core/json.d.ts.map +0 -1
- package/dist/core/json.js.map +0 -1
- package/dist/core/markup.d.ts.map +0 -1
- package/dist/core/markup.js.map +0 -1
- package/dist/core/measure.d.ts.map +0 -1
- package/dist/core/measure.js.map +0 -1
- package/dist/core/oklch.d.ts.map +0 -1
- package/dist/core/oklch.js.map +0 -1
- package/dist/core/pretty.d.ts.map +0 -1
- package/dist/core/pretty.js.map +0 -1
- package/dist/core/protocol.d.ts.map +0 -1
- package/dist/core/protocol.js.map +0 -1
- package/dist/core/render.d.ts.map +0 -1
- package/dist/core/render.js.map +0 -1
- package/dist/core/sanitize.d.ts +0 -16
- package/dist/core/sanitize.d.ts.map +0 -1
- package/dist/core/sanitize.js +0 -19
- package/dist/core/sanitize.js.map +0 -1
- package/dist/core/segment.d.ts.map +0 -1
- package/dist/core/segment.js.map +0 -1
- package/dist/core/spinnerData.d.ts.map +0 -1
- package/dist/core/spinnerData.js.map +0 -1
- package/dist/core/strip.d.ts.map +0 -1
- package/dist/core/strip.js.map +0 -1
- package/dist/core/style.d.ts.map +0 -1
- package/dist/core/style.js.map +0 -1
- package/dist/core/subscription.d.ts.map +0 -1
- package/dist/core/subscription.js.map +0 -1
- package/dist/core/text.d.ts.map +0 -1
- package/dist/core/text.js.map +0 -1
- package/dist/core/wrap.d.ts.map +0 -1
- package/dist/core/wrap.js.map +0 -1
- package/dist/host/host-stream.d.ts.map +0 -1
- package/dist/host/host-stream.js.map +0 -1
- package/dist/host/index.d.ts.map +0 -1
- package/dist/host/index.js.map +0 -1
- package/dist/host/terminal-host.d.ts.map +0 -1
- package/dist/host/terminal-host.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/node/prompt.d.ts.map +0 -1
- package/dist/node/prompt.js.map +0 -1
- package/dist/node/save.d.ts.map +0 -1
- package/dist/node/save.js.map +0 -1
- package/dist/node/terminal-host.d.ts.map +0 -1
- package/dist/node/terminal-host.js.map +0 -1
- package/dist/node/traceback.d.ts.map +0 -1
- package/dist/node/traceback.js.map +0 -1
- package/dist/renderables/align.d.ts.map +0 -1
- package/dist/renderables/align.js.map +0 -1
- package/dist/renderables/columns.d.ts.map +0 -1
- package/dist/renderables/columns.js.map +0 -1
- package/dist/renderables/constrain.d.ts.map +0 -1
- package/dist/renderables/constrain.js.map +0 -1
- package/dist/renderables/flexStrip.d.ts.map +0 -1
- package/dist/renderables/flexStrip.js.map +0 -1
- package/dist/renderables/group.d.ts.map +0 -1
- package/dist/renderables/group.js.map +0 -1
- package/dist/renderables/layout.d.ts.map +0 -1
- package/dist/renderables/layout.js.map +0 -1
- package/dist/renderables/live.d.ts.map +0 -1
- package/dist/renderables/live.js.map +0 -1
- package/dist/renderables/markdown.d.ts.map +0 -1
- package/dist/renderables/markdown.js.map +0 -1
- package/dist/renderables/padding.d.ts.map +0 -1
- package/dist/renderables/padding.js.map +0 -1
- package/dist/renderables/panel.d.ts.map +0 -1
- package/dist/renderables/panel.js.map +0 -1
- package/dist/renderables/progress.d.ts.map +0 -1
- package/dist/renderables/progress.js.map +0 -1
- package/dist/renderables/progressBar.d.ts.map +0 -1
- package/dist/renderables/progressBar.js.map +0 -1
- package/dist/renderables/prompt.d.ts.map +0 -1
- package/dist/renderables/prompt.js.map +0 -1
- package/dist/renderables/rule.d.ts.map +0 -1
- package/dist/renderables/rule.js.map +0 -1
- package/dist/renderables/spinner.d.ts.map +0 -1
- package/dist/renderables/spinner.js.map +0 -1
- package/dist/renderables/status.d.ts.map +0 -1
- package/dist/renderables/status.js.map +0 -1
- package/dist/renderables/syntax.d.ts.map +0 -1
- package/dist/renderables/syntax.js.map +0 -1
- package/dist/renderables/table.d.ts.map +0 -1
- package/dist/renderables/table.js.map +0 -1
- package/dist/renderables/traceback.d.ts.map +0 -1
- package/dist/renderables/traceback.js.map +0 -1
- package/dist/renderables/tree.d.ts.map +0 -1
- package/dist/renderables/tree.js.map +0 -1
- package/dist/template-bindings/color-funcs.d.ts.map +0 -1
- package/dist/template-bindings/color-funcs.js.map +0 -1
- package/dist/template-bindings/helpers.d.ts.map +0 -1
- package/dist/template-bindings/helpers.js.map +0 -1
- package/dist/template-bindings/index.d.ts.map +0 -1
- package/dist/template-bindings/index.js.map +0 -1
- package/dist/template-bindings/palette-funcs.d.ts.map +0 -1
- package/dist/template-bindings/palette-funcs.js.map +0 -1
- package/dist/template-bindings/style-funcs.d.ts.map +0 -1
- package/dist/template-bindings/style-funcs.js.map +0 -1
- package/dist/themes/buildPalette.d.ts.map +0 -1
- package/dist/themes/buildPalette.js.map +0 -1
- package/dist/themes/colorMath.d.ts.map +0 -1
- package/dist/themes/colorMath.js.map +0 -1
- package/dist/themes/colorRef.d.ts.map +0 -1
- package/dist/themes/colorRef.js.map +0 -1
- package/dist/themes/data/atom-one-dark.d.ts.map +0 -1
- package/dist/themes/data/atom-one-dark.js.map +0 -1
- package/dist/themes/data/atom-one-light.d.ts.map +0 -1
- package/dist/themes/data/atom-one-light.js.map +0 -1
- package/dist/themes/data/catppuccin-frappe.d.ts.map +0 -1
- package/dist/themes/data/catppuccin-frappe.js.map +0 -1
- package/dist/themes/data/catppuccin-latte.d.ts.map +0 -1
- package/dist/themes/data/catppuccin-latte.js.map +0 -1
- package/dist/themes/data/catppuccin-macchiato.d.ts.map +0 -1
- package/dist/themes/data/catppuccin-macchiato.js.map +0 -1
- package/dist/themes/data/catppuccin-mocha.d.ts.map +0 -1
- package/dist/themes/data/catppuccin-mocha.js.map +0 -1
- package/dist/themes/data/cyberpunk.d.ts.map +0 -1
- package/dist/themes/data/cyberpunk.js.map +0 -1
- package/dist/themes/data/default.d.ts.map +0 -1
- package/dist/themes/data/default.js.map +0 -1
- package/dist/themes/data/dracula.d.ts.map +0 -1
- package/dist/themes/data/dracula.js.map +0 -1
- package/dist/themes/data/flexoki.d.ts.map +0 -1
- package/dist/themes/data/flexoki.js.map +0 -1
- package/dist/themes/data/gruvbox.d.ts.map +0 -1
- package/dist/themes/data/gruvbox.js.map +0 -1
- package/dist/themes/data/index.d.ts.map +0 -1
- package/dist/themes/data/index.js.map +0 -1
- package/dist/themes/data/monokai.d.ts.map +0 -1
- package/dist/themes/data/monokai.js.map +0 -1
- package/dist/themes/data/nord.d.ts.map +0 -1
- package/dist/themes/data/nord.js.map +0 -1
- package/dist/themes/data/rose-pine-dawn.d.ts.map +0 -1
- package/dist/themes/data/rose-pine-dawn.js.map +0 -1
- package/dist/themes/data/rose-pine-moon.d.ts.map +0 -1
- package/dist/themes/data/rose-pine-moon.js.map +0 -1
- package/dist/themes/data/rose-pine.d.ts.map +0 -1
- package/dist/themes/data/rose-pine.js.map +0 -1
- package/dist/themes/data/solarized-dark.d.ts.map +0 -1
- package/dist/themes/data/solarized-dark.js.map +0 -1
- package/dist/themes/data/solarized-light.d.ts.map +0 -1
- package/dist/themes/data/solarized-light.js.map +0 -1
- package/dist/themes/data/svg-export.d.ts.map +0 -1
- package/dist/themes/data/svg-export.js.map +0 -1
- package/dist/themes/data/textual-ansi.d.ts.map +0 -1
- package/dist/themes/data/textual-ansi.js.map +0 -1
- package/dist/themes/data/textual-dark.d.ts.map +0 -1
- package/dist/themes/data/textual-dark.js.map +0 -1
- package/dist/themes/data/textual-light.d.ts.map +0 -1
- package/dist/themes/data/textual-light.js.map +0 -1
- package/dist/themes/data/tokyo-night.d.ts.map +0 -1
- package/dist/themes/data/tokyo-night.js.map +0 -1
- package/dist/themes/data/types.d.ts.map +0 -1
- package/dist/themes/data/types.js.map +0 -1
- package/dist/themes/palette.d.ts.map +0 -1
- package/dist/themes/palette.js.map +0 -1
- package/dist/themes/ramp.d.ts.map +0 -1
- package/dist/themes/ramp.js.map +0 -1
- package/dist/themes/registry.d.ts.map +0 -1
- package/dist/themes/registry.js.map +0 -1
- package/dist/themes/terminalThemes.d.ts.map +0 -1
- package/dist/themes/terminalThemes.js.map +0 -1
- package/dist/themes/transpose.d.ts.map +0 -1
- package/dist/themes/transpose.js.map +0 -1
- package/dist/widgets/button.d.ts.map +0 -1
- package/dist/widgets/button.js.map +0 -1
- package/dist/widgets/checkbox.d.ts.map +0 -1
- package/dist/widgets/checkbox.js.map +0 -1
- package/dist/widgets/dropdown.d.ts.map +0 -1
- package/dist/widgets/dropdown.js.map +0 -1
- package/dist/widgets/event-router.d.ts.map +0 -1
- package/dist/widgets/event-router.js.map +0 -1
- package/dist/widgets/focus-manager.d.ts.map +0 -1
- package/dist/widgets/focus-manager.js.map +0 -1
- package/dist/widgets/index.d.ts.map +0 -1
- package/dist/widgets/index.js.map +0 -1
- package/dist/widgets/screen.d.ts.map +0 -1
- package/dist/widgets/screen.js.map +0 -1
- package/dist/widgets/slider.d.ts.map +0 -1
- package/dist/widgets/slider.js.map +0 -1
- package/dist/widgets/static-item.d.ts.map +0 -1
- package/dist/widgets/static-item.js.map +0 -1
- package/dist/widgets/text-input.d.ts.map +0 -1
- package/dist/widgets/text-input.js.map +0 -1
- package/dist/widgets/toggle.d.ts.map +0 -1
- package/dist/widgets/toggle.js.map +0 -1
- package/dist/widgets/types.d.ts.map +0 -1
- package/dist/widgets/types.js.map +0 -1
- package/dist/widgets/widget-base.d.ts.map +0 -1
- package/dist/widgets/widget-base.js.map +0 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* export-html — recorded segments drawn as a standalone HTML document.
|
|
3
|
+
*
|
|
4
|
+
* An encoding of `export-lines` and nothing more. What a run looks like under
|
|
5
|
+
* a theme is decided there; this module decides only how CSS says it. It never
|
|
6
|
+
* sees a `Style`, so it cannot disagree with the SVG exporter about what
|
|
7
|
+
* `reverse` or `dim` means — the two old converters that did disagree were
|
|
8
|
+
* deleted when this replaced them.
|
|
9
|
+
*
|
|
10
|
+
* The rows are already laid out at console width, so `pre` never re-wraps
|
|
11
|
+
* them: `white-space: pre`, and a scrollbar rather than a reflow when the page
|
|
12
|
+
* is narrower than the terminal was.
|
|
13
|
+
*/
|
|
14
|
+
import type { TerminalTheme } from "./color.js";
|
|
15
|
+
import type { Segment } from "./segment.js";
|
|
16
|
+
/**
|
|
17
|
+
* `segments` under `theme` as a complete HTML document.
|
|
18
|
+
*
|
|
19
|
+
* A browser draws no line for a newline at either edge of a `pre`: the parser
|
|
20
|
+
* drops the one straight after `<pre>`, and the one before `</pre>` ends a
|
|
21
|
+
* line without starting another. So the page opens with a newline of its own
|
|
22
|
+
* and every row ends with one, and a blank first or last row is still drawn.
|
|
23
|
+
*/
|
|
24
|
+
export declare function encodeHtml(segments: Iterable<Segment>, theme?: TerminalTheme): string;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* export-html — recorded segments drawn as a standalone HTML document.
|
|
3
|
+
*
|
|
4
|
+
* An encoding of `export-lines` and nothing more. What a run looks like under
|
|
5
|
+
* a theme is decided there; this module decides only how CSS says it. It never
|
|
6
|
+
* sees a `Style`, so it cannot disagree with the SVG exporter about what
|
|
7
|
+
* `reverse` or `dim` means — the two old converters that did disagree were
|
|
8
|
+
* deleted when this replaced them.
|
|
9
|
+
*
|
|
10
|
+
* The rows are already laid out at console width, so `pre` never re-wraps
|
|
11
|
+
* them: `white-space: pre`, and a scrollbar rather than a reflow when the page
|
|
12
|
+
* is narrower than the terminal was.
|
|
13
|
+
*/
|
|
14
|
+
import { exportCanvas, exportLines } from "./export-lines.js";
|
|
15
|
+
const ENTITIES = { "&": "&", "<": "<", ">": ">", '"': """ };
|
|
16
|
+
const escapeText = (text) => text.replace(/[&<>]/g, (c) => ENTITIES[c]);
|
|
17
|
+
const escapeAttribute = (value) => value.replace(/[&"<>]/g, (c) => ENTITIES[c]);
|
|
18
|
+
const BLINK_KEYFRAMES = "rich-blink";
|
|
19
|
+
// [LAW:dataflow-not-control-flow] Each enum-valued field of a look is a table
|
|
20
|
+
// from its values to the declarations it adds, so every value is spelled once
|
|
21
|
+
// and `Record` makes a new value a compile error until it has a row.
|
|
22
|
+
// A double underline adds no line to the glyph's own span; `runHtml` draws it.
|
|
23
|
+
const UNDERLINE_LINE = {
|
|
24
|
+
none: [],
|
|
25
|
+
single: ["underline"],
|
|
26
|
+
double: [],
|
|
27
|
+
};
|
|
28
|
+
const BLINK = {
|
|
29
|
+
none: [],
|
|
30
|
+
slow: [`animation:${BLINK_KEYFRAMES} 1s step-end infinite`],
|
|
31
|
+
fast: [`animation:${BLINK_KEYFRAMES} 0.5s step-end infinite`],
|
|
32
|
+
};
|
|
33
|
+
const FRAME = "box-shadow:inset 0 0 0 1px currentColor";
|
|
34
|
+
const OUTLINE = {
|
|
35
|
+
none: [],
|
|
36
|
+
frame: [FRAME],
|
|
37
|
+
encircle: [FRAME, "border-radius:0.5em"],
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* The glyph colour, and the background when one is painted.
|
|
41
|
+
*
|
|
42
|
+
* Dim arrives already blended into `foreground`. `opacity` is never written:
|
|
43
|
+
* it fades a painted background along with the glyph, which is the bug the
|
|
44
|
+
* blend exists to avoid.
|
|
45
|
+
*/
|
|
46
|
+
function paintCss(look) {
|
|
47
|
+
return [
|
|
48
|
+
`color:${look.foreground.hex}`,
|
|
49
|
+
...(look.background === "canvas" ? [] : [`background-color:${look.background.hex}`]),
|
|
50
|
+
];
|
|
51
|
+
}
|
|
52
|
+
/** What is drawn on the glyph: weight, slant, single-style lines, blink, outline. */
|
|
53
|
+
function glyphCss(look) {
|
|
54
|
+
const lines = [
|
|
55
|
+
...UNDERLINE_LINE[look.underline],
|
|
56
|
+
...(look.strike ? ["line-through"] : []),
|
|
57
|
+
...(look.overline ? ["overline"] : []),
|
|
58
|
+
];
|
|
59
|
+
return [
|
|
60
|
+
...(look.bold ? ["font-weight:bold"] : []),
|
|
61
|
+
...(look.italic ? ["font-style:italic"] : []),
|
|
62
|
+
...(lines.length === 0 ? [] : [`text-decoration-line:${lines.join(" ")}`]),
|
|
63
|
+
...BLINK[look.blink],
|
|
64
|
+
...OUTLINE[look.outline],
|
|
65
|
+
];
|
|
66
|
+
}
|
|
67
|
+
const span = (css, content) => `<span style="${escapeAttribute(css.join(";"))}">${content}</span>`;
|
|
68
|
+
/**
|
|
69
|
+
* One run as markup.
|
|
70
|
+
*
|
|
71
|
+
* An element has one `text-decoration-style`, so a double underline sharing a
|
|
72
|
+
* span with a strike would double the strike too. It gets an outer span of its
|
|
73
|
+
* own instead. That span carries the paint, because a descendant's background
|
|
74
|
+
* may be painted over an ancestor's underline, and the blink, so the underline
|
|
75
|
+
* blinks with the glyph.
|
|
76
|
+
*/
|
|
77
|
+
function runHtml({ text, look }) {
|
|
78
|
+
const glyph = escapeText(text);
|
|
79
|
+
const drawn = look.underline === "double"
|
|
80
|
+
? span([...paintCss(look), "text-decoration-line:underline", "text-decoration-style:double", ...BLINK[look.blink]], span([`color:${look.foreground.hex}`, ...glyphCss(look)], glyph))
|
|
81
|
+
: span([...paintCss(look), ...glyphCss(look)], glyph);
|
|
82
|
+
return look.href === null ? drawn : `<a href="${escapeAttribute(look.href)}">${drawn}</a>`;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* `segments` under `theme` as a complete HTML document.
|
|
86
|
+
*
|
|
87
|
+
* A browser draws no line for a newline at either edge of a `pre`: the parser
|
|
88
|
+
* drops the one straight after `<pre>`, and the one before `</pre>` ends a
|
|
89
|
+
* line without starting another. So the page opens with a newline of its own
|
|
90
|
+
* and every row ends with one, and a blank first or last row is still drawn.
|
|
91
|
+
*/
|
|
92
|
+
export function encodeHtml(segments, theme) {
|
|
93
|
+
const canvas = exportCanvas(theme);
|
|
94
|
+
const rows = exportLines(segments, theme).map((row) => `${row.map(runHtml).join("")}\n`);
|
|
95
|
+
const css = [
|
|
96
|
+
`body{background:${canvas.background.hex};color:${canvas.foreground.hex};padding:1em}`,
|
|
97
|
+
"pre{margin:0;font-family:monospace;white-space:pre;overflow-x:auto}",
|
|
98
|
+
"a{color:inherit;text-decoration:inherit}",
|
|
99
|
+
`@keyframes ${BLINK_KEYFRAMES}{50%{color:transparent}}`,
|
|
100
|
+
].join("\n");
|
|
101
|
+
return [
|
|
102
|
+
"<!DOCTYPE html>",
|
|
103
|
+
`<html><head><meta charset="utf-8"><style>\n${css}\n</style></head>`,
|
|
104
|
+
`<body><pre>\n${rows.join("")}</pre></body></html>`,
|
|
105
|
+
].join("\n");
|
|
106
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* export-lines — recorded segments resolved against a `TerminalTheme` into the
|
|
3
|
+
* lines every exporter draws.
|
|
4
|
+
*
|
|
5
|
+
* The HTML and SVG exporters are two encodings of one picture, and this module
|
|
6
|
+
* is the picture. What a styled cell *looks like* — which colour its glyph is,
|
|
7
|
+
* whether its background is painted, which decorations it carries, where it
|
|
8
|
+
* links — is decided here, once, and an exporter decides only how to write
|
|
9
|
+
* that down. Before it existed the decision was made twice, by a CSS method
|
|
10
|
+
* on `Style` and by a private converter on `Console`, and the two had already
|
|
11
|
+
* disagreed: one honoured `underline2`, the other dropped it.
|
|
12
|
+
*
|
|
13
|
+
* [LAW:types-are-the-program] `ExportLook` has no `reverse`, `dim`, `conceal`
|
|
14
|
+
* or default colour, because all four are consumed by `resolveLook` and turned
|
|
15
|
+
* into plain RGB. An exporter holding a look cannot forget to swap a reversed
|
|
16
|
+
* run or to fade a dim one: there is nothing left in its hands to forget. That
|
|
17
|
+
* is the whole reason the representation is resolved rather than a `Style`
|
|
18
|
+
* handed through.
|
|
19
|
+
*
|
|
20
|
+
* Runs rather than a cell grid. A grid gives a wide character a phantom
|
|
21
|
+
* continuation cell every consumer must know to skip, and gives an HTML
|
|
22
|
+
* exporter — which lays text out by flowing it — nothing it needs. A run's
|
|
23
|
+
* column and cell width are `cellLen` of the text before it and of its own
|
|
24
|
+
* text; they are not stored, so they cannot disagree with the text
|
|
25
|
+
* [LAW:one-source-of-truth]. The SVG exporter, the one consumer that positions
|
|
26
|
+
* anything, derives them.
|
|
27
|
+
*
|
|
28
|
+
* Browser-safe by construction: this imports `color`, `style`, `segment` and
|
|
29
|
+
* nothing that touches the host, so `Console` can reach it from the main
|
|
30
|
+
* barrel and the fs half of exporting stays in `src/node/save.ts`.
|
|
31
|
+
*/
|
|
32
|
+
import { type ColorRgba, type TerminalTheme } from "./color.js";
|
|
33
|
+
import { type Style } from "./style.js";
|
|
34
|
+
import type { Segment } from "./segment.js";
|
|
35
|
+
declare const _href: unique symbol;
|
|
36
|
+
/**
|
|
37
|
+
* A link target that is safe to write into a published document.
|
|
38
|
+
*
|
|
39
|
+
* [LAW:parse-dont-validate] Only `parseHref` produces one, so an exporter that
|
|
40
|
+
* writes an `href` attribute from an `Href` cannot have skipped the check.
|
|
41
|
+
*/
|
|
42
|
+
export type Href = string & {
|
|
43
|
+
readonly [_href]: true;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Where a run's background comes from. `"canvas"` is the theme background
|
|
47
|
+
* showing through — nothing painted — and is distinct from a painted colour
|
|
48
|
+
* that happens to equal it, because `on default` and `on #000000` are
|
|
49
|
+
* different requests even over a black theme.
|
|
50
|
+
*/
|
|
51
|
+
export type Background = ColorRgba | "canvas";
|
|
52
|
+
/** Everything an exporter needs to draw one run, and nothing left to resolve. */
|
|
53
|
+
export interface ExportLook {
|
|
54
|
+
readonly foreground: ColorRgba;
|
|
55
|
+
readonly background: Background;
|
|
56
|
+
readonly bold: boolean;
|
|
57
|
+
readonly italic: boolean;
|
|
58
|
+
readonly underline: "none" | "single" | "double";
|
|
59
|
+
readonly strike: boolean;
|
|
60
|
+
readonly overline: boolean;
|
|
61
|
+
readonly blink: "none" | "slow" | "fast";
|
|
62
|
+
readonly outline: "none" | "frame" | "encircle";
|
|
63
|
+
readonly href: Href | null;
|
|
64
|
+
}
|
|
65
|
+
export interface ExportRun {
|
|
66
|
+
readonly text: string;
|
|
67
|
+
readonly look: ExportLook;
|
|
68
|
+
}
|
|
69
|
+
/** One terminal row, left to right. An empty array is a blank row. */
|
|
70
|
+
export type ExportLine = readonly ExportRun[];
|
|
71
|
+
/**
|
|
72
|
+
* `Style.link` as a link an export may write, or `null` when it may not.
|
|
73
|
+
*
|
|
74
|
+
* A refused link loses only its target: the run keeps its text and every other
|
|
75
|
+
* attribute, so nothing the terminal showed disappears from the export. The
|
|
76
|
+
* canonical `URL.href` is what comes back, since the parse is what vouches for
|
|
77
|
+
* it.
|
|
78
|
+
*/
|
|
79
|
+
export declare function parseHref(link: string): Href | null;
|
|
80
|
+
/** What an unstyled cell shows under a theme: the canvas, and ink on it. */
|
|
81
|
+
export interface ExportCanvas {
|
|
82
|
+
readonly background: ColorRgba;
|
|
83
|
+
readonly foreground: ColorRgba;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The ground every export is drawn on under `theme`.
|
|
87
|
+
*
|
|
88
|
+
* An exporter paints its page or window with this; `resolveLook` flattens
|
|
89
|
+
* every run over the same `background`, so a run showing the canvas and the
|
|
90
|
+
* page around it cannot come out different colours.
|
|
91
|
+
*/
|
|
92
|
+
export declare function exportCanvas(theme?: TerminalTheme): ExportCanvas;
|
|
93
|
+
/**
|
|
94
|
+
* A `Style` as it appears on screen under `theme`.
|
|
95
|
+
*
|
|
96
|
+
* The order is the terminal's: colours resolve through the theme and lose
|
|
97
|
+
* their alpha — paper over the canvas, ink over the paper, as `toSgrCodes`
|
|
98
|
+
* flattens them — `reverse` swaps them, `dim` fades the glyph toward whatever
|
|
99
|
+
* background it ended up on, and `conceal` finally paints the glyph in that
|
|
100
|
+
* background. Every step after flattening works on opaque colour, so no
|
|
101
|
+
* exporter ever draws a translucent one. Text under `conceal` is still
|
|
102
|
+
* present, and still selectable, in both formats.
|
|
103
|
+
*
|
|
104
|
+
* The one difference from `toSgrCodes` is the substrate: a terminal cannot
|
|
105
|
+
* know what lies under its cells and assumes black, while an export draws its
|
|
106
|
+
* own canvas and flattens over that.
|
|
107
|
+
*
|
|
108
|
+
* `theme` omitted is `ColorSpec.getTruecolor`'s own fallback — black canvas,
|
|
109
|
+
* white ink, the standard ANSI table. Choosing it there rather than naming a
|
|
110
|
+
* preset here is what keeps `core/` from a third upward edge into `themes/`.
|
|
111
|
+
*/
|
|
112
|
+
export declare function resolveLook(style: Style, theme?: TerminalTheme): ExportLook;
|
|
113
|
+
/**
|
|
114
|
+
* Recorded segments as terminal rows under `theme`.
|
|
115
|
+
*
|
|
116
|
+
* `"\n"` ends a row, so output that ends with a newline — every `print` does —
|
|
117
|
+
* has no empty row after it, and `"a\n\nb"` keeps its blank row. Callers pass
|
|
118
|
+
* the recording buffer, which already holds no control segments.
|
|
119
|
+
*/
|
|
120
|
+
export declare function exportLines(segments: Iterable<Segment>, theme?: TerminalTheme): ExportLine[];
|
|
121
|
+
export {};
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* export-lines — recorded segments resolved against a `TerminalTheme` into the
|
|
3
|
+
* lines every exporter draws.
|
|
4
|
+
*
|
|
5
|
+
* The HTML and SVG exporters are two encodings of one picture, and this module
|
|
6
|
+
* is the picture. What a styled cell *looks like* — which colour its glyph is,
|
|
7
|
+
* whether its background is painted, which decorations it carries, where it
|
|
8
|
+
* links — is decided here, once, and an exporter decides only how to write
|
|
9
|
+
* that down. Before it existed the decision was made twice, by a CSS method
|
|
10
|
+
* on `Style` and by a private converter on `Console`, and the two had already
|
|
11
|
+
* disagreed: one honoured `underline2`, the other dropped it.
|
|
12
|
+
*
|
|
13
|
+
* [LAW:types-are-the-program] `ExportLook` has no `reverse`, `dim`, `conceal`
|
|
14
|
+
* or default colour, because all four are consumed by `resolveLook` and turned
|
|
15
|
+
* into plain RGB. An exporter holding a look cannot forget to swap a reversed
|
|
16
|
+
* run or to fade a dim one: there is nothing left in its hands to forget. That
|
|
17
|
+
* is the whole reason the representation is resolved rather than a `Style`
|
|
18
|
+
* handed through.
|
|
19
|
+
*
|
|
20
|
+
* Runs rather than a cell grid. A grid gives a wide character a phantom
|
|
21
|
+
* continuation cell every consumer must know to skip, and gives an HTML
|
|
22
|
+
* exporter — which lays text out by flowing it — nothing it needs. A run's
|
|
23
|
+
* column and cell width are `cellLen` of the text before it and of its own
|
|
24
|
+
* text; they are not stored, so they cannot disagree with the text
|
|
25
|
+
* [LAW:one-source-of-truth]. The SVG exporter, the one consumer that positions
|
|
26
|
+
* anything, derives them.
|
|
27
|
+
*
|
|
28
|
+
* Browser-safe by construction: this imports `color`, `style`, `segment` and
|
|
29
|
+
* nothing that touches the host, so `Console` can reach it from the main
|
|
30
|
+
* barrel and the fs half of exporting stays in `src/node/save.ts`.
|
|
31
|
+
*/
|
|
32
|
+
import { blendRgb, ColorSpec } from "./color.js";
|
|
33
|
+
import { NULL_STYLE } from "./style.js";
|
|
34
|
+
/**
|
|
35
|
+
* The URL schemes an export will link.
|
|
36
|
+
*
|
|
37
|
+
* A terminal hands an OSC 8 target to the user's opener; an exported page hands
|
|
38
|
+
* it to whoever loads the page, and exports are made to be published. A
|
|
39
|
+
* `javascript:` target that was inert in a terminal is script in a README. The
|
|
40
|
+
* list is an allowance, not a denylist, so a scheme nobody considered is
|
|
41
|
+
* refused rather than trusted.
|
|
42
|
+
*/
|
|
43
|
+
const LINKABLE_SCHEMES = new Set(["http:", "https:", "mailto:", "ftp:", "file:"]);
|
|
44
|
+
/**
|
|
45
|
+
* `Style.link` as a link an export may write, or `null` when it may not.
|
|
46
|
+
*
|
|
47
|
+
* A refused link loses only its target: the run keeps its text and every other
|
|
48
|
+
* attribute, so nothing the terminal showed disappears from the export. The
|
|
49
|
+
* canonical `URL.href` is what comes back, since the parse is what vouches for
|
|
50
|
+
* it.
|
|
51
|
+
*/
|
|
52
|
+
export function parseHref(link) {
|
|
53
|
+
if (!URL.canParse(link))
|
|
54
|
+
return null;
|
|
55
|
+
const url = new URL(link);
|
|
56
|
+
return LINKABLE_SCHEMES.has(url.protocol) ? url.href : null;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* How far a dim glyph moves toward its background — Rich's own factor, so an
|
|
60
|
+
* export of the same program matches the library this ports.
|
|
61
|
+
*/
|
|
62
|
+
const DIM_FADE = 0.4;
|
|
63
|
+
const DEFAULT_COLOR = ColorSpec.default();
|
|
64
|
+
/**
|
|
65
|
+
* The ground every export is drawn on under `theme`.
|
|
66
|
+
*
|
|
67
|
+
* An exporter paints its page or window with this; `resolveLook` flattens
|
|
68
|
+
* every run over the same `background`, so a run showing the canvas and the
|
|
69
|
+
* page around it cannot come out different colours.
|
|
70
|
+
*/
|
|
71
|
+
export function exportCanvas(theme) {
|
|
72
|
+
return {
|
|
73
|
+
background: DEFAULT_COLOR.getTruecolor(theme, false),
|
|
74
|
+
foreground: DEFAULT_COLOR.getTruecolor(theme, true),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* A `Style` as it appears on screen under `theme`.
|
|
79
|
+
*
|
|
80
|
+
* The order is the terminal's: colours resolve through the theme and lose
|
|
81
|
+
* their alpha — paper over the canvas, ink over the paper, as `toSgrCodes`
|
|
82
|
+
* flattens them — `reverse` swaps them, `dim` fades the glyph toward whatever
|
|
83
|
+
* background it ended up on, and `conceal` finally paints the glyph in that
|
|
84
|
+
* background. Every step after flattening works on opaque colour, so no
|
|
85
|
+
* exporter ever draws a translucent one. Text under `conceal` is still
|
|
86
|
+
* present, and still selectable, in both formats.
|
|
87
|
+
*
|
|
88
|
+
* The one difference from `toSgrCodes` is the substrate: a terminal cannot
|
|
89
|
+
* know what lies under its cells and assumes black, while an export draws its
|
|
90
|
+
* own canvas and flattens over that.
|
|
91
|
+
*
|
|
92
|
+
* `theme` omitted is `ColorSpec.getTruecolor`'s own fallback — black canvas,
|
|
93
|
+
* white ink, the standard ANSI table. Choosing it there rather than naming a
|
|
94
|
+
* preset here is what keeps `core/` from a third upward edge into `themes/`.
|
|
95
|
+
*/
|
|
96
|
+
export function resolveLook(style, theme) {
|
|
97
|
+
const inkSpec = style.color ?? DEFAULT_COLOR;
|
|
98
|
+
const paperSpec = style.bgcolor ?? DEFAULT_COLOR;
|
|
99
|
+
const canvas = exportCanvas(theme).background;
|
|
100
|
+
// [LAW:single-enforcer] `flattenAlpha` is the one place alpha is composited.
|
|
101
|
+
const paper = paperSpec.flattenAlpha(canvas).getTruecolor(theme, false);
|
|
102
|
+
const ink = inkSpec.flattenAlpha(paper).getTruecolor(theme, true);
|
|
103
|
+
// A reversed run always paints: its background is the ink, which is never
|
|
104
|
+
// the canvas, even when the ink is the theme's default foreground.
|
|
105
|
+
const glyph = style.reverse ? paper : ink;
|
|
106
|
+
const ground = style.reverse ? ink : paper;
|
|
107
|
+
const background = style.reverse || !paperSpec.isDefault ? ground : "canvas";
|
|
108
|
+
const faded = style.dim ? blendRgb(glyph, ground, DIM_FADE) : glyph;
|
|
109
|
+
return {
|
|
110
|
+
foreground: style.conceal ? ground : faded,
|
|
111
|
+
background,
|
|
112
|
+
bold: style.bold === true,
|
|
113
|
+
italic: style.italic === true,
|
|
114
|
+
underline: style.underline2 ? "double" : style.underline ? "single" : "none",
|
|
115
|
+
strike: style.strike === true,
|
|
116
|
+
overline: style.overline === true,
|
|
117
|
+
blink: style.blink2 ? "fast" : style.blink ? "slow" : "none",
|
|
118
|
+
outline: style.encircle ? "encircle" : style.frame ? "frame" : "none",
|
|
119
|
+
href: style.link === undefined ? null : parseHref(style.link),
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Recorded segments as terminal rows under `theme`.
|
|
124
|
+
*
|
|
125
|
+
* `"\n"` ends a row, so output that ends with a newline — every `print` does —
|
|
126
|
+
* has no empty row after it, and `"a\n\nb"` keeps its blank row. Callers pass
|
|
127
|
+
* the recording buffer, which already holds no control segments.
|
|
128
|
+
*/
|
|
129
|
+
export function exportLines(segments, theme) {
|
|
130
|
+
const rows = [[]];
|
|
131
|
+
for (const segment of segments) {
|
|
132
|
+
const look = resolveLook(segment.style ?? NULL_STYLE, theme);
|
|
133
|
+
segment.text.split("\n").forEach((piece, index) => {
|
|
134
|
+
if (index > 0)
|
|
135
|
+
rows.push([]);
|
|
136
|
+
if (piece.length > 0)
|
|
137
|
+
rows[rows.length - 1].push({ text: piece, look });
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
return rows[rows.length - 1].length === 0 ? rows.slice(0, -1) : rows;
|
|
141
|
+
}
|
package/dist/core/highlighter.js
CHANGED
package/dist/core/json.d.ts
CHANGED
package/dist/core/json.js
CHANGED
package/dist/core/markup.d.ts
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* (`[bold]a[italic]b[/bold]c[/italic]`) because a style is an annotation and
|
|
15
15
|
* annotations may overlap freely; a plugin tag is a replacement whose handler
|
|
16
16
|
* takes one contiguous `inner`, so an overlapping pair has no slice to hand it
|
|
17
|
-
* and is rejected with a `
|
|
17
|
+
* and is rejected with a `MarkupSyntaxError`.
|
|
18
18
|
*/
|
|
19
19
|
import { Style } from "./style.js";
|
|
20
20
|
import { RichText } from "./text.js";
|
|
@@ -28,6 +28,38 @@ export declare class Tag {
|
|
|
28
28
|
export declare class MarkupError extends Error {
|
|
29
29
|
constructor(message: string);
|
|
30
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* A markup string that cannot be parsed, with where it went wrong.
|
|
33
|
+
*
|
|
34
|
+
* [LAW:types-are-the-program] A subclass rather than optional fields on
|
|
35
|
+
* `MarkupError`, because the parent is also what `MarkupRegistry.register`
|
|
36
|
+
* throws, and a registration has no source text to point into. Every error this
|
|
37
|
+
* class describes has a location, so none of its fields is optional and no
|
|
38
|
+
* caller has to ask whether one is present — `instanceof` is the only question.
|
|
39
|
+
*
|
|
40
|
+
* [LAW:one-source-of-truth] The constructor takes the facts the parser holds —
|
|
41
|
+
* the string, the offset of the offending tag, what was open — and derives
|
|
42
|
+
* `line`, `column` and the message from them, so the numbers a caller reads
|
|
43
|
+
* and the caret the message draws cannot disagree.
|
|
44
|
+
*/
|
|
45
|
+
export declare class MarkupSyntaxError extends MarkupError {
|
|
46
|
+
/** The problem alone, with no location, for callers building their own message. */
|
|
47
|
+
readonly reason: string;
|
|
48
|
+
/** The whole markup string that failed, as the caller passed it. */
|
|
49
|
+
readonly markup: string;
|
|
50
|
+
/** Index into `markup` of the tag the parser rejected. */
|
|
51
|
+
readonly offset: number;
|
|
52
|
+
/** 1-based line of `offset`; lines are separated by `\n`. */
|
|
53
|
+
readonly line: number;
|
|
54
|
+
/** 1-based column of `offset` within its line, in UTF-16 code units. */
|
|
55
|
+
readonly column: number;
|
|
56
|
+
/**
|
|
57
|
+
* The opening tags still open at `offset`, outermost first, as written. For
|
|
58
|
+
* overlapping plugin tags, only plugin tags are named.
|
|
59
|
+
*/
|
|
60
|
+
readonly openTags: readonly string[];
|
|
61
|
+
constructor(reason: string, markup: string, offset: number, openTags: readonly string[]);
|
|
62
|
+
}
|
|
31
63
|
/**
|
|
32
64
|
* Escapes markup characters so they render as literal text.
|
|
33
65
|
*/
|
|
@@ -63,4 +95,3 @@ export interface RenderMarkupOptions {
|
|
|
63
95
|
* append path is uniform.
|
|
64
96
|
*/
|
|
65
97
|
export declare function renderMarkup(markup: string, options?: RenderMarkupOptions): RichText;
|
|
66
|
-
//# sourceMappingURL=markup.d.ts.map
|