@astryxdesign/richtext 0.6.5-canary.b421f01 → 0.6.5-canary.b65e45f

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/dist/MarkdownExtensionsPlugin.d.ts +17 -0
  2. package/dist/MarkdownExtensionsPlugin.d.ts.map +1 -0
  3. package/dist/MarkdownExtensionsPlugin.js +185 -0
  4. package/dist/RichTextEditor.d.ts +10 -0
  5. package/dist/RichTextEditor.d.ts.map +1 -1
  6. package/dist/RichTextEditor.js +6 -1
  7. package/dist/RichTextEditorToolbar.d.ts.map +1 -1
  8. package/dist/RichTextEditorToolbar.js +11 -3
  9. package/dist/RichTextView.d.ts +11 -1
  10. package/dist/RichTextView.d.ts.map +1 -1
  11. package/dist/RichTextView.js +9 -1
  12. package/dist/editorNodes.d.ts.map +1 -1
  13. package/dist/editorNodes.js +6 -1
  14. package/dist/editorTheme.d.ts.map +1 -1
  15. package/dist/editorTheme.js +7 -0
  16. package/dist/index.d.ts +2 -0
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +1 -0
  19. package/dist/markdown.d.ts +17 -0
  20. package/dist/markdown.d.ts.map +1 -0
  21. package/dist/markdown.js +17 -0
  22. package/dist/markdownCharacterReferences.d.ts +85 -3
  23. package/dist/markdownCharacterReferences.d.ts.map +1 -1
  24. package/dist/markdownCharacterReferences.js +610 -11
  25. package/dist/markdownCodeFence.d.ts +4 -0
  26. package/dist/markdownCodeFence.d.ts.map +1 -0
  27. package/dist/markdownCodeFence.js +153 -0
  28. package/dist/markdownExtensionNode.d.ts +88 -0
  29. package/dist/markdownExtensionNode.d.ts.map +1 -0
  30. package/dist/markdownExtensionNode.js +244 -0
  31. package/dist/markdownExtensions.d.ts +115 -0
  32. package/dist/markdownExtensions.d.ts.map +1 -0
  33. package/dist/markdownExtensions.js +392 -0
  34. package/dist/markdownLink.d.ts +5 -0
  35. package/dist/markdownLink.d.ts.map +1 -0
  36. package/dist/markdownLink.js +82 -0
  37. package/dist/markdownOrderedList.d.ts +3 -0
  38. package/dist/markdownOrderedList.d.ts.map +1 -0
  39. package/dist/markdownOrderedList.js +51 -0
  40. package/dist/markdownSerializers.d.ts +8 -0
  41. package/dist/markdownSerializers.d.ts.map +1 -1
  42. package/dist/markdownSerializers.js +7 -4
  43. package/dist/markdownSource.d.ts +4 -2
  44. package/dist/markdownSource.d.ts.map +1 -1
  45. package/dist/markdownSource.js +95 -18
  46. package/dist/markdownTable.d.ts +5 -2
  47. package/dist/markdownTable.d.ts.map +1 -1
  48. package/dist/markdownTable.js +11 -5
  49. package/package.json +9 -4
  50. package/src/MarkdownExtensionsPlugin.test.tsx +279 -0
  51. package/src/MarkdownExtensionsPlugin.tsx +289 -0
  52. package/src/RichTextEditor.doc.mjs +12 -1
  53. package/src/RichTextEditor.tsx +18 -0
  54. package/src/RichTextEditorToolbar.tsx +15 -2
  55. package/src/RichTextView.tsx +21 -0
  56. package/src/__tests__/MarkdownParitySandbox.a11y.chromium.spec.ts +167 -10
  57. package/src/__tests__/MarkdownPlugins.a11y.chromium.spec.ts +372 -0
  58. package/src/__tests__/MarkdownPluginsImportExport.a11y.chromium.spec.ts +117 -0
  59. package/src/editorNodes.ts +4 -0
  60. package/src/editorTheme.ts +7 -2
  61. package/src/index.ts +5 -0
  62. package/src/markdown.ts +25 -0
  63. package/src/markdownAngleDestinations.test.ts +134 -0
  64. package/src/markdownCharacterReferences.ts +596 -16
  65. package/src/markdownCodeFence.test.ts +181 -0
  66. package/src/markdownCodeFence.ts +193 -0
  67. package/src/markdownCodeSpans.test.ts +399 -0
  68. package/src/markdownEscapes.test.ts +234 -0
  69. package/src/markdownExtensionNode.ts +332 -0
  70. package/src/markdownExtensionSelection.test.ts +102 -0
  71. package/src/markdownExtensions.test.ts +765 -0
  72. package/src/markdownExtensions.ts +496 -0
  73. package/src/markdownLink.ts +86 -0
  74. package/src/markdownOrderedList.test.ts +62 -0
  75. package/src/markdownOrderedList.ts +60 -0
  76. package/src/markdownRefusedLinks.test.tsx +193 -0
  77. package/src/markdownSerializers.ts +13 -4
  78. package/src/markdownSource.test.tsx +11 -5
  79. package/src/markdownSource.ts +142 -17
  80. package/src/markdownTable.ts +24 -4
  81. package/src/markdownTableLinks.test.ts +69 -0
