arethesis 0.1.5 → 0.2.1
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/CHANGELOG.md +66 -0
- package/README.md +5 -4
- package/dist/arethesis.js +2 -147
- package/dist/binding/data-binder.d.ts +8 -0
- package/dist/binding/data-binder.d.ts.map +1 -1
- package/dist/binding/data-binder.js +605 -0
- package/dist/binding/data-binder.js.map +1 -0
- package/dist/binding/types.d.ts +20 -0
- package/dist/binding/types.d.ts.map +1 -1
- package/dist/binding/validation-engine.js +160 -0
- package/dist/binding/validation-engine.js.map +1 -0
- package/dist/cdn/arethesis.min.js +2 -0
- package/dist/cdn/arethesis.min.js.map +1 -0
- package/dist/cdn/chunks/CdTL-MEv.min.js +3 -0
- package/dist/cdn/chunks/CdTL-MEv.min.js.map +1 -0
- package/dist/cdn/components.min.js +81 -0
- package/dist/cdn/components.min.js.map +1 -0
- package/dist/collab/index.d.ts +22 -0
- package/dist/collab/index.d.ts.map +1 -0
- package/dist/collab/index.js +23 -0
- package/dist/collab/index.js.map +1 -0
- package/dist/components/component.d.ts +17 -0
- package/dist/components/component.d.ts.map +1 -1
- package/dist/components/component.js +765 -0
- package/dist/components/component.js.map +1 -0
- package/dist/components/decorators.js +27 -0
- package/dist/components/decorators.js.map +1 -0
- package/dist/components/form-associated.d.ts +55 -0
- package/dist/components/form-associated.d.ts.map +1 -0
- package/dist/components/form-associated.js +180 -0
- package/dist/components/form-associated.js.map +1 -0
- package/dist/components/runtime.d.ts +2 -0
- package/dist/components/runtime.d.ts.map +1 -1
- package/dist/components/runtime.js +18 -0
- package/dist/components/runtime.js.map +1 -0
- package/dist/components/template-loader.js +90 -0
- package/dist/components/template-loader.js.map +1 -0
- package/dist/components.js +2 -606
- package/dist/core/arethesis.d.ts +13 -9
- package/dist/core/arethesis.d.ts.map +1 -1
- package/dist/core/arethesis.js +249 -0
- package/dist/core/arethesis.js.map +1 -0
- package/dist/core/hooks.d.ts +19 -0
- package/dist/core/hooks.d.ts.map +1 -0
- package/dist/core/hooks.js +23 -0
- package/dist/core/hooks.js.map +1 -0
- package/dist/core/index.d.ts +57 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +25 -0
- package/dist/data/list-view-registry.js +300 -0
- package/dist/data/list-view-registry.js.map +1 -0
- package/dist/data/object-store.js +280 -0
- package/dist/data/object-store.js.map +1 -0
- package/dist/data/optimistic-updates.js +168 -0
- package/dist/data/optimistic-updates.js.map +1 -0
- package/dist/data/persistence-manager.js +233 -0
- package/dist/data/persistence-manager.js.map +1 -0
- package/dist/defaults.d.ts +1 -0
- package/dist/defaults.d.ts.map +1 -0
- package/dist/defaults.js +17 -0
- package/dist/defaults.js.map +1 -0
- package/dist/http/auth-manager.js +260 -0
- package/dist/http/auth-manager.js.map +1 -0
- package/dist/http/http-client.d.ts +7 -0
- package/dist/http/http-client.d.ts.map +1 -1
- package/dist/http/http-client.js +501 -0
- package/dist/http/http-client.js.map +1 -0
- package/dist/http/http-error.js +53 -0
- package/dist/http/http-error.js.map +1 -0
- package/dist/http/mapping.js +64 -0
- package/dist/http/mapping.js.map +1 -0
- package/dist/index.d.ts +3 -52
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +55 -0
- package/dist/kit/calendar.d.ts +43 -0
- package/dist/kit/calendar.d.ts.map +1 -0
- package/dist/kit/calendar.js +423 -0
- package/dist/kit/calendar.js.map +1 -0
- package/dist/kit/cell-editor.d.ts +47 -0
- package/dist/kit/cell-editor.d.ts.map +1 -0
- package/dist/kit/cell-editor.js +191 -0
- package/dist/kit/cell-editor.js.map +1 -0
- package/dist/kit/chart.d.ts +57 -0
- package/dist/kit/chart.d.ts.map +1 -0
- package/dist/kit/chart.js +541 -0
- package/dist/kit/chart.js.map +1 -0
- package/dist/kit/combobox.d.ts +57 -0
- package/dist/kit/combobox.d.ts.map +1 -0
- package/dist/kit/combobox.js +379 -0
- package/dist/kit/combobox.js.map +1 -0
- package/dist/kit/command-palette.d.ts +54 -0
- package/dist/kit/command-palette.d.ts.map +1 -0
- package/dist/kit/command-palette.js +315 -0
- package/dist/kit/command-palette.js.map +1 -0
- package/dist/kit/data-table.d.ts +17 -1
- package/dist/kit/data-table.d.ts.map +1 -1
- package/dist/kit/data-table.js +373 -0
- package/dist/kit/data-table.js.map +1 -0
- package/dist/kit/dialog.d.ts +31 -0
- package/dist/kit/dialog.d.ts.map +1 -0
- package/dist/kit/dialog.js +157 -0
- package/dist/kit/dialog.js.map +1 -0
- package/dist/kit/elements/calendar.d.ts +3 -0
- package/dist/kit/elements/calendar.d.ts.map +1 -0
- package/dist/kit/elements/calendar.js +11 -0
- package/dist/kit/elements/calendar.js.map +1 -0
- package/dist/kit/elements/chart.d.ts +3 -0
- package/dist/kit/elements/chart.d.ts.map +1 -0
- package/dist/kit/elements/chart.js +11 -0
- package/dist/kit/elements/chart.js.map +1 -0
- package/dist/kit/elements/combobox.d.ts +3 -0
- package/dist/kit/elements/combobox.d.ts.map +1 -0
- package/dist/kit/elements/combobox.js +11 -0
- package/dist/kit/elements/combobox.js.map +1 -0
- package/dist/kit/elements/command-palette.d.ts +3 -0
- package/dist/kit/elements/command-palette.d.ts.map +1 -0
- package/dist/kit/elements/command-palette.js +11 -0
- package/dist/kit/elements/command-palette.js.map +1 -0
- package/dist/kit/elements/data-table.d.ts +3 -0
- package/dist/kit/elements/data-table.d.ts.map +1 -0
- package/dist/kit/elements/data-table.js +11 -0
- package/dist/kit/elements/data-table.js.map +1 -0
- package/dist/kit/elements/dialog.d.ts +4 -0
- package/dist/kit/elements/dialog.d.ts.map +1 -0
- package/dist/kit/elements/dialog.js +11 -0
- package/dist/kit/elements/dialog.js.map +1 -0
- package/dist/kit/elements/flex-view.d.ts +3 -0
- package/dist/kit/elements/flex-view.d.ts.map +1 -0
- package/dist/kit/elements/flex-view.js +11 -0
- package/dist/kit/elements/flex-view.js.map +1 -0
- package/dist/kit/elements/form.d.ts +3 -0
- package/dist/kit/elements/form.d.ts.map +1 -0
- package/dist/kit/elements/form.js +11 -0
- package/dist/kit/elements/form.js.map +1 -0
- package/dist/kit/elements/kanban.d.ts +3 -0
- package/dist/kit/elements/kanban.d.ts.map +1 -0
- package/dist/kit/elements/kanban.js +11 -0
- package/dist/kit/elements/kanban.js.map +1 -0
- package/dist/kit/elements/list.d.ts +3 -0
- package/dist/kit/elements/list.d.ts.map +1 -0
- package/dist/kit/elements/list.js +11 -0
- package/dist/kit/elements/list.js.map +1 -0
- package/dist/kit/elements/markdown-editor.d.ts +3 -0
- package/dist/kit/elements/markdown-editor.d.ts.map +1 -0
- package/dist/kit/elements/markdown-editor.js +11 -0
- package/dist/kit/elements/markdown-editor.js.map +1 -0
- package/dist/kit/elements/presence.d.ts +3 -0
- package/dist/kit/elements/presence.d.ts.map +1 -0
- package/dist/kit/elements/presence.js +11 -0
- package/dist/kit/elements/presence.js.map +1 -0
- package/dist/kit/elements/sheet.d.ts +3 -0
- package/dist/kit/elements/sheet.d.ts.map +1 -0
- package/dist/kit/elements/sheet.js +11 -0
- package/dist/kit/elements/sheet.js.map +1 -0
- package/dist/kit/elements/tabs.d.ts +3 -0
- package/dist/kit/elements/tabs.d.ts.map +1 -0
- package/dist/kit/elements/tabs.js +11 -0
- package/dist/kit/elements/tabs.js.map +1 -0
- package/dist/kit/elements/toast.d.ts +4 -0
- package/dist/kit/elements/toast.d.ts.map +1 -0
- package/dist/kit/elements/toast.js +11 -0
- package/dist/kit/elements/toast.js.map +1 -0
- package/dist/kit/elements/tree.d.ts +3 -0
- package/dist/kit/elements/tree.d.ts.map +1 -0
- package/dist/kit/elements/tree.js +11 -0
- package/dist/kit/elements/tree.js.map +1 -0
- package/dist/kit/flex-view.d.ts +2 -0
- package/dist/kit/flex-view.d.ts.map +1 -1
- package/dist/kit/flex-view.js +346 -0
- package/dist/kit/flex-view.js.map +1 -0
- package/dist/kit/form.d.ts +2 -0
- package/dist/kit/form.d.ts.map +1 -1
- package/dist/kit/form.js +211 -0
- package/dist/kit/form.js.map +1 -0
- package/dist/kit/index.d.ts +33 -16
- package/dist/kit/index.d.ts.map +1 -1
- package/dist/kit/index.js +40 -0
- package/dist/kit/internal/modal.d.ts +26 -0
- package/dist/kit/internal/modal.d.ts.map +1 -0
- package/dist/kit/internal/modal.js +59 -0
- package/dist/kit/internal/modal.js.map +1 -0
- package/dist/kit/kanban.d.ts +73 -0
- package/dist/kit/kanban.d.ts.map +1 -0
- package/dist/kit/kanban.js +404 -0
- package/dist/kit/kanban.js.map +1 -0
- package/dist/kit/list.d.ts +4 -0
- package/dist/kit/list.d.ts.map +1 -1
- package/dist/kit/list.js +106 -0
- package/dist/kit/list.js.map +1 -0
- package/dist/kit/markdown/highlight.d.ts +29 -0
- package/dist/kit/markdown/highlight.d.ts.map +1 -0
- package/dist/kit/markdown/highlight.js +106 -0
- package/dist/kit/markdown/highlight.js.map +1 -0
- package/dist/kit/markdown/render.d.ts +31 -0
- package/dist/kit/markdown/render.d.ts.map +1 -0
- package/dist/kit/markdown/render.js +260 -0
- package/dist/kit/markdown/render.js.map +1 -0
- package/dist/kit/markdown-editor.d.ts +54 -0
- package/dist/kit/markdown-editor.d.ts.map +1 -0
- package/dist/kit/markdown-editor.js +797 -0
- package/dist/kit/markdown-editor.js.map +1 -0
- package/dist/kit/presence.d.ts +36 -0
- package/dist/kit/presence.d.ts.map +1 -0
- package/dist/kit/presence.js +262 -0
- package/dist/kit/presence.js.map +1 -0
- package/dist/kit/sheet/formula.d.ts +106 -0
- package/dist/kit/sheet/formula.d.ts.map +1 -0
- package/dist/kit/sheet/formula.js +364 -0
- package/dist/kit/sheet/formula.js.map +1 -0
- package/dist/kit/sheet/model.d.ts +28 -0
- package/dist/kit/sheet/model.d.ts.map +1 -0
- package/dist/kit/sheet/model.js +136 -0
- package/dist/kit/sheet/model.js.map +1 -0
- package/dist/kit/sheet/sheet.d.ts +47 -0
- package/dist/kit/sheet/sheet.d.ts.map +1 -0
- package/dist/kit/sheet/sheet.js +676 -0
- package/dist/kit/sheet/sheet.js.map +1 -0
- package/dist/kit/tabs.d.ts +17 -0
- package/dist/kit/tabs.d.ts.map +1 -0
- package/dist/kit/tabs.js +192 -0
- package/dist/kit/tabs.js.map +1 -0
- package/dist/kit/theme-boot.generated.d.ts +2 -0
- package/dist/kit/theme-boot.generated.d.ts.map +1 -1
- package/dist/kit/theme-boot.generated.js +8 -0
- package/dist/kit/theme-boot.generated.js.map +1 -0
- package/dist/kit/theme.d.ts +5 -3
- package/dist/kit/theme.d.ts.map +1 -1
- package/dist/kit/theme.js +89 -0
- package/dist/kit/theme.js.map +1 -0
- package/dist/kit/toast.d.ts +46 -0
- package/dist/kit/toast.d.ts.map +1 -0
- package/dist/kit/toast.js +154 -0
- package/dist/kit/toast.js.map +1 -0
- package/dist/kit/tree.d.ts +41 -0
- package/dist/kit/tree.d.ts.map +1 -0
- package/dist/kit/tree.js +422 -0
- package/dist/kit/tree.js.map +1 -0
- package/dist/mixins/context-menu.d.ts.map +1 -1
- package/dist/mixins/context-menu.js +183 -0
- package/dist/mixins/context-menu.js.map +1 -0
- package/dist/mixins/draggable.d.ts.map +1 -1
- package/dist/mixins/draggable.js +140 -0
- package/dist/mixins/draggable.js.map +1 -0
- package/dist/mixins/dropdown.d.ts.map +1 -1
- package/dist/mixins/dropdown.js +216 -0
- package/dist/mixins/dropdown.js.map +1 -0
- package/dist/mixins/editable.d.ts.map +1 -1
- package/dist/mixins/editable.js +175 -0
- package/dist/mixins/editable.js.map +1 -0
- package/dist/mixins/grid-navigation.d.ts.map +1 -1
- package/dist/mixins/grid-navigation.js +194 -0
- package/dist/mixins/grid-navigation.js.map +1 -0
- package/dist/mixins/index.d.ts +8 -2
- package/dist/mixins/index.d.ts.map +1 -1
- package/dist/mixins/index.js +38 -0
- package/dist/mixins/index.js.map +1 -0
- package/dist/mixins/infinite-scroll.d.ts.map +1 -1
- package/dist/mixins/infinite-scroll.js +83 -0
- package/dist/mixins/infinite-scroll.js.map +1 -0
- package/dist/mixins/listbox.d.ts +19 -0
- package/dist/mixins/listbox.d.ts.map +1 -0
- package/dist/mixins/listbox.js +208 -0
- package/dist/mixins/listbox.js.map +1 -0
- package/dist/mixins/popup.d.ts +36 -0
- package/dist/mixins/popup.d.ts.map +1 -0
- package/dist/mixins/popup.js +113 -0
- package/dist/mixins/popup.js.map +1 -0
- package/dist/mixins/registry.d.ts +6 -0
- package/dist/mixins/registry.d.ts.map +1 -1
- package/dist/mixins/registry.js +167 -0
- package/dist/mixins/registry.js.map +1 -0
- package/dist/mixins/resizable.d.ts.map +1 -1
- package/dist/mixins/resizable.js +128 -0
- package/dist/mixins/resizable.js.map +1 -0
- package/dist/mixins/sortable.d.ts.map +1 -1
- package/dist/mixins/sortable.js +511 -0
- package/dist/mixins/sortable.js.map +1 -0
- package/dist/mixins/tooltip.d.ts.map +1 -1
- package/dist/mixins/tooltip.js +80 -0
- package/dist/mixins/tooltip.js.map +1 -0
- package/dist/mixins/utils.js +105 -0
- package/dist/mixins/utils.js.map +1 -0
- package/dist/plugins/async-validators.js +118 -0
- package/dist/plugins/async-validators.js.map +1 -0
- package/dist/plugins/builtins.d.ts +1 -1
- package/dist/plugins/builtins.d.ts.map +1 -1
- package/dist/plugins/builtins.js +20 -0
- package/dist/plugins/builtins.js.map +1 -0
- package/dist/plugins/date-utils.js +128 -0
- package/dist/plugins/date-utils.js.map +1 -0
- package/dist/plugins/plugin-manager.d.ts.map +1 -1
- package/dist/plugins/plugin-manager.js +99 -0
- package/dist/plugins/plugin-manager.js.map +1 -0
- package/dist/plugins/rich-text.js +365 -0
- package/dist/plugins/rich-text.js.map +1 -0
- package/dist/realtime/azure-pubsub-manager.js +273 -0
- package/dist/realtime/azure-pubsub-manager.js.map +1 -0
- package/dist/realtime/collab/anchors.d.ts +10 -0
- package/dist/realtime/collab/anchors.d.ts.map +1 -0
- package/dist/realtime/collab/anchors.js +19 -0
- package/dist/realtime/collab/anchors.js.map +1 -0
- package/dist/realtime/collab/collab-session.d.ts +46 -1
- package/dist/realtime/collab/collab-session.d.ts.map +1 -1
- package/dist/realtime/collab/collab-session.js +396 -0
- package/dist/realtime/collab/collab-session.js.map +1 -0
- package/dist/realtime/collab/cursor-overlay.d.ts +10 -0
- package/dist/realtime/collab/cursor-overlay.d.ts.map +1 -1
- package/dist/realtime/collab/cursor-overlay.js +187 -0
- package/dist/realtime/collab/cursor-overlay.js.map +1 -0
- package/dist/realtime/collab/textarea-adapter.d.ts +13 -0
- package/dist/realtime/collab/textarea-adapter.d.ts.map +1 -1
- package/dist/realtime/collab/textarea-adapter.js +125 -0
- package/dist/realtime/collab/textarea-adapter.js.map +1 -0
- package/dist/realtime/collab/undo-manager.d.ts +44 -0
- package/dist/realtime/collab/undo-manager.d.ts.map +1 -0
- package/dist/realtime/collab/undo-manager.js +148 -0
- package/dist/realtime/collab/undo-manager.js.map +1 -0
- package/dist/realtime/index.d.ts +11 -0
- package/dist/realtime/index.d.ts.map +1 -0
- package/dist/realtime/index.js +22 -0
- package/dist/realtime/index.js.map +1 -0
- package/dist/realtime/ot/client.d.ts +1 -1
- package/dist/realtime/ot/client.d.ts.map +1 -1
- package/dist/realtime/ot/client.js +74 -0
- package/dist/realtime/ot/client.js.map +1 -0
- package/dist/realtime/ot/server.d.ts +13 -1
- package/dist/realtime/ot/server.d.ts.map +1 -1
- package/dist/realtime/ot/server.js +292 -0
- package/dist/realtime/ot/server.js.map +1 -0
- package/dist/realtime/ot/text-operation.js +282 -0
- package/dist/realtime/ot/text-operation.js.map +1 -0
- package/dist/realtime/reconnect.js +58 -0
- package/dist/realtime/reconnect.js.map +1 -0
- package/dist/realtime/sse-manager.js +172 -0
- package/dist/realtime/sse-manager.js.map +1 -0
- package/dist/realtime/types.d.ts +29 -1
- package/dist/realtime/types.d.ts.map +1 -1
- package/dist/realtime/websocket-manager.js +180 -0
- package/dist/realtime/websocket-manager.js.map +1 -0
- package/dist/theme-polychrome-boot.js +17 -0
- package/dist/theme-polychrome.css +310 -0
- package/dist/theme.css +490 -1
- package/dist/tokens/base.tokens.json +18 -0
- package/dist/tokens/dark-high-contrast.tokens.json +11 -0
- package/dist/tokens/dark.tokens.json +81 -0
- package/dist/tokens/light-high-contrast.tokens.json +11 -0
- package/dist/tokens/light.tokens.json +81 -0
- package/dist/tokens/polychrome.base.tokens.json +45 -0
- package/dist/tokens/polychrome.dark-high-contrast.tokens.json +183 -0
- package/dist/tokens/polychrome.dark.tokens.json +321 -0
- package/dist/tokens/polychrome.light-high-contrast.tokens.json +115 -0
- package/dist/tokens/polychrome.light.tokens.json +418 -0
- package/dist/tokens/polychrome.resolver.json +78 -0
- package/dist/utils/backoff.js +30 -0
- package/dist/utils/backoff.js.map +1 -0
- package/dist/utils/dates.js +67 -0
- package/dist/utils/dates.js.map +1 -0
- package/dist/utils/dom.js +30 -0
- package/dist/utils/dom.js.map +1 -0
- package/dist/utils/emitter.js +40 -0
- package/dist/utils/emitter.js.map +1 -0
- package/dist/utils/fuzzy.d.ts +23 -0
- package/dist/utils/fuzzy.d.ts.map +1 -0
- package/dist/utils/fuzzy.js +95 -0
- package/dist/utils/fuzzy.js.map +1 -0
- package/dist/utils/path.js +99 -0
- package/dist/utils/path.js.map +1 -0
- package/dist/utils/sanitize.js +161 -0
- package/dist/utils/sanitize.js.map +1 -0
- package/dist/utils/url.js +44 -0
- package/dist/utils/url.js.map +1 -0
- package/dist/utils/virtual-window.d.ts +25 -0
- package/dist/utils/virtual-window.d.ts.map +1 -0
- package/dist/utils/virtual-window.js +19 -0
- package/dist/utils/virtual-window.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +6 -0
- package/dist/version.js.map +1 -0
- package/package.json +63 -11
- package/dist/arethesis-jPH9QdQE.js +0 -5345
- package/dist/arethesis-jPH9QdQE.js.map +0 -1
- package/dist/arethesis.js.map +0 -1
- package/dist/components.js.map +0 -1
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// src/kit/markdown/highlight.ts
|
|
2
|
+
var START_STATE = { fence: null };
|
|
3
|
+
var esc = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
4
|
+
var span = (cls, html) => html ? `<span class="${cls}">${html}</span>` : "";
|
|
5
|
+
var FENCE = /^( {0,3})(`{3,}|~{3,})(.*)$/;
|
|
6
|
+
var HEADING = /^( {0,3})(#{1,6})(\s.*|)$/;
|
|
7
|
+
var RULE = /^ {0,3}([-*_])(?:\s*\1){2,}\s*$/;
|
|
8
|
+
var QUOTE = /^( {0,3}>)( ?)(.*)$/;
|
|
9
|
+
var LIST = /^(\s*)([-*+]|\d{1,9}[.)])(\s+)(\[[ xX]\](?=\s))?(.*)$/;
|
|
10
|
+
var TABLE_DIVIDER = /^\s*\|?\s*:?-{3,}:?\s*(\|\s*:?-{3,}:?\s*)*\|?\s*$/;
|
|
11
|
+
/** Inline tokens, longest first. Each alternative's whole match is one token. */
|
|
12
|
+
var INLINE = /(`+)[\s\S]*?\1|!?\[[^\]\n]*\]\([^)\n]*\)|<(?:https?|mailto):[^\s<>]+>|(\*\*|__)(?=\S)[\s\S]*?\S\2|~~(?=\S)[\s\S]*?\S~~|(?<![\w*])\*(?=\S)[^*\n]*?\S\*(?!\*)|(?<!\w)_(?=\S)[^_\n]*?\S_(?!\w)|\\[\\`*_{}[\]()#+\-.!~|<>]/g;
|
|
13
|
+
/** Highlight inline Markdown. */
|
|
14
|
+
function highlightInline(text) {
|
|
15
|
+
let out = "";
|
|
16
|
+
let last = 0;
|
|
17
|
+
for (const m of text.matchAll(INLINE)) {
|
|
18
|
+
const t = m[0];
|
|
19
|
+
out += esc(text.slice(last, m.index));
|
|
20
|
+
last = m.index + t.length;
|
|
21
|
+
if (t.startsWith("`")) {
|
|
22
|
+
const fence = m[1];
|
|
23
|
+
out += span("md-code", span("md-punct", esc(fence)) + esc(t.slice(fence.length, -fence.length)) + span("md-punct", esc(fence)));
|
|
24
|
+
} else if (t.startsWith("[") || t.startsWith(";
|
|
26
|
+
const open = t.startsWith("!") ? 2 : 1;
|
|
27
|
+
out += span("md-link", span("md-punct", esc(t.slice(0, open))) + highlightInline(t.slice(open, close)) + span("md-punct", "](") + span("md-url", esc(t.slice(close + 2, -1))) + span("md-punct", ")"));
|
|
28
|
+
} else if (t.startsWith("<")) out += span("md-url", esc(t));
|
|
29
|
+
else if (t.startsWith("**") || t.startsWith("__")) out += span("md-strong", span("md-punct", t.slice(0, 2)) + highlightInline(t.slice(2, -2)) + span("md-punct", t.slice(-2)));
|
|
30
|
+
else if (t.startsWith("~~")) out += span("md-del", span("md-punct", "~~") + highlightInline(t.slice(2, -2)) + span("md-punct", "~~"));
|
|
31
|
+
else if (t.startsWith("\\")) out += span("md-punct", esc(t));
|
|
32
|
+
else out += span("md-em", span("md-punct", t[0]) + highlightInline(t.slice(1, -1)) + span("md-punct", t[0]));
|
|
33
|
+
}
|
|
34
|
+
return out + esc(text.slice(last));
|
|
35
|
+
}
|
|
36
|
+
/** Highlight one line, given the state after the previous line. */
|
|
37
|
+
function highlightLine(line, state) {
|
|
38
|
+
if (state.fence) {
|
|
39
|
+
const close = FENCE.exec(line);
|
|
40
|
+
if (close && close[2][0] === state.fence[0] && close[2].length >= state.fence.length && !close[3].trim()) return {
|
|
41
|
+
html: span("md-fence", esc(line)),
|
|
42
|
+
state: START_STATE
|
|
43
|
+
};
|
|
44
|
+
return {
|
|
45
|
+
html: span("md-codeblock", esc(line)),
|
|
46
|
+
state
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
const fence = FENCE.exec(line);
|
|
50
|
+
if (fence && !(fence[2][0] === "`" && fence[3].includes("`"))) return {
|
|
51
|
+
html: span("md-fence", esc(fence[1] + fence[2])) + span("md-lang", esc(fence[3])),
|
|
52
|
+
state: { fence: fence[2] }
|
|
53
|
+
};
|
|
54
|
+
const heading = HEADING.exec(line);
|
|
55
|
+
if (heading) {
|
|
56
|
+
const level = heading[2].length;
|
|
57
|
+
return {
|
|
58
|
+
html: span(`md-h md-h${level}`, esc(heading[1]) + span("md-punct", heading[2]) + highlightInline(heading[3])),
|
|
59
|
+
state
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
if (RULE.test(line)) return {
|
|
63
|
+
html: span("md-hr", esc(line)),
|
|
64
|
+
state
|
|
65
|
+
};
|
|
66
|
+
const quote = QUOTE.exec(line);
|
|
67
|
+
if (quote) {
|
|
68
|
+
const inner = highlightLine(quote[3], START_STATE).html;
|
|
69
|
+
return {
|
|
70
|
+
html: span("md-quote", span("md-punct", esc(quote[1])) + quote[2] + inner),
|
|
71
|
+
state
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
const list = LIST.exec(line);
|
|
75
|
+
if (list) {
|
|
76
|
+
const task = list[4] ? span(/x/i.test(list[4]) ? "md-task is-done" : "md-task", esc(list[4])) : "";
|
|
77
|
+
return {
|
|
78
|
+
html: esc(list[1]) + span("md-list", esc(list[2])) + list[3] + task + highlightInline(list[5]),
|
|
79
|
+
state
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
if (TABLE_DIVIDER.test(line) && line.includes("|")) return {
|
|
83
|
+
html: span("md-punct", esc(line)),
|
|
84
|
+
state
|
|
85
|
+
};
|
|
86
|
+
if (line.includes("|") && /^\s*\|/.test(line)) return {
|
|
87
|
+
html: line.split(/(?<!\\)(\|)/).map((part) => part === "|" ? span("md-punct", "|") : highlightInline(part)).join(""),
|
|
88
|
+
state
|
|
89
|
+
};
|
|
90
|
+
return {
|
|
91
|
+
html: highlightInline(line),
|
|
92
|
+
state
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/** Highlight a whole document; returns one HTML string per line. */
|
|
96
|
+
function highlightMarkdown(source) {
|
|
97
|
+
let state = START_STATE;
|
|
98
|
+
return source.split("\n").map((line) => {
|
|
99
|
+
const result = highlightLine(line, state);
|
|
100
|
+
state = result.state;
|
|
101
|
+
return result.html;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
export { START_STATE, highlightInline, highlightLine, highlightMarkdown };
|
|
105
|
+
|
|
106
|
+
//# sourceMappingURL=highlight.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"highlight.js","names":[],"sources":["../../../src/kit/markdown/highlight.ts"],"sourcesContent":["/**\n * Markdown syntax highlighting for a source editor, one line at a time.\n *\n * The output's text is exactly the input's (only wrapped in spans), so it\n * can sit behind a transparent textarea and line up character for\n * character. Only colors and weights change, never widths, provided the\n * font is monospaced.\n *\n * Lines are highlighted independently given the state left by the previous\n * line (whether it's inside a fenced code block), so an editor only has to\n * re-highlight the lines that changed.\n *\n * @module kit/markdown/highlight\n */\n\nexport interface LineState {\n /** The opening fence (``` or ~~~…) while inside a code block. */\n fence: string | null;\n}\n\nexport const START_STATE: LineState = { fence: null };\n\nconst esc = (s: string): string => s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');\nconst span = (cls: string, html: string): string => (html ? `<span class=\"${cls}\">${html}</span>` : '');\n\nconst FENCE = /^( {0,3})(`{3,}|~{3,})(.*)$/;\nconst HEADING = /^( {0,3})(#{1,6})(\\s.*|)$/;\nconst RULE = /^ {0,3}([-*_])(?:\\s*\\1){2,}\\s*$/;\nconst QUOTE = /^( {0,3}>)( ?)(.*)$/;\nconst LIST = /^(\\s*)([-*+]|\\d{1,9}[.)])(\\s+)(\\[[ xX]\\](?=\\s))?(.*)$/;\nconst TABLE_DIVIDER = /^\\s*\\|?\\s*:?-{3,}:?\\s*(\\|\\s*:?-{3,}:?\\s*)*\\|?\\s*$/;\n\n/** Inline tokens, longest first. Each alternative's whole match is one token. */\nconst INLINE = /(`+)[\\s\\S]*?\\1|!?\\[[^\\]\\n]*\\]\\([^)\\n]*\\)|<(?:https?|mailto):[^\\s<>]+>|(\\*\\*|__)(?=\\S)[\\s\\S]*?\\S\\2|~~(?=\\S)[\\s\\S]*?\\S~~|(?<![\\w*])\\*(?=\\S)[^*\\n]*?\\S\\*(?!\\*)|(?<!\\w)_(?=\\S)[^_\\n]*?\\S_(?!\\w)|\\\\[\\\\`*_{}[\\]()#+\\-.!~|<>]/g;\n\n/** Highlight inline Markdown. */\nexport function highlightInline(text: string): string {\n let out = '';\n let last = 0;\n for (const m of text.matchAll(INLINE)) {\n const t = m[0];\n out += esc(text.slice(last, m.index));\n last = m.index! + t.length;\n if (t.startsWith('`')) {\n const fence = m[1];\n out += span('md-code', span('md-punct', esc(fence)) + esc(t.slice(fence.length, -fence.length)) + span('md-punct', esc(fence)));\n } else if (t.startsWith('[') || t.startsWith(';\n const open = t.startsWith('!') ? 2 : 1;\n out += span('md-link', span('md-punct', esc(t.slice(0, open))) + highlightInline(t.slice(open, close)) + span('md-punct', '](') + span('md-url', esc(t.slice(close + 2, -1))) + span('md-punct', ')'));\n } else if (t.startsWith('<')) {\n out += span('md-url', esc(t));\n } else if (t.startsWith('**') || t.startsWith('__')) {\n out += span('md-strong', span('md-punct', t.slice(0, 2)) + highlightInline(t.slice(2, -2)) + span('md-punct', t.slice(-2)));\n } else if (t.startsWith('~~')) {\n out += span('md-del', span('md-punct', '~~') + highlightInline(t.slice(2, -2)) + span('md-punct', '~~'));\n } else if (t.startsWith('\\\\')) {\n out += span('md-punct', esc(t));\n } else {\n out += span('md-em', span('md-punct', t[0]) + highlightInline(t.slice(1, -1)) + span('md-punct', t[0]));\n }\n }\n return out + esc(text.slice(last));\n}\n\n/** Highlight one line, given the state after the previous line. */\nexport function highlightLine(line: string, state: LineState): { html: string; state: LineState } {\n if (state.fence) {\n const close = FENCE.exec(line);\n if (close && close[2][0] === state.fence[0] && close[2].length >= state.fence.length && !close[3].trim()) {\n return { html: span('md-fence', esc(line)), state: START_STATE };\n }\n return { html: span('md-codeblock', esc(line)), state };\n }\n const fence = FENCE.exec(line);\n if (fence && !(fence[2][0] === '`' && fence[3].includes('`'))) {\n return { html: span('md-fence', esc(fence[1] + fence[2])) + span('md-lang', esc(fence[3])), state: { fence: fence[2] } };\n }\n const heading = HEADING.exec(line);\n if (heading) {\n const level = heading[2].length;\n return { html: span(`md-h md-h${level}`, esc(heading[1]) + span('md-punct', heading[2]) + highlightInline(heading[3])), state };\n }\n if (RULE.test(line)) return { html: span('md-hr', esc(line)), state };\n const quote = QUOTE.exec(line);\n if (quote) {\n // A quote can hold a list or heading: highlight the rest as its own line.\n const inner = highlightLine(quote[3], START_STATE).html;\n return { html: span('md-quote', span('md-punct', esc(quote[1])) + quote[2] + inner), state };\n }\n const list = LIST.exec(line);\n if (list) {\n const task = list[4] ? span(/x/i.test(list[4]) ? 'md-task is-done' : 'md-task', esc(list[4])) : '';\n return { html: esc(list[1]) + span('md-list', esc(list[2])) + list[3] + task + highlightInline(list[5]), state };\n }\n if (TABLE_DIVIDER.test(line) && line.includes('|')) return { html: span('md-punct', esc(line)), state };\n if (line.includes('|') && /^\\s*\\|/.test(line)) {\n return { html: line.split(/(?<!\\\\)(\\|)/).map(part => (part === '|' ? span('md-punct', '|') : highlightInline(part))).join(''), state };\n }\n return { html: highlightInline(line), state };\n}\n\n/** Highlight a whole document; returns one HTML string per line. */\nexport function highlightMarkdown(source: string): string[] {\n let state = START_STATE;\n return source.split('\\n').map(line => {\n const result = highlightLine(line, state);\n state = result.state;\n return result.html;\n });\n}\n"],"mappings":";AAoBA,IAAa,cAAyB,EAAE,OAAO,KAAK;AAEpD,IAAM,OAAO,MAAsB,EAAE,QAAQ,MAAM,OAAO,CAAC,CAAC,QAAQ,MAAM,MAAM,CAAC,CAAC,QAAQ,MAAM,MAAM;AACtG,IAAM,QAAQ,KAAa,SAA0B,OAAO,gBAAgB,IAAI,IAAI,KAAK,WAAW;AAEpG,IAAM,QAAQ;AACd,IAAM,UAAU;AAChB,IAAM,OAAO;AACb,IAAM,QAAQ;AACd,IAAM,OAAO;AACb,IAAM,gBAAgB;;AAGtB,IAAM,SAAS;;AAGf,SAAgB,gBAAgB,MAAsB;CACpD,IAAI,MAAM;CACV,IAAI,OAAO;CACX,KAAK,MAAM,KAAK,KAAK,SAAS,MAAM,GAAG;EACrC,MAAM,IAAI,EAAE;EACZ,OAAO,IAAI,KAAK,MAAM,MAAM,EAAE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D,OAAO;GAAE,MAAM,KAAK,YAAY,KAAK,YAAY,IAAI,MAAM,EAAE,CAAC,IAAI,MAAM,KAAK,KAAK;GAAG;EAAM;CAC7F;CACA,MAAM,OAAO,KAAK,KAAK,IAAI;CAC3B,IAAI,MAAM;EACR,MAAM,OAAO,KAAK,KAAK,KAAK,KAAK,KAAK,KAAK,EAAE,IAAI,oBAAoB,WAAW,IAAI,KAAK,EAAE,CAAC,IAAI;EAChG,OAAO;GAAE,MAAM,IAAI,KAAK,EAAE,IAAI,KAAK,WAAW,IAAI,KAAK,EAAE,CAAC,IAAI,KAAK,KAAK,OAAO,gBAAgB,KAAK,EAAE;GAAG;EAAM;CACjH;CACA,IAAI,cAAc,KAAK,IAAI,KAAK,KAAK,SAAS,GAAG,GAAG,OAAO;EAAE,MAAM,KAAK,YAAY,IAAI,IAAI,CAAC;EAAG;CAAM;CACtG,IAAI,KAAK,SAAS,GAAG,KAAK,SAAS,KAAK,IAAI,GAC1C,OAAO;EAAE,MAAM,KAAK,MAAM,aAAa,CAAC,CAAC,KAAI,SAAS,SAAS,MAAM,KAAK,YAAY,GAAG,IAAI,gBAAgB,IAAI,CAAE,CAAC,CAAC,KAAK,EAAE;EAAG;CAAM;CAEvI,OAAO;EAAE,MAAM,gBAAgB,IAAI;EAAG;CAAM;AAC9C;;AAGA,SAAgB,kBAAkB,QAA0B;CAC1D,IAAI,QAAQ;CACZ,OAAO,OAAO,MAAM,IAAI,CAAC,CAAC,KAAI,SAAQ;EACpC,MAAM,SAAS,cAAc,MAAM,KAAK;EACxC,QAAQ,OAAO;EACf,OAAO,OAAO;CAChB,CAAC;AACH"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A small, safe Markdown renderer: the CommonMark core most documents use,
|
|
3
|
+
* plus GFM tables, task lists and strikethrough.
|
|
4
|
+
*
|
|
5
|
+
* Supported: ATX headings, paragraphs and hard breaks, emphasis, strong,
|
|
6
|
+
* `code`, fenced code blocks, block quotes, nested bulleted, numbered and
|
|
7
|
+
* task lists, links, images, autolinks, horizontal rules, strikethrough and
|
|
8
|
+
* pipe tables. Raw HTML is not supported: it's shown as text.
|
|
9
|
+
*
|
|
10
|
+
* Every piece of text is escaped, URLs go through `sanitizeUrl`, and the
|
|
11
|
+
* result goes through `sanitizeHtml`, so the output is safe to insert.
|
|
12
|
+
* Block elements carry `data-line` (the 0-based source line), so a preview
|
|
13
|
+
* can be scrolled in step with the source.
|
|
14
|
+
*
|
|
15
|
+
* @module kit/markdown/render
|
|
16
|
+
*/
|
|
17
|
+
/** Render inline Markdown (already a single block's text) to HTML. */
|
|
18
|
+
export declare function renderInline(text: string): string;
|
|
19
|
+
/** Render Markdown to sanitized HTML. */
|
|
20
|
+
export declare function renderMarkdown(source: string): string;
|
|
21
|
+
export interface OutlineEntry {
|
|
22
|
+
level: number;
|
|
23
|
+
text: string;
|
|
24
|
+
/** 0-based source line. */
|
|
25
|
+
line: number;
|
|
26
|
+
/** Offset of the heading's first character in the source. */
|
|
27
|
+
offset: number;
|
|
28
|
+
}
|
|
29
|
+
/** The ATX headings of a document (outside code blocks), for an outline. */
|
|
30
|
+
export declare function markdownOutline(source: string): OutlineEntry[];
|
|
31
|
+
//# sourceMappingURL=render.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../../src/kit/markdown/render.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAmBH,sEAAsE;AACtE,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CA+BjD;AAqKD,yCAAyC;AACzC,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAGrD;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,2BAA2B;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,6DAA6D;IAC7D,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,4EAA4E;AAC5E,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,EAAE,CAc9D"}
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { sanitizeHtml } from "../../utils/sanitize.js";
|
|
2
|
+
import { sanitizeUrl } from "../../utils/url.js";
|
|
3
|
+
// src/kit/markdown/render.ts
|
|
4
|
+
/**
|
|
5
|
+
* A small, safe Markdown renderer: the CommonMark core most documents use,
|
|
6
|
+
* plus GFM tables, task lists and strikethrough.
|
|
7
|
+
*
|
|
8
|
+
* Supported: ATX headings, paragraphs and hard breaks, emphasis, strong,
|
|
9
|
+
* `code`, fenced code blocks, block quotes, nested bulleted, numbered and
|
|
10
|
+
* task lists, links, images, autolinks, horizontal rules, strikethrough and
|
|
11
|
+
* pipe tables. Raw HTML is not supported: it's shown as text.
|
|
12
|
+
*
|
|
13
|
+
* Every piece of text is escaped, URLs go through `sanitizeUrl`, and the
|
|
14
|
+
* result goes through `sanitizeHtml`, so the output is safe to insert.
|
|
15
|
+
* Block elements carry `data-line` (the 0-based source line), so a preview
|
|
16
|
+
* can be scrolled in step with the source.
|
|
17
|
+
*
|
|
18
|
+
* @module kit/markdown/render
|
|
19
|
+
*/
|
|
20
|
+
var ALLOWED_TAGS = [
|
|
21
|
+
...[
|
|
22
|
+
"p",
|
|
23
|
+
"h1",
|
|
24
|
+
"h2",
|
|
25
|
+
"h3",
|
|
26
|
+
"h4",
|
|
27
|
+
"h5",
|
|
28
|
+
"h6",
|
|
29
|
+
"ul",
|
|
30
|
+
"ol",
|
|
31
|
+
"li",
|
|
32
|
+
"blockquote",
|
|
33
|
+
"pre",
|
|
34
|
+
"hr",
|
|
35
|
+
"table",
|
|
36
|
+
"thead",
|
|
37
|
+
"tbody",
|
|
38
|
+
"tr",
|
|
39
|
+
"th",
|
|
40
|
+
"td"
|
|
41
|
+
],
|
|
42
|
+
"a",
|
|
43
|
+
"img",
|
|
44
|
+
"em",
|
|
45
|
+
"strong",
|
|
46
|
+
"del",
|
|
47
|
+
"code",
|
|
48
|
+
"br",
|
|
49
|
+
"span"
|
|
50
|
+
];
|
|
51
|
+
var ALLOWED_ATTRIBUTES = {
|
|
52
|
+
"*": [
|
|
53
|
+
"class",
|
|
54
|
+
"data-line",
|
|
55
|
+
"title"
|
|
56
|
+
],
|
|
57
|
+
a: ["href"],
|
|
58
|
+
img: ["src", "alt"],
|
|
59
|
+
ol: ["start"],
|
|
60
|
+
span: [
|
|
61
|
+
"role",
|
|
62
|
+
"aria-label",
|
|
63
|
+
"aria-checked"
|
|
64
|
+
]
|
|
65
|
+
};
|
|
66
|
+
var escapeHtml = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
67
|
+
/** Render inline Markdown (already a single block's text) to HTML. */
|
|
68
|
+
function renderInline(text) {
|
|
69
|
+
const held = [];
|
|
70
|
+
const hold = (html) => `\u0000${held.push(html) - 1}\u0000`;
|
|
71
|
+
let s = text.replace(/(`+)([\s\S]*?[^`])\1(?!`)/g, (_, __, code) => hold(`<code>${escapeHtml(code.trim() || code)}</code>`));
|
|
72
|
+
s = s.replace(/\\([\\`*_{}[\]()#+\-.!~|<>])/g, (_, ch) => hold(escapeHtml(ch)));
|
|
73
|
+
s = s.replace(/!\[([^\]]*)\]\(\s*<?([^\s)>]*)>?(?:\s+"([^"]*)")?\s*\)/g, (_, alt, src, title) => {
|
|
74
|
+
const url = sanitizeUrl(src, "image");
|
|
75
|
+
return url ? hold(`<img src="${escapeHtml(url)}" alt="${escapeHtml(alt)}"${title ? ` title="${escapeHtml(title)}"` : ""}>`) : hold(escapeHtml(alt));
|
|
76
|
+
});
|
|
77
|
+
s = s.replace(/\[([^\]]+)\]\(\s*<?([^\s)>]*)>?(?:\s+"([^"]*)")?\s*\)/g, (_, label, href, title) => {
|
|
78
|
+
const url = sanitizeUrl(href);
|
|
79
|
+
const inner = renderEmphasis(escapeHtml(label));
|
|
80
|
+
return url ? hold(`<a href="${escapeHtml(url)}"${title ? ` title="${escapeHtml(title)}"` : ""}>${inner}</a>`) : hold(inner);
|
|
81
|
+
});
|
|
82
|
+
s = s.replace(/<((?:https?|mailto):[^\s<>]+)>/g, (_, href) => {
|
|
83
|
+
const url = sanitizeUrl(href);
|
|
84
|
+
return url ? hold(`<a href="${escapeHtml(url)}">${escapeHtml(href)}</a>`) : hold(escapeHtml(href));
|
|
85
|
+
});
|
|
86
|
+
s = renderEmphasis(escapeHtml(s));
|
|
87
|
+
s = s.replace(/(?: {2,}|\\)\n/g, "<br>");
|
|
88
|
+
const placeholder = /\u0000(\d+)\u0000/g;
|
|
89
|
+
for (let round = 0; placeholder.test(s) && round < 10; round++) s = s.replace(placeholder, (_, i) => held[Number(i)]);
|
|
90
|
+
return s;
|
|
91
|
+
}
|
|
92
|
+
function renderEmphasis(s) {
|
|
93
|
+
return s.replace(/(\*\*|__)(?=\S)([\s\S]*?\S)\1/g, "<strong>$2</strong>").replace(/(^|[^\w*])\*(?=\S)([\s\S]*?\S)\*(?!\*)/g, "$1<em>$2</em>").replace(/(^|[^\w])_(?=\S)([\s\S]*?\S)_(?!\w)/g, "$1<em>$2</em>").replace(/~~(?=\S)([\s\S]*?\S)~~/g, "<del>$1</del>");
|
|
94
|
+
}
|
|
95
|
+
var FENCE = /^ {0,3}(`{3,}|~{3,})\s*([\w+-]*)/;
|
|
96
|
+
var HEADING = /^ {0,3}(#{1,6})(?:\s+(.*?))?\s*#*\s*$/;
|
|
97
|
+
var RULE = /^ {0,3}([-*_])(?:\s*\1){2,}\s*$/;
|
|
98
|
+
var QUOTE = /^ {0,3}> ?/;
|
|
99
|
+
var LIST_ITEM = /^(\s*)([-*+]|\d{1,9}[.)])\s+(.*)$/;
|
|
100
|
+
var TABLE_DIVIDER = /^\s*\|?\s*:?-+:?\s*(\|\s*:?-+:?\s*)*\|?\s*$/;
|
|
101
|
+
var isBlank = (line) => line.trim() === "";
|
|
102
|
+
var startsBlock = (line, next) => FENCE.test(line) || HEADING.test(line) || RULE.test(line) || QUOTE.test(line) || LIST_ITEM.test(line) || line.includes("|") && next !== void 0 && TABLE_DIVIDER.test(next);
|
|
103
|
+
function renderBlocks(lines, offset) {
|
|
104
|
+
const out = [];
|
|
105
|
+
let i = 0;
|
|
106
|
+
while (i < lines.length) {
|
|
107
|
+
const line = lines[i];
|
|
108
|
+
const at = ` data-line="${offset + i}"`;
|
|
109
|
+
if (isBlank(line)) {
|
|
110
|
+
i++;
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
const fence = FENCE.exec(line);
|
|
114
|
+
if (fence) {
|
|
115
|
+
const close = new RegExp(`^ {0,3}${fence[1][0]}{${fence[1].length},}\\s*$`);
|
|
116
|
+
const body = [];
|
|
117
|
+
let j = i + 1;
|
|
118
|
+
while (j < lines.length && !close.test(lines[j])) body.push(lines[j++]);
|
|
119
|
+
out.push(`<pre${at}><code${fence[2] ? ` class="language-${escapeHtml(fence[2])}"` : ""}>${escapeHtml(body.join("\n"))}</code></pre>`);
|
|
120
|
+
i = j + 1;
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
const heading = HEADING.exec(line);
|
|
124
|
+
if (heading) {
|
|
125
|
+
const level = heading[1].length;
|
|
126
|
+
out.push(`<h${level}${at}>${renderInline(heading[2] ?? "")}</h${level}>`);
|
|
127
|
+
i++;
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
if (RULE.test(line)) {
|
|
131
|
+
out.push(`<hr${at}>`);
|
|
132
|
+
i++;
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
if (QUOTE.test(line)) {
|
|
136
|
+
const body = [];
|
|
137
|
+
let j = i;
|
|
138
|
+
while (j < lines.length && (QUOTE.test(lines[j]) || !isBlank(lines[j]) && !startsBlock(lines[j]) && body.length)) {
|
|
139
|
+
body.push(lines[j].replace(QUOTE, ""));
|
|
140
|
+
j++;
|
|
141
|
+
}
|
|
142
|
+
out.push(`<blockquote${at}>${renderBlocks(body, offset + i)}</blockquote>`);
|
|
143
|
+
i = j;
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
if (LIST_ITEM.test(line)) {
|
|
147
|
+
const block = [];
|
|
148
|
+
const first = LIST_ITEM.exec(line);
|
|
149
|
+
const markerKind = (m) => m[2].replace(/\d+/, "1");
|
|
150
|
+
const sameList = (l) => {
|
|
151
|
+
const m = LIST_ITEM.exec(l);
|
|
152
|
+
return !m || m[1].length > first[1].length + 1 || markerKind(m) === markerKind(first);
|
|
153
|
+
};
|
|
154
|
+
let j = i;
|
|
155
|
+
while (j < lines.length) {
|
|
156
|
+
const l = lines[j];
|
|
157
|
+
if (!sameList(l)) break;
|
|
158
|
+
if (LIST_ITEM.test(l) || !isBlank(l) && /^\s+/.test(l) || !isBlank(l) && block.length && !startsBlock(l) && !isBlank(lines[j - 1])) {
|
|
159
|
+
block.push(l);
|
|
160
|
+
j++;
|
|
161
|
+
} else if (isBlank(l) && j + 1 < lines.length && (LIST_ITEM.test(lines[j + 1]) && sameList(lines[j + 1]) || /^\s{2,}\S/.test(lines[j + 1]))) {
|
|
162
|
+
block.push(l);
|
|
163
|
+
j++;
|
|
164
|
+
} else break;
|
|
165
|
+
}
|
|
166
|
+
out.push(renderList(block, offset + i));
|
|
167
|
+
i = j;
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
if (line.includes("|") && i + 1 < lines.length && TABLE_DIVIDER.test(lines[i + 1])) {
|
|
171
|
+
const rows = [];
|
|
172
|
+
let j = i + 2;
|
|
173
|
+
while (j < lines.length && lines[j].includes("|") && !isBlank(lines[j])) rows.push(lines[j++]);
|
|
174
|
+
out.push(renderTable(line, lines[i + 1], rows, offset + i));
|
|
175
|
+
i = j;
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
const body = [line];
|
|
179
|
+
let j = i + 1;
|
|
180
|
+
while (j < lines.length && !isBlank(lines[j]) && !startsBlock(lines[j], lines[j + 1])) body.push(lines[j++]);
|
|
181
|
+
out.push(`<p${at}>${renderInline(body.map((l) => l.replace(/^\s+/, "")).join("\n"))}</p>`);
|
|
182
|
+
i = j;
|
|
183
|
+
}
|
|
184
|
+
return out.join("");
|
|
185
|
+
}
|
|
186
|
+
function renderList(block, offset) {
|
|
187
|
+
const baseIndent = LIST_ITEM.exec(block[0])[1].length;
|
|
188
|
+
const items = [];
|
|
189
|
+
block.forEach((line, index) => {
|
|
190
|
+
const m = LIST_ITEM.exec(line);
|
|
191
|
+
if (m && m[1].length <= baseIndent + 1) items.push({
|
|
192
|
+
indent: m[1].length,
|
|
193
|
+
ordered: /\d/.test(m[2]),
|
|
194
|
+
start: parseInt(m[2], 10) || 1,
|
|
195
|
+
lines: [m[3]],
|
|
196
|
+
line: offset + index
|
|
197
|
+
});
|
|
198
|
+
else items[items.length - 1].lines.push(line.replace(new RegExp(`^ {0,${baseIndent + 4}}`), ""));
|
|
199
|
+
});
|
|
200
|
+
const ordered = items[0].ordered;
|
|
201
|
+
const tag = ordered ? "ol" : "ul";
|
|
202
|
+
const start = ordered && items[0].start !== 1 ? ` start="${items[0].start}"` : "";
|
|
203
|
+
const tasks = items.some((item) => /^\[[ xX]\]\s/.test(item.lines[0]));
|
|
204
|
+
const html = items.map((item) => {
|
|
205
|
+
let text = item.lines[0];
|
|
206
|
+
let check = "";
|
|
207
|
+
const task = /^\[([ xX])\]\s+/.exec(text);
|
|
208
|
+
if (task) {
|
|
209
|
+
const done = task[1] !== " ";
|
|
210
|
+
check = `<span class="md-check${done ? " is-checked" : ""}" role="img" aria-label="${done ? "Done" : "Not done"}"></span>`;
|
|
211
|
+
text = text.slice(task[0].length);
|
|
212
|
+
}
|
|
213
|
+
const rest = item.lines.slice(1);
|
|
214
|
+
const nested = rest.some((l) => !isBlank(l)) ? renderBlocks(rest, item.line + 1) : "";
|
|
215
|
+
return `<li data-line="${item.line}"${task ? " class=\"md-task\"" : ""}>${check}${renderInline(text)}${nested}</li>`;
|
|
216
|
+
});
|
|
217
|
+
return `<${tag} data-line="${offset}"${start}${tasks ? " class=\"md-tasks\"" : ""}>${html.join("")}</${tag}>`;
|
|
218
|
+
}
|
|
219
|
+
function splitRow(row) {
|
|
220
|
+
return row.trim().replace(/^\|/, "").replace(/(?<!\\)\|$/, "").split(/(?<!\\)\|/).map((c) => c.trim().replace(/\\\|/g, "|"));
|
|
221
|
+
}
|
|
222
|
+
function renderTable(header, divider, rows, offset) {
|
|
223
|
+
const align = splitRow(divider).map((d) => d.startsWith(":") && d.endsWith(":") ? "center" : d.endsWith(":") ? "right" : d.startsWith(":") ? "left" : "");
|
|
224
|
+
const cell = (tag, text, col) => `<${tag}${align[col] ? ` class="md-align-${align[col]}"` : ""}>${renderInline(text)}</${tag}>`;
|
|
225
|
+
const head = splitRow(header).map((c, col) => cell("th", c, col)).join("");
|
|
226
|
+
const body = rows.map((r, n) => `<tr data-line="${offset + 2 + n}">${splitRow(r).map((c, col) => cell("td", c, col)).join("")}</tr>`).join("");
|
|
227
|
+
return `<table data-line="${offset}"><thead><tr>${head}</tr></thead>${body ? `<tbody>${body}</tbody>` : ""}</table>`;
|
|
228
|
+
}
|
|
229
|
+
/** Render Markdown to sanitized HTML. */
|
|
230
|
+
function renderMarkdown(source) {
|
|
231
|
+
const html = renderBlocks(source.replace(/\r\n?/g, "\n").split("\n"), 0);
|
|
232
|
+
return sanitizeHtml(html, {
|
|
233
|
+
allowedTags: ALLOWED_TAGS,
|
|
234
|
+
allowedAttributes: ALLOWED_ATTRIBUTES
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
/** The ATX headings of a document (outside code blocks), for an outline. */
|
|
238
|
+
function markdownOutline(source) {
|
|
239
|
+
const out = [];
|
|
240
|
+
let fence = null;
|
|
241
|
+
let offset = 0;
|
|
242
|
+
source.split("\n").forEach((line, index) => {
|
|
243
|
+
const f = FENCE.exec(line);
|
|
244
|
+
if (f && (!fence || line.trim().startsWith(fence))) fence = fence ? null : f[1];
|
|
245
|
+
else if (!fence) {
|
|
246
|
+
const h = HEADING.exec(line);
|
|
247
|
+
if (h && h[2]) out.push({
|
|
248
|
+
level: h[1].length,
|
|
249
|
+
text: h[2].replace(/[*_`~]/g, ""),
|
|
250
|
+
line: index,
|
|
251
|
+
offset
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
offset += line.length + 1;
|
|
255
|
+
});
|
|
256
|
+
return out;
|
|
257
|
+
}
|
|
258
|
+
export { markdownOutline, renderInline, renderMarkdown };
|
|
259
|
+
|
|
260
|
+
//# sourceMappingURL=render.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.js","names":[],"sources":["../../../src/kit/markdown/render.ts"],"sourcesContent":["/**\n * A small, safe Markdown renderer: the CommonMark core most documents use,\n * plus GFM tables, task lists and strikethrough.\n *\n * Supported: ATX headings, paragraphs and hard breaks, emphasis, strong,\n * `code`, fenced code blocks, block quotes, nested bulleted, numbered and\n * task lists, links, images, autolinks, horizontal rules, strikethrough and\n * pipe tables. Raw HTML is not supported: it's shown as text.\n *\n * Every piece of text is escaped, URLs go through `sanitizeUrl`, and the\n * result goes through `sanitizeHtml`, so the output is safe to insert.\n * Block elements carry `data-line` (the 0-based source line), so a preview\n * can be scrolled in step with the source.\n *\n * @module kit/markdown/render\n */\n\nimport { sanitizeHtml } from '../../utils/sanitize';\nimport { sanitizeUrl } from '../../utils/url';\n\nconst BLOCK_TAGS = ['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'ul', 'ol', 'li', 'blockquote', 'pre', 'hr', 'table', 'thead', 'tbody', 'tr', 'th', 'td'];\nconst ALLOWED_TAGS = [...BLOCK_TAGS, 'a', 'img', 'em', 'strong', 'del', 'code', 'br', 'span'];\nconst ALLOWED_ATTRIBUTES: Record<string, string[]> = {\n '*': ['class', 'data-line', 'title'],\n a: ['href'],\n img: ['src', 'alt'],\n ol: ['start'],\n span: ['role', 'aria-label', 'aria-checked'],\n};\n\nconst escapeHtml = (s: string): string => s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/\"/g, '"').replace(/'/g, ''');\n\n// ── Inline ─────────────────────────────────────────────────────────────────\n\n/** Render inline Markdown (already a single block's text) to HTML. */\nexport function renderInline(text: string): string {\n // Code spans and links are swapped for placeholders so their contents aren't parsed again.\n const held: string[] = [];\n const hold = (html: string): string => `\\u0000${held.push(html) - 1}\\u0000`;\n\n let s = text.replace(/(`+)([\\s\\S]*?[^`])\\1(?!`)/g, (_, __, code: string) => hold(`<code>${escapeHtml(code.trim() || code)}</code>`));\n // Backslash escapes.\n s = s.replace(/\\\\([\\\\`*_{}[\\]()#+\\-.!~|<>])/g, (_, ch: string) => hold(escapeHtml(ch)));\n // Images, then links:  and [text](href \"title\").\n s = s.replace(/!\\[([^\\]]*)\\]\\(\\s*<?([^\\s)>]*)>?(?:\\s+\"([^\"]*)\")?\\s*\\)/g, (_, alt: string, src: string, title?: string) => {\n const url = sanitizeUrl(src, 'image');\n return url ? hold(`<img src=\"${escapeHtml(url)}\" alt=\"${escapeHtml(alt)}\"${title ? ` title=\"${escapeHtml(title)}\"` : ''}>`) : hold(escapeHtml(alt));\n });\n s = s.replace(/\\[([^\\]]+)\\]\\(\\s*<?([^\\s)>]*)>?(?:\\s+\"([^\"]*)\")?\\s*\\)/g, (_, label: string, href: string, title?: string) => {\n const url = sanitizeUrl(href);\n const inner = renderEmphasis(escapeHtml(label));\n return url ? hold(`<a href=\"${escapeHtml(url)}\"${title ? ` title=\"${escapeHtml(title)}\"` : ''}>${inner}</a>`) : hold(inner);\n });\n // Autolinks: <https://…>\n s = s.replace(/<((?:https?|mailto):[^\\s<>]+)>/g, (_, href: string) => {\n const url = sanitizeUrl(href);\n return url ? hold(`<a href=\"${escapeHtml(url)}\">${escapeHtml(href)}</a>`) : hold(escapeHtml(href));\n });\n s = renderEmphasis(escapeHtml(s));\n // Hard breaks: two trailing spaces or a backslash before a newline.\n s = s.replace(/(?: {2,}|\\\\)\\n/g, '<br>');\n // Placeholders can be nested (a code span inside a link label): resolve until none are left.\n // eslint-disable-next-line no-control-regex\n const placeholder = /\\u0000(\\d+)\\u0000/g;\n for (let round = 0; placeholder.test(s) && round < 10; round++) s = s.replace(placeholder, (_, i: string) => held[Number(i)]);\n return s;\n}\n\nfunction renderEmphasis(s: string): string {\n return s\n .replace(/(\\*\\*|__)(?=\\S)([\\s\\S]*?\\S)\\1/g, '<strong>$2</strong>')\n .replace(/(^|[^\\w*])\\*(?=\\S)([\\s\\S]*?\\S)\\*(?!\\*)/g, '$1<em>$2</em>')\n .replace(/(^|[^\\w])_(?=\\S)([\\s\\S]*?\\S)_(?!\\w)/g, '$1<em>$2</em>')\n .replace(/~~(?=\\S)([\\s\\S]*?\\S)~~/g, '<del>$1</del>');\n}\n\n// ── Blocks ─────────────────────────────────────────────────────────────────\n\nconst FENCE = /^ {0,3}(`{3,}|~{3,})\\s*([\\w+-]*)/;\nconst HEADING = /^ {0,3}(#{1,6})(?:\\s+(.*?))?\\s*#*\\s*$/;\nconst RULE = /^ {0,3}([-*_])(?:\\s*\\1){2,}\\s*$/;\nconst QUOTE = /^ {0,3}> ?/;\nconst LIST_ITEM = /^(\\s*)([-*+]|\\d{1,9}[.)])\\s+(.*)$/;\nconst TABLE_DIVIDER = /^\\s*\\|?\\s*:?-+:?\\s*(\\|\\s*:?-+:?\\s*)*\\|?\\s*$/;\n\nconst isBlank = (line: string) => line.trim() === '';\nconst startsBlock = (line: string, next?: string) =>\n FENCE.test(line) || HEADING.test(line) || RULE.test(line) || QUOTE.test(line) || LIST_ITEM.test(line) || (line.includes('|') && next !== undefined && TABLE_DIVIDER.test(next));\n\ninterface ListItem {\n indent: number;\n ordered: boolean;\n start: number;\n lines: string[];\n line: number;\n}\n\nfunction renderBlocks(lines: string[], offset: number): string {\n const out: string[] = [];\n let i = 0;\n while (i < lines.length) {\n const line = lines[i];\n const at = ` data-line=\"${offset + i}\"`;\n if (isBlank(line)) {\n i++;\n continue;\n }\n const fence = FENCE.exec(line);\n if (fence) {\n const close = new RegExp(`^ {0,3}${fence[1][0]}{${fence[1].length},}\\\\s*$`);\n const body: string[] = [];\n let j = i + 1;\n while (j < lines.length && !close.test(lines[j])) body.push(lines[j++]);\n out.push(`<pre${at}><code${fence[2] ? ` class=\"language-${escapeHtml(fence[2])}\"` : ''}>${escapeHtml(body.join('\\n'))}</code></pre>`);\n i = j + 1;\n continue;\n }\n const heading = HEADING.exec(line);\n if (heading) {\n const level = heading[1].length;\n out.push(`<h${level}${at}>${renderInline(heading[2] ?? '')}</h${level}>`);\n i++;\n continue;\n }\n if (RULE.test(line)) {\n out.push(`<hr${at}>`);\n i++;\n continue;\n }\n if (QUOTE.test(line)) {\n const body: string[] = [];\n let j = i;\n while (j < lines.length && (QUOTE.test(lines[j]) || (!isBlank(lines[j]) && !startsBlock(lines[j]) && body.length))) {\n body.push(lines[j].replace(QUOTE, ''));\n j++;\n }\n out.push(`<blockquote${at}>${renderBlocks(body, offset + i)}</blockquote>`);\n i = j;\n continue;\n }\n if (LIST_ITEM.test(line)) {\n const block: string[] = [];\n // A different marker (- vs *, 1. vs 1)) at the same depth starts a new list, as in CommonMark.\n const first = LIST_ITEM.exec(line)!;\n const markerKind = (m: RegExpExecArray) => m[2].replace(/\\d+/, '1');\n const sameList = (l: string) => {\n const m = LIST_ITEM.exec(l);\n return !m || m[1].length > first[1].length + 1 || markerKind(m) === markerKind(first);\n };\n let j = i;\n // A list continues through indented lines and single blank lines followed by more list.\n while (j < lines.length) {\n const l = lines[j];\n if (!sameList(l)) break;\n if (LIST_ITEM.test(l) || (!isBlank(l) && /^\\s+/.test(l)) || (!isBlank(l) && block.length && !startsBlock(l) && !isBlank(lines[j - 1]))) {\n block.push(l);\n j++;\n } else if (isBlank(l) && j + 1 < lines.length && ((LIST_ITEM.test(lines[j + 1]) && sameList(lines[j + 1])) || /^\\s{2,}\\S/.test(lines[j + 1]))) {\n block.push(l);\n j++;\n } else break;\n }\n out.push(renderList(block, offset + i));\n i = j;\n continue;\n }\n if (line.includes('|') && i + 1 < lines.length && TABLE_DIVIDER.test(lines[i + 1])) {\n const rows: string[] = [];\n let j = i + 2;\n while (j < lines.length && lines[j].includes('|') && !isBlank(lines[j])) rows.push(lines[j++]);\n out.push(renderTable(line, lines[i + 1], rows, offset + i));\n i = j;\n continue;\n }\n // Paragraph: until a blank line or another block.\n const body = [line];\n let j = i + 1;\n while (j < lines.length && !isBlank(lines[j]) && !startsBlock(lines[j], lines[j + 1])) body.push(lines[j++]);\n out.push(`<p${at}>${renderInline(body.map(l => l.replace(/^\\s+/, '')).join('\\n'))}</p>`);\n i = j;\n }\n return out.join('');\n}\n\nfunction renderList(block: string[], offset: number): string {\n // Group lines into items: an item starts at a list marker no deeper than the first one.\n const first = LIST_ITEM.exec(block[0])!;\n const baseIndent = first[1].length;\n const items: ListItem[] = [];\n block.forEach((line, index) => {\n const m = LIST_ITEM.exec(line);\n if (m && m[1].length <= baseIndent + 1) {\n items.push({ indent: m[1].length, ordered: /\\d/.test(m[2]), start: parseInt(m[2], 10) || 1, lines: [m[3]], line: offset + index });\n } else {\n // Continuation or nested content, de-indented relative to the item's text.\n items[items.length - 1].lines.push(line.replace(new RegExp(`^ {0,${baseIndent + 4}}`), ''));\n }\n });\n const ordered = items[0].ordered;\n const tag = ordered ? 'ol' : 'ul';\n const start = ordered && items[0].start !== 1 ? ` start=\"${items[0].start}\"` : '';\n const tasks = items.some(item => /^\\[[ xX]\\]\\s/.test(item.lines[0]));\n const html = items.map(item => {\n let text = item.lines[0];\n let check = '';\n const task = /^\\[([ xX])\\]\\s+/.exec(text);\n if (task) {\n const done = task[1] !== ' ';\n check = `<span class=\"md-check${done ? ' is-checked' : ''}\" role=\"img\" aria-label=\"${done ? 'Done' : 'Not done'}\"></span>`;\n text = text.slice(task[0].length);\n }\n const rest = item.lines.slice(1);\n const nested = rest.some(l => !isBlank(l)) ? renderBlocks(rest, item.line + 1) : '';\n return `<li data-line=\"${item.line}\"${task ? ' class=\"md-task\"' : ''}>${check}${renderInline(text)}${nested}</li>`;\n });\n return `<${tag} data-line=\"${offset}\"${start}${tasks ? ' class=\"md-tasks\"' : ''}>${html.join('')}</${tag}>`;\n}\n\nfunction splitRow(row: string): string[] {\n const cells = row.trim().replace(/^\\|/, '').replace(/(?<!\\\\)\\|$/, '').split(/(?<!\\\\)\\|/);\n return cells.map(c => c.trim().replace(/\\\\\\|/g, '|'));\n}\n\nfunction renderTable(header: string, divider: string, rows: string[], offset: number): string {\n const align = splitRow(divider).map(d => (d.startsWith(':') && d.endsWith(':') ? 'center' : d.endsWith(':') ? 'right' : d.startsWith(':') ? 'left' : ''));\n const cell = (tag: string, text: string, col: number) => `<${tag}${align[col] ? ` class=\"md-align-${align[col]}\"` : ''}>${renderInline(text)}</${tag}>`;\n const head = splitRow(header).map((c, col) => cell('th', c, col)).join('');\n const body = rows.map((r, n) => `<tr data-line=\"${offset + 2 + n}\">${splitRow(r).map((c, col) => cell('td', c, col)).join('')}</tr>`).join('');\n return `<table data-line=\"${offset}\"><thead><tr>${head}</tr></thead>${body ? `<tbody>${body}</tbody>` : ''}</table>`;\n}\n\n/** Render Markdown to sanitized HTML. */\nexport function renderMarkdown(source: string): string {\n const html = renderBlocks(source.replace(/\\r\\n?/g, '\\n').split('\\n'), 0);\n return sanitizeHtml(html, { allowedTags: ALLOWED_TAGS, allowedAttributes: ALLOWED_ATTRIBUTES });\n}\n\nexport interface OutlineEntry {\n level: number;\n text: string;\n /** 0-based source line. */\n line: number;\n /** Offset of the heading's first character in the source. */\n offset: number;\n}\n\n/** The ATX headings of a document (outside code blocks), for an outline. */\nexport function markdownOutline(source: string): OutlineEntry[] {\n const out: OutlineEntry[] = [];\n let fence: string | null = null;\n let offset = 0;\n source.split('\\n').forEach((line, index) => {\n const f = FENCE.exec(line);\n if (f && (!fence || line.trim().startsWith(fence))) fence = fence ? null : f[1];\n else if (!fence) {\n const h = HEADING.exec(line);\n if (h && h[2]) out.push({ level: h[1].length, text: h[2].replace(/[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,MAAM;IAAO;GAAO,CAAC;EACxG;EACA,UAAU,KAAK,SAAS;CAC1B,CAAC;CACD,OAAO;AACT"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Component } from '../components/component';
|
|
2
|
+
import { OutlineEntry } from './markdown/render';
|
|
3
|
+
export type MarkdownLayout = 'split' | 'write' | 'preview';
|
|
4
|
+
/** A highlighted range, e.g. a comment. */
|
|
5
|
+
export interface MarkdownMark {
|
|
6
|
+
id: string;
|
|
7
|
+
from: number;
|
|
8
|
+
to: number;
|
|
9
|
+
/** CSS color (hex, rgb() or hsl()). */
|
|
10
|
+
color?: string;
|
|
11
|
+
/** Drawn more strongly, e.g. the comment being read. */
|
|
12
|
+
active?: boolean;
|
|
13
|
+
}
|
|
14
|
+
type Command = 'bold' | 'italic' | 'strike' | 'code' | 'heading' | 'quote' | 'bullet' | 'numbered' | 'task' | 'link' | 'codeblock';
|
|
15
|
+
export declare class MarkdownEditor extends Component {
|
|
16
|
+
#private;
|
|
17
|
+
static get observedAttributes(): string[];
|
|
18
|
+
attributeChangedCallback(name: string): void;
|
|
19
|
+
/** The textarea being edited. */
|
|
20
|
+
get textarea(): HTMLTextAreaElement | null;
|
|
21
|
+
get value(): string;
|
|
22
|
+
get layout(): MarkdownLayout;
|
|
23
|
+
set layout(layout: MarkdownLayout);
|
|
24
|
+
/** The document's headings. */
|
|
25
|
+
get outline(): OutlineEntry[];
|
|
26
|
+
/** Ranges to highlight (comments and the like), in document positions. */
|
|
27
|
+
get annotations(): MarkdownMark[];
|
|
28
|
+
set annotations(marks: MarkdownMark[]);
|
|
29
|
+
protected onConnected(): void;
|
|
30
|
+
protected onDisconnected(): void;
|
|
31
|
+
/** Re-read the textarea (call after changing its value from code without an `input` event). */
|
|
32
|
+
refresh(): void;
|
|
33
|
+
/** Replace `from`–`to` with `text` as a user edit (it fires `input`), then select `select`. */
|
|
34
|
+
replaceRange(from: number, to: number, text: string, select?: [number, number]): void;
|
|
35
|
+
/** Undo your last edit. */
|
|
36
|
+
undo(): boolean;
|
|
37
|
+
/** Redo your last undone edit. */
|
|
38
|
+
redo(): boolean;
|
|
39
|
+
/** Apply a toolbar command to the selection. */
|
|
40
|
+
format(command: Command): void;
|
|
41
|
+
openFind(): void;
|
|
42
|
+
closeFind(): void;
|
|
43
|
+
/** Move to the next (1) or previous (-1) match. */
|
|
44
|
+
findNext(direction?: 1 | -1): void;
|
|
45
|
+
replaceCurrent(): void;
|
|
46
|
+
/** Replace every match, as one edit (one undo step). */
|
|
47
|
+
replaceAll(): void;
|
|
48
|
+
/** Scroll the source so that a position is visible (optionally moving the caret there). */
|
|
49
|
+
revealOffset(offset: number, moveCaret?: boolean): void;
|
|
50
|
+
}
|
|
51
|
+
/** Define `<a-markdown-editor>` (idempotent). `import 'arethesis/components/markdown-editor'` calls this. */
|
|
52
|
+
export declare function defineMarkdownEditor(): void;
|
|
53
|
+
export {};
|
|
54
|
+
//# sourceMappingURL=markdown-editor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-editor.d.ts","sourceRoot":"","sources":["../../src/kit/markdown-editor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAMpD,OAAO,EAAmC,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGvF,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,OAAO,GAAG,SAAS,CAAC;AAE3D,2CAA2C;AAC3C,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,uCAAuC;IACvC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wDAAwD;IACxD,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,KAAK,OAAO,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ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