@doist/typist 10.0.0-next.1 → 10.0.0-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/typist-editor.d.ts +126 -123
- package/dist/components/typist-editor.d.ts.map +1 -1
- package/dist/components/typist-editor.helper.d.ts +8 -11
- package/dist/components/typist-editor.helper.d.ts.map +1 -1
- package/dist/components/typist-editor.helper.js +21 -19
- package/dist/components/typist-editor.helper.js.map +1 -0
- package/dist/components/typist-editor.js +133 -135
- package/dist/components/typist-editor.js.map +1 -0
- package/dist/constants/common.js +9 -5
- package/dist/constants/common.js.map +1 -0
- package/dist/constants/extension-priorities.d.ts +3 -1
- package/dist/constants/extension-priorities.d.ts.map +1 -1
- package/dist/constants/extension-priorities.js +34 -30
- package/dist/constants/extension-priorities.js.map +1 -0
- package/dist/constants/regular-expressions.js +14 -10
- package/dist/constants/regular-expressions.js.map +1 -0
- package/dist/extensions/core/extra-editor-commands/commands/create-paragraph-end.d.ts +12 -9
- package/dist/extensions/core/extra-editor-commands/commands/create-paragraph-end.d.ts.map +1 -1
- package/dist/extensions/core/extra-editor-commands/commands/create-paragraph-end.js +16 -19
- package/dist/extensions/core/extra-editor-commands/commands/create-paragraph-end.js.map +1 -0
- package/dist/extensions/core/extra-editor-commands/commands/extend-word-range.d.ts +12 -9
- package/dist/extensions/core/extra-editor-commands/commands/extend-word-range.d.ts.map +1 -1
- package/dist/extensions/core/extra-editor-commands/commands/extend-word-range.js +25 -28
- package/dist/extensions/core/extra-editor-commands/commands/extend-word-range.js.map +1 -0
- package/dist/extensions/core/extra-editor-commands/commands/insert-markdown-content-at.d.ts +24 -22
- package/dist/extensions/core/extra-editor-commands/commands/insert-markdown-content-at.d.ts.map +1 -1
- package/dist/extensions/core/extra-editor-commands/commands/insert-markdown-content-at.js +34 -36
- package/dist/extensions/core/extra-editor-commands/commands/insert-markdown-content-at.js.map +1 -0
- package/dist/extensions/core/extra-editor-commands/commands/insert-markdown-content.d.ts +23 -20
- package/dist/extensions/core/extra-editor-commands/commands/insert-markdown-content.d.ts.map +1 -1
- package/dist/extensions/core/extra-editor-commands/commands/insert-markdown-content.js +15 -8
- package/dist/extensions/core/extra-editor-commands/commands/insert-markdown-content.js.map +1 -0
- package/dist/extensions/core/extra-editor-commands/extra-editor-commands.js +22 -18
- package/dist/extensions/core/extra-editor-commands/extra-editor-commands.js.map +1 -0
- package/dist/extensions/core/view-event-handlers.d.ts +14 -13
- package/dist/extensions/core/view-event-handlers.d.ts.map +1 -1
- package/dist/extensions/core/view-event-handlers.js +33 -31
- package/dist/extensions/core/view-event-handlers.js.map +1 -0
- package/dist/extensions/plain-text/paste-multiline-text.js +45 -59
- package/dist/extensions/plain-text/paste-multiline-text.js.map +1 -0
- package/dist/extensions/plain-text/plain-text-document.d.ts +7 -7
- package/dist/extensions/plain-text/plain-text-document.d.ts.map +1 -1
- package/dist/extensions/plain-text/plain-text-document.js +14 -13
- package/dist/extensions/plain-text/plain-text-document.js.map +1 -0
- package/dist/extensions/plain-text/plain-text-kit.d.ts +35 -33
- package/dist/extensions/plain-text/plain-text-kit.d.ts.map +1 -1
- package/dist/extensions/plain-text/plain-text-kit.js +33 -48
- package/dist/extensions/plain-text/plain-text-kit.js.map +1 -0
- package/dist/extensions/plain-text/plain-text-paragraph.d.ts +2 -9
- package/dist/extensions/plain-text/plain-text-paragraph.js +11 -11
- package/dist/extensions/plain-text/plain-text-paragraph.js.map +1 -0
- package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-lists.js +37 -81
- package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-lists.js.map +1 -0
- package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-select-wrap.js +32 -42
- package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-select-wrap.js.map +1 -0
- package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-url-pasting.js +24 -37
- package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-url-pasting.js.map +1 -0
- package/dist/extensions/plain-text/smart-markdown-typing/smart-markdown-typing.js +21 -13
- package/dist/extensions/plain-text/smart-markdown-typing/smart-markdown-typing.js.map +1 -0
- package/dist/extensions/rich-text/bold-and-italics.js +42 -40
- package/dist/extensions/rich-text/bold-and-italics.js.map +1 -0
- package/dist/extensions/rich-text/curvenote-codemark.js +16 -14
- package/dist/extensions/rich-text/curvenote-codemark.js.map +1 -0
- package/dist/extensions/rich-text/paste-emojis.js +20 -22
- package/dist/extensions/rich-text/paste-emojis.js.map +1 -0
- package/dist/extensions/rich-text/paste-markdown.js +46 -86
- package/dist/extensions/rich-text/paste-markdown.js.map +1 -0
- package/dist/extensions/rich-text/rich-text-bullet-list.d.ts +10 -9
- package/dist/extensions/rich-text/rich-text-bullet-list.d.ts.map +1 -1
- package/dist/extensions/rich-text/rich-text-bullet-list.js +42 -56
- package/dist/extensions/rich-text/rich-text-bullet-list.js.map +1 -0
- package/dist/extensions/rich-text/rich-text-code.js +34 -34
- package/dist/extensions/rich-text/rich-text-code.js.map +1 -0
- package/dist/extensions/rich-text/rich-text-document.d.ts +7 -7
- package/dist/extensions/rich-text/rich-text-document.d.ts.map +1 -1
- package/dist/extensions/rich-text/rich-text-document.js +14 -13
- package/dist/extensions/rich-text/rich-text-document.js.map +1 -0
- package/dist/extensions/rich-text/rich-text-heading.d.ts +5 -4
- package/dist/extensions/rich-text/rich-text-heading.d.ts.map +1 -1
- package/dist/extensions/rich-text/rich-text-heading.js +25 -25
- package/dist/extensions/rich-text/rich-text-heading.js.map +1 -0
- package/dist/extensions/rich-text/rich-text-image.d.ts +53 -52
- package/dist/extensions/rich-text/rich-text-image.d.ts.map +1 -1
- package/dist/extensions/rich-text/rich-text-image.js +88 -105
- package/dist/extensions/rich-text/rich-text-image.js.map +1 -0
- package/dist/extensions/rich-text/rich-text-kit.d.ts +127 -125
- package/dist/extensions/rich-text/rich-text-kit.d.ts.map +1 -1
- package/dist/extensions/rich-text/rich-text-kit.js +73 -135
- package/dist/extensions/rich-text/rich-text-kit.js.map +1 -0
- package/dist/extensions/rich-text/rich-text-link.d.ts +5 -4
- package/dist/extensions/rich-text/rich-text-link.d.ts.map +1 -1
- package/dist/extensions/rich-text/rich-text-link.js +82 -90
- package/dist/extensions/rich-text/rich-text-link.js.map +1 -0
- package/dist/extensions/rich-text/rich-text-ordered-list.d.ts +10 -9
- package/dist/extensions/rich-text/rich-text-ordered-list.d.ts.map +1 -1
- package/dist/extensions/rich-text/rich-text-ordered-list.js +42 -56
- package/dist/extensions/rich-text/rich-text-ordered-list.js.map +1 -0
- package/dist/extensions/rich-text/rich-text-strikethrough.d.ts +5 -4
- package/dist/extensions/rich-text/rich-text-strikethrough.d.ts.map +1 -1
- package/dist/extensions/rich-text/rich-text-strikethrough.js +10 -10
- package/dist/extensions/rich-text/rich-text-strikethrough.js.map +1 -0
- package/dist/extensions/shared/copy-markdown-source.js +22 -31
- package/dist/extensions/shared/copy-markdown-source.js.map +1 -0
- package/dist/extensions/shared/paste-html-table-as-string.js +47 -60
- package/dist/extensions/shared/paste-html-table-as-string.js.map +1 -0
- package/dist/extensions/shared/paste-singleline-text.js +31 -39
- package/dist/extensions/shared/paste-singleline-text.js.map +1 -0
- package/dist/factories/create-suggestion-extension.d.ts +74 -74
- package/dist/factories/create-suggestion-extension.d.ts.map +1 -1
- package/dist/factories/create-suggestion-extension.js +139 -161
- package/dist/factories/create-suggestion-extension.js.map +1 -0
- package/dist/helpers/dom.js +9 -5
- package/dist/helpers/dom.js.map +1 -0
- package/dist/helpers/schema.d.ts +5 -3
- package/dist/helpers/schema.d.ts.map +1 -1
- package/dist/helpers/schema.js +25 -21
- package/dist/helpers/schema.js.map +1 -0
- package/dist/helpers/serializer.js +24 -28
- package/dist/helpers/serializer.js.map +1 -0
- package/dist/helpers/unified.js +24 -17
- package/dist/helpers/unified.js.map +1 -0
- package/dist/hooks/use-editor.js +50 -53
- package/dist/hooks/use-editor.js.map +1 -0
- package/dist/index.d.ts +25 -31
- package/dist/index.js +24 -24
- package/dist/serializers/html/html.d.ts +12 -10
- package/dist/serializers/html/html.d.ts.map +1 -1
- package/dist/serializers/html/html.js +67 -127
- package/dist/serializers/html/html.js.map +1 -0
- package/dist/serializers/html/plugins/rehype-code-block.js +17 -17
- package/dist/serializers/html/plugins/rehype-code-block.js.map +1 -0
- package/dist/serializers/html/plugins/rehype-image.js +20 -30
- package/dist/serializers/html/plugins/rehype-image.js.map +1 -0
- package/dist/serializers/html/plugins/rehype-suggestions.js +31 -32
- package/dist/serializers/html/plugins/rehype-suggestions.js.map +1 -0
- package/dist/serializers/html/plugins/rehype-task-list.js +31 -32
- package/dist/serializers/html/plugins/rehype-task-list.js.map +1 -0
- package/dist/serializers/html/plugins/remark-autolink-literal.d.ts +4 -1
- package/dist/serializers/html/plugins/remark-autolink-literal.d.ts.map +1 -1
- package/dist/serializers/html/plugins/remark-autolink-literal.js +25 -21
- package/dist/serializers/html/plugins/remark-autolink-literal.js.map +1 -0
- package/dist/serializers/html/plugins/remark-disable-constructs.js +21 -41
- package/dist/serializers/html/plugins/remark-disable-constructs.js.map +1 -0
- package/dist/serializers/html/plugins/remark-strikethrough.d.ts +5 -2
- package/dist/serializers/html/plugins/remark-strikethrough.d.ts.map +1 -1
- package/dist/serializers/html/plugins/remark-strikethrough.js +25 -21
- package/dist/serializers/html/plugins/remark-strikethrough.js.map +1 -0
- package/dist/serializers/markdown/markdown.d.ts +13 -12
- package/dist/serializers/markdown/markdown.d.ts.map +1 -1
- package/dist/serializers/markdown/markdown.js +78 -154
- package/dist/serializers/markdown/markdown.js.map +1 -0
- package/dist/serializers/markdown/plugins/image.js +27 -24
- package/dist/serializers/markdown/plugins/image.js.map +1 -0
- package/dist/serializers/markdown/plugins/list-item.js +32 -37
- package/dist/serializers/markdown/plugins/list-item.js.map +1 -0
- package/dist/serializers/markdown/plugins/paragraph.js +19 -19
- package/dist/serializers/markdown/plugins/paragraph.js.map +1 -0
- package/dist/serializers/markdown/plugins/strikethrough.js +23 -19
- package/dist/serializers/markdown/plugins/strikethrough.js.map +1 -0
- package/dist/serializers/markdown/plugins/suggestion.js +21 -19
- package/dist/serializers/markdown/plugins/suggestion.js.map +1 -0
- package/dist/serializers/markdown/plugins/task-item.js +31 -35
- package/dist/serializers/markdown/plugins/task-item.js.map +1 -0
- package/dist/utilities/can-insert-node-at.d.ts +12 -5
- package/dist/utilities/can-insert-node-at.d.ts.map +1 -1
- package/dist/utilities/can-insert-node-at.js +10 -8
- package/dist/utilities/can-insert-node-at.js.map +1 -0
- package/dist/utilities/can-insert-suggestion.d.ts +11 -5
- package/dist/utilities/can-insert-suggestion.d.ts.map +1 -1
- package/dist/utilities/can-insert-suggestion.js +15 -12
- package/dist/utilities/can-insert-suggestion.js.map +1 -0
- package/package.json +4 -3
- package/dist/constants/common.d.ts +0 -10
- package/dist/constants/common.d.ts.map +0 -1
- package/dist/constants/regular-expressions.d.ts +0 -18
- package/dist/constants/regular-expressions.d.ts.map +0 -1
- package/dist/extensions/core/extra-editor-commands/extra-editor-commands.d.ts +0 -9
- package/dist/extensions/core/extra-editor-commands/extra-editor-commands.d.ts.map +0 -1
- package/dist/extensions/plain-text/paste-multiline-text.d.ts +0 -10
- package/dist/extensions/plain-text/paste-multiline-text.d.ts.map +0 -1
- package/dist/extensions/plain-text/plain-text-paragraph.d.ts.map +0 -1
- package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-lists.d.ts +0 -9
- package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-lists.d.ts.map +0 -1
- package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-select-wrap.d.ts +0 -9
- package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-select-wrap.d.ts.map +0 -1
- package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-url-pasting.d.ts +0 -9
- package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-url-pasting.d.ts.map +0 -1
- package/dist/extensions/plain-text/smart-markdown-typing/smart-markdown-typing.d.ts +0 -8
- package/dist/extensions/plain-text/smart-markdown-typing/smart-markdown-typing.d.ts.map +0 -1
- package/dist/extensions/rich-text/bold-and-italics.d.ts +0 -8
- package/dist/extensions/rich-text/bold-and-italics.d.ts.map +0 -1
- package/dist/extensions/rich-text/curvenote-codemark.d.ts +0 -11
- package/dist/extensions/rich-text/curvenote-codemark.d.ts.map +0 -1
- package/dist/extensions/rich-text/paste-emojis.d.ts +0 -9
- package/dist/extensions/rich-text/paste-emojis.d.ts.map +0 -1
- package/dist/extensions/rich-text/paste-markdown.d.ts +0 -11
- package/dist/extensions/rich-text/paste-markdown.d.ts.map +0 -1
- package/dist/extensions/rich-text/rich-text-code.d.ts +0 -17
- package/dist/extensions/rich-text/rich-text-code.d.ts.map +0 -1
- package/dist/extensions/shared/copy-markdown-source.d.ts +0 -20
- package/dist/extensions/shared/copy-markdown-source.d.ts.map +0 -1
- package/dist/extensions/shared/paste-html-table-as-string.d.ts +0 -20
- package/dist/extensions/shared/paste-html-table-as-string.d.ts.map +0 -1
- package/dist/extensions/shared/paste-singleline-text.d.ts +0 -10
- package/dist/extensions/shared/paste-singleline-text.d.ts.map +0 -1
- package/dist/helpers/dom.d.ts +0 -8
- package/dist/helpers/dom.d.ts.map +0 -1
- package/dist/helpers/serializer.d.ts +0 -21
- package/dist/helpers/serializer.d.ts.map +0 -1
- package/dist/helpers/unified.d.ts +0 -21
- package/dist/helpers/unified.d.ts.map +0 -1
- package/dist/hooks/use-editor.d.ts +0 -19
- package/dist/hooks/use-editor.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/serializers/html/plugins/rehype-code-block.d.ts +0 -10
- package/dist/serializers/html/plugins/rehype-code-block.d.ts.map +0 -1
- package/dist/serializers/html/plugins/rehype-image.d.ts +0 -11
- package/dist/serializers/html/plugins/rehype-image.d.ts.map +0 -1
- package/dist/serializers/html/plugins/rehype-suggestions.d.ts +0 -10
- package/dist/serializers/html/plugins/rehype-suggestions.d.ts.map +0 -1
- package/dist/serializers/html/plugins/rehype-task-list.d.ts +0 -7
- package/dist/serializers/html/plugins/rehype-task-list.d.ts.map +0 -1
- package/dist/serializers/html/plugins/remark-disable-constructs.d.ts +0 -11
- package/dist/serializers/html/plugins/remark-disable-constructs.d.ts.map +0 -1
- package/dist/serializers/markdown/plugins/image.d.ts +0 -12
- package/dist/serializers/markdown/plugins/image.d.ts.map +0 -1
- package/dist/serializers/markdown/plugins/list-item.d.ts +0 -14
- package/dist/serializers/markdown/plugins/list-item.d.ts.map +0 -1
- package/dist/serializers/markdown/plugins/paragraph.d.ts +0 -13
- package/dist/serializers/markdown/plugins/paragraph.d.ts.map +0 -1
- package/dist/serializers/markdown/plugins/strikethrough.d.ts +0 -13
- package/dist/serializers/markdown/plugins/strikethrough.d.ts.map +0 -1
- package/dist/serializers/markdown/plugins/suggestion.d.ts +0 -11
- package/dist/serializers/markdown/plugins/suggestion.d.ts.map +0 -1
- package/dist/serializers/markdown/plugins/task-item.d.ts +0 -14
- package/dist/serializers/markdown/plugins/task-item.d.ts.map +0 -1
package/dist/hooks/use-editor.js
CHANGED
|
@@ -1,62 +1,59 @@
|
|
|
1
|
-
import { useCallback, useEffect, useState } from
|
|
2
|
-
import { Editor } from
|
|
1
|
+
import { useCallback, useEffect, useState } from "react";
|
|
2
|
+
import { Editor } from "@tiptap/react";
|
|
3
|
+
//#region src/hooks/use-editor.ts
|
|
3
4
|
function stateChanger(state) {
|
|
4
|
-
|
|
5
|
+
return (state + 1) % Number.MAX_SAFE_INTEGER;
|
|
5
6
|
}
|
|
6
7
|
/**
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
* This is a copy of the `useRerender` hook from `@react-hookz/web`, which is a utility hook that
|
|
9
|
+
* returns a function that can be called to force a re-render of the component.
|
|
10
|
+
*
|
|
11
|
+
* Turns out we don't have the need to use any of the other hooks from `@react-hookz/web`, which is
|
|
12
|
+
* a peer dependency that often introduces breaking changes, causing upgrade issues across our
|
|
13
|
+
* projects.
|
|
14
|
+
*/
|
|
14
15
|
function useRerender() {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
const [, setState] = useState(0);
|
|
17
|
+
return useCallback(() => {
|
|
18
|
+
setState(stateChanger);
|
|
19
|
+
}, []);
|
|
19
20
|
}
|
|
20
21
|
/**
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
22
|
+
* This is a fork of the official `useEditor` hook with one key difference, which is to prevent a
|
|
23
|
+
* `null` Editor object instance from being returned on the first render.
|
|
24
|
+
*
|
|
25
|
+
* This change was once fixed in the `@tiptap/react` package, but was reverted because it didn't
|
|
26
|
+
* have support for server-side rendering ([ref](https://github.com/ueberdosis/tiptap/pull/2282)),
|
|
27
|
+
* which is a problem we don't currently have.
|
|
28
|
+
*
|
|
29
|
+
* @param options The options to configure the editor component with.
|
|
30
|
+
* @param dependencies If present, re-create the editor instance if the values in the list change.
|
|
31
|
+
*
|
|
32
|
+
* @returns A new editor instance with the given options.
|
|
33
|
+
*/
|
|
33
34
|
function useEditor(options = {}, dependencies = []) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return function destroyEditorInstance() {
|
|
55
|
-
instance.destroy();
|
|
56
|
-
};
|
|
57
|
-
},
|
|
58
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
59
|
-
dependencies);
|
|
60
|
-
return editor;
|
|
35
|
+
const [editor, setEditor] = useState(() => new Editor(options));
|
|
36
|
+
const forceRerender = useRerender();
|
|
37
|
+
useEffect(function initializeEditorInstance() {
|
|
38
|
+
let instance;
|
|
39
|
+
if (editor.isDestroyed) {
|
|
40
|
+
instance = new Editor(options);
|
|
41
|
+
setEditor(instance);
|
|
42
|
+
} else instance = editor;
|
|
43
|
+
instance.on("transaction", () => {
|
|
44
|
+
requestAnimationFrame(() => {
|
|
45
|
+
requestAnimationFrame(() => {
|
|
46
|
+
if (!instance.isDestroyed) forceRerender();
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
return function destroyEditorInstance() {
|
|
51
|
+
instance.destroy();
|
|
52
|
+
};
|
|
53
|
+
}, dependencies);
|
|
54
|
+
return editor;
|
|
61
55
|
}
|
|
56
|
+
//#endregion
|
|
62
57
|
export { useEditor };
|
|
58
|
+
|
|
59
|
+
//# sourceMappingURL=use-editor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-editor.js","names":[],"sources":["../../src/hooks/use-editor.ts"],"sourcesContent":["import { DependencyList, useCallback, useEffect, useState } from 'react'\n\nimport { Editor } from '@tiptap/react'\n\nimport type { EditorOptions } from '@tiptap/core'\n\nfunction stateChanger(state: number) {\n return (state + 1) % Number.MAX_SAFE_INTEGER\n}\n\n/**\n * This is a copy of the `useRerender` hook from `@react-hookz/web`, which is a utility hook that\n * returns a function that can be called to force a re-render of the component.\n *\n * Turns out we don't have the need to use any of the other hooks from `@react-hookz/web`, which is\n * a peer dependency that often introduces breaking changes, causing upgrade issues across our\n * projects.\n */\nfunction useRerender(): () => void {\n const [, setState] = useState(0)\n\n return useCallback(() => {\n setState(stateChanger)\n }, [])\n}\n\n/**\n * This is a fork of the official `useEditor` hook with one key difference, which is to prevent a\n * `null` Editor object instance from being returned on the first render.\n *\n * This change was once fixed in the `@tiptap/react` package, but was reverted because it didn't\n * have support for server-side rendering ([ref](https://github.com/ueberdosis/tiptap/pull/2282)),\n * which is a problem we don't currently have.\n *\n * @param options The options to configure the editor component with.\n * @param dependencies If present, re-create the editor instance if the values in the list change.\n *\n * @returns A new editor instance with the given options.\n */\nfunction useEditor(\n options: Partial<EditorOptions> = {},\n dependencies: DependencyList = [],\n): Editor {\n const [editor, setEditor] = useState<Editor>(() => new Editor(options))\n\n const forceRerender = useRerender()\n\n useEffect(\n function initializeEditorInstance() {\n let instance: Editor\n\n if (editor.isDestroyed) {\n instance = new Editor(options)\n setEditor(instance)\n } else {\n instance = editor\n }\n\n instance.on('transaction', () => {\n requestAnimationFrame(() => {\n requestAnimationFrame(() => {\n if (!instance.isDestroyed) {\n forceRerender()\n }\n })\n })\n })\n\n return function destroyEditorInstance() {\n instance.destroy()\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n dependencies,\n )\n\n return editor\n}\n\nexport { useEditor }\n"],"mappings":";;;AAMA,SAAS,aAAa,OAAe;AACjC,SAAQ,QAAQ,KAAK,OAAO;;;;;;;;;;AAWhC,SAAS,cAA0B;CAC/B,MAAM,GAAG,YAAY,SAAS,EAAE;AAEhC,QAAO,kBAAkB;AACrB,WAAS,aAAa;IACvB,EAAE,CAAC;;;;;;;;;;;;;;;AAgBV,SAAS,UACL,UAAkC,EAAE,EACpC,eAA+B,EAAE,EAC3B;CACN,MAAM,CAAC,QAAQ,aAAa,eAAuB,IAAI,OAAO,QAAQ,CAAC;CAEvE,MAAM,gBAAgB,aAAa;AAEnC,WACI,SAAS,2BAA2B;EAChC,IAAI;AAEJ,MAAI,OAAO,aAAa;AACpB,cAAW,IAAI,OAAO,QAAQ;AAC9B,aAAU,SAAS;QAEnB,YAAW;AAGf,WAAS,GAAG,qBAAqB;AAC7B,+BAA4B;AACxB,gCAA4B;AACxB,SAAI,CAAC,SAAS,YACV,gBAAe;MAErB;KACJ;IACJ;AAEF,SAAO,SAAS,wBAAwB;AACpC,YAAS,SAAS;;IAI1B,aACH;AAED,QAAO"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,31 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
export *
|
|
25
|
-
export
|
|
26
|
-
export * as ProseMirrorView from '@tiptap/pm/view';
|
|
27
|
-
export type { Editor, NodeViewProps, ReactRendererOptions } from '@tiptap/react';
|
|
28
|
-
export { NodeViewWrapper, ReactRenderer } from '@tiptap/react';
|
|
29
|
-
export type { SuggestionKeyDownProps, SuggestionOptions as TiptapSuggestionOptions, } from '@tiptap/suggestion';
|
|
30
|
-
export { Suggestion } from '@tiptap/suggestion';
|
|
31
|
-
//# sourceMappingURL=index.d.ts.map
|
|
1
|
+
import { BeforeCreateProps, BlurProps, CreateProps, DestroyProps, FocusProps, SelectionUpdateProps, TransacationProps, TypistEditor, TypistEditorProps, TypistEditorRef, UpdateProps } from "./components/typist-editor.js";
|
|
2
|
+
import { BLOCKQUOTE_EXTENSION_PRIORITY, CODE_EXTENSION_PRIORITY, PASTE_HTML_TABLE_AS_STRING_EXTENSION_PRIORITY, PASTE_MARKDOWN_EXTENSION_PRIORITY, SMART_MARKDOWN_TYPING_PRIORITY, SUGGESTION_EXTENSION_PRIORITY, VIEW_EVENT_HANDLERS_PRIORITY } from "./constants/extension-priorities.js";
|
|
3
|
+
import { createParagraphEnd } from "./extensions/core/extra-editor-commands/commands/create-paragraph-end.js";
|
|
4
|
+
import { extendWordRange } from "./extensions/core/extra-editor-commands/commands/extend-word-range.js";
|
|
5
|
+
import { insertMarkdownContent } from "./extensions/core/extra-editor-commands/commands/insert-markdown-content.js";
|
|
6
|
+
import { insertMarkdownContentAt } from "./extensions/core/extra-editor-commands/commands/insert-markdown-content-at.js";
|
|
7
|
+
import { PlainTextKit } from "./extensions/plain-text/plain-text-kit.js";
|
|
8
|
+
import { RichTextImageAttributes, RichTextImageOptions } from "./extensions/rich-text/rich-text-image.js";
|
|
9
|
+
import { RichTextKit } from "./extensions/rich-text/rich-text-kit.js";
|
|
10
|
+
import { SuggestionExtensionResult, SuggestionOptions, SuggestionRendererProps, SuggestionRendererRef, SuggestionStorage, createSuggestionExtension } from "./factories/create-suggestion-extension.js";
|
|
11
|
+
import { isMultilineDocument, isPlainTextDocument } from "./helpers/schema.js";
|
|
12
|
+
import { createHTMLSerializer, getHTMLSerializerInstance } from "./serializers/html/html.js";
|
|
13
|
+
import { remarkAutolinkLiteral } from "./serializers/html/plugins/remark-autolink-literal.js";
|
|
14
|
+
import { remarkStrikethrough } from "./serializers/html/plugins/remark-strikethrough.js";
|
|
15
|
+
import { createMarkdownSerializer, getMarkdownSerializerInstance } from "./serializers/markdown/markdown.js";
|
|
16
|
+
import { canInsertNodeAt } from "./utilities/can-insert-node-at.js";
|
|
17
|
+
import { canInsertSuggestion } from "./utilities/can-insert-suggestion.js";
|
|
18
|
+
import { AnyConfig, Editor as CoreEditor, EditorEvents, Extension, Mark, MarkRange, Range, combineTransactionSteps, defaultBlockAt, findChildren, findChildrenInRange, findParentNode, findParentNodeClosestToPos, generateHTML, generateJSON, generateText, getAttributes, getChangedRanges, getDebugJSON, getExtensionField, getHTMLFromFragment, getMarkAttributes, getMarkRange, getMarkType, getMarksBetween, getNodeAttributes, getNodeType, getSchema, getText, getTextBetween, isActive, isList, isMarkActive, isNodeActive, isNodeEmpty, isNodeSelection, isTextSelection, mergeAttributes, posToDOMRect } from "@tiptap/core";
|
|
19
|
+
import { Editor, NodeViewProps, NodeViewWrapper, ReactRenderer, ReactRendererOptions } from "@tiptap/react";
|
|
20
|
+
import * as ProseMirrorState from "@tiptap/pm/state";
|
|
21
|
+
import * as ProseMirrorModel from "@tiptap/pm/model";
|
|
22
|
+
import { Suggestion, SuggestionKeyDownProps, SuggestionOptions as TiptapSuggestionOptions } from "@tiptap/suggestion";
|
|
23
|
+
import * as ProseMirrorView from "@tiptap/pm/view";
|
|
24
|
+
export * from "@tiptap/extension-character-count";
|
|
25
|
+
export { type AnyConfig, BLOCKQUOTE_EXTENSION_PRIORITY, type BeforeCreateProps, type BlurProps, CODE_EXTENSION_PRIORITY, type CoreEditor, type CreateProps, type DestroyProps, type Editor, type EditorEvents, Extension, type FocusProps, Mark, type MarkRange, type NodeViewProps, NodeViewWrapper, PASTE_HTML_TABLE_AS_STRING_EXTENSION_PRIORITY, PASTE_MARKDOWN_EXTENSION_PRIORITY, PlainTextKit, ProseMirrorModel, ProseMirrorState, ProseMirrorView, type Range, ReactRenderer, type ReactRendererOptions, type RichTextImageAttributes, type RichTextImageOptions, RichTextKit, SMART_MARKDOWN_TYPING_PRIORITY, SUGGESTION_EXTENSION_PRIORITY, type SelectionUpdateProps, Suggestion, type SuggestionExtensionResult, type SuggestionKeyDownProps, type SuggestionOptions, type SuggestionRendererProps, type SuggestionRendererRef, type SuggestionStorage, type TiptapSuggestionOptions, type TransacationProps, TypistEditor, type TypistEditorProps, type TypistEditorRef, type UpdateProps, VIEW_EVENT_HANDLERS_PRIORITY, canInsertNodeAt, canInsertSuggestion, combineTransactionSteps, createHTMLSerializer, createMarkdownSerializer, createParagraphEnd, createSuggestionExtension, defaultBlockAt, extendWordRange, findChildren, findChildrenInRange, findParentNode, findParentNodeClosestToPos, generateHTML, generateJSON, generateText, getAttributes, getChangedRanges, getDebugJSON, getExtensionField, getHTMLFromFragment, getHTMLSerializerInstance, getMarkAttributes, getMarkRange, getMarkType, getMarkdownSerializerInstance, getMarksBetween, getNodeAttributes, getNodeType, getSchema, getText, getTextBetween, insertMarkdownContent, insertMarkdownContentAt, isActive, isList, isMarkActive, isMultilineDocument, isNodeActive, isNodeEmpty, isNodeSelection, isPlainTextDocument, isTextSelection, mergeAttributes, posToDOMRect, remarkAutolinkLiteral, remarkStrikethrough };
|
package/dist/index.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
export
|
|
24
|
-
export { Suggestion
|
|
1
|
+
import { createParagraphEnd } from "./extensions/core/extra-editor-commands/commands/create-paragraph-end.js";
|
|
2
|
+
import { extendWordRange } from "./extensions/core/extra-editor-commands/commands/extend-word-range.js";
|
|
3
|
+
import { insertMarkdownContent } from "./extensions/core/extra-editor-commands/commands/insert-markdown-content.js";
|
|
4
|
+
import { isMultilineDocument, isPlainTextDocument } from "./helpers/schema.js";
|
|
5
|
+
import { remarkAutolinkLiteral } from "./serializers/html/plugins/remark-autolink-literal.js";
|
|
6
|
+
import { remarkStrikethrough } from "./serializers/html/plugins/remark-strikethrough.js";
|
|
7
|
+
import { createHTMLSerializer, getHTMLSerializerInstance } from "./serializers/html/html.js";
|
|
8
|
+
import { insertMarkdownContentAt } from "./extensions/core/extra-editor-commands/commands/insert-markdown-content-at.js";
|
|
9
|
+
import { BLOCKQUOTE_EXTENSION_PRIORITY, CODE_EXTENSION_PRIORITY, PASTE_HTML_TABLE_AS_STRING_EXTENSION_PRIORITY, PASTE_MARKDOWN_EXTENSION_PRIORITY, SMART_MARKDOWN_TYPING_PRIORITY, SUGGESTION_EXTENSION_PRIORITY, VIEW_EVENT_HANDLERS_PRIORITY } from "./constants/extension-priorities.js";
|
|
10
|
+
import { createMarkdownSerializer, getMarkdownSerializerInstance } from "./serializers/markdown/markdown.js";
|
|
11
|
+
import { TypistEditor } from "./components/typist-editor.js";
|
|
12
|
+
import { PlainTextKit } from "./extensions/plain-text/plain-text-kit.js";
|
|
13
|
+
import { RichTextKit } from "./extensions/rich-text/rich-text-kit.js";
|
|
14
|
+
import { canInsertNodeAt } from "./utilities/can-insert-node-at.js";
|
|
15
|
+
import { canInsertSuggestion } from "./utilities/can-insert-suggestion.js";
|
|
16
|
+
import { createSuggestionExtension } from "./factories/create-suggestion-extension.js";
|
|
17
|
+
import { Extension, Mark, combineTransactionSteps, defaultBlockAt, findChildren, findChildrenInRange, findParentNode, findParentNodeClosestToPos, generateHTML, generateJSON, generateText, getAttributes, getChangedRanges, getDebugJSON, getExtensionField, getHTMLFromFragment, getMarkAttributes, getMarkRange, getMarkType, getMarksBetween, getNodeAttributes, getNodeType, getSchema, getText, getTextBetween, isActive, isList, isMarkActive, isNodeActive, isNodeEmpty, isNodeSelection, isTextSelection, mergeAttributes, posToDOMRect } from "@tiptap/core";
|
|
18
|
+
import { NodeViewWrapper, ReactRenderer } from "@tiptap/react";
|
|
19
|
+
import * as ProseMirrorState from "@tiptap/pm/state";
|
|
20
|
+
import * as ProseMirrorModel from "@tiptap/pm/model";
|
|
21
|
+
import { Suggestion } from "@tiptap/suggestion";
|
|
22
|
+
import * as ProseMirrorView from "@tiptap/pm/view";
|
|
23
|
+
export * from "@tiptap/extension-character-count";
|
|
24
|
+
export { BLOCKQUOTE_EXTENSION_PRIORITY, CODE_EXTENSION_PRIORITY, Extension, Mark, NodeViewWrapper, PASTE_HTML_TABLE_AS_STRING_EXTENSION_PRIORITY, PASTE_MARKDOWN_EXTENSION_PRIORITY, PlainTextKit, ProseMirrorModel, ProseMirrorState, ProseMirrorView, ReactRenderer, RichTextKit, SMART_MARKDOWN_TYPING_PRIORITY, SUGGESTION_EXTENSION_PRIORITY, Suggestion, TypistEditor, VIEW_EVENT_HANDLERS_PRIORITY, canInsertNodeAt, canInsertSuggestion, combineTransactionSteps, createHTMLSerializer, createMarkdownSerializer, createParagraphEnd, createSuggestionExtension, defaultBlockAt, extendWordRange, findChildren, findChildrenInRange, findParentNode, findParentNodeClosestToPos, generateHTML, generateJSON, generateText, getAttributes, getChangedRanges, getDebugJSON, getExtensionField, getHTMLFromFragment, getHTMLSerializerInstance, getMarkAttributes, getMarkRange, getMarkType, getMarkdownSerializerInstance, getMarksBetween, getNodeAttributes, getNodeType, getSchema, getText, getTextBetween, insertMarkdownContent, insertMarkdownContentAt, isActive, isList, isMarkActive, isMultilineDocument, isNodeActive, isNodeEmpty, isNodeSelection, isPlainTextDocument, isTextSelection, mergeAttributes, posToDOMRect, remarkAutolinkLiteral, remarkStrikethrough };
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Schema } from "@tiptap/pm/model";
|
|
2
|
+
|
|
3
|
+
//#region src/serializers/html/html.d.ts
|
|
2
4
|
/**
|
|
3
5
|
* The return type for the `createHTMLSerializer` function.
|
|
4
6
|
*/
|
|
5
7
|
type HTMLSerializerReturnType = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Serializes an input Markdown string to an output HTML string.
|
|
10
|
+
*
|
|
11
|
+
* @param markdown The Markdown string to serialize.
|
|
12
|
+
*
|
|
13
|
+
* @returns The serialized HTML.
|
|
14
|
+
*/
|
|
15
|
+
serialize: (markdown: string) => string;
|
|
14
16
|
};
|
|
15
17
|
/**
|
|
16
18
|
* Create a Markdown to HTML serializer with the unified ecosystem for a rich-text editor, or use a
|
|
@@ -30,6 +32,6 @@ declare function createHTMLSerializer(schema: Schema): HTMLSerializerReturnType;
|
|
|
30
32
|
* @returns The HTML serializer instance for the given editor schema.
|
|
31
33
|
*/
|
|
32
34
|
declare function getHTMLSerializerInstance(schema: Schema): HTMLSerializerReturnType;
|
|
35
|
+
//#endregion
|
|
33
36
|
export { createHTMLSerializer, getHTMLSerializerInstance };
|
|
34
|
-
export type { HTMLSerializerReturnType };
|
|
35
37
|
//# sourceMappingURL=html.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html.d.ts","
|
|
1
|
+
{"version":3,"file":"html.d.ts","names":[],"sources":["../../../src/serializers/html/html.ts"],"mappings":";;;;;AAkB8C;KAKzC,wBAAA;;;;AAQ2B;;;;EAA5B,SAAA,GAAY,QAAA;AAAA;;;;AAoDuD;;;;;;iBAA9D,oBAAA,CAAqB,MAAA,EAAQ,MAAA,GAAS,wBAAA;;;;;;;;iBA+FtC,yBAAA,CAA0B,MAAA,EAAQ,MAAA,GAAM,wBAAA"}
|
|
@@ -1,139 +1,79 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import {
|
|
1
|
+
import { computeSchemaId, isPlainTextDocument } from "../../helpers/schema.js";
|
|
2
|
+
import { rehypeCodeBlock } from "./plugins/rehype-code-block.js";
|
|
3
|
+
import { rehypeImage } from "./plugins/rehype-image.js";
|
|
4
|
+
import { rehypeSuggestions } from "./plugins/rehype-suggestions.js";
|
|
5
|
+
import { rehypeTaskList } from "./plugins/rehype-task-list.js";
|
|
6
|
+
import { remarkAutolinkLiteral } from "./plugins/remark-autolink-literal.js";
|
|
7
|
+
import { remarkDisableConstructs } from "./plugins/remark-disable-constructs.js";
|
|
8
|
+
import { remarkStrikethrough } from "./plugins/remark-strikethrough.js";
|
|
9
|
+
import { escape, kebabCase } from "lodash-es";
|
|
10
|
+
import rehypeMinifyWhitespace from "rehype-minify-whitespace";
|
|
11
|
+
import rehypeStringify from "rehype-stringify";
|
|
12
|
+
import remarkBreaks from "remark-breaks";
|
|
13
|
+
import remarkParse from "remark-parse";
|
|
14
|
+
import remarkRehype from "remark-rehype";
|
|
15
|
+
import { unified } from "unified";
|
|
16
|
+
//#region src/serializers/html/html.ts
|
|
16
17
|
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
* Create a custom Markdown to HTML serializer for plain-text editors only.
|
|
19
|
+
*
|
|
20
|
+
* @param schema The editor schema to be used for nodes and marks detection.
|
|
21
|
+
*
|
|
22
|
+
* @returns A normalized object for the HTML serializer.
|
|
23
|
+
*/
|
|
23
24
|
function createHTMLSerializerForPlainTextEditor(schema) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
.filter((node) => node.name.endsWith('Suggestion'))
|
|
33
|
-
.forEach((suggestionNode) => {
|
|
34
|
-
const linkSchema = kebabCase(suggestionNode.name.replace(/Suggestion$/, ''));
|
|
35
|
-
htmlResult = htmlResult.replace(new RegExp(`\\[([^\\[]+)\\]\\((?:${linkSchema}):\\/\\/(\\d+)\\)`, 'gm'), `<span data-${linkSchema} data-id="$2" data-label="$1"></span>`);
|
|
36
|
-
});
|
|
37
|
-
// Return the serialized HTML with every line wrapped in a paragraph element
|
|
38
|
-
return htmlResult.replace(/^([^\n]+)\n?|\n+/gm, `<p>$1</p>`);
|
|
39
|
-
},
|
|
40
|
-
};
|
|
25
|
+
return { serialize(markdown) {
|
|
26
|
+
let htmlResult = escape(markdown);
|
|
27
|
+
Object.values(schema.nodes).filter((node) => node.name.endsWith("Suggestion")).forEach((suggestionNode) => {
|
|
28
|
+
const linkSchema = kebabCase(suggestionNode.name.replace(/Suggestion$/, ""));
|
|
29
|
+
htmlResult = htmlResult.replace(new RegExp(`\\[([^\\[]+)\\]\\((?:${linkSchema}):\\/\\/(\\d+)\\)`, "gm"), `<span data-${linkSchema} data-id="$2" data-label="$1"></span>`);
|
|
30
|
+
});
|
|
31
|
+
return htmlResult.replace(/^([^\n]+)\n?|\n+/gm, `<p>$1</p>`);
|
|
32
|
+
} };
|
|
41
33
|
}
|
|
42
34
|
/**
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
35
|
+
* Create a Markdown to HTML serializer with the unified ecosystem for a rich-text editor, or use a
|
|
36
|
+
* custom serializer for a plain-text editor. The editor schema is used to detect which nodes and
|
|
37
|
+
* marks are available in the editor, and only parses the input with the minimal required plugins.
|
|
38
|
+
*
|
|
39
|
+
* @param schema The editor schema to be used for nodes and marks detection.
|
|
40
|
+
*
|
|
41
|
+
* @returns A normalized object for the HTML serializer.
|
|
42
|
+
*/
|
|
51
43
|
function createHTMLSerializer(schema) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
// Configure the unified processor to use a custom plugin to add support for the strikethrough
|
|
68
|
-
// extension from the GitHub Flavored Markdown (GFM) specification
|
|
69
|
-
if (schema.marks.strike) {
|
|
70
|
-
unifiedProcessor.use(remarkStrikethrough, { singleTilde: false });
|
|
71
|
-
}
|
|
72
|
-
// Configure the unified processor to use a custom plugin to add support for the autolink
|
|
73
|
-
// literals extension from the GitHub Flavored Markdown (GFM) specification
|
|
74
|
-
if (schema.marks.link) {
|
|
75
|
-
unifiedProcessor.use(remarkAutolinkLiteral);
|
|
76
|
-
}
|
|
77
|
-
// Configure the unified processor with an official plugin to convert Markdown into HTML to
|
|
78
|
-
// support rehype (a tool that transforms HTML with plugins), followed by another official
|
|
79
|
-
// plugin to minify whitespace between tags (prevents line feeds from appearing as blank)
|
|
80
|
-
unifiedProcessor
|
|
81
|
-
.use(remarkRehype, {
|
|
82
|
-
// Persist raw HTML (disables support for custom elements/tags)
|
|
83
|
-
// ref: https://github.com/Doist/Issues/issues/5689
|
|
84
|
-
allowDangerousHtml: true,
|
|
85
|
-
})
|
|
86
|
-
// This must come before all rehype plugins that transform the HTML output
|
|
87
|
-
.use(rehypeMinifyWhitespace, {
|
|
88
|
-
// Preserve line breaks when collapsing whitespace (e.g., line feeds)
|
|
89
|
-
newlines: true,
|
|
90
|
-
});
|
|
91
|
-
// Configure the unified processor with a custom plugin to remove the trailing newline from code
|
|
92
|
-
// blocks (i.e. the newline between the last code line and `</code></pre>`)
|
|
93
|
-
if (schema.nodes.codeBlock) {
|
|
94
|
-
unifiedProcessor.use(rehypeCodeBlock);
|
|
95
|
-
}
|
|
96
|
-
// Configure the unified processor with a custom plugin to remove the wrapping paragraph from
|
|
97
|
-
// images and to remove all inline images based on inline images support in the editor schema
|
|
98
|
-
if (schema.nodes.paragraph && schema.nodes.image) {
|
|
99
|
-
unifiedProcessor.use(rehypeImage, schema);
|
|
100
|
-
}
|
|
101
|
-
// Configure the unified processor with a custom plugin to add support Tiptap task lists
|
|
102
|
-
if (schema.nodes.taskList && schema.nodes.taskItem) {
|
|
103
|
-
unifiedProcessor.use(rehypeTaskList);
|
|
104
|
-
}
|
|
105
|
-
// Configure the unified processor with a custom plugin to add support for suggestions nodes
|
|
106
|
-
unifiedProcessor.use(rehypeSuggestions, schema);
|
|
107
|
-
// Configure the unified processor with an official plugin that defines how to take a syntax
|
|
108
|
-
// tree as input and turn it into serialized HTML
|
|
109
|
-
unifiedProcessor.use(rehypeStringify, {
|
|
110
|
-
characterReferences: {
|
|
111
|
-
// Compatibility with the previous implementation in Marked
|
|
112
|
-
useNamedReferences: true,
|
|
113
|
-
},
|
|
114
|
-
});
|
|
115
|
-
return {
|
|
116
|
-
serialize(markdown) {
|
|
117
|
-
return unifiedProcessor.processSync(markdown).toString();
|
|
118
|
-
},
|
|
119
|
-
};
|
|
44
|
+
if (isPlainTextDocument(schema)) return createHTMLSerializerForPlainTextEditor(schema);
|
|
45
|
+
const unifiedProcessor = unified().use(remarkParse);
|
|
46
|
+
unifiedProcessor.use(remarkDisableConstructs, schema);
|
|
47
|
+
if (schema.nodes.hardBreak) unifiedProcessor.use(remarkBreaks);
|
|
48
|
+
if (schema.marks.strike) unifiedProcessor.use(remarkStrikethrough, { singleTilde: false });
|
|
49
|
+
if (schema.marks.link) unifiedProcessor.use(remarkAutolinkLiteral);
|
|
50
|
+
unifiedProcessor.use(remarkRehype, { allowDangerousHtml: true }).use(rehypeMinifyWhitespace, { newlines: true });
|
|
51
|
+
if (schema.nodes.codeBlock) unifiedProcessor.use(rehypeCodeBlock);
|
|
52
|
+
if (schema.nodes.paragraph && schema.nodes.image) unifiedProcessor.use(rehypeImage, schema);
|
|
53
|
+
if (schema.nodes.taskList && schema.nodes.taskItem) unifiedProcessor.use(rehypeTaskList);
|
|
54
|
+
unifiedProcessor.use(rehypeSuggestions, schema);
|
|
55
|
+
unifiedProcessor.use(rehypeStringify, { characterReferences: { useNamedReferences: true } });
|
|
56
|
+
return { serialize(markdown) {
|
|
57
|
+
return unifiedProcessor.processSync(markdown).toString();
|
|
58
|
+
} };
|
|
120
59
|
}
|
|
121
60
|
/**
|
|
122
|
-
|
|
123
|
-
|
|
61
|
+
* Object that holds multiple HTML serializer instances based on a given ID.
|
|
62
|
+
*/
|
|
124
63
|
const htmlSerializerInstanceById = {};
|
|
125
64
|
/**
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
65
|
+
* Returns a singleton instance of a HTML serializer based on the provided editor schema.
|
|
66
|
+
*
|
|
67
|
+
* @param schema The editor schema connected to the HTML serializer instance.
|
|
68
|
+
*
|
|
69
|
+
* @returns The HTML serializer instance for the given editor schema.
|
|
70
|
+
*/
|
|
132
71
|
function getHTMLSerializerInstance(schema) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
137
|
-
return htmlSerializerInstanceById[id];
|
|
72
|
+
const id = computeSchemaId(schema);
|
|
73
|
+
if (!htmlSerializerInstanceById[id]) htmlSerializerInstanceById[id] = createHTMLSerializer(schema);
|
|
74
|
+
return htmlSerializerInstanceById[id];
|
|
138
75
|
}
|
|
76
|
+
//#endregion
|
|
139
77
|
export { createHTMLSerializer, getHTMLSerializerInstance };
|
|
78
|
+
|
|
79
|
+
//# sourceMappingURL=html.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html.js","names":[],"sources":["../../../src/serializers/html/html.ts"],"sourcesContent":["import { escape, kebabCase } from 'lodash-es'\nimport rehypeMinifyWhitespace from 'rehype-minify-whitespace'\nimport rehypeStringify from 'rehype-stringify'\nimport remarkBreaks from 'remark-breaks'\nimport remarkParse from 'remark-parse'\nimport remarkRehype from 'remark-rehype'\nimport { unified } from 'unified'\n\nimport { computeSchemaId, isPlainTextDocument } from '../../helpers/schema'\n\nimport { rehypeCodeBlock } from './plugins/rehype-code-block'\nimport { rehypeImage } from './plugins/rehype-image'\nimport { rehypeSuggestions } from './plugins/rehype-suggestions'\nimport { rehypeTaskList } from './plugins/rehype-task-list'\nimport { remarkAutolinkLiteral } from './plugins/remark-autolink-literal'\nimport { remarkDisableConstructs } from './plugins/remark-disable-constructs'\nimport { remarkStrikethrough } from './plugins/remark-strikethrough'\n\nimport type { Schema } from '@tiptap/pm/model'\n\n/**\n * The return type for the `createHTMLSerializer` function.\n */\ntype HTMLSerializerReturnType = {\n /**\n * Serializes an input Markdown string to an output HTML string.\n *\n * @param markdown The Markdown string to serialize.\n *\n * @returns The serialized HTML.\n */\n serialize: (markdown: string) => string\n}\n\n/**\n * The type for the object that holds multiple HTML serializer instances.\n */\ntype HTMLSerializerInstanceById = {\n [id: string]: HTMLSerializerReturnType\n}\n\n/**\n * Create a custom Markdown to HTML serializer for plain-text editors only.\n *\n * @param schema The editor schema to be used for nodes and marks detection.\n *\n * @returns A normalized object for the HTML serializer.\n */\nfunction createHTMLSerializerForPlainTextEditor(schema: Schema) {\n return {\n serialize(markdown: string) {\n // Converts special characters (i.e. `&`, `<`, `>`, `\"`, and `'`) to their corresponding\n // HTML entities because we need to output the full content as valid HTML (i.e. the\n // editor should not drop invalid HTML).\n let htmlResult = escape(markdown)\n\n // Serialize all suggestion links if any suggestion node exists in the schema\n Object.values(schema.nodes)\n .filter((node) => node.name.endsWith('Suggestion'))\n .forEach((suggestionNode) => {\n const linkSchema = kebabCase(suggestionNode.name.replace(/Suggestion$/, ''))\n\n htmlResult = htmlResult.replace(\n new RegExp(`\\\\[([^\\\\[]+)\\\\]\\\\((?:${linkSchema}):\\\\/\\\\/(\\\\d+)\\\\)`, 'gm'),\n `<span data-${linkSchema} data-id=\"$2\" data-label=\"$1\"></span>`,\n )\n })\n\n // Return the serialized HTML with every line wrapped in a paragraph element\n return htmlResult.replace(/^([^\\n]+)\\n?|\\n+/gm, `<p>$1</p>`)\n },\n }\n}\n\n/**\n * Create a Markdown to HTML serializer with the unified ecosystem for a rich-text editor, or use a\n * custom serializer for a plain-text editor. The editor schema is used to detect which nodes and\n * marks are available in the editor, and only parses the input with the minimal required plugins.\n *\n * @param schema The editor schema to be used for nodes and marks detection.\n *\n * @returns A normalized object for the HTML serializer.\n */\nfunction createHTMLSerializer(schema: Schema): HTMLSerializerReturnType {\n // Returns a custom HTML serializer for plain-text editors\n if (isPlainTextDocument(schema)) {\n return createHTMLSerializerForPlainTextEditor(schema)\n }\n\n // Initialize a unified processor with a remark plugin for parsing Markdown\n const unifiedProcessor = unified().use(remarkParse)\n\n // Configure the unified processor to use a custom plugin to disable constructs based on the\n // supported extensions that are enabled in the editor schema\n unifiedProcessor.use(remarkDisableConstructs, schema)\n\n // Configure the unified processor to use a third-party plugin to turn soft line endings into\n // hard breaks (i.e. `<br>`), which will display user content closer to how it was authored\n // (although not CommonMark compliant, this resembles the behaviour we always supported)\n if (schema.nodes.hardBreak) {\n unifiedProcessor.use(remarkBreaks)\n }\n\n // Configure the unified processor to use a custom plugin to add support for the strikethrough\n // extension from the GitHub Flavored Markdown (GFM) specification\n if (schema.marks.strike) {\n unifiedProcessor.use(remarkStrikethrough, { singleTilde: false })\n }\n\n // Configure the unified processor to use a custom plugin to add support for the autolink\n // literals extension from the GitHub Flavored Markdown (GFM) specification\n if (schema.marks.link) {\n unifiedProcessor.use(remarkAutolinkLiteral)\n }\n\n // Configure the unified processor with an official plugin to convert Markdown into HTML to\n // support rehype (a tool that transforms HTML with plugins), followed by another official\n // plugin to minify whitespace between tags (prevents line feeds from appearing as blank)\n unifiedProcessor\n .use(remarkRehype, {\n // Persist raw HTML (disables support for custom elements/tags)\n // ref: https://github.com/Doist/Issues/issues/5689\n allowDangerousHtml: true,\n })\n // This must come before all rehype plugins that transform the HTML output\n .use(rehypeMinifyWhitespace, {\n // Preserve line breaks when collapsing whitespace (e.g., line feeds)\n newlines: true,\n })\n\n // Configure the unified processor with a custom plugin to remove the trailing newline from code\n // blocks (i.e. the newline between the last code line and `</code></pre>`)\n if (schema.nodes.codeBlock) {\n unifiedProcessor.use(rehypeCodeBlock)\n }\n\n // Configure the unified processor with a custom plugin to remove the wrapping paragraph from\n // images and to remove all inline images based on inline images support in the editor schema\n if (schema.nodes.paragraph && schema.nodes.image) {\n unifiedProcessor.use(rehypeImage, schema)\n }\n\n // Configure the unified processor with a custom plugin to add support Tiptap task lists\n if (schema.nodes.taskList && schema.nodes.taskItem) {\n unifiedProcessor.use(rehypeTaskList)\n }\n\n // Configure the unified processor with a custom plugin to add support for suggestions nodes\n unifiedProcessor.use(rehypeSuggestions, schema)\n\n // Configure the unified processor with an official plugin that defines how to take a syntax\n // tree as input and turn it into serialized HTML\n unifiedProcessor.use(rehypeStringify, {\n characterReferences: {\n // Compatibility with the previous implementation in Marked\n useNamedReferences: true,\n },\n })\n\n return {\n serialize(markdown: string) {\n return unifiedProcessor.processSync(markdown).toString()\n },\n }\n}\n\n/**\n * Object that holds multiple HTML serializer instances based on a given ID.\n */\nconst htmlSerializerInstanceById: HTMLSerializerInstanceById = {}\n\n/**\n * Returns a singleton instance of a HTML serializer based on the provided editor schema.\n *\n * @param schema The editor schema connected to the HTML serializer instance.\n *\n * @returns The HTML serializer instance for the given editor schema.\n */\nfunction getHTMLSerializerInstance(schema: Schema) {\n const id = computeSchemaId(schema)\n\n if (!htmlSerializerInstanceById[id]) {\n htmlSerializerInstanceById[id] = createHTMLSerializer(schema)\n }\n\n return htmlSerializerInstanceById[id]\n}\n\nexport { createHTMLSerializer, getHTMLSerializerInstance }\n\nexport type { HTMLSerializerReturnType }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAgDA,SAAS,uCAAuC,QAAgB;AAC5D,QAAO,EACH,UAAU,UAAkB;EAIxB,IAAI,aAAa,OAAO,SAAS;AAGjC,SAAO,OAAO,OAAO,MAAM,CACtB,QAAQ,SAAS,KAAK,KAAK,SAAS,aAAa,CAAC,CAClD,SAAS,mBAAmB;GACzB,MAAM,aAAa,UAAU,eAAe,KAAK,QAAQ,eAAe,GAAG,CAAC;AAE5E,gBAAa,WAAW,QACpB,IAAI,OAAO,wBAAwB,WAAW,oBAAoB,KAAK,EACvE,cAAc,WAAW,uCAC5B;IACH;AAGN,SAAO,WAAW,QAAQ,sBAAsB,YAAY;IAEnE;;;;;;;;;;;AAYL,SAAS,qBAAqB,QAA0C;AAEpE,KAAI,oBAAoB,OAAO,CAC3B,QAAO,uCAAuC,OAAO;CAIzD,MAAM,mBAAmB,SAAS,CAAC,IAAI,YAAY;AAInD,kBAAiB,IAAI,yBAAyB,OAAO;AAKrD,KAAI,OAAO,MAAM,UACb,kBAAiB,IAAI,aAAa;AAKtC,KAAI,OAAO,MAAM,OACb,kBAAiB,IAAI,qBAAqB,EAAE,aAAa,OAAO,CAAC;AAKrE,KAAI,OAAO,MAAM,KACb,kBAAiB,IAAI,sBAAsB;AAM/C,kBACK,IAAI,cAAc,EAGf,oBAAoB,MACvB,CAAC,CAED,IAAI,wBAAwB,EAEzB,UAAU,MACb,CAAC;AAIN,KAAI,OAAO,MAAM,UACb,kBAAiB,IAAI,gBAAgB;AAKzC,KAAI,OAAO,MAAM,aAAa,OAAO,MAAM,MACvC,kBAAiB,IAAI,aAAa,OAAO;AAI7C,KAAI,OAAO,MAAM,YAAY,OAAO,MAAM,SACtC,kBAAiB,IAAI,eAAe;AAIxC,kBAAiB,IAAI,mBAAmB,OAAO;AAI/C,kBAAiB,IAAI,iBAAiB,EAClC,qBAAqB,EAEjB,oBAAoB,MACvB,EACJ,CAAC;AAEF,QAAO,EACH,UAAU,UAAkB;AACxB,SAAO,iBAAiB,YAAY,SAAS,CAAC,UAAU;IAE/D;;;;;AAML,MAAM,6BAAyD,EAAE;;;;;;;;AASjE,SAAS,0BAA0B,QAAgB;CAC/C,MAAM,KAAK,gBAAgB,OAAO;AAElC,KAAI,CAAC,2BAA2B,IAC5B,4BAA2B,MAAM,qBAAqB,OAAO;AAGjE,QAAO,2BAA2B"}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { isHastElementNode, isHastTextNode } from "../../../helpers/unified.js";
|
|
2
|
+
import { visit } from "unist-util-visit";
|
|
3
|
+
//#region src/serializers/html/plugins/rehype-code-block.ts
|
|
3
4
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
* A rehype plugin to remove the trailing newline from code blocks (i.e. the newline between the
|
|
6
|
+
* last code line and `</code></pre>`). Although that newline is part of the CommonMark
|
|
7
|
+
* specification, this custom plugin is required to prevent Tiptap from rendering a blank line at
|
|
8
|
+
* the end of the code block.
|
|
9
|
+
*/
|
|
9
10
|
function rehypeCodeBlock() {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
return tree;
|
|
19
|
-
};
|
|
11
|
+
return (...[tree]) => {
|
|
12
|
+
visit(tree, "element", (node) => {
|
|
13
|
+
if (isHastElementNode(node, "pre") && isHastElementNode(node.children[0], "code") && isHastTextNode(node.children[0].children[0])) node.children[0].children[0].value = node.children[0].children[0].value.replace(/\n$/, "");
|
|
14
|
+
});
|
|
15
|
+
return tree;
|
|
16
|
+
};
|
|
20
17
|
}
|
|
18
|
+
//#endregion
|
|
21
19
|
export { rehypeCodeBlock };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=rehype-code-block.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rehype-code-block.js","names":[],"sources":["../../../../src/serializers/html/plugins/rehype-code-block.ts"],"sourcesContent":["import { visit } from 'unist-util-visit'\n\nimport { isHastElementNode, isHastTextNode } from '../../../helpers/unified'\n\nimport type { Node as HastNode } from 'hast'\nimport type { Transformer } from 'unified'\n\n/**\n * A rehype plugin to remove the trailing newline from code blocks (i.e. the newline between the\n * last code line and `</code></pre>`). Although that newline is part of the CommonMark\n * specification, this custom plugin is required to prevent Tiptap from rendering a blank line at\n * the end of the code block.\n */\nfunction rehypeCodeBlock(): Transformer {\n return (...[tree]: Parameters<Transformer>): ReturnType<Transformer> => {\n visit(tree, 'element', (node: HastNode) => {\n if (\n isHastElementNode(node, 'pre') &&\n isHastElementNode(node.children[0], 'code') &&\n isHastTextNode(node.children[0].children[0])\n ) {\n node.children[0].children[0].value = node.children[0].children[0].value.replace(\n /\\n$/,\n '',\n )\n }\n })\n\n return tree\n }\n}\n\nexport { rehypeCodeBlock }\n"],"mappings":";;;;;;;;;AAaA,SAAS,kBAA+B;AACpC,SAAQ,GAAG,CAAC,UAA4D;AACpE,QAAM,MAAM,YAAY,SAAmB;AACvC,OACI,kBAAkB,MAAM,MAAM,IAC9B,kBAAkB,KAAK,SAAS,IAAI,OAAO,IAC3C,eAAe,KAAK,SAAS,GAAG,SAAS,GAAG,CAE5C,MAAK,SAAS,GAAG,SAAS,GAAG,QAAQ,KAAK,SAAS,GAAG,SAAS,GAAG,MAAM,QACpE,OACA,GACH;IAEP;AAEF,SAAO"}
|