@@ -0,0 +1,17 @@
1
+ import type { Transformer } from '@lexical/markdown';
2
+ import type { MarkdownExtensionNode, MarkdownPluginEntry } from '@astryxdesign/core/Markdown/plugins';
3
+ import { type RichTextMarkdownExtension } from './markdownExtensions';
4
+ import { type RichTextExtensionNodeFacts } from './markdownExtensionNode';
5
+ /**
6
+ * The node core derives from a stored node's source with `plugins`, or null
7
+ * when no adopted plugin of the same protocol version reads that exact source
8
+ * as that node.
9
+ */
10
+ export declare function deriveExtensionNode(facts: RichTextExtensionNodeFacts, plugins: ReadonlyArray<MarkdownPluginEntry>): MarkdownExtensionNode | null;
11
+ export interface MarkdownExtensionsPluginProps {
12
+ extensions: ReadonlyArray<RichTextMarkdownExtension>;
13
+ /** The surface's Markdown transformers, checked against the extensions. */
14
+ transformers: ReadonlyArray<Transformer>;
15
+ }
16
+ export declare function MarkdownExtensionsPlugin({ extensions, transformers, }: MarkdownExtensionsPluginProps): null;
17
+ //# sourceMappingURL=MarkdownExtensionsPlugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MarkdownExtensionsPlugin.d.ts","sourceRoot":"","sources":["../src/MarkdownExtensionsPlugin.tsx"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,mBAAmB,CAAC;AAwBnD,OAAO,KAAK,EACV,qBAAqB,EACrB,mBAAmB,EACpB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAY,KAAK,yBAAyB,EAAC,MAAM,sBAAsB,CAAC;AAC/E,OAAO,EAKL,KAAK,0BAA0B,EAChC,MAAM,yBAAyB,CAAC;AAEjC;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,0BAA0B,EACjC,OAAO,EAAE,aAAa,CAAC,mBAAmB,CAAC,GAC1C,qBAAqB,GAAG,IAAI,CAoB9B;AAyHD,MAAM,WAAW,6BAA6B;IAC5C,UAAU,EAAE,aAAa,CAAC,yBAAyB,CAAC,CAAC;IACrD,2EAA2E;IAC3E,YAAY,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC;CAC1C;AAED,wBAAgB,wBAAwB,CAAC,EACvC,UAAU,EACV,YAAY,GACb,EAAE,6BAA6B,GAAG,IAAI,CAoEtC"}
@@ -0,0 +1,185 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ 'use client';
4
+
5
+ /**
6
+ * @file MarkdownExtensionsPlugin.tsx
7
+ * @input Uses @lexical/react (composer context), @lexical/utils ($dfs),
8
+ * lexical, core's client-only MarkdownPluginNodeRenderer and server-safe
9
+ * parser, and the RichText adapter and extension node.
10
+ * @output Exports MarkdownExtensionsPlugin, which draws every Markdown plugin
11
+ * node in an editor with its plugin's renderer, and deriveExtensionNode.
12
+ * @position Rendered by RichTextEditor and RichTextView when they are given
13
+ * `markdownExtensions` (spec:AST-064 FR2). It checks the configuration
14
+ * first (FR6), so a conflicting one throws a RichTextExtensionError while
15
+ * the surface renders. Each node is derived again from its source with the
16
+ * adopted plugins and drawn by core's MarkdownPluginNodeRenderer, so it
17
+ * renders, falls back, and reports failures exactly as Markdown does (FR8,
18
+ * FR9); stored data is never drawn on its own, and a node its plugin no
19
+ * longer recognizes — or whose plugin is not adopted — shows its source
20
+ * (FR11). Without this plugin a node shows its source.
21
+ */
22
+ import { useEffect, useMemo } from 'react';
23
+ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
24
+ import { useLexicalNodeSelection } from '@lexical/react/useLexicalNodeSelection';
25
+ import { $dfs, addClassNamesToElement, removeClassNamesFromElement } from '@lexical/utils';
26
+ import { $getSelection, $isRangeSelection, CLICK_COMMAND, COMMAND_PRIORITY_LOW, FORMAT_TEXT_COMMAND, HISTORY_MERGE_TAG, TEXT_TYPE_TO_FORMAT } from 'lexical';
27
+ import { MarkdownPluginNodeRenderer } from '@astryxdesign/core/Markdown/plugin-renderer';
28
+ import { parseInlineAst, parseMarkdownAst } from '@astryxdesign/core/Markdown/parser';
29
+ import { pluginsOf } from "./markdownExtensions.js";
30
+ import { $firstSelectedText, $isRichTextExtensionNode, setRichTextExtensionNodeDecorator } from "./markdownExtensionNode.js";
31
+
32
+ /**
33
+ * The node core derives from a stored node's source with `plugins`, or null
34
+ * when no adopted plugin of the same protocol version reads that exact source
35
+ * as that node.
36
+ */
37
+ import { jsx as _jsx } from "react/jsx-runtime";
38
+ export function deriveExtensionNode(facts, plugins) {
39
+ const plugin = plugins.find(entry => entry.name === facts.plugin);
40
+ if (plugin == null || plugin.apiVersion !== facts.apiVersion) {
41
+ return null;
42
+ }
43
+ const nodes = facts.display === 'inline' ? parseInlineAst(facts.source, {
44
+ plugins: [plugin]
45
+ }) : parseMarkdownAst(facts.source, {
46
+ plugins: [plugin]
47
+ }).children;
48
+ const [node] = nodes;
49
+ if (nodes.length !== 1 || node?.type !== 'extension') {
50
+ return null;
51
+ }
52
+ const extension = node;
53
+ return extension.plugin === facts.plugin && extension.name === facts.name && extension.display === facts.display && extension.source === facts.source ? extension : null;
54
+ }
55
+
56
+ /**
57
+ * The formats a plugin node can sit inside, outermost first, as RichText draws
58
+ * them around text (textSemantics.ts): a deletion, then emphasis, then strong.
59
+ */
60
+ const MARKS = [['strikethrough', 'del'], ['italic', 'em'], ['bold', 'strong']];
61
+
62
+ /** The formats a toggle can put a plugin node inside. */
63
+ const NODE_FORMATS = new Set(MARKS.map(([format]) => format));
64
+ function ExtensionNodeView({
65
+ facts,
66
+ format,
67
+ nodeKey,
68
+ plugins
69
+ }) {
70
+ const [editor] = useLexicalComposerContext();
71
+ const [isSelected, setSelected, clearSelection] = useLexicalNodeSelection(nodeKey);
72
+ // A click on the node selects it whole, as a click on a rule does, so a
73
+ // pointer user can format or delete it like a keyboard user.
74
+ useEffect(() => editor.registerCommand(CLICK_COMMAND, event => {
75
+ const element = editor.getElementByKey(nodeKey);
76
+ if (!editor.isEditable() || element == null || !(event.target instanceof Node) || !element.contains(event.target)) {
77
+ return false;
78
+ }
79
+ clearSelection();
80
+ setSelected(true);
81
+ return true;
82
+ }, COMMAND_PRIORITY_LOW), [clearSelection, editor, nodeKey, setSelected]);
83
+ // A selected node shows the focus ring a selected rule shows.
84
+ useEffect(() => {
85
+ const element = editor.getElementByKey(nodeKey);
86
+ const className = editor._config.theme.markdownExtensionSelected;
87
+ if (element == null || typeof className !== 'string' || className === '') {
88
+ return;
89
+ }
90
+ if (isSelected) {
91
+ addClassNamesToElement(element, className);
92
+ } else {
93
+ removeClassNamesFromElement(element, className);
94
+ }
95
+ }, [editor, isSelected, nodeKey]);
96
+ const node = useMemo(() => deriveExtensionNode(facts, plugins), [facts, plugins]);
97
+ let content = node == null ? facts.source : /*#__PURE__*/_jsx(MarkdownPluginNodeRenderer, {
98
+ plugins: plugins,
99
+ node: node
100
+ });
101
+ // Inside emphasis, strong, or strikethrough, the node is drawn inside the
102
+ // same elements, as core Markdown draws it inside the text's.
103
+ for (const [type, Tag] of [...MARKS].reverse()) {
104
+ if ((format & TEXT_TYPE_TO_FORMAT[type]) !== 0) {
105
+ content = /*#__PURE__*/_jsx(Tag, {
106
+ children: content
107
+ });
108
+ }
109
+ }
110
+ return content;
111
+ }
112
+
113
+ /**
114
+ * Marks every plugin node so Lexical draws it again with the decorator the
115
+ * editor has now. Not an edit, so it adds nothing to undo history.
116
+ */
117
+ function redrawExtensionNodes(editor) {
118
+ editor.update(() => {
119
+ for (const {
120
+ node
121
+ } of $dfs()) {
122
+ if ($isRichTextExtensionNode(node)) {
123
+ node.markDirty();
124
+ }
125
+ }
126
+ }, {
127
+ tag: HISTORY_MERGE_TAG
128
+ });
129
+ }
130
+
131
+ /**
132
+ * Whether `format` will be on for the text a range selects once it is
133
+ * toggled, as Lexical's formatText decides it from the first selected
134
+ * character; null when the range selects no text, only nodes.
135
+ */
136
+ function $nextTextFormat(selection, format) {
137
+ const first = $firstSelectedText(selection);
138
+ return first == null ? null : (first.getFormatFlags(format, null) & TEXT_TYPE_TO_FORMAT[format]) !== 0;
139
+ }
140
+ export function MarkdownExtensionsPlugin({
141
+ extensions,
142
+ transformers
143
+ }) {
144
+ const [editor] = useLexicalComposerContext();
145
+ const plugins = useMemo(() => pluginsOf(extensions, transformers), [extensions, transformers]);
146
+ useEffect(() => {
147
+ const unset = setRichTextExtensionNodeDecorator(editor, (facts, format, nodeKey) => /*#__PURE__*/_jsx(ExtensionNodeView, {
148
+ facts: facts,
149
+ format: format,
150
+ nodeKey: nodeKey,
151
+ plugins: plugins
152
+ }));
153
+ redrawExtensionNodes(editor);
154
+ return () => {
155
+ unset();
156
+ redrawExtensionNodes(editor);
157
+ };
158
+ }, [editor, plugins]);
159
+
160
+ // Bold, italic, or strikethrough toggled on a selection takes the plugin
161
+ // nodes in it along, so they stay inside the marks the text around them
162
+ // gets — and a selection of nodes alone toggles them by themselves.
163
+ useEffect(() => editor.registerCommand(FORMAT_TEXT_COMMAND, format => {
164
+ const selection = $getSelection();
165
+ if (!NODE_FORMATS.has(format) || selection == null) {
166
+ return false;
167
+ }
168
+ const nodes = selection.getNodes().filter(node => $isRichTextExtensionNode(node) && node.isInline());
169
+ if (nodes.length === 0) {
170
+ return false;
171
+ }
172
+ // The state Lexical gives the selected text, read before it does;
173
+ // null when no text is selected, only nodes.
174
+ const textState = $isRangeSelection(selection) ? $nextTextFormat(selection, format) : null;
175
+ if ($isRangeSelection(selection)) {
176
+ selection.formatText(format);
177
+ }
178
+ const isOn = textState ?? !nodes.every(node => node.hasFormat(format));
179
+ for (const node of nodes) {
180
+ node.setFormatFlag(format, isOn);
181
+ }
182
+ return true;
183
+ }, COMMAND_PRIORITY_LOW), [editor]);
184
+ return null;
185
+ }
@@ -26,6 +26,7 @@ import { type ReactNode } from 'react';
26
26
  import { type FieldStatusVariant } from '@astryxdesign/core/Field';
