platejs 54.0.0-beta.2 → 54.0.0-beta.4
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/README.md +1 -1
- package/THIRD_PARTY_NOTICES.md +56 -0
- package/dist/{AIChatRequestContext-BMVWhfPV.d.ts → AIChatRequestContext-DrUahdTc.d.ts} +2 -2
- package/dist/{BaseSuggestionPlugin-DBl3fqnm.d.ts → BaseSuggestionPlugin-_7Ka6nY3.d.ts} +7 -3
- package/dist/{PlateStatic-DhNv2ejp.d.ts → PlateStatic-D3Cb-QwH.d.ts} +7 -7
- package/dist/ai/index.d.ts +1 -1
- package/dist/ai/react/AIChatPlugin.js +113 -78
- package/dist/ai/react/CopilotPlugin.js +1 -1
- package/dist/ai/react/index.d.ts +23 -16
- package/dist/authored/index.d.ts +4 -4
- package/dist/code-block/codemirror/createCodeMirrorAdapter.js +12 -9
- package/dist/code-block/codemirror/index.d.ts +1 -1
- package/dist/{combobox-DkBGgyd3.d.ts → combobox-Dr0OYZIE.d.ts} +2 -2
- package/dist/{comparison-types-CYnJ35qU.d.ts → comparison-types-DdwE6mYq-BogsHoUO.d.ts} +10 -2
- package/dist/compiler/index.d.ts +2 -2
- package/dist/{core-BJG8l_mk.d.ts → core-BqR-fEDp.d.ts} +493 -116
- package/dist/diff/index.d.ts +2 -2
- package/dist/docs/ai.md +4 -3
- package/dist/docs/api/core/plate-components.md +0 -19
- package/dist/docs/api/core/plate-controller.md +5 -3
- package/dist/docs/api/core/plate-plugin.md +3 -0
- package/dist/docs/api/core/plate-store.md +3 -3
- package/dist/docs/api/core.md +45 -5
- package/dist/docs/api/dom.md +11 -4
- package/dist/docs/api/editor-transforms.md +2 -1
- package/dist/docs/api/react-hooks.md +45 -13
- package/dist/docs/authored-changes.md +9 -4
- package/dist/docs/basic-blocks.md +42 -29
- package/dist/docs/block-placeholder.md +4 -2
- package/dist/docs/blockquote.md +5 -3
- package/dist/docs/board.md +118 -10
- package/dist/docs/code-block.md +47 -0
- package/dist/docs/comment.md +2 -2
- package/dist/docs/discussion.md +1 -1
- package/dist/docs/document-model.md +15 -3
- package/dist/docs/docx.md +1 -1
- package/dist/docs/dom-coverage.md +5 -0
- package/dist/docs/editor.md +50 -4
- package/dist/docs/examples/editable-voids.md +2 -3
- package/dist/docs/external-text.md +2 -0
- package/dist/docs/field.md +370 -0
- package/dist/docs/find.md +9 -6
- package/dist/docs/form.md +2 -0
- package/dist/docs/heading.md +6 -0
- package/dist/docs/installation/manual.md +0 -4
- package/dist/docs/link.md +3 -3
- package/dist/docs/llms.txt +4 -2
- package/dist/docs/markdown.md +270 -14
- package/dist/docs/plugin-components.md +13 -10
- package/dist/docs/plugin-input-rules.md +66 -15
- package/dist/docs/prompt-editor.md +205 -0
- package/dist/docs/roots.md +8 -6
- package/dist/docs/rtl.md +6 -4
- package/dist/docs/selection.md +7 -4
- package/dist/docs/suggestion.md +1 -1
- package/dist/docs/toolbar.md +26 -30
- package/dist/docs/upload.md +106 -17
- package/dist/docx/export/index.d.ts +3 -3
- package/dist/docx/export/lib/docxStaticComponents.js +12 -2
- package/dist/docx/export/lib/exportDocx.js +46 -17
- package/dist/docx/export/lib/internal/xml-builder.js +11 -16
- package/dist/docx/export/lib/reviewPart.js +1 -1
- package/dist/docx/export/lib/reviewProjection.js +52 -10
- package/dist/docx/import/index.d.ts +4 -4
- package/dist/docx/paste/index.d.ts +4 -4
- package/dist/dom/index.d.ts +1 -6
- package/dist/dom/plite-dom.internal.js +2 -2
- package/dist/excalidraw/index.d.ts +3 -2
- package/dist/excalidraw/react/index.d.ts +3 -2
- package/dist/facade.js +2 -2
- package/dist/features/basic-nodes/lib/BaseBlockPlugins.js +13 -5
- package/dist/features/basic-nodes/lib/BaseHeadingPlugins.js +32 -10
- package/dist/features/board/index.d.ts +2 -2
- package/dist/features/board/lib/BaseBoardPlugin.js +14 -1
- package/dist/features/board/lib/boardStroke.internal.js +13 -1
- package/dist/features/board/lib/boardTypes.internal.js +16 -0
- package/dist/features/callout/index.d.ts +3 -2
- package/dist/features/code-block/lib/BaseCodeBlockPlugin.js +14 -5
- package/dist/features/combobox/index.d.ts +2 -2
- package/dist/features/comments/BaseCommentsPlugin.js +33 -17
- package/dist/features/comments/index.d.ts +1 -1
- package/dist/features/date/index.d.ts +3 -2
- package/dist/features/details/index.d.ts +3 -2
- package/dist/features/details/lib/BaseDetailsPlugin.js +25 -12
- package/dist/features/field/index.d.ts +2 -0
- package/dist/features/field/index.js +4 -0
- package/dist/features/field/lib/BaseFieldPlugin.js +360 -0
- package/dist/features/field/lib/applyFieldValues.js +188 -0
- package/dist/features/field/lib/fieldRules.internal.js +204 -0
- package/dist/features/find/index.d.ts +3 -2
- package/dist/features/footnote/index.d.ts +1 -1
- package/dist/features/ink/index.d.ts +1 -1
- package/dist/features/ink/lib/BaseInkPlugin.js +126 -103
- package/dist/features/ink/lib/inkCodec.internal.js +130 -0
- package/dist/features/ink/lib/inkGone.internal.js +229 -48
- package/dist/features/ink/lib/inkPlaces.internal.js +534 -64
- package/dist/features/layout/index.d.ts +1 -1
- package/dist/features/link/lib/BaseLinkPlugin.js +6 -4
- package/dist/features/lint/index.d.ts +3 -2
- package/dist/features/media/index.d.ts +2 -2
- package/dist/features/media/index.js +2 -2
- package/dist/features/media/lib/media/parseMediaUrl.js +11 -1
- package/dist/features/media/lib/media-embed/BaseMediaEmbedPlugin.js +206 -4
- package/dist/features/mention/index.d.ts +5 -4
- package/dist/features/suggestion/index.d.ts +1 -1
- package/dist/features/table/index.d.ts +1 -1
- package/dist/features/table/lib/BaseTablePlugin.js +64 -15
- package/dist/features/table/lib/internal/selection.js +4 -2
- package/dist/features/toc/index.d.ts +1 -1
- package/dist/features/upload/index.d.ts +2 -2
- package/dist/features/upload/lib/BaseUploadPlugin.js +464 -250
- package/dist/history/index.d.ts +2 -2
- package/dist/html/index.d.ts +3 -3
- package/dist/html/server/index.d.ts +1 -1
- package/dist/{htmlTypes-DjeFG3P8.d.ts → htmlTypes-eT2ZGDAj.d.ts} +2 -31
- package/dist/hyperscript/index.d.ts +1 -1
- package/dist/{index-DzD6BIFJ.d.ts → index-B33E1CRJ.d.ts} +295 -6
- package/dist/{index-Cl77E9yr.d.ts → index-B7moSod7.d.ts} +2 -2
- package/dist/{index-hsC_sOn2.d.ts → index-B8-5Sr7I.d.ts} +35 -5
- package/dist/{index-BiQerPJS.d.ts → index-B8QJDAmG.d.ts} +2 -2
- package/dist/{index-BBKGrsG3.d.ts → index-BTx5oK7k.d.ts} +1 -1
- package/dist/{index-iaZOhA76.d.ts → index-BWPcE4ac-Cto_IsNs.d.ts} +7 -1
- package/dist/{index-BU6k1Aev.d.ts → index-BXjLmx1n-CXk17buG.d.ts} +4781 -4584
- package/dist/{index-kLKMc-pI.d.ts → index-BXwU9QH6.d.ts} +2 -2
- package/dist/{index-DTgaSxKr.d.ts → index-BkwR-5hH.d.ts} +40 -4
- package/dist/{index-Bq3sdm3S.d.ts → index-BsV2McRr.d.ts} +5 -4
- package/dist/index-C9Fu-P4E.d.ts +773 -0
- package/dist/{index-D5W-p9bS.d.ts → index-Ca48r1ng.d.ts} +49 -4
- package/dist/{index-CcZbqPqk.d.ts → index-Cob_iBdu.d.ts} +116 -41
- package/dist/{index-Bxfvicyy.d.ts → index-CpY7Xnxw.d.ts} +4 -3
- package/dist/{index-BkR7-GLI.d.ts → index-DNQXzU-X.d.ts} +2 -2
- package/dist/{index-D1CFXA-i.d.ts → index-DPowErHa.d.ts} +471 -141
- package/dist/{index-DaM37gF6.d.ts → index-DShbzec2.d.ts} +38 -23
- package/dist/{index-DC_MNGyu.d.ts → index-DYdObeFQ.d.ts} +3 -3
- package/dist/{index-Bc2Yg_2j.d.ts → index-Dq3Jlj8O-BJ6NxZm0.d.ts} +2 -2
- package/dist/{index-CT7miqQN.d.ts → index-DwWQVwQt.d.ts} +29 -11
- package/dist/{index-xdmCBvlT.d.ts → index-JWgwL5l3.d.ts} +5 -2
- package/dist/{index-DLA2DUR2.d.ts → index-M781pyx9.d.ts} +4 -3
- package/dist/{index-DdIRduDG.d.ts → index-d7io3MzC.d.ts} +3 -2
- package/dist/index.d.ts +4 -4
- package/dist/{react/internal → internal}/penStroke.internal.js +1 -1
- package/dist/internal/plugin/OverridePlugin.js +101 -119
- package/dist/internal/plugin/collectPlateNodeMappings.js +5 -1
- package/dist/internal/plugin/pastedUploadFiles.js +4 -0
- package/dist/internal/plugin/resolvePlugin.js +1 -1
- package/dist/internal/plugin/resolvePlugins.js +3 -0
- package/dist/internal/plugin/uploadDrafts.js +6 -0
- package/dist/internal/utils/mergePlugins.js +1 -0
- package/dist/lib/plugins/element-id/ElementIdPlugin.js +14 -18
- package/dist/lib/plugins/html/HtmlPlugin.js +9 -0
- package/dist/lib/plugins/html/htmlSafety.js +1 -1
- package/dist/lib/plugins/input-rules/InputRulesPlugin.js +77 -28
- package/dist/lib/plugins/input-rules/inputRuleVeto.internal.js +16 -0
- package/dist/markdown/index.d.ts +2 -2
- package/dist/markdown/index.js +3 -1
- package/dist/markdown/lib/MarkdownPlugin.js +14 -11
- package/dist/markdown/lib/RawHtmlPlugin.js +26 -0
- package/dist/markdown/lib/deserializer/mdastToSlate.js +12 -2
- package/dist/markdown/lib/internal/markdownConversion.js +776 -74
- package/dist/markdown/lib/internal/markdownDiagnostics.js +18 -7
- package/dist/markdown/lib/internal/markdownFootnoteWriter.js +35 -0
- package/dist/markdown/lib/internal/markdownFrontmatter.js +102 -0
- package/dist/markdown/lib/internal/markdownIntrinsics.js +125 -43
- package/dist/markdown/lib/internal/markdownLine.js +5 -3
- package/dist/markdown/lib/internal/markdownMappings.js +19 -7
- package/dist/markdown/lib/internal/markdownOpenTail.js +381 -0
- package/dist/markdown/lib/internal/markdownRawHtml.js +353 -0
- package/dist/markdown/lib/internal/markdownSegments.js +57 -48
- package/dist/markdown/lib/internal/markdownTags.js +29 -9
- package/dist/markdown/lib/serializer/convertNodesSerialize.js +10 -8
- package/dist/markdown/lib/serializer/convertPhrasingSerialize.js +226 -0
- package/dist/markdown/lib/serializer/listToMdastTree.js +2 -0
- package/dist/math/index.d.ts +3 -2
- package/dist/math/react/index.d.ts +4 -3
- package/dist/migrations/index.d.ts +3 -3
- package/dist/migrations/migratePlateV54.js +4 -6
- package/dist/migrations/migratePlateV54RetiredMarks.internal.js +23 -8
- package/dist/migrations/migratePlateV54Suggestions.internal.js +2 -2
- package/dist/migrations/v53-manifest.internal.js +4 -0
- package/dist/pagination/index.d.ts +1 -1
- package/dist/pagination/react/index.d.ts +4 -4
- package/dist/react/components/EditorContentView.internal.js +42 -23
- package/dist/react/components/EditorProvider.js +5 -5
- package/dist/react/components/Plate.js +102 -128
- package/dist/react/components/PlateContainer.js +40 -32
- package/dist/react/components/PlateController.js +28 -16
- package/dist/react/components/PlateRoot.internal.js +3 -2
- package/dist/react/core.js +4 -4
- package/dist/react/features/board/BoardSurface.js +116 -87
- package/dist/react/features/board/boardClipboard.internal.js +15 -5
- package/dist/react/features/board/boardExport.internal.js +470 -0
- package/dist/react/features/board/boardGesture.internal.js +6 -3
- package/dist/react/features/board/boardIndex.internal.js +7 -18
- package/dist/react/features/board/boardPictureStyles.internal.js +415 -0
- package/dist/react/features/board/boardPictures.internal.js +19 -13
- package/dist/react/features/board/boardView.internal.js +190 -50
- package/dist/react/features/board/boardVoice.internal.js +10 -11
- package/dist/react/features/board/index.d.ts +108 -18
- package/dist/react/features/callout/index.d.ts +3 -2
- package/dist/react/features/combobox/index.d.ts +8 -8
- package/dist/react/features/comments/index.d.ts +6 -5
- package/dist/react/features/date/index.d.ts +4 -3
- package/dist/react/features/details/index.d.ts +4 -3
- package/dist/react/features/field/FieldPlugin.js +35 -0
- package/dist/react/features/field/index.d.ts +315 -0
- package/dist/react/features/field/index.js +2 -0
- package/dist/react/features/footnote/index.d.ts +7 -6
- package/dist/react/features/format-painter/index.d.ts +4 -3
- package/dist/react/features/ink/InkContent.js +313 -0
- package/dist/react/features/ink/index.d.ts +57 -33
- package/dist/react/features/ink/index.js +2 -2
- package/dist/react/features/ink/inkCapture.internal.js +39 -17
- package/dist/react/features/ink/inkInput.internal.js +1 -1
- package/dist/react/features/ink/inkLayout.internal.js +6 -3
- package/dist/react/features/ink/inkPaint.internal.js +78 -2
- package/dist/react/features/ink/inkPlacement.internal.js +332 -104
- package/dist/react/features/ink/inkWatch.internal.js +7 -5
- package/dist/react/features/layout/index.d.ts +5 -4
- package/dist/react/features/media/index.d.ts +5 -4
- package/dist/react/features/mention/index.d.ts +6 -5
- package/dist/react/features/resizable/Resizable.js +4 -6
- package/dist/react/features/resizable/index.d.ts +5 -5
- package/dist/react/features/suggestion/index.d.ts +6 -5
- package/dist/react/features/table/TablePlugin.js +4 -11
- package/dist/react/features/table/index.d.ts +10 -8
- package/dist/react/features/table/useTableResize.js +10 -1
- package/dist/react/features/toc/index.d.ts +2 -2
- package/dist/react/features/upload/index.d.ts +11 -6
- package/dist/react/index.d.ts +6 -6
- package/dist/react/index.js +4 -4
- package/dist/react/internal/plate-context.js +434 -188
- package/dist/react/plite-react.js +2 -2
- package/dist/react/plugins/navigation-feedback/NavigationFeedbackPlugin.js +12 -10
- package/dist/react/stores/plate/useEditor.js +32 -14
- package/dist/react/stores/plate/useEditorHistory.js +55 -0
- package/dist/react/stores/plate/useEditorSelector.js +79 -21
- package/dist/react/utils/BlockPlaceholderPlugin.js +5 -2
- package/dist/react/utils/pipeRenderElement.internal.js +1 -1
- package/dist/react/utils/pluginRenderElement.internal.js +1 -1
- package/dist/react/virtualized.d.ts +4 -4
- package/dist/{source-CNKy99Th.d.ts → source-BGohy8vH.d.ts} +4 -4
- package/dist/static/index.d.ts +18 -18
- package/dist/static/internal/renderStaticHtmlWithOverrides.js +2 -2
- package/dist/static/internal/staticPresentation.js +4 -4
- package/dist/static/internal/writeStaticSelectionClipboardData.js +7 -2
- package/dist/tabbable/index.d.ts +1 -1
- package/dist/tabbable/react/index.d.ts +3 -3
- package/dist/testing/index.d.ts +3 -3
- package/dist/yjs/index.d.ts +1 -1
- package/dist/yjs/react/index.d.ts +6 -6
- package/package.json +20 -2
- package/dist/markdown/lib/serializer/convertTextsSerialize.js +0 -163
- package/dist/react/components/EditorSelectionView.js +0 -40
- package/dist/react/features/ink/InkLayer.js +0 -218
- package/dist/react/internal/createPlateTargetScope.js +0 -62
|
@@ -24,6 +24,13 @@ const freezeDiagnostic = (diagnostic) => {
|
|
|
24
24
|
...contextual.source ? { source: freezeSourceLocation(contextual.source) } : {}
|
|
25
25
|
});
|
|
26
26
|
};
|
|
27
|
+
const sourceStart = (diagnostic) => "source" in diagnostic ? diagnostic.source?.start : void 0;
|
|
28
|
+
const bySource = (a, b) => {
|
|
29
|
+
const left = sourceStart(a);
|
|
30
|
+
const right = sourceStart(b);
|
|
31
|
+
if (!left || !right) return left ? -1 : right ? 1 : 0;
|
|
32
|
+
return left.line - right.line || left.column - right.column;
|
|
33
|
+
};
|
|
27
34
|
var MarkdownDiagnostics = class {
|
|
28
35
|
#diagnostics = [];
|
|
29
36
|
#keys = /* @__PURE__ */ new Set();
|
|
@@ -37,15 +44,19 @@ var MarkdownDiagnostics = class {
|
|
|
37
44
|
this.#keys.add(key);
|
|
38
45
|
this.#diagnostics.push(frozen);
|
|
39
46
|
};
|
|
47
|
+
#ordered() {
|
|
48
|
+
return [...this.#diagnostics].sort(bySource);
|
|
49
|
+
}
|
|
40
50
|
all() {
|
|
41
|
-
return Object.freeze(
|
|
51
|
+
return Object.freeze(this.#ordered());
|
|
42
52
|
}
|
|
43
53
|
failure() {
|
|
44
54
|
if (this.#diagnostics.findIndex((diagnostic) => diagnostic.severity === "error") === -1) return null;
|
|
45
|
-
|
|
55
|
+
const ordered = this.#ordered();
|
|
56
|
+
return Object.freeze([...ordered.filter((diagnostic) => diagnostic.severity === "error"), ...ordered.filter((diagnostic) => diagnostic.severity === "warning")]);
|
|
46
57
|
}
|
|
47
58
|
warnings() {
|
|
48
|
-
return Object.freeze(this.#
|
|
59
|
+
return Object.freeze(this.#ordered().filter((diagnostic) => diagnostic.severity === "warning"));
|
|
49
60
|
}
|
|
50
61
|
};
|
|
51
62
|
const pointFromPosition = (point) => Object.freeze({
|
|
@@ -64,11 +75,11 @@ const createMarkdownSourceLocation = (node, source, positionsReferToSource) => {
|
|
|
64
75
|
start: pointFromPosition(start)
|
|
65
76
|
});
|
|
66
77
|
};
|
|
67
|
-
const createMarkdownModelLocator = (document) => {
|
|
78
|
+
const createMarkdownModelLocator = (document, { from = 0 } = {}) => {
|
|
68
79
|
const locations = /* @__PURE__ */ new WeakMap();
|
|
69
|
-
const visit = (nodes, path, root) => {
|
|
80
|
+
const visit = (nodes, path, root, offset = 0) => {
|
|
70
81
|
nodes.forEach((node, index) => {
|
|
71
|
-
const nodePath = Object.freeze([...path, index]);
|
|
82
|
+
const nodePath = Object.freeze([...path, offset + index]);
|
|
72
83
|
locations.set(node, Object.freeze({
|
|
73
84
|
path: nodePath,
|
|
74
85
|
...root === void 0 ? {} : { root }
|
|
@@ -76,7 +87,7 @@ const createMarkdownModelLocator = (document) => {
|
|
|
76
87
|
if (ElementApi.isElement(node)) visit(node.children, nodePath, root);
|
|
77
88
|
});
|
|
78
89
|
};
|
|
79
|
-
visit(document.children, []);
|
|
90
|
+
visit(document.children.slice(from), [], void 0, from);
|
|
80
91
|
Object.entries(document.roots ?? {}).forEach(([root, nodes]) => {
|
|
81
92
|
visit(nodes, [], root);
|
|
82
93
|
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { decideUrl } from "../../../internal/utils/urlPolicy.js";
|
|
2
|
+
//#region src/markdown/lib/internal/markdownFootnoteWriter.ts
|
|
3
|
+
const DEFINITION_START = /^(\[\^(?:\\.|[^\\\]])*\]:)(?: |\n {4})/;
|
|
4
|
+
const definesRefusedUrl = (node) => node.type === "definition" ? !decideUrl("navigation", node.url).ok : "children" in node && node.children.some(definesRefusedUrl);
|
|
5
|
+
const findHandler = (extensions, name) => {
|
|
6
|
+
let found;
|
|
7
|
+
for (const extension of extensions) {
|
|
8
|
+
found = findHandler(extension.extensions ?? [], name) ?? found;
|
|
9
|
+
found = extension.handlers?.[name] ?? found;
|
|
10
|
+
}
|
|
11
|
+
return found;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* CommonMark without footnotes reads `[^1]: javascript:alert(1)` as a link
|
|
15
|
+
* definition, which turns every `[^1]` into a link to that destination, and
|
|
16
|
+
* the definitions after it, such as a `$$` block's TeX lines, read the same
|
|
17
|
+
* way. A footnote that `read`, the CommonMark reader, reads as defining a URL
|
|
18
|
+
* the navigation policy refuses starts its content after a blank line, which
|
|
19
|
+
* both readers read as the same footnote and CommonMark as indented code.
|
|
20
|
+
*/
|
|
21
|
+
const remarkFootnoteDefinitionWriter = function({ read }) {
|
|
22
|
+
const data = this.data();
|
|
23
|
+
data.toMarkdownExtensions ??= [];
|
|
24
|
+
const extensions = data.toMarkdownExtensions;
|
|
25
|
+
const write = findHandler(extensions, "footnoteDefinition");
|
|
26
|
+
if (!write) return;
|
|
27
|
+
extensions.push({ handlers: { footnoteDefinition: (...args) => {
|
|
28
|
+
const value = write(...args);
|
|
29
|
+
const start = DEFINITION_START.exec(value);
|
|
30
|
+
if (!start || !definesRefusedUrl(read(value))) return value;
|
|
31
|
+
return `${start[1]}\n\n ${value.slice(start[0].length)}`;
|
|
32
|
+
} } });
|
|
33
|
+
};
|
|
34
|
+
//#endregion
|
|
35
|
+
export { remarkFootnoteDefinitionWriter };
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
//#region src/markdown/lib/internal/markdownFrontmatter.ts
|
|
2
|
+
const MARKDOWN_FRONTMATTER_KEY = "markdown.frontmatter";
|
|
3
|
+
const FORMATS = ["yaml", "toml"];
|
|
4
|
+
const FENCES = {
|
|
5
|
+
toml: "+++",
|
|
6
|
+
yaml: "---"
|
|
7
|
+
};
|
|
8
|
+
const BLANK_LINE = /^[ \t]*$/;
|
|
9
|
+
const COMMENT_LINE = /^[ \t]*#/;
|
|
10
|
+
const TOML_KEY = String.raw`(?:[A-Za-z0-9_-]+|"(?:[^"\\]|\\.)*"|'[^']*')`;
|
|
11
|
+
const TOML_DOTTED_KEY = String.raw`${TOML_KEY}(?:[ \t]*\.[ \t]*${TOML_KEY})*`;
|
|
12
|
+
const GRAMMAR = {
|
|
13
|
+
toml: {
|
|
14
|
+
close: /^\+\+\+[ \t]*$/,
|
|
15
|
+
open: /^\+\+\+[ \t]*$/,
|
|
16
|
+
setting: new RegExp([String.raw`^[ \t]*(?:\[\[[ \t]*${TOML_DOTTED_KEY}[ \t]*\]\]|\[[ \t]*${TOML_DOTTED_KEY}[ \t]*\])[ \t]*(?:#.*)?$`, String.raw`^[ \t]*${TOML_DOTTED_KEY}[ \t]*=`].join("|"))
|
|
17
|
+
},
|
|
18
|
+
yaml: {
|
|
19
|
+
close: /^(?:---|\.\.\.)[ \t]*$/,
|
|
20
|
+
open: /^---[ \t]*$/,
|
|
21
|
+
setting: new RegExp([
|
|
22
|
+
String.raw`^[ \t]*(?:"(?:[^"\\]|\\.)*"|'(?:[^']|'')*')[ \t]*:(?:[ \t]|$)`,
|
|
23
|
+
String.raw`^[ \t]*\{`,
|
|
24
|
+
String.raw`^[ \t]*<<[ \t]*:(?:[ \t]|$)`,
|
|
25
|
+
String.raw`^[ \t]*(?!\d+[.)](?:[ \t]|$))[^\s#\-?:,\[\]{}&*!|>'"%@\x60<+=~][^\r\n]*?:(?:[ \t]|$)`
|
|
26
|
+
].join("|"))
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const readMarkdownFrontmatter = (source) => {
|
|
30
|
+
const start = source.startsWith("") ? 1 : 0;
|
|
31
|
+
const format = FORMATS.find((name) => source.startsWith(FENCES[name], start));
|
|
32
|
+
if (!format) return null;
|
|
33
|
+
const grammar = GRAMMAR[format];
|
|
34
|
+
const lineEnding = /\r\n|\r|\n/g;
|
|
35
|
+
const lineAt = (from) => {
|
|
36
|
+
if (from >= source.length) return null;
|
|
37
|
+
lineEnding.lastIndex = from;
|
|
38
|
+
const ending = lineEnding.exec(source);
|
|
39
|
+
return ending ? {
|
|
40
|
+
end: ending.index + ending[0].length,
|
|
41
|
+
ended: true,
|
|
42
|
+
start: from,
|
|
43
|
+
text: source.slice(from, ending.index)
|
|
44
|
+
} : {
|
|
45
|
+
end: source.length,
|
|
46
|
+
ended: false,
|
|
47
|
+
start: from,
|
|
48
|
+
text: source.slice(from)
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
const opener = lineAt(start);
|
|
52
|
+
if (!opener?.ended || !grammar.open.test(opener.text)) return null;
|
|
53
|
+
let line = lineAt(opener.end);
|
|
54
|
+
if (line && grammar.open.test(line.text)) return {
|
|
55
|
+
end: line.end,
|
|
56
|
+
format,
|
|
57
|
+
value: ""
|
|
58
|
+
};
|
|
59
|
+
while (line && (BLANK_LINE.test(line.text) || COMMENT_LINE.test(line.text))) line = lineAt(line.end);
|
|
60
|
+
if (!line || !grammar.setting.test(line.text)) return null;
|
|
61
|
+
do
|
|
62
|
+
line = lineAt(line.end);
|
|
63
|
+
while (line && !grammar.close.test(line.text));
|
|
64
|
+
if (!line) return null;
|
|
65
|
+
const value = source.slice(opener.end, line.start).replaceAll(/\r\n?/g, "\n").replace(/\n$/u, "");
|
|
66
|
+
return value.isWellFormed() ? {
|
|
67
|
+
end: line.end,
|
|
68
|
+
format,
|
|
69
|
+
value
|
|
70
|
+
} : null;
|
|
71
|
+
};
|
|
72
|
+
const blankMarkdownFrontmatter = (source, end) => source.slice(0, end).replaceAll("\r\n", " \n").replaceAll("\r", "\n").replaceAll(/[^\n]/g, " ") + source.slice(end);
|
|
73
|
+
const opensMarkdownFrontmatterFence = (text) => {
|
|
74
|
+
const start = text.startsWith("") ? 1 : 0;
|
|
75
|
+
const format = FORMATS.find((name) => text.startsWith(FENCES[name], start));
|
|
76
|
+
if (!format) return false;
|
|
77
|
+
const [opener = "", ...lines] = text.slice(start).split(/\r\n|\r|\n/);
|
|
78
|
+
return GRAMMAR[format].open.test(opener) && lines.some((line) => GRAMMAR[format].close.test(line));
|
|
79
|
+
};
|
|
80
|
+
const writeMarkdownFrontmatter = ({ format, value }) => {
|
|
81
|
+
const fence = FENCES[format];
|
|
82
|
+
const block = `${fence}\n${value && `${value}\n`}${fence}\n`;
|
|
83
|
+
return readMarkdownFrontmatter(block)?.value === value ? block : null;
|
|
84
|
+
};
|
|
85
|
+
const hasMarkdownFrontmatterShape = (stored) => {
|
|
86
|
+
if (typeof stored !== "object" || stored === null) return false;
|
|
87
|
+
const entries = new Map(Object.entries(stored));
|
|
88
|
+
return entries.size === 2 && typeof entries.get("format") === "string" && typeof entries.get("value") === "string";
|
|
89
|
+
};
|
|
90
|
+
const isMarkdownFrontmatter = (stored) => hasMarkdownFrontmatterShape(stored) && (stored.format === "yaml" || stored.format === "toml");
|
|
91
|
+
/**
|
|
92
|
+
* The front matter block that a Markdown document parse stored on the
|
|
93
|
+
* document, or `undefined` when the stored value is missing or is not a
|
|
94
|
+
* `MarkdownFrontmatter`. The block comes back as stored; a document serialize
|
|
95
|
+
* is what checks that it can be written.
|
|
96
|
+
*/
|
|
97
|
+
const getMarkdownFrontmatter = (document) => {
|
|
98
|
+
const stored = document.meta?.[MARKDOWN_FRONTMATTER_KEY];
|
|
99
|
+
return isMarkdownFrontmatter(stored) ? stored : void 0;
|
|
100
|
+
};
|
|
101
|
+
//#endregion
|
|
102
|
+
export { MARKDOWN_FRONTMATTER_KEY, blankMarkdownFrontmatter, getMarkdownFrontmatter, hasMarkdownFrontmatterShape, isMarkdownFrontmatter, opensMarkdownFrontmatterFence, readMarkdownFrontmatter, writeMarkdownFrontmatter };
|
|
@@ -2,14 +2,34 @@ import { PLUGINS } from "../../../utils/plate-keys.js";
|
|
|
2
2
|
import { ElementApi, TextApi } from "../../../core.js";
|
|
3
3
|
import { getMarkdownParagraphType } from "../../../internal/plugin/markdownParagraph.js";
|
|
4
4
|
import { convertChildrenDeserialize } from "../deserializer/convertChildrenDeserialize.js";
|
|
5
|
+
import { RawHtmlPlugin } from "../RawHtmlPlugin.js";
|
|
5
6
|
import { getMarkdownTagRepair } from "./markdownTags.js";
|
|
6
7
|
import { convertNodesSerialize } from "../serializer/convertNodesSerialize.js";
|
|
7
8
|
//#region src/markdown/lib/internal/markdownIntrinsics.ts
|
|
8
9
|
const BR_TAG = /<br\s*\/?>/gi;
|
|
9
10
|
const ONLY_BR_TAGS = /^(?:\s*<br\s*\/?>)+\s*$/i;
|
|
10
|
-
const HTML_COMMENT =
|
|
11
|
+
const HTML_COMMENT = /^[\t\n\f\r ]*(?:<!--(?!-?>)(?:(?!--!?>)[\s\S])*-->[\t\n\f\r ]*)+$/;
|
|
11
12
|
const TAG_NAME = /^<\/?([A-Za-z][\w-]*)/;
|
|
12
13
|
const BARE_URL_HTML = /^[a-z][a-z\d+.-]*:\S*$/i;
|
|
14
|
+
const isMarkdownBreakHtml = (value) => ONLY_BR_TAGS.test(value);
|
|
15
|
+
/** Encode marked leaves as raw HTML that their block's decision may keep. */
|
|
16
|
+
const encodeRawHtmlLeaves = (leaves) => {
|
|
17
|
+
return {
|
|
18
|
+
data: { rawHtmlPiece: { leaves } },
|
|
19
|
+
type: "html",
|
|
20
|
+
value: leaves.map((leaf) => leaf.text).join("")
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
const rawHtmlDataOf = (node) => node.data;
|
|
24
|
+
const rawHtmlPieceOf = (node) => node.type === "html" ? rawHtmlDataOf(node)?.rawHtmlPiece : void 0;
|
|
25
|
+
const markRawHtmlFlow = (paragraph) => {
|
|
26
|
+
const data = { rawHtmlFlow: true };
|
|
27
|
+
paragraph.data = {
|
|
28
|
+
...paragraph.data,
|
|
29
|
+
...data
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
const isRawHtmlFlow = (node) => rawHtmlPieceOf(node) !== void 0 || node.type === "paragraph" && rawHtmlDataOf(node)?.rawHtmlFlow === true;
|
|
13
33
|
/** Markdown drops an empty paragraph, so the writer gives it this text. */
|
|
14
34
|
const EMPTY_PARAGRAPH_TEXT = "";
|
|
15
35
|
/** The text an empty paragraph is written with, read back as empty. */
|
|
@@ -17,6 +37,10 @@ const readEmptyParagraphMarker = (child) => TextApi.isText(child) && child.text
|
|
|
17
37
|
...child,
|
|
18
38
|
text: ""
|
|
19
39
|
} : child;
|
|
40
|
+
const withoutLoneBreakSeparators = (children) => children.filter((child, index) => {
|
|
41
|
+
const previous = children[index - 1];
|
|
42
|
+
return !(child.type === "html" && child.value === WRITER_SEPARATOR && previous?.type === "html" && previous.value === WRITTEN_BREAK_HTML);
|
|
43
|
+
});
|
|
20
44
|
const withoutTrailingBreakMarkup = (children) => {
|
|
21
45
|
const last = children.at(-1);
|
|
22
46
|
const previous = children.at(-2);
|
|
@@ -46,6 +70,45 @@ const withUnmarkedLineEndings = (text, marks) => text.includes("\n") ? text.spli
|
|
|
46
70
|
...marks,
|
|
47
71
|
text
|
|
48
72
|
};
|
|
73
|
+
const FLOW_CONTAINERS = /* @__PURE__ */ new Set([
|
|
74
|
+
"blockquote",
|
|
75
|
+
"list",
|
|
76
|
+
"listItem"
|
|
77
|
+
]);
|
|
78
|
+
const WRITER_SEPARATOR = "<!---->";
|
|
79
|
+
const isBlockWrapper = (node) => node.type === "mdxJsxFlowElement" && node.name === "block";
|
|
80
|
+
const wholeHtmlBlockRefusal = (value, follows) => {
|
|
81
|
+
if (value === WRITER_SEPARATOR) return "comment";
|
|
82
|
+
if (/^ *\t/.test(value) || follows !== "block" && /^[\t ]/.test(value)) return "flow-shape";
|
|
83
|
+
};
|
|
84
|
+
const isMarkdownHtmlComment = (value) => HTML_COMMENT.test(value);
|
|
85
|
+
const isEmptyBlockWrapper = (node) => isBlockWrapper(node) && node.children.every((child) => isEmptyBlockWrapper(child));
|
|
86
|
+
const wrapsOneHtmlBlock = (wrapper) => {
|
|
87
|
+
const [only, ...rest] = wrapper.children.filter((child) => !isEmptyBlockWrapper(child));
|
|
88
|
+
if (!only || rest.length > 0) return false;
|
|
89
|
+
return only.type === "html" || isBlockWrapper(only) && wrapsOneHtmlBlock(only);
|
|
90
|
+
};
|
|
91
|
+
const findMarkdownRawHtml = (tree, before = "block") => {
|
|
92
|
+
const blocks = /* @__PURE__ */ new Set();
|
|
93
|
+
const visit = (parent, split, held, start) => {
|
|
94
|
+
let follows = start;
|
|
95
|
+
for (const child of parent.children) if (child.type === "html") {
|
|
96
|
+
if (split && !held && !wholeHtmlBlockRefusal(child.value, follows)) {
|
|
97
|
+
blocks.add(child);
|
|
98
|
+
follows = "block";
|
|
99
|
+
} else if (!HTML_COMMENT.test(child.value)) follows = "block";
|
|
100
|
+
} else if (isBlockWrapper(child)) follows = visit(child, split, held || !wrapsOneHtmlBlock(child), follows);
|
|
101
|
+
else {
|
|
102
|
+
if ("children" in child) visit(child, split && FLOW_CONTAINERS.has(child.type), held, child.type === "listItem" ? "marker" : "block");
|
|
103
|
+
follows = child.type === "list" ? "list" : "block";
|
|
104
|
+
}
|
|
105
|
+
return follows;
|
|
106
|
+
};
|
|
107
|
+
return {
|
|
108
|
+
blocks,
|
|
109
|
+
follows: visit(tree, true, false, before)
|
|
110
|
+
};
|
|
111
|
+
};
|
|
49
112
|
/**
|
|
50
113
|
* Language-level decoders every editor needs, even without feature plugins.
|
|
51
114
|
* They run after every feature mapping on the same MDAST kind has declined.
|
|
@@ -70,7 +133,8 @@ const markdownIntrinsicDecoders = {
|
|
|
70
133
|
};
|
|
71
134
|
}
|
|
72
135
|
if (ONLY_BR_TAGS.test(value)) return { text: value.replace(BR_TAG, "\n") };
|
|
73
|
-
|
|
136
|
+
const { rawHtml } = options;
|
|
137
|
+
if (HTML_COMMENT.test(value) && !rawHtml?.blocks.has(node)) {
|
|
74
138
|
options.report({
|
|
75
139
|
action: "dropped",
|
|
76
140
|
code: "markdown-unsupported-node",
|
|
@@ -95,15 +159,24 @@ const markdownIntrinsicDecoders = {
|
|
|
95
159
|
severity: "warning",
|
|
96
160
|
source: options.sourceLocation(node)
|
|
97
161
|
});
|
|
98
|
-
return {
|
|
162
|
+
if (!rawHtml) return {
|
|
99
163
|
...marks,
|
|
100
164
|
text: value
|
|
101
165
|
};
|
|
166
|
+
const text = {
|
|
167
|
+
...marks,
|
|
168
|
+
[RawHtmlPlugin.name]: true,
|
|
169
|
+
text: value
|
|
170
|
+
};
|
|
171
|
+
return rawHtml.blocks.has(node) ? {
|
|
172
|
+
children: [text],
|
|
173
|
+
type: getMarkdownParagraphType(options.registry)
|
|
174
|
+
} : text;
|
|
102
175
|
},
|
|
103
176
|
paragraph: (node, marks, options) => {
|
|
104
177
|
const paragraphType = getMarkdownParagraphType(options.registry);
|
|
105
178
|
const imageType = options.registry.type(PLUGINS.image);
|
|
106
|
-
const children = convertChildrenDeserialize(withoutTrailingBreakMarkup(node.children), marks, options).map(readEmptyParagraphMarker);
|
|
179
|
+
const children = convertChildrenDeserialize(withoutTrailingBreakMarkup(withoutLoneBreakSeparators(node.children)), marks, options).map(readEmptyParagraphMarker);
|
|
107
180
|
const elements = [];
|
|
108
181
|
let inlineNodes = [];
|
|
109
182
|
const flushInlineNodes = () => {
|
|
@@ -152,6 +225,25 @@ const writtenStart = (node) => {
|
|
|
152
225
|
default: return node.type.startsWith("mdxJsx") ? "<" : JOINS_URL;
|
|
153
226
|
}
|
|
154
227
|
};
|
|
228
|
+
const writtenEnd = (node) => {
|
|
229
|
+
switch (node.type) {
|
|
230
|
+
case "break": return "\n";
|
|
231
|
+
case "delete": return "~";
|
|
232
|
+
case "emphasis":
|
|
233
|
+
case "strong": return "*";
|
|
234
|
+
case "html":
|
|
235
|
+
case "text": return node.value;
|
|
236
|
+
default: return JOINS_URL;
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
const ENDS_IN_LETTER = /[a-z]$/i;
|
|
240
|
+
const writtenBefore = (parent, index) => {
|
|
241
|
+
for (let previous = index - 1; previous >= 0; previous -= 1) {
|
|
242
|
+
const written = writtenEnd(parent.children[previous]);
|
|
243
|
+
if (written) return written;
|
|
244
|
+
}
|
|
245
|
+
return parent.type === "link" || parent.type.startsWith("mdxJsx") ? JOINS_URL : "";
|
|
246
|
+
};
|
|
155
247
|
const writtenAfter = (parent, index) => {
|
|
156
248
|
let written = "";
|
|
157
249
|
for (let next = index + 1; next < parent.children.length; next += 1) {
|
|
@@ -176,7 +268,7 @@ const writeBareUrlsSafely = (parent) => {
|
|
|
176
268
|
writeBareUrlsSafely(child);
|
|
177
269
|
return;
|
|
178
270
|
}
|
|
179
|
-
if (child.type !== "html" || !BARE_URL_HTML.test(child.value) || staysBare(child.value, writtenAfter(parent, index))) return;
|
|
271
|
+
if (child.type !== "html" || rawHtmlPieceOf(child) || !BARE_URL_HTML.test(child.value) || !ENDS_IN_LETTER.test(writtenBefore(parent, index)) && staysBare(child.value, writtenAfter(parent, index))) return;
|
|
180
272
|
parent.children[index] = {
|
|
181
273
|
children: [{
|
|
182
274
|
type: "text",
|
|
@@ -242,55 +334,45 @@ const remarkSeparateEscapes = function() {
|
|
|
242
334
|
if (/[&\\]/.test(String(file.value))) joinTexts(tree);
|
|
243
335
|
};
|
|
244
336
|
};
|
|
245
|
-
/** The `<br />` that keeps a paragraph's trailing line break, after its line ending. */
|
|
246
337
|
const TRAILING_BREAK_HTML = "\n<br />";
|
|
338
|
+
const WRITTEN_BREAK_HTML = "<br />";
|
|
339
|
+
/**
|
|
340
|
+
* The first break of a paragraph that holds only hard breaks. `<br />` alone
|
|
341
|
+
* on a paragraph's first line opens an HTML block, which reads back as an
|
|
342
|
+
* empty paragraph; the comment after it keeps the line a paragraph and drops
|
|
343
|
+
* on import.
|
|
344
|
+
*/
|
|
345
|
+
const LONE_BREAK_HTML = `${WRITTEN_BREAK_HTML}${WRITER_SEPARATOR}`;
|
|
247
346
|
/**
|
|
248
347
|
* Encode the paragraph type when no feature mapping claims it. Newlines in text
|
|
249
348
|
* become hard breaks; a trailing one is kept as `<br />` because Markdown drops
|
|
250
349
|
* a hard break at the end of a paragraph.
|
|
251
350
|
*/
|
|
252
351
|
const encodeMarkdownParagraph = (node, options) => {
|
|
253
|
-
const
|
|
254
|
-
const
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
origins.set(copy, child);
|
|
261
|
-
return copy;
|
|
262
|
-
};
|
|
263
|
-
const isEmpty = node.children.length === 1 && TextApi.isText(node.children[0]) && node.children[0].text === "";
|
|
264
|
-
for (const child of node.children) {
|
|
265
|
-
if (!TextApi.isText(child) || !child.text.includes("\n")) {
|
|
266
|
-
lines.at(-1)?.push(isEmpty && options.preserveEmptyParagraphs !== false ? part(child, EMPTY_PARAGRAPH_TEXT) : child);
|
|
267
|
-
continue;
|
|
268
|
-
}
|
|
269
|
-
child.text.split(/\r?\n/).forEach((text, index) => {
|
|
270
|
-
if (index > 0) lines.push([]);
|
|
271
|
-
if (text) lines.at(-1)?.push(part(child, text));
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
const lineOptions = {
|
|
352
|
+
const [only] = node.children;
|
|
353
|
+
const placeholder = node.children.length === 1 && TextApi.isText(only) && only.text === "" && options.preserveEmptyParagraphs !== false ? {
|
|
354
|
+
...only,
|
|
355
|
+
...options.rawHtml ? { [RawHtmlPlugin.name]: void 0 } : {},
|
|
356
|
+
text: EMPTY_PARAGRAPH_TEXT
|
|
357
|
+
} : void 0;
|
|
358
|
+
const children = convertNodesSerialize(placeholder ? [placeholder] : node.children, placeholder ? {
|
|
275
359
|
...options,
|
|
276
|
-
modelLocation: (child) => options.modelLocation(
|
|
277
|
-
};
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
if (children[index].type !== "break") break;
|
|
285
|
-
children[index] = {
|
|
286
|
-
type: "html",
|
|
287
|
-
value: "<br />"
|
|
288
|
-
};
|
|
289
|
-
}
|
|
360
|
+
modelLocation: (child) => options.modelLocation(child === placeholder ? only : child)
|
|
361
|
+
} : options, { hardBreaks: true });
|
|
362
|
+
if (children.at(-1)?.type === "break") {
|
|
363
|
+
let index = children.length - 2;
|
|
364
|
+
for (; index >= 0 && children[index].type === "break"; index -= 1) children[index] = {
|
|
365
|
+
type: "html",
|
|
366
|
+
value: WRITTEN_BREAK_HTML
|
|
367
|
+
};
|
|
290
368
|
children[children.length - 1] = {
|
|
291
369
|
type: "html",
|
|
292
370
|
value: TRAILING_BREAK_HTML
|
|
293
371
|
};
|
|
372
|
+
if (index < 0) children[0] = {
|
|
373
|
+
type: "html",
|
|
374
|
+
value: LONE_BREAK_HTML
|
|
375
|
+
};
|
|
294
376
|
}
|
|
295
377
|
return {
|
|
296
378
|
children,
|
|
@@ -298,4 +380,4 @@ const encodeMarkdownParagraph = (node, options) => {
|
|
|
298
380
|
};
|
|
299
381
|
};
|
|
300
382
|
//#endregion
|
|
301
|
-
export { BARE_URL_HTML, TRAILING_BREAK_HTML, encodeMarkdownParagraph, getMarkdownParagraphLanding, markdownIntrinsicDecoders, readEmptyParagraphMarker, remarkSeparateEscapes, writeBareUrlsSafely };
|
|
383
|
+
export { BARE_URL_HTML, LONE_BREAK_HTML, TRAILING_BREAK_HTML, encodeMarkdownParagraph, encodeRawHtmlLeaves, findMarkdownRawHtml, getMarkdownParagraphLanding, isMarkdownBreakHtml, isMarkdownHtmlComment, isRawHtmlFlow, markRawHtmlFlow, markdownIntrinsicDecoders, rawHtmlPieceOf, readEmptyParagraphMarker, remarkSeparateEscapes, wholeHtmlBlockRefusal, writeBareUrlsSafely };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ElementApi, TextApi } from "../../../core.js";
|
|
2
2
|
import { toMarkdownBlockContent } from "./markdownDocument.js";
|
|
3
|
-
import { BARE_URL_HTML, readEmptyParagraphMarker } from "./markdownIntrinsics.js";
|
|
3
|
+
import { BARE_URL_HTML, LONE_BREAK_HTML, rawHtmlPieceOf, readEmptyParagraphMarker } from "./markdownIntrinsics.js";
|
|
4
4
|
import { isMdPhrasingContent } from "../serializer/mdastContent.js";
|
|
5
5
|
import { ReportedMarkdownFailureError } from "./markdownDiagnostics.js";
|
|
6
6
|
import { getMarkdownDecoders, runMarkdownDecoders } from "./markdownMappings.js";
|
|
@@ -152,7 +152,8 @@ const lowerPhrasing = (children, line, beforeBreak = false) => children.flatMap(
|
|
|
152
152
|
}];
|
|
153
153
|
}
|
|
154
154
|
case "html": {
|
|
155
|
-
if (child
|
|
155
|
+
if (rawHtmlPieceOf(child)) return [child];
|
|
156
|
+
if (child.value === "\n<br />" || child.value === LONE_BREAK_HTML) return [html("<br />")];
|
|
156
157
|
const value = child.value.replace(LINE_ENDINGS, " ");
|
|
157
158
|
if (value !== child.value) reportReplaced(line, "line endings in raw HTML became spaces.", "html");
|
|
158
159
|
if (!value.includes("|")) return [{
|
|
@@ -364,6 +365,7 @@ const readListToken = (node) => {
|
|
|
364
365
|
kind: "checkbox"
|
|
365
366
|
};
|
|
366
367
|
};
|
|
368
|
+
const isMarkdownLineListToken = (node) => readListToken(node) !== null;
|
|
367
369
|
const isBlank = (node) => node?.type === "text" && /^[ \t\r\n]*$/.test(node.value);
|
|
368
370
|
/**
|
|
369
371
|
* Match every list tag of one line in a single pass, so malformed input stays
|
|
@@ -545,4 +547,4 @@ const decodeMarkdownLine = (nodes, marks, options) => {
|
|
|
545
547
|
return blocks;
|
|
546
548
|
};
|
|
547
549
|
//#endregion
|
|
548
|
-
export { decodeMarkdownLine, encodeMarkdownLine };
|
|
550
|
+
export { decodeMarkdownLine, encodeMarkdownLine, isMarkdownLineListToken };
|
|
@@ -616,11 +616,22 @@ const refusedTagText = (node, options) => {
|
|
|
616
616
|
}];
|
|
617
617
|
};
|
|
618
618
|
const getMarkdownDecoders = (compiled, node) => isTagNode(node) ? compiled.decodeByTag.get(node.name ?? "") : compiled.decodeByNode.get(node.type);
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
619
|
+
const isValidFragmentNode = (node, options) => {
|
|
620
|
+
try {
|
|
621
|
+
options.state.schema.assertFragment([node]);
|
|
622
|
+
return true;
|
|
623
|
+
} catch {
|
|
624
|
+
return false;
|
|
625
|
+
}
|
|
626
|
+
};
|
|
627
|
+
const withInlineText = (decoded, options) => decoded.map((item) => {
|
|
628
|
+
if (!ElementApi.isElement(item) || item.children.length > 0 || !options.isInline(item)) return item;
|
|
629
|
+
const filled = {
|
|
630
|
+
...item,
|
|
631
|
+
children: [{ text: "" }]
|
|
632
|
+
};
|
|
633
|
+
return !isValidFragmentNode(item, options) && isValidFragmentNode(filled, options) ? filled : item;
|
|
634
|
+
});
|
|
624
635
|
const runMarkdownDecoders = (decoders, node, marks, options, previousSibling = null) => {
|
|
625
636
|
if (decoders[0]?.mark) {
|
|
626
637
|
let marked;
|
|
@@ -636,9 +647,10 @@ const runMarkdownDecoders = (decoders, node, marks, options, previousSibling = n
|
|
|
636
647
|
}
|
|
637
648
|
if (!marked) return void 0;
|
|
638
649
|
if ("children" in node && Array.isArray(node.children)) return convertChildrenDeserialize(node.children, marked, options);
|
|
650
|
+
const value = "value" in node && typeof node.value === "string" ? node.value : "";
|
|
639
651
|
return [{
|
|
640
652
|
...marked,
|
|
641
|
-
text:
|
|
653
|
+
text: node.type === "inlineCode" ? value.replaceAll(/\r\n?|\n/g, " ") : value
|
|
642
654
|
}];
|
|
643
655
|
}
|
|
644
656
|
for (const decoder of decoders) {
|
|
@@ -658,7 +670,7 @@ const runMarkdownDecoders = (decoders, node, marks, options, previousSibling = n
|
|
|
658
670
|
});
|
|
659
671
|
return isTagNode(node) ? refusedTagText(node, options) : [];
|
|
660
672
|
}
|
|
661
|
-
if (decoded !== void 0) return Array.isArray(decoded) ? decoded : [decoded];
|
|
673
|
+
if (decoded !== void 0) return withInlineText(Array.isArray(decoded) ? decoded : [decoded], options);
|
|
662
674
|
}
|
|
663
675
|
};
|
|
664
676
|
//#endregion
|