27
27
  import type { BaseProps } from '@astryxdesign/core';
28
28
  import { type SizeValue } from '@astryxdesign/core/utils';
29
+ import type { RichTextMarkdownExtension } from './markdownExtensions';
29
30
  import { type Transformer } from '@lexical/markdown';
30
31
  export type { Transformer } from '@lexical/markdown';
31
32
  import { type EditorState, type Klass, type LexicalEditor, type LexicalNode } from 'lexical';
@@ -201,6 +202,15 @@ export interface RichTextEditorProps extends Omit<BaseProps, 'onChange' | 'defau
201
202
  * the serialization APIs added in later phases.
202
203
  */
203
204
  transformers?: ReadonlyArray<Transformer>;
205
+ /**
206
+ * Markdown plugins whose nodes this surface draws, each adopted with
207
+ * `createRichTextExtension` (spec:AST-064). A plugin node renders exactly as
208
+ * core `Markdown` renders it, and one whose plugin is not given here shows
209
+ * its source. Pass the extensions the content was converted with. Create
210
+ * them in a client module: they hold the plugins' functions, so they are not
211
+ * serializable props.
212
+ */
213
+ markdownExtensions?: ReadonlyArray<RichTextMarkdownExtension>;
204
214
  /** Whether to automatically focus the editor on mount. @default false */
205
215
  hasAutoFocus?: boolean;
206
216
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"RichTextEditor.d.ts","sourceRoot":"","sources":["../src/RichTextEditor.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAQL,KAAK,SAAS,EAEf,MAAM,OAAO,CAAC;AASf,OAAO,EAML,KAAK,kBAAkB,EACxB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,oBAAoB,CAAC;AAGlD,OAAO,EAAyB,KAAK,SAAS,EAAC,MAAM,0BAA0B,CAAC;AAqBhF,OAAO,EAAC,KAAK,WAAW,EAAC,MAAM,mBAAmB,CAAC;AACnD,YAAY,EAAC,WAAW,EAAC,MAAM,mBAAmB,CAAC;AAKnD,OAAO,EASL,KAAK,WAAW,EAChB,KAAK,KAAK,EACV,KAAK,aAAa,EAClB,KAAK,WAAW,EAEjB,MAAM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;;;;OAMG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,cAAc,mHAkRzB,CAAC"}
@@ -53,6 +53,7 @@ import { TextSemanticsExtension } from "./textSemantics.js";
53
53
  import { TableColumnFloorPlugin } from "./TableColumnFloorPlugin.js";
54
54
  import { CodeBlockHeaderPlugin } from "./CodeBlockHeaderPlugin.js";
55
55
  import { CodeSyntaxPlugin } from "./CodeSyntaxPlugin.js";
56
+ import { MarkdownExtensionsPlugin } from "./MarkdownExtensionsPlugin.js";
56
57
  import { TaskCheckboxPlugin } from "./TaskCheckboxPlugin.js";
57
58
  import { $generateHtmlFromNodes } from '@lexical/html';
58
59
  import { DEFAULT_NODES } from "./editorNodes.js";
@@ -224,6 +225,7 @@ export const RichTextEditor = /*#__PURE__*/forwardRef(function RichTextEditor({
224
225
  plugins,
225
226
  hasMarkdownShortcuts = true,
226
227
  transformers = DEFAULT_TRANSFORMERS,
228
+ markdownExtensions,
227
229
  hasAutoFocus = false,
228
230
  tabEscapeHint = DEFAULT_TAB_ESCAPE_HINT,
229
231
  maxLength,
@@ -363,7 +365,10 @@ export const RichTextEditor = /*#__PURE__*/forwardRef(function RichTextEditor({
363
365
  hasCellBackgroundColor: false,
364
366
  hasTabHandler: false,
365
367
  hasHorizontalScroll: true
366
- }), /*#__PURE__*/_jsx(TableColumnFloorPlugin, {}), /*#__PURE__*/_jsx(CodeBlockHeaderPlugin, {}), /*#__PURE__*/_jsx(CodeSyntaxPlugin, {}), /*#__PURE__*/_jsx(TabIndentationPlugin, {}), /*#__PURE__*/_jsx(TabFocusEscapePlugin, {}), hasMarkdownShortcuts && /*#__PURE__*/_jsx(MarkdownShortcutPlugin, {
368
+ }), /*#__PURE__*/_jsx(TableColumnFloorPlugin, {}), /*#__PURE__*/_jsx(CodeBlockHeaderPlugin, {}), /*#__PURE__*/_jsx(CodeSyntaxPlugin, {}), markdownExtensions != null && markdownExtensions.length > 0 ? /*#__PURE__*/_jsx(MarkdownExtensionsPlugin, {
369
+ extensions: markdownExtensions,
370
+ transformers: markdownTransformers
371
+ }) : null, /*#__PURE__*/_jsx(TabIndentationPlugin, {}), /*#__PURE__*/_jsx(TabFocusEscapePlugin, {}), hasMarkdownShortcuts && /*#__PURE__*/_jsx(MarkdownShortcutPlugin, {
367
372
  transformers: markdownTransformers
368
373
  }), hasAutoFocus && /*#__PURE__*/_jsx(AutoFocusOnMount, {}), onChange && /*#__PURE__*/_jsx(OnChangePlugin, {
369
374
  onChange: onChange,
@@ -1 +1 @@
1
- {"version":3,"file":"RichTextEditorToolbar.d.ts","sourceRoot":"","sources":["../src/RichTextEditorToolbar.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAML,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAgHf;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;CAgBrB,CAAC;AAwOX,MAAM,WAAW,0BAA0B;IACzC;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,aAAa,CAAC,EAAE,aAAa,CAAC,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC;IAClD;;;;OAIG;IACH,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;IAC1B;;;;;;;;;OASG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACnE;;;;;;;OAOG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;;;OAIG;IACH,UAAU,CAAC,EAAE,SAAS,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,qBAAqB,CAAC,EACpC,KAAyB,EACzB,aAAkC,EAClC,IAAW,EACX,OAAc,EACd,YAAY,EACZ,iBAAwB,EACxB,UAAU,GACX,EAAE,0BAA0B,+BA6d5B;yBAree,qBAAqB"}
1
+ {"version":3,"file":"RichTextEditorToolbar.d.ts","sourceRoot":"","sources":["../src/RichTextEditorToolbar.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAML,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAkHf;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;CAgBrB,CAAC;AAwOX,MAAM,WAAW,0BAA0B;IACzC;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,aAAa,CAAC,EAAE,aAAa,CAAC,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC;IAClD;;;;OAIG;IACH,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;IAC1B;;;;;;;;;OASG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACnE;;;;;;;OAOG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;;;OAIG;IACH,UAAU,CAAC,EAAE,SAAS,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,qBAAqB,CAAC,EACpC,KAAyB,EACzB,aAAkC,EAClC,IAAW,EACX,OAAc,EACd,YAAY,EACZ,iBAAwB,EACxB,UAAU,GACX,EAAE,0BAA0B,+BAwe5B;yBAhfe,qBAAqB"}
@@ -51,8 +51,9 @@ import { Button } from '@astryxdesign/core/Button';
51
51
  import { Stack } from '@astryxdesign/core/Stack';
52
52
  import { HStack, Layout, LayoutContent, LayoutFooter } from '@astryxdesign/core/Layout';
53
53
  import { getExtendedIcon } from '@astryxdesign/core/Icon';
54
- import { FORMAT_TEXT_COMMAND, UNDO_COMMAND, REDO_COMMAND, CAN_UNDO_COMMAND, CAN_REDO_COMMAND, SELECTION_CHANGE_COMMAND, KEY_DOWN_COMMAND, COMMAND_PRIORITY_CRITICAL, COMMAND_PRIORITY_NORMAL, IS_APPLE, isExactShortcutMatch, $getSelection, $isRangeSelection, $setSelection, $createParagraphNode, $createTextNode } from 'lexical';
54
+ import { FORMAT_TEXT_COMMAND, UNDO_COMMAND, REDO_COMMAND, CAN_UNDO_COMMAND, CAN_REDO_COMMAND, SELECTION_CHANGE_COMMAND, KEY_DOWN_COMMAND, COMMAND_PRIORITY_CRITICAL, COMMAND_PRIORITY_NORMAL, IS_APPLE, isExactShortcutMatch, $getSelection, $isNodeSelection, $isRangeSelection, $setSelection, $createParagraphNode, $createTextNode } from 'lexical';
55
55
  import { sanitizeUrl } from "./linkUtils.js";
56
+ import { $selectedExtensionNodesOnly } from "./markdownExtensionNode.js";
56
57
 
57
58
  /** Block types exposed by the toolbar's format selector. */
58
59
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
@@ -419,16 +420,23 @@ export function RichTextEditorToolbar({
419
420
  const [linkError, setLinkError] = useState('');
420
421
  const $syncToolbar = useCallback(() => {
421
422
  const selection = $getSelection();
422
- if (!$isRangeSelection(selection)) {
423
+ if (!$isRangeSelection(selection) && !$isNodeSelection(selection)) {
423
424
  return;
424
425
  }
425
426
  const formats = new Set();
427
+ // A selection of Markdown plugin nodes alone — a range around them, or
428
+ // a node selection from a click — shows their formats. Any other node
429
+ // selection, such as a rule, has none.
430
+ const nodesOnly = $selectedExtensionNodesOnly(selection);
426
431
  for (const fmt of ['bold', 'italic', 'underline', 'strikethrough', 'code']) {
427
- if (selection.hasFormat(fmt)) {
432
+ if (nodesOnly != null ? nodesOnly.every(node => node.hasFormat(fmt)) : $isRangeSelection(selection) && selection.hasFormat(fmt)) {
428
433
  formats.add(fmt);
429
434
  }
430
435
  }
431
436
  setActiveFormats(formats);
437
+ if (!$isRangeSelection(selection)) {
438
+ return;
439
+ }
432
440
 
433
441
  // Link active state — a link is "active" when the caret/selection anchor
434
442
  // sits inside a LinkNode (or its immediate parent is one):
@@ -15,6 +15,7 @@
15
15
  */
16
16
  import { type ReactNode } from 'react';
17
17
  import type { BaseProps } from '@astryxdesign/core';
18
+ import type { RichTextMarkdownExtension } from './markdownExtensions';
18
19
  import type { Klass, LexicalNode } from 'lexical';
19
20
  export interface RichTextViewProps extends BaseProps {
20
21
  /**
@@ -27,6 +28,15 @@ export interface RichTextViewProps extends BaseProps {
27
28
  * the nodes used to author `value` so custom node types deserialize.
28
29
  */
29
30
  nodes?: ReadonlyArray<Klass<LexicalNode>>;
31
+ /**
32
+ * Markdown plugins whose nodes this surface draws, each adopted with
33
+ * `createRichTextExtension` (spec:AST-064). A plugin node renders exactly as
34
+ * core `Markdown` renders it, and one whose plugin is not given here shows
35
+ * its source. Pass the extensions the content was converted with. Create
36
+ * them in a client module: they hold the plugins' functions, so they are not
37
+ * serializable props.
38
+ */
39
+ markdownExtensions?: ReadonlyArray<RichTextMarkdownExtension>;
30
40
  /**
31
41
  * Additional read-only plugins to render inside the composer (e.g. hover
32
42
  * cards, decorators).
@@ -66,7 +76,7 @@ export interface RichTextViewProps extends BaseProps {
66
76
  * <RichTextView value={storedEditorStateJSON} />
67
77
  * ```
68
78
  */
69
- export declare function RichTextView({ value, nodes, plugins, namespace, onParseError, errorFallback, xstyle, className, style, ...rest }: RichTextViewProps): import("react").JSX.Element;
79
+ export declare function RichTextView({ value, nodes, markdownExtensions, plugins, namespace, onParseError, errorFallback, xstyle, className, style, ...rest }: RichTextViewProps): import("react").JSX.Element;
70
80
  export declare namespace RichTextView {
71
81
  var displayName: string;
72
82
  }
@@ -1 +1 @@
1
- {"version":3,"file":"RichTextView.d.ts","sourceRoot":"","sources":["../src/RichTextView.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAA8B,KAAK,SAAS,EAAC,MAAM,OAAO,CAAC;AAGlE,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,oBAAoB,CAAC;AAclD,OAAO,KAAK,EAEV,KAAK,EACL,WAAW,EAEZ,MAAM,SAAS,CAAC;AA0CjB,MAAM,WAAW,iBAAkB,SAAQ,SAAS;IAClD;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,KAAK,CAAC,EAAE,aAAa,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC;IAC1C;;;OAGG;IACH,OAAO,CAAC,EAAE,SAAS,CAAC;IACpB,6DAA6D;IAC7D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;;;OAOG;IACH,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACtC;;;;OAIG;IACH,aAAa,CAAC,EAAE,SAAS,CAAC;CAC3B;AAyCD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAAC,EAC3B,KAAK,EACL,KAAK,EACL,OAAO,EACP,SAAyB,EACzB,YAAY,EACZ,aAAoB,EACpB,MAAM,EACN,SAAS,EACT,KAAK,EACL,GAAG,IAAI,EACR,EAAE,iBAAiB,+BAwHnB;yBAnIe,YAAY"}
1
+ {"version":3,"file":"RichTextView.d.ts","sourceRoot":"","sources":["../src/RichTextView.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAA8B,KAAK,SAAS,EAAC,MAAM,OAAO,CAAC;AAGlE,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,oBAAoB,CAAC;AAclD,OAAO,KAAK,EAAC,yBAAyB,EAAC,MAAM,sBAAsB,CAAC;AAEpE,OAAO,KAAK,EAEV,KAAK,EACL,WAAW,EAEZ,MAAM,SAAS,CAAC;AA6CjB,MAAM,WAAW,iBAAkB,SAAQ,SAAS;IAClD;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,KAAK,CAAC,EAAE,aAAa,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC;IAC1C;;;;;;;OAOG;IACH,kBAAkB,CAAC,EAAE,aAAa,CAAC,yBAAyB,CAAC,CAAC;IAC9D;;;OAGG;IACH,OAAO,CAAC,EAAE,SAAS,CAAC;IACpB,6DAA6D;IAC7D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;;;OAOG;IACH,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACtC;;;;OAIG;IACH,aAAa,CAAC,EAAE,SAAS,CAAC;CAC3B;AAyCD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAAC,EAC3B,KAAK,EACL,KAAK,EACL,kBAAkB,EAClB,OAAO,EACP,SAAyB,EACzB,YAAY,EACZ,aAAoB,EACpB,MAAM,EACN,SAAS,EACT,KAAK,EACL,GAAG,IAAI,EACR,EAAE,iBAAiB,+BA8HnB;yBA1Ie,YAAY"}
@@ -31,6 +31,7 @@ import { TableScrollRegionPlugin } from "./TableScrollRegionPlugin.js";
31
31
  import { TableColumnFloorPlugin } from "./TableColumnFloorPlugin.js";
32
32
  import { CodeBlockHeaderPlugin } from "./CodeBlockHeaderPlugin.js";
33
33
  import { CodeSyntaxPlugin } from "./CodeSyntaxPlugin.js";
34
+ import { MarkdownExtensionsPlugin } from "./MarkdownExtensionsPlugin.js";
34
35
  import { TaskCheckboxPlugin } from "./TaskCheckboxPlugin.js";
35
36
  import { defineExtension } from 'lexical';
36
37
  import { TextSemanticsExtension } from "./textSemantics.js";
@@ -71,6 +72,9 @@ const VIEW_CONTENT_EDITABLE_PROPS = {
71
72
  'aria-readonly': undefined,
72
73
  role: null
73
74
  };
75
+
76
+ /** The view imports and exports no Markdown, so it uses no transformers. */
77
+ const NO_TRANSFORMERS = [];
74
78
  /**
75
79
  * Keeps the rendered content in sync with the `value` prop after mount.
76
80
  *
@@ -131,6 +135,7 @@ function SyncValuePlugin({
131
135
  export function RichTextView({
132
136
  value,
133
137
  nodes,
138
+ markdownExtensions,
134
139
  plugins,
135
140
  namespace = 'astryx-view',
136
141
  onParseError,
@@ -239,7 +244,10 @@ export function RichTextView({
239
244
  }),
240
245
  placeholder: null,
241
246
  ErrorBoundary: LexicalErrorBoundary
242
- }), /*#__PURE__*/_jsx(CodeBlockHeaderPlugin, {}), /*#__PURE__*/_jsx(CodeSyntaxPlugin, {}), /*#__PURE__*/_jsx(TaskCheckboxPlugin, {
247
+ }), /*#__PURE__*/_jsx(CodeBlockHeaderPlugin, {}), /*#__PURE__*/_jsx(CodeSyntaxPlugin, {}), markdownExtensions != null && markdownExtensions.length > 0 ? /*#__PURE__*/_jsx(MarkdownExtensionsPlugin, {
248
+ extensions: markdownExtensions,
249
+ transformers: NO_TRANSFORMERS
250
+ }) : null, /*#__PURE__*/_jsx(TaskCheckboxPlugin, {
243
251
  isReadOnly: true
244
252
  }), plugins]
245
253
  })
@@ -1 +1 @@
1
- {"version":3,"file":"editorNodes.d.ts","sourceRoot":"","sources":["../src/editorNodes.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAC,KAAK,EAAE,WAAW,EAAC,MAAM,SAAS,CAAC;AAEhD;;;;GAIG;AACH,eAAO,MAAM,aAAa,EAAE,aAAa,CAAC,KAAK,CAAC,WAAW,CAAC,CAa3D,CAAC"}
1
+ {"version":3,"file":"editorNodes.d.ts","sourceRoot":"","sources":["../src/editorNodes.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAC,KAAK,EAAE,WAAW,EAAC,MAAM,SAAS,CAAC;AAGhD;;;;GAIG;AACH,eAAO,MAAM,aAAa,EAAE,aAAa,CAAC,KAAK,CAAC,WAAW,CAAC,CAgB3D,CAAC"}
@@ -17,9 +17,14 @@ import { LinkNode, AutoLinkNode } from '@lexical/link';
17
17
  import { CodeNode, CodeHighlightNode } from '@lexical/code';
18
18
  import { TableNode, TableRowNode, TableCellNode } from '@lexical/table';
19
19
  import { HorizontalRuleNode } from '@lexical/extension';
20
+ import { RichTextExtensionNode } from "./markdownExtensionNode.js";
21
+
20
22
  /**
21
23
  * The default OSS node set registered with the editor: headings, quotes,
22
24
  * lists, links, code, and tables. Extend via the `nodes` prop / option rather
23
25
  * than editing this list.
24
26
  */
25
- export const DEFAULT_NODES = [HeadingNode, QuoteNode, ListNode, ListItemNode, LinkNode, AutoLinkNode, CodeNode, CodeHighlightNode, TableNode, TableRowNode, TableCellNode, HorizontalRuleNode];
27
+ export const DEFAULT_NODES = [HeadingNode, QuoteNode, ListNode, ListItemNode, LinkNode, AutoLinkNode, CodeNode, CodeHighlightNode, TableNode, TableRowNode, TableCellNode, HorizontalRuleNode,
28
+ // Markdown plugin nodes (spec:AST-064): registered everywhere so stored
29
+ // state that holds them always loads.
30
+ RichTextExtensionNode];
@@ -1 +1 @@
1
- {"version":3,"file":"editorTheme.d.ts","sourceRoot":"","sources":["../src/editorTheme.ts"],"names":[],"mappings":"AA2BA,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,SAAS,CAAC;AAsXhD;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,kBAAkB,CAwDtD"}
1
+ {"version":3,"file":"editorTheme.d.ts","sourceRoot":"","sources":["../src/editorTheme.ts"],"names":[],"mappings":"AA2BA,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,SAAS,CAAC;AAsXhD;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,kBAAkB,CA6DtD"}
@@ -236,6 +236,9 @@ export function sharedEditorTheme() {
236
236
  const className = style => stylex.props(style).className ?? '';
237
237
  return {
238
238
  paragraph: block(editorTheme.paragraph),
239
+ // A Markdown plugin's block node is spaced and measured as a paragraph,
240
+ // as core Markdown spaces its block (RichTextExtensionNode reads it).
241
+ markdownExtensionBlock: block(editorTheme.paragraph),
239
242
  heading: {
240
243
  h1: block(editorTheme.h1),
241
244
  h2: block(editorTheme.h2),
@@ -288,6 +291,10 @@ export function sharedEditorTheme() {
288
291
  hrSelected: {
289
292
  className: "xak0ai5 x9ssot5 x19bwoy8 x1eqjuhu"
290
293
  }.className,
294
+ // MarkdownExtensionsPlugin puts it on a selected plugin node.
295
+ markdownExtensionSelected: {
296
+ className: "xak0ai5 x9ssot5 x19bwoy8 x1eqjuhu"
297
+ }.className,
291
298
  table: block(editorTheme.table),
292
299
  // Lexical stamps rows and cells `dir="auto"` too, which would set a cell
293
300
  // of English text left-to-right inside a right-to-left document.
package/dist/index.d.ts CHANGED
@@ -16,6 +16,8 @@ export type { RichTextViewProps } from './RichTextView';
16
16
  export { sharedEditorTheme } from './editorTheme';
17
17
  export { markdownToEditorStateJSON, editorStateJSONToMarkdown, } from './markdownSerializers';
18
18
  export type { MarkdownSerializerOptions } from './markdownSerializers';
19
+ export { createRichTextExtension, RichTextExtensionError, } from './markdownExtensions';
20
+ export type { RichTextMarkdownExtension } from './markdownExtensions';
19
21
  export { RichTextEditorToolbar, RICHTEXT_ICON_KEYS, } from './RichTextEditorToolbar';
20
22
  export type { RichTextEditorToolbarProps } from './RichTextEditorToolbar';
21
23
  export { RichTextEditorAutoLinkPlugin, DEFAULT_LINK_MATCHERS, NEW_TAB_LINK_ATTRIBUTES, } from './RichTextEditorAutoLinkPlugin';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;GAUG;AAEH,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAChD,YAAY,EACV,mBAAmB,EACnB,iBAAiB,EACjB,oBAAoB,EACpB,wBAAwB,EACxB,kBAAkB,EAClB,WAAW,GACZ,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAC5C,YAAY,EAAC,iBAAiB,EAAC,MAAM,gB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AM,yBAAyB,CAAC;AACjC,YAAY,EAAC,0BAA0B,EAAC,MAAM,yBAAyB,CAAC;AAExE,OAAO,EACL,4BAA4B,EAC5B,qBAAqB,EACrB,uBAAuB,GACxB,MAAM,gCAAgC,CAAC;AACxC,YAAY,EAAC,iCAAiC,EAAC,MAAM,gCAAgC,CAAC;AAEtF,OAAO,EACL,WAAW,EACX,WAAW,EACX,WAAW,EACX,aAAa,GACd,MAAM,aAAa,CAAC"}
package/dist/index.js CHANGED
@@ -17,6 +17,7 @@ export { RichTextEditor } from "./RichTextEditor.js";
17
17
  export { RichTextView } from "./RichTextView.js";
18
18
  export { sharedEditorTheme } from "./editorTheme.js";
19
19
  export { markdownToEditorStateJSON, editorStateJSONToMarkdown } from "./markdownSerializers.js";
20
+ export { createRichTextExtension, RichTextExtensionError } from "./markdownExtensions.js";
20
21
  export { RichTextEditorToolbar, RICHTEXT_ICON_KEYS } from "./RichTextEditorToolbar.js";
21
22
  export { RichTextEditorAutoLinkPlugin, DEFAULT_LINK_MATCHERS, NEW_TAB_LINK_ATTRIBUTES } from "./RichTextEditorAutoLinkPlugin.js";
22
23
  export { sanitizeUrl, validateUrl, URL_MATCHER, EMAIL_MATCHER } from "./linkUtils.js";
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @file markdown.ts
3
+ * @output Server-safe entry `@astryxdesign/richtext/markdown`: the Markdown
4
+ * serializers, createRichTextExtension, RichTextExtensionError, and their
5
+ * types.
6
+ * @position Imports no React, DOM, or client-only module, so server and Node
7
+ * code converts Markdown and adopts plugins here (spec:AST-064 FR3, FR12).
8
+ * The package's main entry is a client module and re-exports all of this
9
+ * for client code. An extension holds its plugin's functions, so it is not
10
+ * serializable: create the extensions a page passes to the surfaces in a
11
+ * client module, and create your own for headless use.
12
+ */
13
+ export { markdownToEditorStateJSON, editorStateJSONToMarkdown, } from './markdownSerializers';
14
+ export type { MarkdownSerializerOptions } from './markdownSerializers';
15
+ export { createRichTextExtension, RichTextExtensionError, } from './markdownExtensions';
16
+ export type { RichTextMarkdownExtension } from './markdownExtensions';
17
+ //# sourceMappingURL=markdown.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../src/markdown.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AAEH,OAAO,EACL,yBAAyB,EACzB,yBAAyB,GAC1B,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EAAC,yBAAyB,EAAC,MAAM,uBAAuB,CAAC;AACrE,OAAO,EACL,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EAAC,yBAAyB,EAAC,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1,17 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file markdown.ts
5
+ * @output Server-safe entry `@astryxdesign/richtext/markdown`: the Markdown
6
+ * serializers, createRichTextExtension, RichTextExtensionError, and their
7
+ * types.
8
+ * @position Imports no React, DOM, or client-only module, so server and Node
9
+ * code converts Markdown and adopts plugins here (spec:AST-064 FR3, FR12).
10
+ * The package's main entry is a client module and re-exports all of this
11
+ * for client code. An extension holds its plugin's functions, so it is not
12
+ * serializable: create the extensions a page passes to the surfaces in a
13
+ * client module, and create your own for headless use.
14
+ */
15
+
16
+ export { markdownToEditorStateJSON, editorStateJSONToMarkdown } from "./markdownSerializers.js";
17
+ export { createRichTextExtension, RichTextExtensionError } from "./markdownExtensions.js";
@@ -1,10 +1,21 @@
1
1
  import { type ElementNode } from 'lexical';
2
- /** What a stand-in replaced: a reference as written, or an escaped `&`. */
2
+ /**
3
+ * What a stand-in replaced: a reference as written, an escaped `&`, or a
4
+ * backslash-escaped character.
5
+ */
3
6
  type StandIn = {
4
7
  readonly kind: 'reference';
5
8
  readonly source: string;
6
9
  } | {
7
10
  readonly kind: 'ampersand';
11
+ } | {
12
+ readonly kind: 'escape';
13
+ readonly character: string;
14
+ } | {
15
+ readonly kind: 'backslash';
16
+ } | {
17
+ readonly kind: 'literal';
18
+ readonly text: string;
8
19
  };
9
20
  export interface ProtectedMarkdown {
10
21
  /** The source with stand-ins in place of references. */
@@ -12,6 +23,76 @@ export interface ProtectedMarkdown {
12
23
  /** What each stand-in replaced. */
13
24
  readonly standIns: ReadonlyMap<string, StandIn>;
14
25
  }
26
+ /**
27
+ * Returns `markdown` with every backslash escape outside code — a backslash
28
+ * before ASCII punctuation — replaced by a private-use stand-in for the
29
+ * escaped character, and every backslash in code by a stand-in for itself,
30
+ * which Lexical would otherwise drop from a code span — except before `|`,
31
+ * which a table reads before its code. A backslash before anything else
32
+ * outside code stays as written. One pass over the source.
33
+ */
34
+ export declare function protectBackslashEscapes(markdown: string): ProtectedMarkdown;
35
+ /**
36
+ * Whether core Markdown refuses a link to `url`, a destination already
37
+ * decoded: the probe writes it back with every special character escaped.
38
+ * A URL that cannot be written back is refused.
39
+ */
40
+ export declare function coreRefusesUrl(url: string): boolean;
41
+ /**
42
+ * Returns `markdown` with each inline link whose destination core Markdown
43
+ * refuses — `javascript:` and the like — kept from becoming a link
44
+ * (spec:AST-061 FR7). Where core shows the link as its source text, exactly
45
+ * as written, the whole source becomes one stand-in that comes back as that
46
+ * text. Where core reads no link there at all (its link text holds brackets
47
+ * of its own), only the `(` that opens the destination becomes a stand-in,
48
+ * so the text around it reads as core reads it, marks included. Brackets and
49
+ * parentheses pair by nesting, so link text holding brackets is found whole.
50
+ * Linear in the source: pairs come from one pass, and a destination inside a
51
+ * found link is not probed again. Run first, on the source as written;
52
+ * `$unwrapRefusedLinks` catches any link the editor still makes.
53
+ */
54
+ export declare function protectRefusedLinks(markdown: string): ProtectedMarkdown;
55
+ /**
56
+ * Takes every link under `node` whose URL core Markdown refuses out of its
57
+ * link, leaving its text in place, so no form of link text or destination
58
+ * the source pass did not find can store or draw an unsafe URL.
59
+ */
60
+ export declare function $unwrapRefusedLinks(node: ElementNode): void;
61
+ /**
62
+ * Returns `markdown` with every parenthesis inside an inline link
63
+ * destination — between the destination's own parentheses, balanced, as core
64
+ * Markdown and CommonMark read them — replaced by a private-use stand-in for
65
+ * itself, outside code. Run after protectBackslashEscapes, so an escaped
66
+ * parenthesis is already a stand-in and never counts toward the balance.
67
+ */
68
+ export declare function protectLinkDestinationParentheses(markdown: string): ProtectedMarkdown;
69
+ /** The code spans a stand-in pass replaced: each stand-in's code. */
70
+ export interface ProtectedCodeSpans {
71
+ readonly markdown: string;
72
+ readonly spans: ReadonlyMap<string, string>;
73
+ /** Stand-ins for backticks in link destinations and titles. */
74
+ readonly standIns: ReadonlyMap<string, StandIn>;
75
+ }
76
+ /**
77
+ * Returns `markdown` with each code span outside fenced code replaced by a
78
+ * private-use stand-in, and the code each stands for, as core Markdown reads
79
+ * it. Code spans bind tighter than emphasis and links (CommonMark 0.31
80
+ * §6.1), but Lexical's import applies a code span before an earlier mark on
81
+ * the same line, which breaks every mark around code that follows another
82
+ * (`~~a~~ ~~`c`~~`); with the code out of the way, the marks pair first and
83
+ * the code comes back inside them. Backticks in a link's destination or
84
+ * title are the link's, never a code span: they become stand-ins too, put
85
+ * back into the link's address and title after import, so Lexical cannot
86
+ * pair them into code either. In a table row, a span holding an unescaped
87
+ * `|` is left alone, so the row still splits its cells there, as GFM does.
88
+ */
89
+ export declare function protectCodeSpans(markdown: string): ProtectedCodeSpans;
90
+ /**
91
+ * Puts each code span back where its stand-in sits under `node`: the code as
92
+ * text with the code format, inside whatever marks the stand-in took. In a
93
+ * table cell an escaped `\|` in code is a `|`, as GFM reads cells.
94
+ */
95
+ export declare function $restoreCodeSpans(node: ElementNode, spans: ReadonlyMap<string, string>): void;
15
96
  /**
16
97
  * Returns `markdown` with every character reference outside code replaced by
17
98
  * a private-use stand-in that occurs nowhere else in it, and the escaped `&`
@@ -20,8 +101,9 @@ export interface ProtectedMarkdown {
20
101
  export declare function protectCharacterReferences(markdown: string): ProtectedMarkdown;
21
102
  /**
22
103
  * Replaces the stand-ins under `node` with the characters their references
23
- * name — or, in code Lexical read as code, with the references as written —
24
- * in text, link destinations, and link titles. One pass over the text.
104
+ * name or their escapes stand for — or, in code Lexical read as code, with
105
+ * the references and escapes as written — in text, link destinations, and
106
+ * link titles. One pass over the text.
25
107
  */
26
108
  export declare function $restoreCharacterReferences(node: ElementNode, standIns: ReadonlyMap<string, StandIn>): void;
27
109
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"markdownCharacterReferences.d.ts","sourceRoot":"","sources":["../src/markdownCharacterReferences.ts"],"names":[],"mappings":"AAsBA,OAAO,EAGL,KAAK,WAAW,EAEjB,MAAM,SAAS,CAAC;AAGjB,2EAA2E;AAC3E,KAAK,OAAO,GACR;IAAC,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAC,GACrD;IAAC,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAA;CAAC,CAAC;AAEjC,MAAM,WAAW,iBAAiB;IAChC,wDAAwD;IACxD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,mCAAmC;IACnC,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjD;AAyID;;;;GAIG;AACH,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,MAAM,GACf,iBAAiB,CA+EnB;AA6BD;;;;GAIG;AACH,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,WAAW,EACjB,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,GACrC,IAAI,CAsCN"}
1
+ {"version":3,"file":"markdownCharacterReferences.d.ts","sourceRoot":"","sources":["../src/markdownCharacterReferences.ts"],"names":[],"mappings":"AAiCA,OAAO,EAGL,KAAK,WAAW,EAEjB,MAAM,SAAS,CAAC;AAMjB;;;GAGG;AACH,KAAK,OAAO,GACR;IAAC,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA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