@pod-os/elements 0.32.1-rc.f28b628.0 → 0.33.1-rc.77c38a0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/pos-add-new-thing_29.cjs.entry.js +2 -1
- package/dist/cjs/pos-markdown-document.cjs.entry.js +2667 -250
- package/dist/cjs/pos-markdown-document.entry.cjs.js.map +1 -1
- package/dist/collection/components/pos-upload/pos-upload.js +2 -1
- package/dist/collection/components/pos-upload/pos-upload.js.map +1 -1
- package/dist/components/pos-markdown-document2.js +2667 -250
- package/dist/components/pos-markdown-document2.js.map +1 -1
- package/dist/components/pos-upload2.js +2 -1
- package/dist/components/pos-upload2.js.map +1 -1
- package/dist/elements/elements.esm.js +1 -1
- package/dist/elements/{p-634ec3ba.entry.js → p-3f3bfccf.entry.js} +2 -2
- package/dist/elements/{p-634ec3ba.entry.js.map → p-3f3bfccf.entry.js.map} +1 -1
- package/dist/elements/p-66ff17ba.entry.js +2 -0
- package/dist/elements/p-66ff17ba.entry.js.map +1 -0
- package/dist/elements/pos-markdown-document.entry.esm.js.map +1 -1
- package/dist/esm/pos-add-new-thing_29.entry.js +2 -1
- package/dist/esm/pos-markdown-document.entry.js +2667 -250
- package/dist/esm/pos-markdown-document.entry.js.map +1 -1
- package/package.json +10 -10
- package/dist/elements/p-300ef87f.entry.js +0 -2
- package/dist/elements/p-300ef87f.entry.js.map +0 -1
|
@@ -7616,13 +7616,13 @@ const agent = (nav && nav.userAgent) || "";
|
|
|
7616
7616
|
const ie_edge = /Edge\/(\d+)/.exec(agent);
|
|
7617
7617
|
const ie_upto10 = /MSIE \d/.exec(agent);
|
|
7618
7618
|
const ie_11up = /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(agent);
|
|
7619
|
-
const ie$
|
|
7619
|
+
const ie$1 = !!(ie_upto10 || ie_11up || ie_edge);
|
|
7620
7620
|
const ie_version = ie_upto10 ? document.documentMode : ie_11up ? +ie_11up[1] : ie_edge ? +ie_edge[1] : 0;
|
|
7621
|
-
const gecko = !ie$
|
|
7622
|
-
const _chrome = !ie$
|
|
7621
|
+
const gecko = !ie$1 && /gecko\/(\d+)/i.test(agent);
|
|
7622
|
+
const _chrome = !ie$1 && /Chrome\/(\d+)/.exec(agent);
|
|
7623
7623
|
const chrome = !!_chrome;
|
|
7624
7624
|
const chrome_version = _chrome ? +_chrome[1] : 0;
|
|
7625
|
-
const safari = !ie$
|
|
7625
|
+
const safari = !ie$1 && !!nav && /Apple Computer/.test(nav.vendor);
|
|
7626
7626
|
// Is true for both iOS and iPadOS for convenience
|
|
7627
7627
|
const ios = safari && (/Mobile\/\w+/.test(agent) || !!nav && nav.maxTouchPoints > 2);
|
|
7628
7628
|
const mac$2 = ios || (nav ? /Mac/.test(nav.platform) : false);
|
|
@@ -9794,7 +9794,7 @@ function selectCursorWrapper(view) {
|
|
|
9794
9794
|
// resize handles and a selection that considers the absolutely
|
|
9795
9795
|
// positioned wrapper, rather than the root editable node, the
|
|
9796
9796
|
// focused element.
|
|
9797
|
-
if (!img && !view.state.selection.visible && ie$
|
|
9797
|
+
if (!img && !view.state.selection.visible && ie$1 && ie_version <= 11) {
|
|
9798
9798
|
node.disabled = true;
|
|
9799
9799
|
node.disabled = false;
|
|
9800
9800
|
}
|
|
@@ -11047,7 +11047,7 @@ function captureCopy(view, dom) {
|
|
|
11047
11047
|
// This is very crude, but unfortunately both these browsers _pretend_
|
|
11048
11048
|
// that they have a clipboard API—all the objects and methods are
|
|
11049
11049
|
// there, they just don't work, and they are hard to test.
|
|
11050
|
-
const brokenClipboardAPI = (ie$
|
|
11050
|
+
const brokenClipboardAPI = (ie$1 && ie_version < 15) ||
|
|
11051
11051
|
(ios && webkit_version < 604);
|
|
11052
11052
|
handlers.copy = editHandlers.cut = (view, _event) => {
|
|
11053
11053
|
let event = _event;
|
|
@@ -11978,7 +11978,7 @@ const observeOptions = {
|
|
|
11978
11978
|
subtree: true
|
|
11979
11979
|
};
|
|
11980
11980
|
// IE11 has very broken mutation observers, so we also listen to DOMCharacterDataModified
|
|
11981
|
-
const useCharData = ie$
|
|
11981
|
+
const useCharData = ie$1 && ie_version <= 11;
|
|
11982
11982
|
class SelectionState {
|
|
11983
11983
|
constructor() {
|
|
11984
11984
|
this.anchorNode = null;
|
|
@@ -12019,7 +12019,7 @@ class DOMObserver {
|
|
|
12019
12019
|
// text node after a BR node) call the observer callback
|
|
12020
12020
|
// before actually updating the DOM, which will cause
|
|
12021
12021
|
// ProseMirror to miss the change (see #930)
|
|
12022
|
-
if (ie$
|
|
12022
|
+
if (ie$1 && ie_version <= 11 && mutations.some(m => m.type == "childList" && m.removedNodes.length ||
|
|
12023
12023
|
m.type == "characterData" && m.oldValue.length > m.target.nodeValue.length))
|
|
12024
12024
|
this.flushSoon();
|
|
12025
12025
|
else
|
|
@@ -12085,7 +12085,7 @@ class DOMObserver {
|
|
|
12085
12085
|
// Deletions on IE11 fire their events in the wrong order, giving
|
|
12086
12086
|
// us a selection change event before the DOM changes are
|
|
12087
12087
|
// reported.
|
|
12088
|
-
if (ie$
|
|
12088
|
+
if (ie$1 && ie_version <= 11 && !this.view.state.selection.empty) {
|
|
12089
12089
|
let sel = this.view.domSelectionRange();
|
|
12090
12090
|
// Selection.isCollapsed isn't reliable on IE
|
|
12091
12091
|
if (sel.focusNode && isEquivalentPosition(sel.focusNode, sel.focusOffset, sel.anchorNode, sel.anchorOffset))
|
|
@@ -12209,7 +12209,7 @@ class DOMObserver {
|
|
|
12209
12209
|
if (desc.contentDOM && desc.contentDOM != desc.dom && !desc.contentDOM.contains(mut.target))
|
|
12210
12210
|
return { from: desc.posBefore, to: desc.posAfter };
|
|
12211
12211
|
let prev = mut.previousSibling, next = mut.nextSibling;
|
|
12212
|
-
if (ie$
|
|
12212
|
+
if (ie$1 && ie_version <= 11 && mut.addedNodes.length) {
|
|
12213
12213
|
// IE11 gives us incorrect next/prev siblings for some
|
|
12214
12214
|
// insertions, so if there are added nodes, recompute those
|
|
12215
12215
|
for (let i = 0; i < mut.addedNodes.length; i++) {
|
|
@@ -12464,7 +12464,7 @@ function readDOMChange(view, from, to, typeOver, addedNodes) {
|
|
|
12464
12464
|
// IE11 will insert a non-breaking space _ahead_ of the space after
|
|
12465
12465
|
// the cursor space when adding a space before another space. When
|
|
12466
12466
|
// that happened, adjust the change to cover the space instead.
|
|
12467
|
-
if (ie$
|
|
12467
|
+
if (ie$1 && ie_version <= 11 && change.endB == change.start + 1 &&
|
|
12468
12468
|
change.endA == change.start && change.start > parse.from &&
|
|
12469
12469
|
parse.doc.textBetween(change.start - parse.from - 1, change.start - parse.from + 1) == " \u00a0") {
|
|
12470
12470
|
change.start--;
|
|
@@ -12528,7 +12528,7 @@ function readDOMChange(view, from, to, typeOver, addedNodes) {
|
|
|
12528
12528
|
if (sel && !(chrome && view.composing && sel.empty &&
|
|
12529
12529
|
(change.start != change.endB || view.input.lastChromeDelete < Date.now() - 100) &&
|
|
12530
12530
|
(sel.head == chFrom || sel.head == tr.mapping.map(chTo) - 1) ||
|
|
12531
|
-
ie$
|
|
12531
|
+
ie$1 && sel.empty && sel.head == chFrom))
|
|
12532
12532
|
tr.setSelection(sel);
|
|
12533
12533
|
}
|
|
12534
12534
|
if (compositionID)
|
|
@@ -12540,7 +12540,7 @@ function readDOMChange(view, from, to, typeOver, addedNodes) {
|
|
|
12540
12540
|
if ($from.pos == $to.pos) { // Deletion
|
|
12541
12541
|
// IE11 sometimes weirdly moves the DOM selection around after
|
|
12542
12542
|
// backspacing out the first element in a textblock
|
|
12543
|
-
if (ie$
|
|
12543
|
+
if (ie$1 && ie_version <= 11 && $from.parentOffset == 0) {
|
|
12544
12544
|
view.domObserver.suppressSelectionUpdates();
|
|
12545
12545
|
setTimeout(() => selectionToDOM(view), 20);
|
|
12546
12546
|
}
|
|
@@ -12847,7 +12847,7 @@ class EditorView {
|
|
|
12847
12847
|
// state where the thing the user sees differs from the
|
|
12848
12848
|
// selection reported by the Selection object (#710, #973,
|
|
12849
12849
|
// #1011, #1013, #1035).
|
|
12850
|
-
let forceSelUpdate = updateDoc && (ie$
|
|
12850
|
+
let forceSelUpdate = updateDoc && (ie$1 || chrome) && !this.composing &&
|
|
12851
12851
|
!prev.selection.empty && !state.selection.empty && selectionContextChanged(prev.selection, state.selection);
|
|
12852
12852
|
if (updateDoc) {
|
|
12853
12853
|
// If the node that the selection points into is written to,
|
|
@@ -12975,7 +12975,7 @@ class EditorView {
|
|
|
12975
12975
|
// Work around IE not handling focus correctly if resize handles are shown.
|
|
12976
12976
|
// If the cursor is inside an element with resize handles, activeElement
|
|
12977
12977
|
// will be that element instead of this.dom.
|
|
12978
|
-
if (ie$
|
|
12978
|
+
if (ie$1) {
|
|
12979
12979
|
// If activeElement is within this.dom, and there are no other elements
|
|
12980
12980
|
// setting `contenteditable` to false in between, treat it as focused.
|
|
12981
12981
|
let node = this.root.activeElement;
|
|
@@ -13337,7 +13337,7 @@ var shift = {
|
|
|
13337
13337
|
};
|
|
13338
13338
|
|
|
13339
13339
|
var mac$1 = typeof navigator != "undefined" && /Mac/.test(navigator.platform);
|
|
13340
|
-
var ie
|
|
13340
|
+
var ie = typeof navigator != "undefined" && /MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);
|
|
13341
13341
|
|
|
13342
13342
|
// Fill in the digit keys
|
|
13343
13343
|
for (var i = 0; i < 10; i++) base[48 + i] = base[96 + i] = String(i);
|
|
@@ -13358,7 +13358,7 @@ function keyName(event) {
|
|
|
13358
13358
|
// On macOS, keys held with Shift and Cmd don't reflect the effect of Shift in `.key`.
|
|
13359
13359
|
// On IE, shift effect is never included in `.key`.
|
|
13360
13360
|
var ignoreKey = mac$1 && event.metaKey && event.shiftKey && !event.ctrlKey && !event.altKey ||
|
|
13361
|
-
ie
|
|
13361
|
+
ie && event.shiftKey && event.key && event.key.length == 1 ||
|
|
13362
13362
|
event.key == "Unidentified";
|
|
13363
13363
|
var name = (!ignoreKey && event.key) ||
|
|
13364
13364
|
(event.shiftKey ? shift : base)[event.keyCode] ||
|
|
@@ -13689,6 +13689,7 @@ __export$1(commands_exports, {
|
|
|
13689
13689
|
setMeta: () => setMeta,
|
|
13690
13690
|
setNode: () => setNode,
|
|
13691
13691
|
setNodeSelection: () => setNodeSelection,
|
|
13692
|
+
setTextDirection: () => setTextDirection,
|
|
13692
13693
|
setTextSelection: () => setTextSelection,
|
|
13693
13694
|
sinkListItem: () => sinkListItem,
|
|
13694
13695
|
splitBlock: () => splitBlock,
|
|
@@ -13700,6 +13701,7 @@ __export$1(commands_exports, {
|
|
|
13700
13701
|
undoInputRule: () => undoInputRule,
|
|
13701
13702
|
unsetAllMarks: () => unsetAllMarks,
|
|
13702
13703
|
unsetMark: () => unsetMark,
|
|
13704
|
+
unsetTextDirection: () => unsetTextDirection,
|
|
13703
13705
|
updateAttributes: () => updateAttributes,
|
|
13704
13706
|
wrapIn: () => wrapIn,
|
|
13705
13707
|
wrapInList: () => wrapInList
|
|
@@ -14475,23 +14477,28 @@ var resetAttributes = (typeOrName, attributes) => ({ tr, state, dispatch }) => {
|
|
|
14475
14477
|
if (schemaType === "mark") {
|
|
14476
14478
|
markType = getMarkType(typeOrName, state.schema);
|
|
14477
14479
|
}
|
|
14478
|
-
|
|
14479
|
-
|
|
14480
|
-
|
|
14481
|
-
|
|
14480
|
+
let canReset = false;
|
|
14481
|
+
tr.selection.ranges.forEach((range) => {
|
|
14482
|
+
state.doc.nodesBetween(range.$from.pos, range.$to.pos, (node, pos) => {
|
|
14483
|
+
if (nodeType && nodeType === node.type) {
|
|
14484
|
+
canReset = true;
|
|
14485
|
+
if (dispatch) {
|
|
14482
14486
|
tr.setNodeMarkup(pos, void 0, deleteProps(node.attrs, attributes));
|
|
14483
14487
|
}
|
|
14484
|
-
|
|
14485
|
-
|
|
14486
|
-
|
|
14488
|
+
}
|
|
14489
|
+
if (markType && node.marks.length) {
|
|
14490
|
+
node.marks.forEach((mark) => {
|
|
14491
|
+
if (markType === mark.type) {
|
|
14492
|
+
canReset = true;
|
|
14493
|
+
if (dispatch) {
|
|
14487
14494
|
tr.addMark(pos, pos + node.nodeSize, markType.create(deleteProps(mark.attrs, attributes)));
|
|
14488
14495
|
}
|
|
14489
|
-
}
|
|
14490
|
-
}
|
|
14491
|
-
}
|
|
14496
|
+
}
|
|
14497
|
+
});
|
|
14498
|
+
}
|
|
14492
14499
|
});
|
|
14493
|
-
}
|
|
14494
|
-
return
|
|
14500
|
+
});
|
|
14501
|
+
return canReset;
|
|
14495
14502
|
};
|
|
14496
14503
|
|
|
14497
14504
|
// src/commands/scrollIntoView.ts
|
|
@@ -14886,6 +14893,17 @@ function cleanUpSchemaItem(data) {
|
|
|
14886
14893
|
})
|
|
14887
14894
|
);
|
|
14888
14895
|
}
|
|
14896
|
+
function buildAttributeSpec(extensionAttribute) {
|
|
14897
|
+
var _a, _b;
|
|
14898
|
+
const spec = {};
|
|
14899
|
+
if (!((_a = extensionAttribute == null ? void 0 : extensionAttribute.attribute) == null ? void 0 : _a.isRequired) && "default" in ((extensionAttribute == null ? void 0 : extensionAttribute.attribute) || {})) {
|
|
14900
|
+
spec.default = extensionAttribute.attribute.default;
|
|
14901
|
+
}
|
|
14902
|
+
if (((_b = extensionAttribute == null ? void 0 : extensionAttribute.attribute) == null ? void 0 : _b.validate) !== void 0) {
|
|
14903
|
+
spec.validate = extensionAttribute.attribute.validate;
|
|
14904
|
+
}
|
|
14905
|
+
return [extensionAttribute.name, spec];
|
|
14906
|
+
}
|
|
14889
14907
|
function getSchemaByResolvedExtensions(extensions, editor) {
|
|
14890
14908
|
var _a;
|
|
14891
14909
|
const allAttributes = getAttributesFromExtensions(extensions);
|
|
@@ -14923,15 +14941,7 @@ function getSchemaByResolvedExtensions(extensions, editor) {
|
|
|
14923
14941
|
),
|
|
14924
14942
|
defining: callOrReturn(getExtensionField(extension, "defining", context)),
|
|
14925
14943
|
isolating: callOrReturn(getExtensionField(extension, "isolating", context)),
|
|
14926
|
-
attrs: Object.fromEntries(
|
|
14927
|
-
extensionAttributes.map((extensionAttribute) => {
|
|
14928
|
-
var _a2, _b;
|
|
14929
|
-
return [
|
|
14930
|
-
extensionAttribute.name,
|
|
14931
|
-
{ default: (_a2 = extensionAttribute == null ? void 0 : extensionAttribute.attribute) == null ? void 0 : _a2.default, validate: (_b = extensionAttribute == null ? void 0 : extensionAttribute.attribute) == null ? void 0 : _b.validate }
|
|
14932
|
-
];
|
|
14933
|
-
})
|
|
14934
|
-
)
|
|
14944
|
+
attrs: Object.fromEntries(extensionAttributes.map(buildAttributeSpec))
|
|
14935
14945
|
});
|
|
14936
14946
|
const parseHTML = callOrReturn(getExtensionField(extension, "parseHTML", context));
|
|
14937
14947
|
if (parseHTML) {
|
|
@@ -14976,15 +14986,7 @@ function getSchemaByResolvedExtensions(extensions, editor) {
|
|
|
14976
14986
|
group: callOrReturn(getExtensionField(extension, "group", context)),
|
|
14977
14987
|
spanning: callOrReturn(getExtensionField(extension, "spanning", context)),
|
|
14978
14988
|
code: callOrReturn(getExtensionField(extension, "code", context)),
|
|
14979
|
-
attrs: Object.fromEntries(
|
|
14980
|
-
extensionAttributes.map((extensionAttribute) => {
|
|
14981
|
-
var _a2, _b;
|
|
14982
|
-
return [
|
|
14983
|
-
extensionAttribute.name,
|
|
14984
|
-
{ default: (_a2 = extensionAttribute == null ? void 0 : extensionAttribute.attribute) == null ? void 0 : _a2.default, validate: (_b = extensionAttribute == null ? void 0 : extensionAttribute.attribute) == null ? void 0 : _b.validate }
|
|
14985
|
-
];
|
|
14986
|
-
})
|
|
14987
|
-
)
|
|
14989
|
+
attrs: Object.fromEntries(extensionAttributes.map(buildAttributeSpec))
|
|
14988
14990
|
});
|
|
14989
14991
|
const parseHTML = callOrReturn(getExtensionField(extension, "parseHTML", context));
|
|
14990
14992
|
if (parseHTML) {
|
|
@@ -15546,6 +15548,35 @@ var setNodeSelection = (position) => ({ tr, dispatch }) => {
|
|
|
15546
15548
|
}
|
|
15547
15549
|
return true;
|
|
15548
15550
|
};
|
|
15551
|
+
|
|
15552
|
+
// src/commands/setTextDirection.ts
|
|
15553
|
+
var setTextDirection = (direction, position) => ({ tr, state, dispatch }) => {
|
|
15554
|
+
const { selection } = state;
|
|
15555
|
+
let from;
|
|
15556
|
+
let to;
|
|
15557
|
+
if (typeof position === "number") {
|
|
15558
|
+
from = position;
|
|
15559
|
+
to = position;
|
|
15560
|
+
} else if (position && "from" in position && "to" in position) {
|
|
15561
|
+
from = position.from;
|
|
15562
|
+
to = position.to;
|
|
15563
|
+
} else {
|
|
15564
|
+
from = selection.from;
|
|
15565
|
+
to = selection.to;
|
|
15566
|
+
}
|
|
15567
|
+
if (dispatch) {
|
|
15568
|
+
tr.doc.nodesBetween(from, to, (node, pos) => {
|
|
15569
|
+
if (node.isText) {
|
|
15570
|
+
return;
|
|
15571
|
+
}
|
|
15572
|
+
tr.setNodeMarkup(pos, void 0, {
|
|
15573
|
+
...node.attrs,
|
|
15574
|
+
dir: direction
|
|
15575
|
+
});
|
|
15576
|
+
});
|
|
15577
|
+
}
|
|
15578
|
+
return true;
|
|
15579
|
+
};
|
|
15549
15580
|
var setTextSelection = (position) => ({ tr, dispatch }) => {
|
|
15550
15581
|
if (dispatch) {
|
|
15551
15582
|
const { doc } = tr;
|
|
@@ -15892,6 +15923,34 @@ var unsetMark = (typeOrName, options = {}) => ({ tr, state, dispatch }) => {
|
|
|
15892
15923
|
return true;
|
|
15893
15924
|
};
|
|
15894
15925
|
|
|
15926
|
+
// src/commands/unsetTextDirection.ts
|
|
15927
|
+
var unsetTextDirection = (position) => ({ tr, state, dispatch }) => {
|
|
15928
|
+
const { selection } = state;
|
|
15929
|
+
let from;
|
|
15930
|
+
let to;
|
|
15931
|
+
if (typeof position === "number") {
|
|
15932
|
+
from = position;
|
|
15933
|
+
to = position;
|
|
15934
|
+
} else if (position && "from" in position && "to" in position) {
|
|
15935
|
+
from = position.from;
|
|
15936
|
+
to = position.to;
|
|
15937
|
+
} else {
|
|
15938
|
+
from = selection.from;
|
|
15939
|
+
to = selection.to;
|
|
15940
|
+
}
|
|
15941
|
+
if (dispatch) {
|
|
15942
|
+
tr.doc.nodesBetween(from, to, (node, pos) => {
|
|
15943
|
+
if (node.isText) {
|
|
15944
|
+
return;
|
|
15945
|
+
}
|
|
15946
|
+
const newAttrs = { ...node.attrs };
|
|
15947
|
+
delete newAttrs.dir;
|
|
15948
|
+
tr.setNodeMarkup(pos, void 0, newAttrs);
|
|
15949
|
+
});
|
|
15950
|
+
}
|
|
15951
|
+
return true;
|
|
15952
|
+
};
|
|
15953
|
+
|
|
15895
15954
|
// src/commands/updateAttributes.ts
|
|
15896
15955
|
var updateAttributes = (typeOrName, attributes = {}) => ({ tr, state, dispatch }) => {
|
|
15897
15956
|
let nodeType = null;
|
|
@@ -15909,41 +15968,48 @@ var updateAttributes = (typeOrName, attributes = {}) => ({ tr, state, dispatch }
|
|
|
15909
15968
|
if (schemaType === "mark") {
|
|
15910
15969
|
markType = getMarkType(typeOrName, state.schema);
|
|
15911
15970
|
}
|
|
15912
|
-
|
|
15913
|
-
|
|
15914
|
-
|
|
15915
|
-
|
|
15916
|
-
|
|
15917
|
-
|
|
15918
|
-
|
|
15919
|
-
|
|
15920
|
-
|
|
15921
|
-
|
|
15971
|
+
let canUpdate = false;
|
|
15972
|
+
tr.selection.ranges.forEach((range) => {
|
|
15973
|
+
const from = range.$from.pos;
|
|
15974
|
+
const to = range.$to.pos;
|
|
15975
|
+
let lastPos;
|
|
15976
|
+
let lastNode;
|
|
15977
|
+
let trimmedFrom;
|
|
15978
|
+
let trimmedTo;
|
|
15979
|
+
if (tr.selection.empty) {
|
|
15980
|
+
state.doc.nodesBetween(from, to, (node, pos) => {
|
|
15981
|
+
if (nodeType && nodeType === node.type) {
|
|
15982
|
+
canUpdate = true;
|
|
15983
|
+
trimmedFrom = Math.max(pos, from);
|
|
15984
|
+
trimmedTo = Math.min(pos + node.nodeSize, to);
|
|
15985
|
+
lastPos = pos;
|
|
15986
|
+
lastNode = node;
|
|
15987
|
+
}
|
|
15988
|
+
});
|
|
15989
|
+
} else {
|
|
15990
|
+
state.doc.nodesBetween(from, to, (node, pos) => {
|
|
15991
|
+
if (pos < from && nodeType && nodeType === node.type) {
|
|
15992
|
+
canUpdate = true;
|
|
15993
|
+
trimmedFrom = Math.max(pos, from);
|
|
15994
|
+
trimmedTo = Math.min(pos + node.nodeSize, to);
|
|
15995
|
+
lastPos = pos;
|
|
15996
|
+
lastNode = node;
|
|
15997
|
+
}
|
|
15998
|
+
if (pos >= from && pos <= to) {
|
|
15922
15999
|
if (nodeType && nodeType === node.type) {
|
|
15923
|
-
|
|
15924
|
-
|
|
15925
|
-
lastPos = pos;
|
|
15926
|
-
lastNode = node;
|
|
15927
|
-
}
|
|
15928
|
-
});
|
|
15929
|
-
} else {
|
|
15930
|
-
state.doc.nodesBetween(from, to, (node, pos) => {
|
|
15931
|
-
if (pos < from && nodeType && nodeType === node.type) {
|
|
15932
|
-
trimmedFrom = Math.max(pos, from);
|
|
15933
|
-
trimmedTo = Math.min(pos + node.nodeSize, to);
|
|
15934
|
-
lastPos = pos;
|
|
15935
|
-
lastNode = node;
|
|
15936
|
-
}
|
|
15937
|
-
if (pos >= from && pos <= to) {
|
|
15938
|
-
if (nodeType && nodeType === node.type) {
|
|
16000
|
+
canUpdate = true;
|
|
16001
|
+
if (dispatch) {
|
|
15939
16002
|
tr.setNodeMarkup(pos, void 0, {
|
|
15940
16003
|
...node.attrs,
|
|
15941
16004
|
...attributes
|
|
15942
16005
|
});
|
|
15943
16006
|
}
|
|
15944
|
-
|
|
15945
|
-
|
|
15946
|
-
|
|
16007
|
+
}
|
|
16008
|
+
if (markType && node.marks.length) {
|
|
16009
|
+
node.marks.forEach((mark) => {
|
|
16010
|
+
if (markType === mark.type) {
|
|
16011
|
+
canUpdate = true;
|
|
16012
|
+
if (dispatch) {
|
|
15947
16013
|
const trimmedFrom2 = Math.max(pos, from);
|
|
15948
16014
|
const trimmedTo2 = Math.min(pos + node.nodeSize, to);
|
|
15949
16015
|
tr.addMark(
|
|
@@ -15955,36 +16021,36 @@ var updateAttributes = (typeOrName, attributes = {}) => ({ tr, state, dispatch }
|
|
|
15955
16021
|
})
|
|
15956
16022
|
);
|
|
15957
16023
|
}
|
|
15958
|
-
}
|
|
15959
|
-
}
|
|
16024
|
+
}
|
|
16025
|
+
});
|
|
15960
16026
|
}
|
|
16027
|
+
}
|
|
16028
|
+
});
|
|
16029
|
+
}
|
|
16030
|
+
if (lastNode) {
|
|
16031
|
+
if (lastPos !== void 0 && dispatch) {
|
|
16032
|
+
tr.setNodeMarkup(lastPos, void 0, {
|
|
16033
|
+
...lastNode.attrs,
|
|
16034
|
+
...attributes
|
|
15961
16035
|
});
|
|
15962
16036
|
}
|
|
15963
|
-
if (lastNode) {
|
|
15964
|
-
|
|
15965
|
-
|
|
15966
|
-
|
|
15967
|
-
|
|
15968
|
-
|
|
15969
|
-
|
|
15970
|
-
|
|
15971
|
-
|
|
15972
|
-
|
|
15973
|
-
|
|
15974
|
-
|
|
15975
|
-
|
|
15976
|
-
markType.create({
|
|
15977
|
-
...mark.attrs,
|
|
15978
|
-
...attributes
|
|
15979
|
-
})
|
|
15980
|
-
);
|
|
15981
|
-
}
|
|
15982
|
-
});
|
|
15983
|
-
}
|
|
16037
|
+
if (markType && lastNode.marks.length) {
|
|
16038
|
+
lastNode.marks.forEach((mark) => {
|
|
16039
|
+
if (markType === mark.type && dispatch) {
|
|
16040
|
+
tr.addMark(
|
|
16041
|
+
trimmedFrom,
|
|
16042
|
+
trimmedTo,
|
|
16043
|
+
markType.create({
|
|
16044
|
+
...mark.attrs,
|
|
16045
|
+
...attributes
|
|
16046
|
+
})
|
|
16047
|
+
);
|
|
16048
|
+
}
|
|
16049
|
+
});
|
|
15984
16050
|
}
|
|
15985
|
-
}
|
|
15986
|
-
}
|
|
15987
|
-
return
|
|
16051
|
+
}
|
|
16052
|
+
});
|
|
16053
|
+
return canUpdate;
|
|
15988
16054
|
};
|
|
15989
16055
|
var wrapIn = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
|
|
15990
16056
|
const type = getNodeType(typeOrName, state.schema);
|
|
@@ -16840,6 +16906,7 @@ __export$1(extensions_exports, {
|
|
|
16840
16906
|
Keymap: () => Keymap,
|
|
16841
16907
|
Paste: () => Paste,
|
|
16842
16908
|
Tabindex: () => Tabindex,
|
|
16909
|
+
TextDirection: () => TextDirection,
|
|
16843
16910
|
focusEventsPluginKey: () => focusEventsPluginKey
|
|
16844
16911
|
});
|
|
16845
16912
|
|
|
@@ -17184,6 +17251,63 @@ var Tabindex = Extension.create({
|
|
|
17184
17251
|
];
|
|
17185
17252
|
}
|
|
17186
17253
|
});
|
|
17254
|
+
var TextDirection = Extension.create({
|
|
17255
|
+
name: "textDirection",
|
|
17256
|
+
addOptions() {
|
|
17257
|
+
return {
|
|
17258
|
+
direction: void 0
|
|
17259
|
+
};
|
|
17260
|
+
},
|
|
17261
|
+
addGlobalAttributes() {
|
|
17262
|
+
if (!this.options.direction) {
|
|
17263
|
+
return [];
|
|
17264
|
+
}
|
|
17265
|
+
const { nodeExtensions } = splitExtensions(this.extensions);
|
|
17266
|
+
return [
|
|
17267
|
+
{
|
|
17268
|
+
types: nodeExtensions.filter((extension) => extension.name !== "text").map((extension) => extension.name),
|
|
17269
|
+
attributes: {
|
|
17270
|
+
dir: {
|
|
17271
|
+
default: this.options.direction,
|
|
17272
|
+
parseHTML: (element) => {
|
|
17273
|
+
const dir = element.getAttribute("dir");
|
|
17274
|
+
if (dir && (dir === "ltr" || dir === "rtl" || dir === "auto")) {
|
|
17275
|
+
return dir;
|
|
17276
|
+
}
|
|
17277
|
+
return this.options.direction;
|
|
17278
|
+
},
|
|
17279
|
+
renderHTML: (attributes) => {
|
|
17280
|
+
if (!attributes.dir) {
|
|
17281
|
+
return {};
|
|
17282
|
+
}
|
|
17283
|
+
return {
|
|
17284
|
+
dir: attributes.dir
|
|
17285
|
+
};
|
|
17286
|
+
}
|
|
17287
|
+
}
|
|
17288
|
+
}
|
|
17289
|
+
}
|
|
17290
|
+
];
|
|
17291
|
+
},
|
|
17292
|
+
addProseMirrorPlugins() {
|
|
17293
|
+
return [
|
|
17294
|
+
new Plugin({
|
|
17295
|
+
key: new PluginKey("textDirection"),
|
|
17296
|
+
props: {
|
|
17297
|
+
attributes: () => {
|
|
17298
|
+
const direction = this.options.direction;
|
|
17299
|
+
if (!direction) {
|
|
17300
|
+
return {};
|
|
17301
|
+
}
|
|
17302
|
+
return {
|
|
17303
|
+
dir: direction
|
|
17304
|
+
};
|
|
17305
|
+
}
|
|
17306
|
+
}
|
|
17307
|
+
})
|
|
17308
|
+
];
|
|
17309
|
+
}
|
|
17310
|
+
});
|
|
17187
17311
|
|
|
17188
17312
|
// src/NodePos.ts
|
|
17189
17313
|
var NodePos = class _NodePos {
|
|
@@ -17467,6 +17591,7 @@ var Editor = class extends EventEmitter {
|
|
|
17467
17591
|
extensions: [],
|
|
17468
17592
|
autofocus: false,
|
|
17469
17593
|
editable: true,
|
|
17594
|
+
textDirection: void 0,
|
|
17470
17595
|
editorProps: {},
|
|
17471
17596
|
parseOptions: {},
|
|
17472
17597
|
coreExtensionOptions: {},
|
|
@@ -17542,7 +17667,9 @@ var Editor = class extends EventEmitter {
|
|
|
17542
17667
|
if (this.isDestroyed) {
|
|
17543
17668
|
return;
|
|
17544
17669
|
}
|
|
17545
|
-
this.
|
|
17670
|
+
if (this.options.autofocus !== false && this.options.autofocus !== null) {
|
|
17671
|
+
this.commands.focus(this.options.autofocus);
|
|
17672
|
+
}
|
|
17546
17673
|
this.emit("create", { editor: this });
|
|
17547
17674
|
this.isInitialized = true;
|
|
17548
17675
|
}, 0);
|
|
@@ -17742,7 +17869,10 @@ var Editor = class extends EventEmitter {
|
|
|
17742
17869
|
Tabindex,
|
|
17743
17870
|
Drop,
|
|
17744
17871
|
Paste,
|
|
17745
|
-
Delete
|
|
17872
|
+
Delete,
|
|
17873
|
+
TextDirection.configure({
|
|
17874
|
+
direction: this.options.textDirection
|
|
17875
|
+
})
|
|
17746
17876
|
].filter((ext) => {
|
|
17747
17877
|
if (typeof this.options.enableCoreExtensions === "object") {
|
|
17748
17878
|
return this.options.enableCoreExtensions[ext.name] !== false;
|
|
@@ -19062,6 +19192,8 @@ function parseIndentedBlocks(src, config, lexer) {
|
|
|
19062
19192
|
break;
|
|
19063
19193
|
} else if (currentLine.trim() === "") {
|
|
19064
19194
|
i += 1;
|
|
19195
|
+
totalRaw = `${totalRaw}${currentLine}
|
|
19196
|
+
`;
|
|
19065
19197
|
continue;
|
|
19066
19198
|
} else {
|
|
19067
19199
|
return void 0;
|
|
@@ -19122,7 +19254,7 @@ function parseIndentedBlocks(src, config, lexer) {
|
|
|
19122
19254
|
}
|
|
19123
19255
|
return {
|
|
19124
19256
|
items,
|
|
19125
|
-
raw: totalRaw
|
|
19257
|
+
raw: totalRaw
|
|
19126
19258
|
};
|
|
19127
19259
|
}
|
|
19128
19260
|
|
|
@@ -19170,153 +19302,2240 @@ function updateMarkViewAttributes(checkMark, editor, attrs = {}) {
|
|
|
19170
19302
|
if (attrs[k] !== foundMark.attrs[k]) {
|
|
19171
19303
|
needsUpdate = true;
|
|
19172
19304
|
}
|
|
19173
|
-
});
|
|
19174
|
-
if (needsUpdate) {
|
|
19175
|
-
const updatedMark = checkMark.type.create({
|
|
19176
|
-
...checkMark.attrs,
|
|
19177
|
-
...attrs
|
|
19178
|
-
});
|
|
19179
|
-
tr.removeMark(from, to, checkMark.type);
|
|
19180
|
-
tr.addMark(from, to, updatedMark);
|
|
19305
|
+
});
|
|
19306
|
+
if (needsUpdate) {
|
|
19307
|
+
const updatedMark = checkMark.type.create({
|
|
19308
|
+
...checkMark.attrs,
|
|
19309
|
+
...attrs
|
|
19310
|
+
});
|
|
19311
|
+
tr.removeMark(from, to, checkMark.type);
|
|
19312
|
+
tr.addMark(from, to, updatedMark);
|
|
19313
|
+
}
|
|
19314
|
+
});
|
|
19315
|
+
if (tr.docChanged) {
|
|
19316
|
+
editor.view.dispatch(tr);
|
|
19317
|
+
}
|
|
19318
|
+
}
|
|
19319
|
+
|
|
19320
|
+
// src/Node.ts
|
|
19321
|
+
var Node3 = class _Node extends Extendable {
|
|
19322
|
+
constructor() {
|
|
19323
|
+
super(...arguments);
|
|
19324
|
+
this.type = "node";
|
|
19325
|
+
}
|
|
19326
|
+
/**
|
|
19327
|
+
* Create a new Node instance
|
|
19328
|
+
* @param config - Node configuration object or a function that returns a configuration object
|
|
19329
|
+
*/
|
|
19330
|
+
static create(config = {}) {
|
|
19331
|
+
const resolvedConfig = typeof config === "function" ? config() : config;
|
|
19332
|
+
return new _Node(resolvedConfig);
|
|
19333
|
+
}
|
|
19334
|
+
configure(options) {
|
|
19335
|
+
return super.configure(options);
|
|
19336
|
+
}
|
|
19337
|
+
extend(extendedConfig) {
|
|
19338
|
+
const resolvedConfig = typeof extendedConfig === "function" ? extendedConfig() : extendedConfig;
|
|
19339
|
+
return super.extend(resolvedConfig);
|
|
19340
|
+
}
|
|
19341
|
+
};
|
|
19342
|
+
|
|
19343
|
+
// src/pasteRules/markPasteRule.ts
|
|
19344
|
+
function markPasteRule(config) {
|
|
19345
|
+
return new PasteRule({
|
|
19346
|
+
find: config.find,
|
|
19347
|
+
handler: ({ state, range, match, pasteEvent }) => {
|
|
19348
|
+
const attributes = callOrReturn(config.getAttributes, void 0, match, pasteEvent);
|
|
19349
|
+
if (attributes === false || attributes === null) {
|
|
19350
|
+
return null;
|
|
19351
|
+
}
|
|
19352
|
+
const { tr } = state;
|
|
19353
|
+
const captureGroup = match[match.length - 1];
|
|
19354
|
+
const fullMatch = match[0];
|
|
19355
|
+
let markEnd = range.to;
|
|
19356
|
+
if (captureGroup) {
|
|
19357
|
+
const startSpaces = fullMatch.search(/\S/);
|
|
19358
|
+
const textStart = range.from + fullMatch.indexOf(captureGroup);
|
|
19359
|
+
const textEnd = textStart + captureGroup.length;
|
|
19360
|
+
const excludedMarks = getMarksBetween(range.from, range.to, state.doc).filter((item) => {
|
|
19361
|
+
const excluded = item.mark.type.excluded;
|
|
19362
|
+
return excluded.find((type) => type === config.type && type !== item.mark.type);
|
|
19363
|
+
}).filter((item) => item.to > textStart);
|
|
19364
|
+
if (excludedMarks.length) {
|
|
19365
|
+
return null;
|
|
19366
|
+
}
|
|
19367
|
+
if (textEnd < range.to) {
|
|
19368
|
+
tr.delete(textEnd, range.to);
|
|
19369
|
+
}
|
|
19370
|
+
if (textStart > range.from) {
|
|
19371
|
+
tr.delete(range.from + startSpaces, textStart);
|
|
19372
|
+
}
|
|
19373
|
+
markEnd = range.from + startSpaces + captureGroup.length;
|
|
19374
|
+
tr.addMark(range.from + startSpaces, markEnd, config.type.create(attributes || {}));
|
|
19375
|
+
tr.removeStoredMark(config.type);
|
|
19376
|
+
}
|
|
19377
|
+
}
|
|
19378
|
+
});
|
|
19379
|
+
}
|
|
19380
|
+
|
|
19381
|
+
/**
|
|
19382
|
+
* marked v15.0.12 - a markdown parser
|
|
19383
|
+
* Copyright (c) 2011-2025, Christopher Jeffrey. (MIT Licensed)
|
|
19384
|
+
* https://github.com/markedjs/marked
|
|
19385
|
+
*/
|
|
19386
|
+
|
|
19387
|
+
/**
|
|
19388
|
+
* DO NOT EDIT THIS FILE
|
|
19389
|
+
* The code in this file is generated from files in ./src/
|
|
19390
|
+
*/
|
|
19391
|
+
|
|
19392
|
+
|
|
19393
|
+
// src/defaults.ts
|
|
19394
|
+
function _getDefaults() {
|
|
19395
|
+
return {
|
|
19396
|
+
async: false,
|
|
19397
|
+
breaks: false,
|
|
19398
|
+
extensions: null,
|
|
19399
|
+
gfm: true,
|
|
19400
|
+
hooks: null,
|
|
19401
|
+
pedantic: false,
|
|
19402
|
+
renderer: null,
|
|
19403
|
+
silent: false,
|
|
19404
|
+
tokenizer: null,
|
|
19405
|
+
walkTokens: null
|
|
19406
|
+
};
|
|
19407
|
+
}
|
|
19408
|
+
var _defaults = _getDefaults();
|
|
19409
|
+
function changeDefaults(newDefaults) {
|
|
19410
|
+
_defaults = newDefaults;
|
|
19411
|
+
}
|
|
19412
|
+
|
|
19413
|
+
// src/rules.ts
|
|
19414
|
+
var noopTest = { exec: () => null };
|
|
19415
|
+
function edit(regex, opt = "") {
|
|
19416
|
+
let source = typeof regex === "string" ? regex : regex.source;
|
|
19417
|
+
const obj = {
|
|
19418
|
+
replace: (name, val) => {
|
|
19419
|
+
let valSource = typeof val === "string" ? val : val.source;
|
|
19420
|
+
valSource = valSource.replace(other.caret, "$1");
|
|
19421
|
+
source = source.replace(name, valSource);
|
|
19422
|
+
return obj;
|
|
19423
|
+
},
|
|
19424
|
+
getRegex: () => {
|
|
19425
|
+
return new RegExp(source, opt);
|
|
19426
|
+
}
|
|
19427
|
+
};
|
|
19428
|
+
return obj;
|
|
19429
|
+
}
|
|
19430
|
+
var other = {
|
|
19431
|
+
codeRemoveIndent: /^(?: {1,4}| {0,3}\t)/gm,
|
|
19432
|
+
outputLinkReplace: /\\([\[\]])/g,
|
|
19433
|
+
indentCodeCompensation: /^(\s+)(?:```)/,
|
|
19434
|
+
beginningSpace: /^\s+/,
|
|
19435
|
+
endingHash: /#$/,
|
|
19436
|
+
startingSpaceChar: /^ /,
|
|
19437
|
+
endingSpaceChar: / $/,
|
|
19438
|
+
nonSpaceChar: /[^ ]/,
|
|
19439
|
+
newLineCharGlobal: /\n/g,
|
|
19440
|
+
tabCharGlobal: /\t/g,
|
|
19441
|
+
multipleSpaceGlobal: /\s+/g,
|
|
19442
|
+
blankLine: /^[ \t]*$/,
|
|
19443
|
+
doubleBlankLine: /\n[ \t]*\n[ \t]*$/,
|
|
19444
|
+
blockquoteStart: /^ {0,3}>/,
|
|
19445
|
+
blockquoteSetextReplace: /\n {0,3}((?:=+|-+) *)(?=\n|$)/g,
|
|
19446
|
+
blockquoteSetextReplace2: /^ {0,3}>[ \t]?/gm,
|
|
19447
|
+
listReplaceTabs: /^\t+/,
|
|
19448
|
+
listReplaceNesting: /^ {1,4}(?=( {4})*[^ ])/g,
|
|
19449
|
+
listIsTask: /^\[[ xX]\] /,
|
|
19450
|
+
listReplaceTask: /^\[[ xX]\] +/,
|
|
19451
|
+
anyLine: /\n.*\n/,
|
|
19452
|
+
hrefBrackets: /^<(.*)>$/,
|
|
19453
|
+
tableDelimiter: /[:|]/,
|
|
19454
|
+
tableAlignChars: /^\||\| *$/g,
|
|
19455
|
+
tableRowBlankLine: /\n[ \t]*$/,
|
|
19456
|
+
tableAlignRight: /^ *-+: *$/,
|
|
19457
|
+
tableAlignCenter: /^ *:-+: *$/,
|
|
19458
|
+
tableAlignLeft: /^ *:-+ *$/,
|
|
19459
|
+
startATag: /^<a /i,
|
|
19460
|
+
endATag: /^<\/a>/i,
|
|
19461
|
+
startPreScriptTag: /^<(pre|code|kbd|script)(\s|>)/i,
|
|
19462
|
+
endPreScriptTag: /^<\/(pre|code|kbd|script)(\s|>)/i,
|
|
19463
|
+
startAngleBracket: /^</,
|
|
19464
|
+
endAngleBracket: />$/,
|
|
19465
|
+
pedanticHrefTitle: /^([^'"]*[^\s])\s+(['"])(.*)\2/,
|
|
19466
|
+
unicodeAlphaNumeric: /[\p{L}\p{N}]/u,
|
|
19467
|
+
escapeTest: /[&<>"']/,
|
|
19468
|
+
escapeReplace: /[&<>"']/g,
|
|
19469
|
+
escapeTestNoEncode: /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,
|
|
19470
|
+
escapeReplaceNoEncode: /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,
|
|
19471
|
+
unescapeTest: /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig,
|
|
19472
|
+
caret: /(^|[^\[])\^/g,
|
|
19473
|
+
percentDecode: /%25/g,
|
|
19474
|
+
findPipe: /\|/g,
|
|
19475
|
+
splitPipe: / \|/,
|
|
19476
|
+
slashPipe: /\\\|/g,
|
|
19477
|
+
carriageReturn: /\r\n|\r/g,
|
|
19478
|
+
spaceLine: /^ +$/gm,
|
|
19479
|
+
notSpaceStart: /^\S*/,
|
|
19480
|
+
endingNewline: /\n$/,
|
|
19481
|
+
listItemRegex: (bull) => new RegExp(`^( {0,3}${bull})((?:[ ][^\\n]*)?(?:\\n|$))`),
|
|
19482
|
+
nextBulletRegex: (indent) => new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),
|
|
19483
|
+
hrRegex: (indent) => new RegExp(`^ {0,${Math.min(3, indent - 1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),
|
|
19484
|
+
fencesBeginRegex: (indent) => new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:\`\`\`|~~~)`),
|
|
19485
|
+
headingBeginRegex: (indent) => new RegExp(`^ {0,${Math.min(3, indent - 1)}}#`),
|
|
19486
|
+
htmlBeginRegex: (indent) => new RegExp(`^ {0,${Math.min(3, indent - 1)}}<(?:[a-z].*>|!--)`, "i")
|
|
19487
|
+
};
|
|
19488
|
+
var newline = /^(?:[ \t]*(?:\n|$))+/;
|
|
19489
|
+
var blockCode = /^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/;
|
|
19490
|
+
var fences = /^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/;
|
|
19491
|
+
var hr = /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/;
|
|
19492
|
+
var heading = /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/;
|
|
19493
|
+
var bullet = /(?:[*+-]|\d{1,9}[.)])/;
|
|
19494
|
+
var lheadingCore = /^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/;
|
|
19495
|
+
var lheading = edit(lheadingCore).replace(/bull/g, bullet).replace(/blockCode/g, /(?: {4}| {0,3}\t)/).replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g, / {0,3}>/).replace(/heading/g, / {0,3}#{1,6}/).replace(/html/g, / {0,3}<[^\n>]+>\n/).replace(/\|table/g, "").getRegex();
|
|
19496
|
+
var lheadingGfm = edit(lheadingCore).replace(/bull/g, bullet).replace(/blockCode/g, /(?: {4}| {0,3}\t)/).replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g, / {0,3}>/).replace(/heading/g, / {0,3}#{1,6}/).replace(/html/g, / {0,3}<[^\n>]+>\n/).replace(/table/g, / {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex();
|
|
19497
|
+
var _paragraph = /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/;
|
|
19498
|
+
var blockText = /^[^\n]+/;
|
|
19499
|
+
var _blockLabel = /(?!\s*\])(?:\\.|[^\[\]\\])+/;
|
|
19500
|
+
var def = edit(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label", _blockLabel).replace("title", /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex();
|
|
19501
|
+
var list = edit(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g, bullet).getRegex();
|
|
19502
|
+
var _tag = "address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul";
|
|
19503
|
+
var _comment = /<!--(?:-?>|[\s\S]*?(?:-->|$))/;
|
|
19504
|
+
var html = edit(
|
|
19505
|
+
"^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))",
|
|
19506
|
+
"i"
|
|
19507
|
+
).replace("comment", _comment).replace("tag", _tag).replace("attribute", / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex();
|
|
19508
|
+
var paragraph = edit(_paragraph).replace("hr", hr).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("|lheading", "").replace("|table", "").replace("blockquote", " {0,3}>").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)]) ").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", _tag).getRegex();
|
|
19509
|
+
var blockquote = edit(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph", paragraph).getRegex();
|
|
19510
|
+
var blockNormal = {
|
|
19511
|
+
blockquote,
|
|
19512
|
+
code: blockCode,
|
|
19513
|
+
def,
|
|
19514
|
+
fences,
|
|
19515
|
+
heading,
|
|
19516
|
+
hr,
|
|
19517
|
+
html,
|
|
19518
|
+
lheading,
|
|
19519
|
+
list,
|
|
19520
|
+
newline,
|
|
19521
|
+
paragraph,
|
|
19522
|
+
table: noopTest,
|
|
19523
|
+
text: blockText
|
|
19524
|
+
};
|
|
19525
|
+
var gfmTable = edit(
|
|
19526
|
+
"^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)"
|
|
19527
|
+
).replace("hr", hr).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("blockquote", " {0,3}>").replace("code", "(?: {4}| {0,3} )[^\\n]").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)]) ").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", _tag).getRegex();
|
|
19528
|
+
var blockGfm = {
|
|
19529
|
+
...blockNormal,
|
|
19530
|
+
lheading: lheadingGfm,
|
|
19531
|
+
table: gfmTable,
|
|
19532
|
+
paragraph: edit(_paragraph).replace("hr", hr).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("|lheading", "").replace("table", gfmTable).replace("blockquote", " {0,3}>").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)]) ").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", _tag).getRegex()
|
|
19533
|
+
};
|
|
19534
|
+
var blockPedantic = {
|
|
19535
|
+
...blockNormal,
|
|
19536
|
+
html: edit(
|
|
19537
|
+
`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`
|
|
19538
|
+
).replace("comment", _comment).replace(/tag/g, "(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),
|
|
19539
|
+
def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,
|
|
19540
|
+
heading: /^(#{1,6})(.*)(?:\n+|$)/,
|
|
19541
|
+
fences: noopTest,
|
|
19542
|
+
// fences not supported
|
|
19543
|
+
lheading: /^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,
|
|
19544
|
+
paragraph: edit(_paragraph).replace("hr", hr).replace("heading", " *#{1,6} *[^\n]").replace("lheading", lheading).replace("|table", "").replace("blockquote", " {0,3}>").replace("|fences", "").replace("|list", "").replace("|html", "").replace("|tag", "").getRegex()
|
|
19545
|
+
};
|
|
19546
|
+
var escape = /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/;
|
|
19547
|
+
var inlineCode = /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/;
|
|
19548
|
+
var br = /^( {2,}|\\)\n(?!\s*$)/;
|
|
19549
|
+
var inlineText = /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/;
|
|
19550
|
+
var _punctuation = /[\p{P}\p{S}]/u;
|
|
19551
|
+
var _punctuationOrSpace = /[\s\p{P}\p{S}]/u;
|
|
19552
|
+
var _notPunctuationOrSpace = /[^\s\p{P}\p{S}]/u;
|
|
19553
|
+
var punctuation = edit(/^((?![*_])punctSpace)/, "u").replace(/punctSpace/g, _punctuationOrSpace).getRegex();
|
|
19554
|
+
var _punctuationGfmStrongEm = /(?!~)[\p{P}\p{S}]/u;
|
|
19555
|
+
var _punctuationOrSpaceGfmStrongEm = /(?!~)[\s\p{P}\p{S}]/u;
|
|
19556
|
+
var _notPunctuationOrSpaceGfmStrongEm = /(?:[^\s\p{P}\p{S}]|~)/u;
|
|
19557
|
+
var blockSkip = /\[[^[\]]*?\]\((?:\\.|[^\\\(\)]|\((?:\\.|[^\\\(\)])*\))*\)|`[^`]*?`|<[^<>]*?>/g;
|
|
19558
|
+
var emStrongLDelimCore = /^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/;
|
|
19559
|
+
var emStrongLDelim = edit(emStrongLDelimCore, "u").replace(/punct/g, _punctuation).getRegex();
|
|
19560
|
+
var emStrongLDelimGfm = edit(emStrongLDelimCore, "u").replace(/punct/g, _punctuationGfmStrongEm).getRegex();
|
|
19561
|
+
var emStrongRDelimAstCore = "^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)";
|
|
19562
|
+
var emStrongRDelimAst = edit(emStrongRDelimAstCore, "gu").replace(/notPunctSpace/g, _notPunctuationOrSpace).replace(/punctSpace/g, _punctuationOrSpace).replace(/punct/g, _punctuation).getRegex();
|
|
19563
|
+
var emStrongRDelimAstGfm = edit(emStrongRDelimAstCore, "gu").replace(/notPunctSpace/g, _notPunctuationOrSpaceGfmStrongEm).replace(/punctSpace/g, _punctuationOrSpaceGfmStrongEm).replace(/punct/g, _punctuationGfmStrongEm).getRegex();
|
|
19564
|
+
var emStrongRDelimUnd = edit(
|
|
19565
|
+
"^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)",
|
|
19566
|
+
"gu"
|
|
19567
|
+
).replace(/notPunctSpace/g, _notPunctuationOrSpace).replace(/punctSpace/g, _punctuationOrSpace).replace(/punct/g, _punctuation).getRegex();
|
|
19568
|
+
var anyPunctuation = edit(/\\(punct)/, "gu").replace(/punct/g, _punctuation).getRegex();
|
|
19569
|
+
var autolink$1 = edit(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme", /[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email", /[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex();
|
|
19570
|
+
var _inlineComment = edit(_comment).replace("(?:-->|$)", "-->").getRegex();
|
|
19571
|
+
var tag = edit(
|
|
19572
|
+
"^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>"
|
|
19573
|
+
).replace("comment", _inlineComment).replace("attribute", /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex();
|
|
19574
|
+
var _inlineLabel = /(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/;
|
|
19575
|
+
var link = edit(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label", _inlineLabel).replace("href", /<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title", /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex();
|
|
19576
|
+
var reflink = edit(/^!?\[(label)\]\[(ref)\]/).replace("label", _inlineLabel).replace("ref", _blockLabel).getRegex();
|
|
19577
|
+
var nolink = edit(/^!?\[(ref)\](?:\[\])?/).replace("ref", _blockLabel).getRegex();
|
|
19578
|
+
var reflinkSearch = edit("reflink|nolink(?!\\()", "g").replace("reflink", reflink).replace("nolink", nolink).getRegex();
|
|
19579
|
+
var inlineNormal = {
|
|
19580
|
+
_backpedal: noopTest,
|
|
19581
|
+
// only used for GFM url
|
|
19582
|
+
anyPunctuation,
|
|
19583
|
+
autolink: autolink$1,
|
|
19584
|
+
blockSkip,
|
|
19585
|
+
br,
|
|
19586
|
+
code: inlineCode,
|
|
19587
|
+
del: noopTest,
|
|
19588
|
+
emStrongLDelim,
|
|
19589
|
+
emStrongRDelimAst,
|
|
19590
|
+
emStrongRDelimUnd,
|
|
19591
|
+
escape,
|
|
19592
|
+
link,
|
|
19593
|
+
nolink,
|
|
19594
|
+
punctuation,
|
|
19595
|
+
reflink,
|
|
19596
|
+
reflinkSearch,
|
|
19597
|
+
tag,
|
|
19598
|
+
text: inlineText,
|
|
19599
|
+
url: noopTest
|
|
19600
|
+
};
|
|
19601
|
+
var inlinePedantic = {
|
|
19602
|
+
...inlineNormal,
|
|
19603
|
+
link: edit(/^!?\[(label)\]\((.*?)\)/).replace("label", _inlineLabel).getRegex(),
|
|
19604
|
+
reflink: edit(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label", _inlineLabel).getRegex()
|
|
19605
|
+
};
|
|
19606
|
+
var inlineGfm = {
|
|
19607
|
+
...inlineNormal,
|
|
19608
|
+
emStrongRDelimAst: emStrongRDelimAstGfm,
|
|
19609
|
+
emStrongLDelim: emStrongLDelimGfm,
|
|
19610
|
+
url: edit(/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/, "i").replace("email", /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),
|
|
19611
|
+
_backpedal: /(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,
|
|
19612
|
+
del: /^(~~?)(?=[^\s~])((?:\\.|[^\\])*?(?:\\.|[^\s~\\]))\1(?=[^~]|$)/,
|
|
19613
|
+
text: /^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/
|
|
19614
|
+
};
|
|
19615
|
+
var inlineBreaks = {
|
|
19616
|
+
...inlineGfm,
|
|
19617
|
+
br: edit(br).replace("{2,}", "*").getRegex(),
|
|
19618
|
+
text: edit(inlineGfm.text).replace("\\b_", "\\b_| {2,}\\n").replace(/\{2,\}/g, "*").getRegex()
|
|
19619
|
+
};
|
|
19620
|
+
var block = {
|
|
19621
|
+
normal: blockNormal,
|
|
19622
|
+
gfm: blockGfm,
|
|
19623
|
+
pedantic: blockPedantic
|
|
19624
|
+
};
|
|
19625
|
+
var inline = {
|
|
19626
|
+
normal: inlineNormal,
|
|
19627
|
+
gfm: inlineGfm,
|
|
19628
|
+
breaks: inlineBreaks,
|
|
19629
|
+
pedantic: inlinePedantic
|
|
19630
|
+
};
|
|
19631
|
+
|
|
19632
|
+
// src/helpers.ts
|
|
19633
|
+
var escapeReplacements = {
|
|
19634
|
+
"&": "&",
|
|
19635
|
+
"<": "<",
|
|
19636
|
+
">": ">",
|
|
19637
|
+
'"': """,
|
|
19638
|
+
"'": "'"
|
|
19639
|
+
};
|
|
19640
|
+
var getEscapeReplacement = (ch) => escapeReplacements[ch];
|
|
19641
|
+
function escape2(html2, encode) {
|
|
19642
|
+
if (encode) {
|
|
19643
|
+
if (other.escapeTest.test(html2)) {
|
|
19644
|
+
return html2.replace(other.escapeReplace, getEscapeReplacement);
|
|
19645
|
+
}
|
|
19646
|
+
} else {
|
|
19647
|
+
if (other.escapeTestNoEncode.test(html2)) {
|
|
19648
|
+
return html2.replace(other.escapeReplaceNoEncode, getEscapeReplacement);
|
|
19649
|
+
}
|
|
19650
|
+
}
|
|
19651
|
+
return html2;
|
|
19652
|
+
}
|
|
19653
|
+
function cleanUrl(href) {
|
|
19654
|
+
try {
|
|
19655
|
+
href = encodeURI(href).replace(other.percentDecode, "%");
|
|
19656
|
+
} catch {
|
|
19657
|
+
return null;
|
|
19658
|
+
}
|
|
19659
|
+
return href;
|
|
19660
|
+
}
|
|
19661
|
+
function splitCells(tableRow, count) {
|
|
19662
|
+
const row = tableRow.replace(other.findPipe, (match, offset, str) => {
|
|
19663
|
+
let escaped = false;
|
|
19664
|
+
let curr = offset;
|
|
19665
|
+
while (--curr >= 0 && str[curr] === "\\") escaped = !escaped;
|
|
19666
|
+
if (escaped) {
|
|
19667
|
+
return "|";
|
|
19668
|
+
} else {
|
|
19669
|
+
return " |";
|
|
19670
|
+
}
|
|
19671
|
+
}), cells = row.split(other.splitPipe);
|
|
19672
|
+
let i = 0;
|
|
19673
|
+
if (!cells[0].trim()) {
|
|
19674
|
+
cells.shift();
|
|
19675
|
+
}
|
|
19676
|
+
if (cells.length > 0 && !cells.at(-1)?.trim()) {
|
|
19677
|
+
cells.pop();
|
|
19678
|
+
}
|
|
19679
|
+
if (count) {
|
|
19680
|
+
if (cells.length > count) {
|
|
19681
|
+
cells.splice(count);
|
|
19682
|
+
} else {
|
|
19683
|
+
while (cells.length < count) cells.push("");
|
|
19684
|
+
}
|
|
19685
|
+
}
|
|
19686
|
+
for (; i < cells.length; i++) {
|
|
19687
|
+
cells[i] = cells[i].trim().replace(other.slashPipe, "|");
|
|
19688
|
+
}
|
|
19689
|
+
return cells;
|
|
19690
|
+
}
|
|
19691
|
+
function rtrim(str, c, invert) {
|
|
19692
|
+
const l = str.length;
|
|
19693
|
+
if (l === 0) {
|
|
19694
|
+
return "";
|
|
19695
|
+
}
|
|
19696
|
+
let suffLen = 0;
|
|
19697
|
+
while (suffLen < l) {
|
|
19698
|
+
const currChar = str.charAt(l - suffLen - 1);
|
|
19699
|
+
if (currChar === c && true) {
|
|
19700
|
+
suffLen++;
|
|
19701
|
+
} else {
|
|
19702
|
+
break;
|
|
19703
|
+
}
|
|
19704
|
+
}
|
|
19705
|
+
return str.slice(0, l - suffLen);
|
|
19706
|
+
}
|
|
19707
|
+
function findClosingBracket(str, b) {
|
|
19708
|
+
if (str.indexOf(b[1]) === -1) {
|
|
19709
|
+
return -1;
|
|
19710
|
+
}
|
|
19711
|
+
let level = 0;
|
|
19712
|
+
for (let i = 0; i < str.length; i++) {
|
|
19713
|
+
if (str[i] === "\\") {
|
|
19714
|
+
i++;
|
|
19715
|
+
} else if (str[i] === b[0]) {
|
|
19716
|
+
level++;
|
|
19717
|
+
} else if (str[i] === b[1]) {
|
|
19718
|
+
level--;
|
|
19719
|
+
if (level < 0) {
|
|
19720
|
+
return i;
|
|
19721
|
+
}
|
|
19722
|
+
}
|
|
19723
|
+
}
|
|
19724
|
+
if (level > 0) {
|
|
19725
|
+
return -2;
|
|
19726
|
+
}
|
|
19727
|
+
return -1;
|
|
19728
|
+
}
|
|
19729
|
+
|
|
19730
|
+
// src/Tokenizer.ts
|
|
19731
|
+
function outputLink(cap, link2, raw, lexer2, rules) {
|
|
19732
|
+
const href = link2.href;
|
|
19733
|
+
const title = link2.title || null;
|
|
19734
|
+
const text = cap[1].replace(rules.other.outputLinkReplace, "$1");
|
|
19735
|
+
lexer2.state.inLink = true;
|
|
19736
|
+
const token = {
|
|
19737
|
+
type: cap[0].charAt(0) === "!" ? "image" : "link",
|
|
19738
|
+
raw,
|
|
19739
|
+
href,
|
|
19740
|
+
title,
|
|
19741
|
+
text,
|
|
19742
|
+
tokens: lexer2.inlineTokens(text)
|
|
19743
|
+
};
|
|
19744
|
+
lexer2.state.inLink = false;
|
|
19745
|
+
return token;
|
|
19746
|
+
}
|
|
19747
|
+
function indentCodeCompensation(raw, text, rules) {
|
|
19748
|
+
const matchIndentToCode = raw.match(rules.other.indentCodeCompensation);
|
|
19749
|
+
if (matchIndentToCode === null) {
|
|
19750
|
+
return text;
|
|
19751
|
+
}
|
|
19752
|
+
const indentToCode = matchIndentToCode[1];
|
|
19753
|
+
return text.split("\n").map((node) => {
|
|
19754
|
+
const matchIndentInNode = node.match(rules.other.beginningSpace);
|
|
19755
|
+
if (matchIndentInNode === null) {
|
|
19756
|
+
return node;
|
|
19757
|
+
}
|
|
19758
|
+
const [indentInNode] = matchIndentInNode;
|
|
19759
|
+
if (indentInNode.length >= indentToCode.length) {
|
|
19760
|
+
return node.slice(indentToCode.length);
|
|
19761
|
+
}
|
|
19762
|
+
return node;
|
|
19763
|
+
}).join("\n");
|
|
19764
|
+
}
|
|
19765
|
+
var _Tokenizer = class {
|
|
19766
|
+
options;
|
|
19767
|
+
rules;
|
|
19768
|
+
// set by the lexer
|
|
19769
|
+
lexer;
|
|
19770
|
+
// set by the lexer
|
|
19771
|
+
constructor(options2) {
|
|
19772
|
+
this.options = options2 || _defaults;
|
|
19773
|
+
}
|
|
19774
|
+
space(src) {
|
|
19775
|
+
const cap = this.rules.block.newline.exec(src);
|
|
19776
|
+
if (cap && cap[0].length > 0) {
|
|
19777
|
+
return {
|
|
19778
|
+
type: "space",
|
|
19779
|
+
raw: cap[0]
|
|
19780
|
+
};
|
|
19781
|
+
}
|
|
19782
|
+
}
|
|
19783
|
+
code(src) {
|
|
19784
|
+
const cap = this.rules.block.code.exec(src);
|
|
19785
|
+
if (cap) {
|
|
19786
|
+
const text = cap[0].replace(this.rules.other.codeRemoveIndent, "");
|
|
19787
|
+
return {
|
|
19788
|
+
type: "code",
|
|
19789
|
+
raw: cap[0],
|
|
19790
|
+
codeBlockStyle: "indented",
|
|
19791
|
+
text: !this.options.pedantic ? rtrim(text, "\n") : text
|
|
19792
|
+
};
|
|
19793
|
+
}
|
|
19794
|
+
}
|
|
19795
|
+
fences(src) {
|
|
19796
|
+
const cap = this.rules.block.fences.exec(src);
|
|
19797
|
+
if (cap) {
|
|
19798
|
+
const raw = cap[0];
|
|
19799
|
+
const text = indentCodeCompensation(raw, cap[3] || "", this.rules);
|
|
19800
|
+
return {
|
|
19801
|
+
type: "code",
|
|
19802
|
+
raw,
|
|
19803
|
+
lang: cap[2] ? cap[2].trim().replace(this.rules.inline.anyPunctuation, "$1") : cap[2],
|
|
19804
|
+
text
|
|
19805
|
+
};
|
|
19806
|
+
}
|
|
19807
|
+
}
|
|
19808
|
+
heading(src) {
|
|
19809
|
+
const cap = this.rules.block.heading.exec(src);
|
|
19810
|
+
if (cap) {
|
|
19811
|
+
let text = cap[2].trim();
|
|
19812
|
+
if (this.rules.other.endingHash.test(text)) {
|
|
19813
|
+
const trimmed = rtrim(text, "#");
|
|
19814
|
+
if (this.options.pedantic) {
|
|
19815
|
+
text = trimmed.trim();
|
|
19816
|
+
} else if (!trimmed || this.rules.other.endingSpaceChar.test(trimmed)) {
|
|
19817
|
+
text = trimmed.trim();
|
|
19818
|
+
}
|
|
19819
|
+
}
|
|
19820
|
+
return {
|
|
19821
|
+
type: "heading",
|
|
19822
|
+
raw: cap[0],
|
|
19823
|
+
depth: cap[1].length,
|
|
19824
|
+
text,
|
|
19825
|
+
tokens: this.lexer.inline(text)
|
|
19826
|
+
};
|
|
19827
|
+
}
|
|
19828
|
+
}
|
|
19829
|
+
hr(src) {
|
|
19830
|
+
const cap = this.rules.block.hr.exec(src);
|
|
19831
|
+
if (cap) {
|
|
19832
|
+
return {
|
|
19833
|
+
type: "hr",
|
|
19834
|
+
raw: rtrim(cap[0], "\n")
|
|
19835
|
+
};
|
|
19836
|
+
}
|
|
19837
|
+
}
|
|
19838
|
+
blockquote(src) {
|
|
19839
|
+
const cap = this.rules.block.blockquote.exec(src);
|
|
19840
|
+
if (cap) {
|
|
19841
|
+
let lines = rtrim(cap[0], "\n").split("\n");
|
|
19842
|
+
let raw = "";
|
|
19843
|
+
let text = "";
|
|
19844
|
+
const tokens = [];
|
|
19845
|
+
while (lines.length > 0) {
|
|
19846
|
+
let inBlockquote = false;
|
|
19847
|
+
const currentLines = [];
|
|
19848
|
+
let i;
|
|
19849
|
+
for (i = 0; i < lines.length; i++) {
|
|
19850
|
+
if (this.rules.other.blockquoteStart.test(lines[i])) {
|
|
19851
|
+
currentLines.push(lines[i]);
|
|
19852
|
+
inBlockquote = true;
|
|
19853
|
+
} else if (!inBlockquote) {
|
|
19854
|
+
currentLines.push(lines[i]);
|
|
19855
|
+
} else {
|
|
19856
|
+
break;
|
|
19857
|
+
}
|
|
19858
|
+
}
|
|
19859
|
+
lines = lines.slice(i);
|
|
19860
|
+
const currentRaw = currentLines.join("\n");
|
|
19861
|
+
const currentText = currentRaw.replace(this.rules.other.blockquoteSetextReplace, "\n $1").replace(this.rules.other.blockquoteSetextReplace2, "");
|
|
19862
|
+
raw = raw ? `${raw}
|
|
19863
|
+
${currentRaw}` : currentRaw;
|
|
19864
|
+
text = text ? `${text}
|
|
19865
|
+
${currentText}` : currentText;
|
|
19866
|
+
const top = this.lexer.state.top;
|
|
19867
|
+
this.lexer.state.top = true;
|
|
19868
|
+
this.lexer.blockTokens(currentText, tokens, true);
|
|
19869
|
+
this.lexer.state.top = top;
|
|
19870
|
+
if (lines.length === 0) {
|
|
19871
|
+
break;
|
|
19872
|
+
}
|
|
19873
|
+
const lastToken = tokens.at(-1);
|
|
19874
|
+
if (lastToken?.type === "code") {
|
|
19875
|
+
break;
|
|
19876
|
+
} else if (lastToken?.type === "blockquote") {
|
|
19877
|
+
const oldToken = lastToken;
|
|
19878
|
+
const newText = oldToken.raw + "\n" + lines.join("\n");
|
|
19879
|
+
const newToken = this.blockquote(newText);
|
|
19880
|
+
tokens[tokens.length - 1] = newToken;
|
|
19881
|
+
raw = raw.substring(0, raw.length - oldToken.raw.length) + newToken.raw;
|
|
19882
|
+
text = text.substring(0, text.length - oldToken.text.length) + newToken.text;
|
|
19883
|
+
break;
|
|
19884
|
+
} else if (lastToken?.type === "list") {
|
|
19885
|
+
const oldToken = lastToken;
|
|
19886
|
+
const newText = oldToken.raw + "\n" + lines.join("\n");
|
|
19887
|
+
const newToken = this.list(newText);
|
|
19888
|
+
tokens[tokens.length - 1] = newToken;
|
|
19889
|
+
raw = raw.substring(0, raw.length - lastToken.raw.length) + newToken.raw;
|
|
19890
|
+
text = text.substring(0, text.length - oldToken.raw.length) + newToken.raw;
|
|
19891
|
+
lines = newText.substring(tokens.at(-1).raw.length).split("\n");
|
|
19892
|
+
continue;
|
|
19893
|
+
}
|
|
19894
|
+
}
|
|
19895
|
+
return {
|
|
19896
|
+
type: "blockquote",
|
|
19897
|
+
raw,
|
|
19898
|
+
tokens,
|
|
19899
|
+
text
|
|
19900
|
+
};
|
|
19901
|
+
}
|
|
19902
|
+
}
|
|
19903
|
+
list(src) {
|
|
19904
|
+
let cap = this.rules.block.list.exec(src);
|
|
19905
|
+
if (cap) {
|
|
19906
|
+
let bull = cap[1].trim();
|
|
19907
|
+
const isordered = bull.length > 1;
|
|
19908
|
+
const list2 = {
|
|
19909
|
+
type: "list",
|
|
19910
|
+
raw: "",
|
|
19911
|
+
ordered: isordered,
|
|
19912
|
+
start: isordered ? +bull.slice(0, -1) : "",
|
|
19913
|
+
loose: false,
|
|
19914
|
+
items: []
|
|
19915
|
+
};
|
|
19916
|
+
bull = isordered ? `\\d{1,9}\\${bull.slice(-1)}` : `\\${bull}`;
|
|
19917
|
+
if (this.options.pedantic) {
|
|
19918
|
+
bull = isordered ? bull : "[*+-]";
|
|
19919
|
+
}
|
|
19920
|
+
const itemRegex = this.rules.other.listItemRegex(bull);
|
|
19921
|
+
let endsWithBlankLine = false;
|
|
19922
|
+
while (src) {
|
|
19923
|
+
let endEarly = false;
|
|
19924
|
+
let raw = "";
|
|
19925
|
+
let itemContents = "";
|
|
19926
|
+
if (!(cap = itemRegex.exec(src))) {
|
|
19927
|
+
break;
|
|
19928
|
+
}
|
|
19929
|
+
if (this.rules.block.hr.test(src)) {
|
|
19930
|
+
break;
|
|
19931
|
+
}
|
|
19932
|
+
raw = cap[0];
|
|
19933
|
+
src = src.substring(raw.length);
|
|
19934
|
+
let line = cap[2].split("\n", 1)[0].replace(this.rules.other.listReplaceTabs, (t) => " ".repeat(3 * t.length));
|
|
19935
|
+
let nextLine = src.split("\n", 1)[0];
|
|
19936
|
+
let blankLine = !line.trim();
|
|
19937
|
+
let indent = 0;
|
|
19938
|
+
if (this.options.pedantic) {
|
|
19939
|
+
indent = 2;
|
|
19940
|
+
itemContents = line.trimStart();
|
|
19941
|
+
} else if (blankLine) {
|
|
19942
|
+
indent = cap[1].length + 1;
|
|
19943
|
+
} else {
|
|
19944
|
+
indent = cap[2].search(this.rules.other.nonSpaceChar);
|
|
19945
|
+
indent = indent > 4 ? 1 : indent;
|
|
19946
|
+
itemContents = line.slice(indent);
|
|
19947
|
+
indent += cap[1].length;
|
|
19948
|
+
}
|
|
19949
|
+
if (blankLine && this.rules.other.blankLine.test(nextLine)) {
|
|
19950
|
+
raw += nextLine + "\n";
|
|
19951
|
+
src = src.substring(nextLine.length + 1);
|
|
19952
|
+
endEarly = true;
|
|
19953
|
+
}
|
|
19954
|
+
if (!endEarly) {
|
|
19955
|
+
const nextBulletRegex = this.rules.other.nextBulletRegex(indent);
|
|
19956
|
+
const hrRegex = this.rules.other.hrRegex(indent);
|
|
19957
|
+
const fencesBeginRegex = this.rules.other.fencesBeginRegex(indent);
|
|
19958
|
+
const headingBeginRegex = this.rules.other.headingBeginRegex(indent);
|
|
19959
|
+
const htmlBeginRegex = this.rules.other.htmlBeginRegex(indent);
|
|
19960
|
+
while (src) {
|
|
19961
|
+
const rawLine = src.split("\n", 1)[0];
|
|
19962
|
+
let nextLineWithoutTabs;
|
|
19963
|
+
nextLine = rawLine;
|
|
19964
|
+
if (this.options.pedantic) {
|
|
19965
|
+
nextLine = nextLine.replace(this.rules.other.listReplaceNesting, " ");
|
|
19966
|
+
nextLineWithoutTabs = nextLine;
|
|
19967
|
+
} else {
|
|
19968
|
+
nextLineWithoutTabs = nextLine.replace(this.rules.other.tabCharGlobal, " ");
|
|
19969
|
+
}
|
|
19970
|
+
if (fencesBeginRegex.test(nextLine)) {
|
|
19971
|
+
break;
|
|
19972
|
+
}
|
|
19973
|
+
if (headingBeginRegex.test(nextLine)) {
|
|
19974
|
+
break;
|
|
19975
|
+
}
|
|
19976
|
+
if (htmlBeginRegex.test(nextLine)) {
|
|
19977
|
+
break;
|
|
19978
|
+
}
|
|
19979
|
+
if (nextBulletRegex.test(nextLine)) {
|
|
19980
|
+
break;
|
|
19981
|
+
}
|
|
19982
|
+
if (hrRegex.test(nextLine)) {
|
|
19983
|
+
break;
|
|
19984
|
+
}
|
|
19985
|
+
if (nextLineWithoutTabs.search(this.rules.other.nonSpaceChar) >= indent || !nextLine.trim()) {
|
|
19986
|
+
itemContents += "\n" + nextLineWithoutTabs.slice(indent);
|
|
19987
|
+
} else {
|
|
19988
|
+
if (blankLine) {
|
|
19989
|
+
break;
|
|
19990
|
+
}
|
|
19991
|
+
if (line.replace(this.rules.other.tabCharGlobal, " ").search(this.rules.other.nonSpaceChar) >= 4) {
|
|
19992
|
+
break;
|
|
19993
|
+
}
|
|
19994
|
+
if (fencesBeginRegex.test(line)) {
|
|
19995
|
+
break;
|
|
19996
|
+
}
|
|
19997
|
+
if (headingBeginRegex.test(line)) {
|
|
19998
|
+
break;
|
|
19999
|
+
}
|
|
20000
|
+
if (hrRegex.test(line)) {
|
|
20001
|
+
break;
|
|
20002
|
+
}
|
|
20003
|
+
itemContents += "\n" + nextLine;
|
|
20004
|
+
}
|
|
20005
|
+
if (!blankLine && !nextLine.trim()) {
|
|
20006
|
+
blankLine = true;
|
|
20007
|
+
}
|
|
20008
|
+
raw += rawLine + "\n";
|
|
20009
|
+
src = src.substring(rawLine.length + 1);
|
|
20010
|
+
line = nextLineWithoutTabs.slice(indent);
|
|
20011
|
+
}
|
|
20012
|
+
}
|
|
20013
|
+
if (!list2.loose) {
|
|
20014
|
+
if (endsWithBlankLine) {
|
|
20015
|
+
list2.loose = true;
|
|
20016
|
+
} else if (this.rules.other.doubleBlankLine.test(raw)) {
|
|
20017
|
+
endsWithBlankLine = true;
|
|
20018
|
+
}
|
|
20019
|
+
}
|
|
20020
|
+
let istask = null;
|
|
20021
|
+
let ischecked;
|
|
20022
|
+
if (this.options.gfm) {
|
|
20023
|
+
istask = this.rules.other.listIsTask.exec(itemContents);
|
|
20024
|
+
if (istask) {
|
|
20025
|
+
ischecked = istask[0] !== "[ ] ";
|
|
20026
|
+
itemContents = itemContents.replace(this.rules.other.listReplaceTask, "");
|
|
20027
|
+
}
|
|
20028
|
+
}
|
|
20029
|
+
list2.items.push({
|
|
20030
|
+
type: "list_item",
|
|
20031
|
+
raw,
|
|
20032
|
+
task: !!istask,
|
|
20033
|
+
checked: ischecked,
|
|
20034
|
+
loose: false,
|
|
20035
|
+
text: itemContents,
|
|
20036
|
+
tokens: []
|
|
20037
|
+
});
|
|
20038
|
+
list2.raw += raw;
|
|
20039
|
+
}
|
|
20040
|
+
const lastItem = list2.items.at(-1);
|
|
20041
|
+
if (lastItem) {
|
|
20042
|
+
lastItem.raw = lastItem.raw.trimEnd();
|
|
20043
|
+
lastItem.text = lastItem.text.trimEnd();
|
|
20044
|
+
} else {
|
|
20045
|
+
return;
|
|
20046
|
+
}
|
|
20047
|
+
list2.raw = list2.raw.trimEnd();
|
|
20048
|
+
for (let i = 0; i < list2.items.length; i++) {
|
|
20049
|
+
this.lexer.state.top = false;
|
|
20050
|
+
list2.items[i].tokens = this.lexer.blockTokens(list2.items[i].text, []);
|
|
20051
|
+
if (!list2.loose) {
|
|
20052
|
+
const spacers = list2.items[i].tokens.filter((t) => t.type === "space");
|
|
20053
|
+
const hasMultipleLineBreaks = spacers.length > 0 && spacers.some((t) => this.rules.other.anyLine.test(t.raw));
|
|
20054
|
+
list2.loose = hasMultipleLineBreaks;
|
|
20055
|
+
}
|
|
20056
|
+
}
|
|
20057
|
+
if (list2.loose) {
|
|
20058
|
+
for (let i = 0; i < list2.items.length; i++) {
|
|
20059
|
+
list2.items[i].loose = true;
|
|
20060
|
+
}
|
|
20061
|
+
}
|
|
20062
|
+
return list2;
|
|
20063
|
+
}
|
|
20064
|
+
}
|
|
20065
|
+
html(src) {
|
|
20066
|
+
const cap = this.rules.block.html.exec(src);
|
|
20067
|
+
if (cap) {
|
|
20068
|
+
const token = {
|
|
20069
|
+
type: "html",
|
|
20070
|
+
block: true,
|
|
20071
|
+
raw: cap[0],
|
|
20072
|
+
pre: cap[1] === "pre" || cap[1] === "script" || cap[1] === "style",
|
|
20073
|
+
text: cap[0]
|
|
20074
|
+
};
|
|
20075
|
+
return token;
|
|
20076
|
+
}
|
|
20077
|
+
}
|
|
20078
|
+
def(src) {
|
|
20079
|
+
const cap = this.rules.block.def.exec(src);
|
|
20080
|
+
if (cap) {
|
|
20081
|
+
const tag2 = cap[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal, " ");
|
|
20082
|
+
const href = cap[2] ? cap[2].replace(this.rules.other.hrefBrackets, "$1").replace(this.rules.inline.anyPunctuation, "$1") : "";
|
|
20083
|
+
const title = cap[3] ? cap[3].substring(1, cap[3].length - 1).replace(this.rules.inline.anyPunctuation, "$1") : cap[3];
|
|
20084
|
+
return {
|
|
20085
|
+
type: "def",
|
|
20086
|
+
tag: tag2,
|
|
20087
|
+
raw: cap[0],
|
|
20088
|
+
href,
|
|
20089
|
+
title
|
|
20090
|
+
};
|
|
20091
|
+
}
|
|
20092
|
+
}
|
|
20093
|
+
table(src) {
|
|
20094
|
+
const cap = this.rules.block.table.exec(src);
|
|
20095
|
+
if (!cap) {
|
|
20096
|
+
return;
|
|
20097
|
+
}
|
|
20098
|
+
if (!this.rules.other.tableDelimiter.test(cap[2])) {
|
|
20099
|
+
return;
|
|
20100
|
+
}
|
|
20101
|
+
const headers = splitCells(cap[1]);
|
|
20102
|
+
const aligns = cap[2].replace(this.rules.other.tableAlignChars, "").split("|");
|
|
20103
|
+
const rows = cap[3]?.trim() ? cap[3].replace(this.rules.other.tableRowBlankLine, "").split("\n") : [];
|
|
20104
|
+
const item = {
|
|
20105
|
+
type: "table",
|
|
20106
|
+
raw: cap[0],
|
|
20107
|
+
header: [],
|
|
20108
|
+
align: [],
|
|
20109
|
+
rows: []
|
|
20110
|
+
};
|
|
20111
|
+
if (headers.length !== aligns.length) {
|
|
20112
|
+
return;
|
|
20113
|
+
}
|
|
20114
|
+
for (const align of aligns) {
|
|
20115
|
+
if (this.rules.other.tableAlignRight.test(align)) {
|
|
20116
|
+
item.align.push("right");
|
|
20117
|
+
} else if (this.rules.other.tableAlignCenter.test(align)) {
|
|
20118
|
+
item.align.push("center");
|
|
20119
|
+
} else if (this.rules.other.tableAlignLeft.test(align)) {
|
|
20120
|
+
item.align.push("left");
|
|
20121
|
+
} else {
|
|
20122
|
+
item.align.push(null);
|
|
20123
|
+
}
|
|
20124
|
+
}
|
|
20125
|
+
for (let i = 0; i < headers.length; i++) {
|
|
20126
|
+
item.header.push({
|
|
20127
|
+
text: headers[i],
|
|
20128
|
+
tokens: this.lexer.inline(headers[i]),
|
|
20129
|
+
header: true,
|
|
20130
|
+
align: item.align[i]
|
|
20131
|
+
});
|
|
20132
|
+
}
|
|
20133
|
+
for (const row of rows) {
|
|
20134
|
+
item.rows.push(splitCells(row, item.header.length).map((cell, i) => {
|
|
20135
|
+
return {
|
|
20136
|
+
text: cell,
|
|
20137
|
+
tokens: this.lexer.inline(cell),
|
|
20138
|
+
header: false,
|
|
20139
|
+
align: item.align[i]
|
|
20140
|
+
};
|
|
20141
|
+
}));
|
|
20142
|
+
}
|
|
20143
|
+
return item;
|
|
20144
|
+
}
|
|
20145
|
+
lheading(src) {
|
|
20146
|
+
const cap = this.rules.block.lheading.exec(src);
|
|
20147
|
+
if (cap) {
|
|
20148
|
+
return {
|
|
20149
|
+
type: "heading",
|
|
20150
|
+
raw: cap[0],
|
|
20151
|
+
depth: cap[2].charAt(0) === "=" ? 1 : 2,
|
|
20152
|
+
text: cap[1],
|
|
20153
|
+
tokens: this.lexer.inline(cap[1])
|
|
20154
|
+
};
|
|
20155
|
+
}
|
|
20156
|
+
}
|
|
20157
|
+
paragraph(src) {
|
|
20158
|
+
const cap = this.rules.block.paragraph.exec(src);
|
|
20159
|
+
if (cap) {
|
|
20160
|
+
const text = cap[1].charAt(cap[1].length - 1) === "\n" ? cap[1].slice(0, -1) : cap[1];
|
|
20161
|
+
return {
|
|
20162
|
+
type: "paragraph",
|
|
20163
|
+
raw: cap[0],
|
|
20164
|
+
text,
|
|
20165
|
+
tokens: this.lexer.inline(text)
|
|
20166
|
+
};
|
|
20167
|
+
}
|
|
20168
|
+
}
|
|
20169
|
+
text(src) {
|
|
20170
|
+
const cap = this.rules.block.text.exec(src);
|
|
20171
|
+
if (cap) {
|
|
20172
|
+
return {
|
|
20173
|
+
type: "text",
|
|
20174
|
+
raw: cap[0],
|
|
20175
|
+
text: cap[0],
|
|
20176
|
+
tokens: this.lexer.inline(cap[0])
|
|
20177
|
+
};
|
|
20178
|
+
}
|
|
20179
|
+
}
|
|
20180
|
+
escape(src) {
|
|
20181
|
+
const cap = this.rules.inline.escape.exec(src);
|
|
20182
|
+
if (cap) {
|
|
20183
|
+
return {
|
|
20184
|
+
type: "escape",
|
|
20185
|
+
raw: cap[0],
|
|
20186
|
+
text: cap[1]
|
|
20187
|
+
};
|
|
20188
|
+
}
|
|
20189
|
+
}
|
|
20190
|
+
tag(src) {
|
|
20191
|
+
const cap = this.rules.inline.tag.exec(src);
|
|
20192
|
+
if (cap) {
|
|
20193
|
+
if (!this.lexer.state.inLink && this.rules.other.startATag.test(cap[0])) {
|
|
20194
|
+
this.lexer.state.inLink = true;
|
|
20195
|
+
} else if (this.lexer.state.inLink && this.rules.other.endATag.test(cap[0])) {
|
|
20196
|
+
this.lexer.state.inLink = false;
|
|
20197
|
+
}
|
|
20198
|
+
if (!this.lexer.state.inRawBlock && this.rules.other.startPreScriptTag.test(cap[0])) {
|
|
20199
|
+
this.lexer.state.inRawBlock = true;
|
|
20200
|
+
} else if (this.lexer.state.inRawBlock && this.rules.other.endPreScriptTag.test(cap[0])) {
|
|
20201
|
+
this.lexer.state.inRawBlock = false;
|
|
20202
|
+
}
|
|
20203
|
+
return {
|
|
20204
|
+
type: "html",
|
|
20205
|
+
raw: cap[0],
|
|
20206
|
+
inLink: this.lexer.state.inLink,
|
|
20207
|
+
inRawBlock: this.lexer.state.inRawBlock,
|
|
20208
|
+
block: false,
|
|
20209
|
+
text: cap[0]
|
|
20210
|
+
};
|
|
20211
|
+
}
|
|
20212
|
+
}
|
|
20213
|
+
link(src) {
|
|
20214
|
+
const cap = this.rules.inline.link.exec(src);
|
|
20215
|
+
if (cap) {
|
|
20216
|
+
const trimmedUrl = cap[2].trim();
|
|
20217
|
+
if (!this.options.pedantic && this.rules.other.startAngleBracket.test(trimmedUrl)) {
|
|
20218
|
+
if (!this.rules.other.endAngleBracket.test(trimmedUrl)) {
|
|
20219
|
+
return;
|
|
20220
|
+
}
|
|
20221
|
+
const rtrimSlash = rtrim(trimmedUrl.slice(0, -1), "\\");
|
|
20222
|
+
if ((trimmedUrl.length - rtrimSlash.length) % 2 === 0) {
|
|
20223
|
+
return;
|
|
20224
|
+
}
|
|
20225
|
+
} else {
|
|
20226
|
+
const lastParenIndex = findClosingBracket(cap[2], "()");
|
|
20227
|
+
if (lastParenIndex === -2) {
|
|
20228
|
+
return;
|
|
20229
|
+
}
|
|
20230
|
+
if (lastParenIndex > -1) {
|
|
20231
|
+
const start = cap[0].indexOf("!") === 0 ? 5 : 4;
|
|
20232
|
+
const linkLen = start + cap[1].length + lastParenIndex;
|
|
20233
|
+
cap[2] = cap[2].substring(0, lastParenIndex);
|
|
20234
|
+
cap[0] = cap[0].substring(0, linkLen).trim();
|
|
20235
|
+
cap[3] = "";
|
|
20236
|
+
}
|
|
20237
|
+
}
|
|
20238
|
+
let href = cap[2];
|
|
20239
|
+
let title = "";
|
|
20240
|
+
if (this.options.pedantic) {
|
|
20241
|
+
const link2 = this.rules.other.pedanticHrefTitle.exec(href);
|
|
20242
|
+
if (link2) {
|
|
20243
|
+
href = link2[1];
|
|
20244
|
+
title = link2[3];
|
|
20245
|
+
}
|
|
20246
|
+
} else {
|
|
20247
|
+
title = cap[3] ? cap[3].slice(1, -1) : "";
|
|
20248
|
+
}
|
|
20249
|
+
href = href.trim();
|
|
20250
|
+
if (this.rules.other.startAngleBracket.test(href)) {
|
|
20251
|
+
if (this.options.pedantic && !this.rules.other.endAngleBracket.test(trimmedUrl)) {
|
|
20252
|
+
href = href.slice(1);
|
|
20253
|
+
} else {
|
|
20254
|
+
href = href.slice(1, -1);
|
|
20255
|
+
}
|
|
20256
|
+
}
|
|
20257
|
+
return outputLink(cap, {
|
|
20258
|
+
href: href ? href.replace(this.rules.inline.anyPunctuation, "$1") : href,
|
|
20259
|
+
title: title ? title.replace(this.rules.inline.anyPunctuation, "$1") : title
|
|
20260
|
+
}, cap[0], this.lexer, this.rules);
|
|
20261
|
+
}
|
|
20262
|
+
}
|
|
20263
|
+
reflink(src, links) {
|
|
20264
|
+
let cap;
|
|
20265
|
+
if ((cap = this.rules.inline.reflink.exec(src)) || (cap = this.rules.inline.nolink.exec(src))) {
|
|
20266
|
+
const linkString = (cap[2] || cap[1]).replace(this.rules.other.multipleSpaceGlobal, " ");
|
|
20267
|
+
const link2 = links[linkString.toLowerCase()];
|
|
20268
|
+
if (!link2) {
|
|
20269
|
+
const text = cap[0].charAt(0);
|
|
20270
|
+
return {
|
|
20271
|
+
type: "text",
|
|
20272
|
+
raw: text,
|
|
20273
|
+
text
|
|
20274
|
+
};
|
|
20275
|
+
}
|
|
20276
|
+
return outputLink(cap, link2, cap[0], this.lexer, this.rules);
|
|
20277
|
+
}
|
|
20278
|
+
}
|
|
20279
|
+
emStrong(src, maskedSrc, prevChar = "") {
|
|
20280
|
+
let match = this.rules.inline.emStrongLDelim.exec(src);
|
|
20281
|
+
if (!match) return;
|
|
20282
|
+
if (match[3] && prevChar.match(this.rules.other.unicodeAlphaNumeric)) return;
|
|
20283
|
+
const nextChar = match[1] || match[2] || "";
|
|
20284
|
+
if (!nextChar || !prevChar || this.rules.inline.punctuation.exec(prevChar)) {
|
|
20285
|
+
const lLength = [...match[0]].length - 1;
|
|
20286
|
+
let rDelim, rLength, delimTotal = lLength, midDelimTotal = 0;
|
|
20287
|
+
const endReg = match[0][0] === "*" ? this.rules.inline.emStrongRDelimAst : this.rules.inline.emStrongRDelimUnd;
|
|
20288
|
+
endReg.lastIndex = 0;
|
|
20289
|
+
maskedSrc = maskedSrc.slice(-1 * src.length + lLength);
|
|
20290
|
+
while ((match = endReg.exec(maskedSrc)) != null) {
|
|
20291
|
+
rDelim = match[1] || match[2] || match[3] || match[4] || match[5] || match[6];
|
|
20292
|
+
if (!rDelim) continue;
|
|
20293
|
+
rLength = [...rDelim].length;
|
|
20294
|
+
if (match[3] || match[4]) {
|
|
20295
|
+
delimTotal += rLength;
|
|
20296
|
+
continue;
|
|
20297
|
+
} else if (match[5] || match[6]) {
|
|
20298
|
+
if (lLength % 3 && !((lLength + rLength) % 3)) {
|
|
20299
|
+
midDelimTotal += rLength;
|
|
20300
|
+
continue;
|
|
20301
|
+
}
|
|
20302
|
+
}
|
|
20303
|
+
delimTotal -= rLength;
|
|
20304
|
+
if (delimTotal > 0) continue;
|
|
20305
|
+
rLength = Math.min(rLength, rLength + delimTotal + midDelimTotal);
|
|
20306
|
+
const lastCharLength = [...match[0]][0].length;
|
|
20307
|
+
const raw = src.slice(0, lLength + match.index + lastCharLength + rLength);
|
|
20308
|
+
if (Math.min(lLength, rLength) % 2) {
|
|
20309
|
+
const text2 = raw.slice(1, -1);
|
|
20310
|
+
return {
|
|
20311
|
+
type: "em",
|
|
20312
|
+
raw,
|
|
20313
|
+
text: text2,
|
|
20314
|
+
tokens: this.lexer.inlineTokens(text2)
|
|
20315
|
+
};
|
|
20316
|
+
}
|
|
20317
|
+
const text = raw.slice(2, -2);
|
|
20318
|
+
return {
|
|
20319
|
+
type: "strong",
|
|
20320
|
+
raw,
|
|
20321
|
+
text,
|
|
20322
|
+
tokens: this.lexer.inlineTokens(text)
|
|
20323
|
+
};
|
|
20324
|
+
}
|
|
20325
|
+
}
|
|
20326
|
+
}
|
|
20327
|
+
codespan(src) {
|
|
20328
|
+
const cap = this.rules.inline.code.exec(src);
|
|
20329
|
+
if (cap) {
|
|
20330
|
+
let text = cap[2].replace(this.rules.other.newLineCharGlobal, " ");
|
|
20331
|
+
const hasNonSpaceChars = this.rules.other.nonSpaceChar.test(text);
|
|
20332
|
+
const hasSpaceCharsOnBothEnds = this.rules.other.startingSpaceChar.test(text) && this.rules.other.endingSpaceChar.test(text);
|
|
20333
|
+
if (hasNonSpaceChars && hasSpaceCharsOnBothEnds) {
|
|
20334
|
+
text = text.substring(1, text.length - 1);
|
|
20335
|
+
}
|
|
20336
|
+
return {
|
|
20337
|
+
type: "codespan",
|
|
20338
|
+
raw: cap[0],
|
|
20339
|
+
text
|
|
20340
|
+
};
|
|
20341
|
+
}
|
|
20342
|
+
}
|
|
20343
|
+
br(src) {
|
|
20344
|
+
const cap = this.rules.inline.br.exec(src);
|
|
20345
|
+
if (cap) {
|
|
20346
|
+
return {
|
|
20347
|
+
type: "br",
|
|
20348
|
+
raw: cap[0]
|
|
20349
|
+
};
|
|
20350
|
+
}
|
|
20351
|
+
}
|
|
20352
|
+
del(src) {
|
|
20353
|
+
const cap = this.rules.inline.del.exec(src);
|
|
20354
|
+
if (cap) {
|
|
20355
|
+
return {
|
|
20356
|
+
type: "del",
|
|
20357
|
+
raw: cap[0],
|
|
20358
|
+
text: cap[2],
|
|
20359
|
+
tokens: this.lexer.inlineTokens(cap[2])
|
|
20360
|
+
};
|
|
20361
|
+
}
|
|
20362
|
+
}
|
|
20363
|
+
autolink(src) {
|
|
20364
|
+
const cap = this.rules.inline.autolink.exec(src);
|
|
20365
|
+
if (cap) {
|
|
20366
|
+
let text, href;
|
|
20367
|
+
if (cap[2] === "@") {
|
|
20368
|
+
text = cap[1];
|
|
20369
|
+
href = "mailto:" + text;
|
|
20370
|
+
} else {
|
|
20371
|
+
text = cap[1];
|
|
20372
|
+
href = text;
|
|
20373
|
+
}
|
|
20374
|
+
return {
|
|
20375
|
+
type: "link",
|
|
20376
|
+
raw: cap[0],
|
|
20377
|
+
text,
|
|
20378
|
+
href,
|
|
20379
|
+
tokens: [
|
|
20380
|
+
{
|
|
20381
|
+
type: "text",
|
|
20382
|
+
raw: text,
|
|
20383
|
+
text
|
|
20384
|
+
}
|
|
20385
|
+
]
|
|
20386
|
+
};
|
|
20387
|
+
}
|
|
20388
|
+
}
|
|
20389
|
+
url(src) {
|
|
20390
|
+
let cap;
|
|
20391
|
+
if (cap = this.rules.inline.url.exec(src)) {
|
|
20392
|
+
let text, href;
|
|
20393
|
+
if (cap[2] === "@") {
|
|
20394
|
+
text = cap[0];
|
|
20395
|
+
href = "mailto:" + text;
|
|
20396
|
+
} else {
|
|
20397
|
+
let prevCapZero;
|
|
20398
|
+
do {
|
|
20399
|
+
prevCapZero = cap[0];
|
|
20400
|
+
cap[0] = this.rules.inline._backpedal.exec(cap[0])?.[0] ?? "";
|
|
20401
|
+
} while (prevCapZero !== cap[0]);
|
|
20402
|
+
text = cap[0];
|
|
20403
|
+
if (cap[1] === "www.") {
|
|
20404
|
+
href = "http://" + cap[0];
|
|
20405
|
+
} else {
|
|
20406
|
+
href = cap[0];
|
|
20407
|
+
}
|
|
20408
|
+
}
|
|
20409
|
+
return {
|
|
20410
|
+
type: "link",
|
|
20411
|
+
raw: cap[0],
|
|
20412
|
+
text,
|
|
20413
|
+
href,
|
|
20414
|
+
tokens: [
|
|
20415
|
+
{
|
|
20416
|
+
type: "text",
|
|
20417
|
+
raw: text,
|
|
20418
|
+
text
|
|
20419
|
+
}
|
|
20420
|
+
]
|
|
20421
|
+
};
|
|
20422
|
+
}
|
|
20423
|
+
}
|
|
20424
|
+
inlineText(src) {
|
|
20425
|
+
const cap = this.rules.inline.text.exec(src);
|
|
20426
|
+
if (cap) {
|
|
20427
|
+
const escaped = this.lexer.state.inRawBlock;
|
|
20428
|
+
return {
|
|
20429
|
+
type: "text",
|
|
20430
|
+
raw: cap[0],
|
|
20431
|
+
text: cap[0],
|
|
20432
|
+
escaped
|
|
20433
|
+
};
|
|
20434
|
+
}
|
|
20435
|
+
}
|
|
20436
|
+
};
|
|
20437
|
+
|
|
20438
|
+
// src/Lexer.ts
|
|
20439
|
+
var _Lexer = class __Lexer {
|
|
20440
|
+
tokens;
|
|
20441
|
+
options;
|
|
20442
|
+
state;
|
|
20443
|
+
tokenizer;
|
|
20444
|
+
inlineQueue;
|
|
20445
|
+
constructor(options2) {
|
|
20446
|
+
this.tokens = [];
|
|
20447
|
+
this.tokens.links = /* @__PURE__ */ Object.create(null);
|
|
20448
|
+
this.options = options2 || _defaults;
|
|
20449
|
+
this.options.tokenizer = this.options.tokenizer || new _Tokenizer();
|
|
20450
|
+
this.tokenizer = this.options.tokenizer;
|
|
20451
|
+
this.tokenizer.options = this.options;
|
|
20452
|
+
this.tokenizer.lexer = this;
|
|
20453
|
+
this.inlineQueue = [];
|
|
20454
|
+
this.state = {
|
|
20455
|
+
inLink: false,
|
|
20456
|
+
inRawBlock: false,
|
|
20457
|
+
top: true
|
|
20458
|
+
};
|
|
20459
|
+
const rules = {
|
|
20460
|
+
other,
|
|
20461
|
+
block: block.normal,
|
|
20462
|
+
inline: inline.normal
|
|
20463
|
+
};
|
|
20464
|
+
if (this.options.pedantic) {
|
|
20465
|
+
rules.block = block.pedantic;
|
|
20466
|
+
rules.inline = inline.pedantic;
|
|
20467
|
+
} else if (this.options.gfm) {
|
|
20468
|
+
rules.block = block.gfm;
|
|
20469
|
+
if (this.options.breaks) {
|
|
20470
|
+
rules.inline = inline.breaks;
|
|
20471
|
+
} else {
|
|
20472
|
+
rules.inline = inline.gfm;
|
|
20473
|
+
}
|
|
20474
|
+
}
|
|
20475
|
+
this.tokenizer.rules = rules;
|
|
20476
|
+
}
|
|
20477
|
+
/**
|
|
20478
|
+
* Expose Rules
|
|
20479
|
+
*/
|
|
20480
|
+
static get rules() {
|
|
20481
|
+
return {
|
|
20482
|
+
block,
|
|
20483
|
+
inline
|
|
20484
|
+
};
|
|
20485
|
+
}
|
|
20486
|
+
/**
|
|
20487
|
+
* Static Lex Method
|
|
20488
|
+
*/
|
|
20489
|
+
static lex(src, options2) {
|
|
20490
|
+
const lexer2 = new __Lexer(options2);
|
|
20491
|
+
return lexer2.lex(src);
|
|
20492
|
+
}
|
|
20493
|
+
/**
|
|
20494
|
+
* Static Lex Inline Method
|
|
20495
|
+
*/
|
|
20496
|
+
static lexInline(src, options2) {
|
|
20497
|
+
const lexer2 = new __Lexer(options2);
|
|
20498
|
+
return lexer2.inlineTokens(src);
|
|
20499
|
+
}
|
|
20500
|
+
/**
|
|
20501
|
+
* Preprocessing
|
|
20502
|
+
*/
|
|
20503
|
+
lex(src) {
|
|
20504
|
+
src = src.replace(other.carriageReturn, "\n");
|
|
20505
|
+
this.blockTokens(src, this.tokens);
|
|
20506
|
+
for (let i = 0; i < this.inlineQueue.length; i++) {
|
|
20507
|
+
const next = this.inlineQueue[i];
|
|
20508
|
+
this.inlineTokens(next.src, next.tokens);
|
|
20509
|
+
}
|
|
20510
|
+
this.inlineQueue = [];
|
|
20511
|
+
return this.tokens;
|
|
20512
|
+
}
|
|
20513
|
+
blockTokens(src, tokens = [], lastParagraphClipped = false) {
|
|
20514
|
+
if (this.options.pedantic) {
|
|
20515
|
+
src = src.replace(other.tabCharGlobal, " ").replace(other.spaceLine, "");
|
|
20516
|
+
}
|
|
20517
|
+
while (src) {
|
|
20518
|
+
let token;
|
|
20519
|
+
if (this.options.extensions?.block?.some((extTokenizer) => {
|
|
20520
|
+
if (token = extTokenizer.call({ lexer: this }, src, tokens)) {
|
|
20521
|
+
src = src.substring(token.raw.length);
|
|
20522
|
+
tokens.push(token);
|
|
20523
|
+
return true;
|
|
20524
|
+
}
|
|
20525
|
+
return false;
|
|
20526
|
+
})) {
|
|
20527
|
+
continue;
|
|
20528
|
+
}
|
|
20529
|
+
if (token = this.tokenizer.space(src)) {
|
|
20530
|
+
src = src.substring(token.raw.length);
|
|
20531
|
+
const lastToken = tokens.at(-1);
|
|
20532
|
+
if (token.raw.length === 1 && lastToken !== void 0) {
|
|
20533
|
+
lastToken.raw += "\n";
|
|
20534
|
+
} else {
|
|
20535
|
+
tokens.push(token);
|
|
20536
|
+
}
|
|
20537
|
+
continue;
|
|
20538
|
+
}
|
|
20539
|
+
if (token = this.tokenizer.code(src)) {
|
|
20540
|
+
src = src.substring(token.raw.length);
|
|
20541
|
+
const lastToken = tokens.at(-1);
|
|
20542
|
+
if (lastToken?.type === "paragraph" || lastToken?.type === "text") {
|
|
20543
|
+
lastToken.raw += "\n" + token.raw;
|
|
20544
|
+
lastToken.text += "\n" + token.text;
|
|
20545
|
+
this.inlineQueue.at(-1).src = lastToken.text;
|
|
20546
|
+
} else {
|
|
20547
|
+
tokens.push(token);
|
|
20548
|
+
}
|
|
20549
|
+
continue;
|
|
20550
|
+
}
|
|
20551
|
+
if (token = this.tokenizer.fences(src)) {
|
|
20552
|
+
src = src.substring(token.raw.length);
|
|
20553
|
+
tokens.push(token);
|
|
20554
|
+
continue;
|
|
20555
|
+
}
|
|
20556
|
+
if (token = this.tokenizer.heading(src)) {
|
|
20557
|
+
src = src.substring(token.raw.length);
|
|
20558
|
+
tokens.push(token);
|
|
20559
|
+
continue;
|
|
20560
|
+
}
|
|
20561
|
+
if (token = this.tokenizer.hr(src)) {
|
|
20562
|
+
src = src.substring(token.raw.length);
|
|
20563
|
+
tokens.push(token);
|
|
20564
|
+
continue;
|
|
20565
|
+
}
|
|
20566
|
+
if (token = this.tokenizer.blockquote(src)) {
|
|
20567
|
+
src = src.substring(token.raw.length);
|
|
20568
|
+
tokens.push(token);
|
|
20569
|
+
continue;
|
|
20570
|
+
}
|
|
20571
|
+
if (token = this.tokenizer.list(src)) {
|
|
20572
|
+
src = src.substring(token.raw.length);
|
|
20573
|
+
tokens.push(token);
|
|
20574
|
+
continue;
|
|
20575
|
+
}
|
|
20576
|
+
if (token = this.tokenizer.html(src)) {
|
|
20577
|
+
src = src.substring(token.raw.length);
|
|
20578
|
+
tokens.push(token);
|
|
20579
|
+
continue;
|
|
20580
|
+
}
|
|
20581
|
+
if (token = this.tokenizer.def(src)) {
|
|
20582
|
+
src = src.substring(token.raw.length);
|
|
20583
|
+
const lastToken = tokens.at(-1);
|
|
20584
|
+
if (lastToken?.type === "paragraph" || lastToken?.type === "text") {
|
|
20585
|
+
lastToken.raw += "\n" + token.raw;
|
|
20586
|
+
lastToken.text += "\n" + token.raw;
|
|
20587
|
+
this.inlineQueue.at(-1).src = lastToken.text;
|
|
20588
|
+
} else if (!this.tokens.links[token.tag]) {
|
|
20589
|
+
this.tokens.links[token.tag] = {
|
|
20590
|
+
href: token.href,
|
|
20591
|
+
title: token.title
|
|
20592
|
+
};
|
|
20593
|
+
}
|
|
20594
|
+
continue;
|
|
20595
|
+
}
|
|
20596
|
+
if (token = this.tokenizer.table(src)) {
|
|
20597
|
+
src = src.substring(token.raw.length);
|
|
20598
|
+
tokens.push(token);
|
|
20599
|
+
continue;
|
|
20600
|
+
}
|
|
20601
|
+
if (token = this.tokenizer.lheading(src)) {
|
|
20602
|
+
src = src.substring(token.raw.length);
|
|
20603
|
+
tokens.push(token);
|
|
20604
|
+
continue;
|
|
20605
|
+
}
|
|
20606
|
+
let cutSrc = src;
|
|
20607
|
+
if (this.options.extensions?.startBlock) {
|
|
20608
|
+
let startIndex = Infinity;
|
|
20609
|
+
const tempSrc = src.slice(1);
|
|
20610
|
+
let tempStart;
|
|
20611
|
+
this.options.extensions.startBlock.forEach((getStartIndex) => {
|
|
20612
|
+
tempStart = getStartIndex.call({ lexer: this }, tempSrc);
|
|
20613
|
+
if (typeof tempStart === "number" && tempStart >= 0) {
|
|
20614
|
+
startIndex = Math.min(startIndex, tempStart);
|
|
20615
|
+
}
|
|
20616
|
+
});
|
|
20617
|
+
if (startIndex < Infinity && startIndex >= 0) {
|
|
20618
|
+
cutSrc = src.substring(0, startIndex + 1);
|
|
20619
|
+
}
|
|
20620
|
+
}
|
|
20621
|
+
if (this.state.top && (token = this.tokenizer.paragraph(cutSrc))) {
|
|
20622
|
+
const lastToken = tokens.at(-1);
|
|
20623
|
+
if (lastParagraphClipped && lastToken?.type === "paragraph") {
|
|
20624
|
+
lastToken.raw += "\n" + token.raw;
|
|
20625
|
+
lastToken.text += "\n" + token.text;
|
|
20626
|
+
this.inlineQueue.pop();
|
|
20627
|
+
this.inlineQueue.at(-1).src = lastToken.text;
|
|
20628
|
+
} else {
|
|
20629
|
+
tokens.push(token);
|
|
20630
|
+
}
|
|
20631
|
+
lastParagraphClipped = cutSrc.length !== src.length;
|
|
20632
|
+
src = src.substring(token.raw.length);
|
|
20633
|
+
continue;
|
|
20634
|
+
}
|
|
20635
|
+
if (token = this.tokenizer.text(src)) {
|
|
20636
|
+
src = src.substring(token.raw.length);
|
|
20637
|
+
const lastToken = tokens.at(-1);
|
|
20638
|
+
if (lastToken?.type === "text") {
|
|
20639
|
+
lastToken.raw += "\n" + token.raw;
|
|
20640
|
+
lastToken.text += "\n" + token.text;
|
|
20641
|
+
this.inlineQueue.pop();
|
|
20642
|
+
this.inlineQueue.at(-1).src = lastToken.text;
|
|
20643
|
+
} else {
|
|
20644
|
+
tokens.push(token);
|
|
20645
|
+
}
|
|
20646
|
+
continue;
|
|
20647
|
+
}
|
|
20648
|
+
if (src) {
|
|
20649
|
+
const errMsg = "Infinite loop on byte: " + src.charCodeAt(0);
|
|
20650
|
+
if (this.options.silent) {
|
|
20651
|
+
console.error(errMsg);
|
|
20652
|
+
break;
|
|
20653
|
+
} else {
|
|
20654
|
+
throw new Error(errMsg);
|
|
20655
|
+
}
|
|
20656
|
+
}
|
|
20657
|
+
}
|
|
20658
|
+
this.state.top = true;
|
|
20659
|
+
return tokens;
|
|
20660
|
+
}
|
|
20661
|
+
inline(src, tokens = []) {
|
|
20662
|
+
this.inlineQueue.push({ src, tokens });
|
|
20663
|
+
return tokens;
|
|
20664
|
+
}
|
|
20665
|
+
/**
|
|
20666
|
+
* Lexing/Compiling
|
|
20667
|
+
*/
|
|
20668
|
+
inlineTokens(src, tokens = []) {
|
|
20669
|
+
let maskedSrc = src;
|
|
20670
|
+
let match = null;
|
|
20671
|
+
if (this.tokens.links) {
|
|
20672
|
+
const links = Object.keys(this.tokens.links);
|
|
20673
|
+
if (links.length > 0) {
|
|
20674
|
+
while ((match = this.tokenizer.rules.inline.reflinkSearch.exec(maskedSrc)) != null) {
|
|
20675
|
+
if (links.includes(match[0].slice(match[0].lastIndexOf("[") + 1, -1))) {
|
|
20676
|
+
maskedSrc = maskedSrc.slice(0, match.index) + "[" + "a".repeat(match[0].length - 2) + "]" + maskedSrc.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex);
|
|
20677
|
+
}
|
|
20678
|
+
}
|
|
20679
|
+
}
|
|
20680
|
+
}
|
|
20681
|
+
while ((match = this.tokenizer.rules.inline.anyPunctuation.exec(maskedSrc)) != null) {
|
|
20682
|
+
maskedSrc = maskedSrc.slice(0, match.index) + "++" + maskedSrc.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);
|
|
20683
|
+
}
|
|
20684
|
+
while ((match = this.tokenizer.rules.inline.blockSkip.exec(maskedSrc)) != null) {
|
|
20685
|
+
maskedSrc = maskedSrc.slice(0, match.index) + "[" + "a".repeat(match[0].length - 2) + "]" + maskedSrc.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
|
|
20686
|
+
}
|
|
20687
|
+
let keepPrevChar = false;
|
|
20688
|
+
let prevChar = "";
|
|
20689
|
+
while (src) {
|
|
20690
|
+
if (!keepPrevChar) {
|
|
20691
|
+
prevChar = "";
|
|
20692
|
+
}
|
|
20693
|
+
keepPrevChar = false;
|
|
20694
|
+
let token;
|
|
20695
|
+
if (this.options.extensions?.inline?.some((extTokenizer) => {
|
|
20696
|
+
if (token = extTokenizer.call({ lexer: this }, src, tokens)) {
|
|
20697
|
+
src = src.substring(token.raw.length);
|
|
20698
|
+
tokens.push(token);
|
|
20699
|
+
return true;
|
|
20700
|
+
}
|
|
20701
|
+
return false;
|
|
20702
|
+
})) {
|
|
20703
|
+
continue;
|
|
20704
|
+
}
|
|
20705
|
+
if (token = this.tokenizer.escape(src)) {
|
|
20706
|
+
src = src.substring(token.raw.length);
|
|
20707
|
+
tokens.push(token);
|
|
20708
|
+
continue;
|
|
20709
|
+
}
|
|
20710
|
+
if (token = this.tokenizer.tag(src)) {
|
|
20711
|
+
src = src.substring(token.raw.length);
|
|
20712
|
+
tokens.push(token);
|
|
20713
|
+
continue;
|
|
20714
|
+
}
|
|
20715
|
+
if (token = this.tokenizer.link(src)) {
|
|
20716
|
+
src = src.substring(token.raw.length);
|
|
20717
|
+
tokens.push(token);
|
|
20718
|
+
continue;
|
|
20719
|
+
}
|
|
20720
|
+
if (token = this.tokenizer.reflink(src, this.tokens.links)) {
|
|
20721
|
+
src = src.substring(token.raw.length);
|
|
20722
|
+
const lastToken = tokens.at(-1);
|
|
20723
|
+
if (token.type === "text" && lastToken?.type === "text") {
|
|
20724
|
+
lastToken.raw += token.raw;
|
|
20725
|
+
lastToken.text += token.text;
|
|
20726
|
+
} else {
|
|
20727
|
+
tokens.push(token);
|
|
20728
|
+
}
|
|
20729
|
+
continue;
|
|
20730
|
+
}
|
|
20731
|
+
if (token = this.tokenizer.emStrong(src, maskedSrc, prevChar)) {
|
|
20732
|
+
src = src.substring(token.raw.length);
|
|
20733
|
+
tokens.push(token);
|
|
20734
|
+
continue;
|
|
20735
|
+
}
|
|
20736
|
+
if (token = this.tokenizer.codespan(src)) {
|
|
20737
|
+
src = src.substring(token.raw.length);
|
|
20738
|
+
tokens.push(token);
|
|
20739
|
+
continue;
|
|
20740
|
+
}
|
|
20741
|
+
if (token = this.tokenizer.br(src)) {
|
|
20742
|
+
src = src.substring(token.raw.length);
|
|
20743
|
+
tokens.push(token);
|
|
20744
|
+
continue;
|
|
20745
|
+
}
|
|
20746
|
+
if (token = this.tokenizer.del(src)) {
|
|
20747
|
+
src = src.substring(token.raw.length);
|
|
20748
|
+
tokens.push(token);
|
|
20749
|
+
continue;
|
|
20750
|
+
}
|
|
20751
|
+
if (token = this.tokenizer.autolink(src)) {
|
|
20752
|
+
src = src.substring(token.raw.length);
|
|
20753
|
+
tokens.push(token);
|
|
20754
|
+
continue;
|
|
20755
|
+
}
|
|
20756
|
+
if (!this.state.inLink && (token = this.tokenizer.url(src))) {
|
|
20757
|
+
src = src.substring(token.raw.length);
|
|
20758
|
+
tokens.push(token);
|
|
20759
|
+
continue;
|
|
20760
|
+
}
|
|
20761
|
+
let cutSrc = src;
|
|
20762
|
+
if (this.options.extensions?.startInline) {
|
|
20763
|
+
let startIndex = Infinity;
|
|
20764
|
+
const tempSrc = src.slice(1);
|
|
20765
|
+
let tempStart;
|
|
20766
|
+
this.options.extensions.startInline.forEach((getStartIndex) => {
|
|
20767
|
+
tempStart = getStartIndex.call({ lexer: this }, tempSrc);
|
|
20768
|
+
if (typeof tempStart === "number" && tempStart >= 0) {
|
|
20769
|
+
startIndex = Math.min(startIndex, tempStart);
|
|
20770
|
+
}
|
|
20771
|
+
});
|
|
20772
|
+
if (startIndex < Infinity && startIndex >= 0) {
|
|
20773
|
+
cutSrc = src.substring(0, startIndex + 1);
|
|
20774
|
+
}
|
|
20775
|
+
}
|
|
20776
|
+
if (token = this.tokenizer.inlineText(cutSrc)) {
|
|
20777
|
+
src = src.substring(token.raw.length);
|
|
20778
|
+
if (token.raw.slice(-1) !== "_") {
|
|
20779
|
+
prevChar = token.raw.slice(-1);
|
|
20780
|
+
}
|
|
20781
|
+
keepPrevChar = true;
|
|
20782
|
+
const lastToken = tokens.at(-1);
|
|
20783
|
+
if (lastToken?.type === "text") {
|
|
20784
|
+
lastToken.raw += token.raw;
|
|
20785
|
+
lastToken.text += token.text;
|
|
20786
|
+
} else {
|
|
20787
|
+
tokens.push(token);
|
|
20788
|
+
}
|
|
20789
|
+
continue;
|
|
20790
|
+
}
|
|
20791
|
+
if (src) {
|
|
20792
|
+
const errMsg = "Infinite loop on byte: " + src.charCodeAt(0);
|
|
20793
|
+
if (this.options.silent) {
|
|
20794
|
+
console.error(errMsg);
|
|
20795
|
+
break;
|
|
20796
|
+
} else {
|
|
20797
|
+
throw new Error(errMsg);
|
|
20798
|
+
}
|
|
20799
|
+
}
|
|
20800
|
+
}
|
|
20801
|
+
return tokens;
|
|
20802
|
+
}
|
|
20803
|
+
};
|
|
20804
|
+
|
|
20805
|
+
// src/Renderer.ts
|
|
20806
|
+
var _Renderer = class {
|
|
20807
|
+
options;
|
|
20808
|
+
parser;
|
|
20809
|
+
// set by the parser
|
|
20810
|
+
constructor(options2) {
|
|
20811
|
+
this.options = options2 || _defaults;
|
|
20812
|
+
}
|
|
20813
|
+
space(token) {
|
|
20814
|
+
return "";
|
|
20815
|
+
}
|
|
20816
|
+
code({ text, lang, escaped }) {
|
|
20817
|
+
const langString = (lang || "").match(other.notSpaceStart)?.[0];
|
|
20818
|
+
const code = text.replace(other.endingNewline, "") + "\n";
|
|
20819
|
+
if (!langString) {
|
|
20820
|
+
return "<pre><code>" + (escaped ? code : escape2(code, true)) + "</code></pre>\n";
|
|
20821
|
+
}
|
|
20822
|
+
return '<pre><code class="language-' + escape2(langString) + '">' + (escaped ? code : escape2(code, true)) + "</code></pre>\n";
|
|
20823
|
+
}
|
|
20824
|
+
blockquote({ tokens }) {
|
|
20825
|
+
const body = this.parser.parse(tokens);
|
|
20826
|
+
return `<blockquote>
|
|
20827
|
+
${body}</blockquote>
|
|
20828
|
+
`;
|
|
20829
|
+
}
|
|
20830
|
+
html({ text }) {
|
|
20831
|
+
return text;
|
|
20832
|
+
}
|
|
20833
|
+
heading({ tokens, depth }) {
|
|
20834
|
+
return `<h${depth}>${this.parser.parseInline(tokens)}</h${depth}>
|
|
20835
|
+
`;
|
|
20836
|
+
}
|
|
20837
|
+
hr(token) {
|
|
20838
|
+
return "<hr>\n";
|
|
20839
|
+
}
|
|
20840
|
+
list(token) {
|
|
20841
|
+
const ordered = token.ordered;
|
|
20842
|
+
const start = token.start;
|
|
20843
|
+
let body = "";
|
|
20844
|
+
for (let j = 0; j < token.items.length; j++) {
|
|
20845
|
+
const item = token.items[j];
|
|
20846
|
+
body += this.listitem(item);
|
|
20847
|
+
}
|
|
20848
|
+
const type = ordered ? "ol" : "ul";
|
|
20849
|
+
const startAttr = ordered && start !== 1 ? ' start="' + start + '"' : "";
|
|
20850
|
+
return "<" + type + startAttr + ">\n" + body + "</" + type + ">\n";
|
|
20851
|
+
}
|
|
20852
|
+
listitem(item) {
|
|
20853
|
+
let itemBody = "";
|
|
20854
|
+
if (item.task) {
|
|
20855
|
+
const checkbox = this.checkbox({ checked: !!item.checked });
|
|
20856
|
+
if (item.loose) {
|
|
20857
|
+
if (item.tokens[0]?.type === "paragraph") {
|
|
20858
|
+
item.tokens[0].text = checkbox + " " + item.tokens[0].text;
|
|
20859
|
+
if (item.tokens[0].tokens && item.tokens[0].tokens.length > 0 && item.tokens[0].tokens[0].type === "text") {
|
|
20860
|
+
item.tokens[0].tokens[0].text = checkbox + " " + escape2(item.tokens[0].tokens[0].text);
|
|
20861
|
+
item.tokens[0].tokens[0].escaped = true;
|
|
20862
|
+
}
|
|
20863
|
+
} else {
|
|
20864
|
+
item.tokens.unshift({
|
|
20865
|
+
type: "text",
|
|
20866
|
+
raw: checkbox + " ",
|
|
20867
|
+
text: checkbox + " ",
|
|
20868
|
+
escaped: true
|
|
20869
|
+
});
|
|
20870
|
+
}
|
|
20871
|
+
} else {
|
|
20872
|
+
itemBody += checkbox + " ";
|
|
20873
|
+
}
|
|
20874
|
+
}
|
|
20875
|
+
itemBody += this.parser.parse(item.tokens, !!item.loose);
|
|
20876
|
+
return `<li>${itemBody}</li>
|
|
20877
|
+
`;
|
|
20878
|
+
}
|
|
20879
|
+
checkbox({ checked }) {
|
|
20880
|
+
return "<input " + (checked ? 'checked="" ' : "") + 'disabled="" type="checkbox">';
|
|
20881
|
+
}
|
|
20882
|
+
paragraph({ tokens }) {
|
|
20883
|
+
return `<p>${this.parser.parseInline(tokens)}</p>
|
|
20884
|
+
`;
|
|
20885
|
+
}
|
|
20886
|
+
table(token) {
|
|
20887
|
+
let header = "";
|
|
20888
|
+
let cell = "";
|
|
20889
|
+
for (let j = 0; j < token.header.length; j++) {
|
|
20890
|
+
cell += this.tablecell(token.header[j]);
|
|
20891
|
+
}
|
|
20892
|
+
header += this.tablerow({ text: cell });
|
|
20893
|
+
let body = "";
|
|
20894
|
+
for (let j = 0; j < token.rows.length; j++) {
|
|
20895
|
+
const row = token.rows[j];
|
|
20896
|
+
cell = "";
|
|
20897
|
+
for (let k = 0; k < row.length; k++) {
|
|
20898
|
+
cell += this.tablecell(row[k]);
|
|
20899
|
+
}
|
|
20900
|
+
body += this.tablerow({ text: cell });
|
|
20901
|
+
}
|
|
20902
|
+
if (body) body = `<tbody>${body}</tbody>`;
|
|
20903
|
+
return "<table>\n<thead>\n" + header + "</thead>\n" + body + "</table>\n";
|
|
20904
|
+
}
|
|
20905
|
+
tablerow({ text }) {
|
|
20906
|
+
return `<tr>
|
|
20907
|
+
${text}</tr>
|
|
20908
|
+
`;
|
|
20909
|
+
}
|
|
20910
|
+
tablecell(token) {
|
|
20911
|
+
const content = this.parser.parseInline(token.tokens);
|
|
20912
|
+
const type = token.header ? "th" : "td";
|
|
20913
|
+
const tag2 = token.align ? `<${type} align="${token.align}">` : `<${type}>`;
|
|
20914
|
+
return tag2 + content + `</${type}>
|
|
20915
|
+
`;
|
|
20916
|
+
}
|
|
20917
|
+
/**
|
|
20918
|
+
* span level renderer
|
|
20919
|
+
*/
|
|
20920
|
+
strong({ tokens }) {
|
|
20921
|
+
return `<strong>${this.parser.parseInline(tokens)}</strong>`;
|
|
20922
|
+
}
|
|
20923
|
+
em({ tokens }) {
|
|
20924
|
+
return `<em>${this.parser.parseInline(tokens)}</em>`;
|
|
20925
|
+
}
|
|
20926
|
+
codespan({ text }) {
|
|
20927
|
+
return `<code>${escape2(text, true)}</code>`;
|
|
20928
|
+
}
|
|
20929
|
+
br(token) {
|
|
20930
|
+
return "<br>";
|
|
20931
|
+
}
|
|
20932
|
+
del({ tokens }) {
|
|
20933
|
+
return `<del>${this.parser.parseInline(tokens)}</del>`;
|
|
20934
|
+
}
|
|
20935
|
+
link({ href, title, tokens }) {
|
|
20936
|
+
const text = this.parser.parseInline(tokens);
|
|
20937
|
+
const cleanHref = cleanUrl(href);
|
|
20938
|
+
if (cleanHref === null) {
|
|
20939
|
+
return text;
|
|
20940
|
+
}
|
|
20941
|
+
href = cleanHref;
|
|
20942
|
+
let out = '<a href="' + href + '"';
|
|
20943
|
+
if (title) {
|
|
20944
|
+
out += ' title="' + escape2(title) + '"';
|
|
20945
|
+
}
|
|
20946
|
+
out += ">" + text + "</a>";
|
|
20947
|
+
return out;
|
|
20948
|
+
}
|
|
20949
|
+
image({ href, title, text, tokens }) {
|
|
20950
|
+
if (tokens) {
|
|
20951
|
+
text = this.parser.parseInline(tokens, this.parser.textRenderer);
|
|
20952
|
+
}
|
|
20953
|
+
const cleanHref = cleanUrl(href);
|
|
20954
|
+
if (cleanHref === null) {
|
|
20955
|
+
return escape2(text);
|
|
20956
|
+
}
|
|
20957
|
+
href = cleanHref;
|
|
20958
|
+
let out = `<img src="${href}" alt="${text}"`;
|
|
20959
|
+
if (title) {
|
|
20960
|
+
out += ` title="${escape2(title)}"`;
|
|
20961
|
+
}
|
|
20962
|
+
out += ">";
|
|
20963
|
+
return out;
|
|
20964
|
+
}
|
|
20965
|
+
text(token) {
|
|
20966
|
+
return "tokens" in token && token.tokens ? this.parser.parseInline(token.tokens) : "escaped" in token && token.escaped ? token.text : escape2(token.text);
|
|
20967
|
+
}
|
|
20968
|
+
};
|
|
20969
|
+
|
|
20970
|
+
// src/TextRenderer.ts
|
|
20971
|
+
var _TextRenderer = class {
|
|
20972
|
+
// no need for block level renderers
|
|
20973
|
+
strong({ text }) {
|
|
20974
|
+
return text;
|
|
20975
|
+
}
|
|
20976
|
+
em({ text }) {
|
|
20977
|
+
return text;
|
|
20978
|
+
}
|
|
20979
|
+
codespan({ text }) {
|
|
20980
|
+
return text;
|
|
20981
|
+
}
|
|
20982
|
+
del({ text }) {
|
|
20983
|
+
return text;
|
|
20984
|
+
}
|
|
20985
|
+
html({ text }) {
|
|
20986
|
+
return text;
|
|
20987
|
+
}
|
|
20988
|
+
text({ text }) {
|
|
20989
|
+
return text;
|
|
20990
|
+
}
|
|
20991
|
+
link({ text }) {
|
|
20992
|
+
return "" + text;
|
|
20993
|
+
}
|
|
20994
|
+
image({ text }) {
|
|
20995
|
+
return "" + text;
|
|
20996
|
+
}
|
|
20997
|
+
br() {
|
|
20998
|
+
return "";
|
|
20999
|
+
}
|
|
21000
|
+
};
|
|
21001
|
+
|
|
21002
|
+
// src/Parser.ts
|
|
21003
|
+
var _Parser = class __Parser {
|
|
21004
|
+
options;
|
|
21005
|
+
renderer;
|
|
21006
|
+
textRenderer;
|
|
21007
|
+
constructor(options2) {
|
|
21008
|
+
this.options = options2 || _defaults;
|
|
21009
|
+
this.options.renderer = this.options.renderer || new _Renderer();
|
|
21010
|
+
this.renderer = this.options.renderer;
|
|
21011
|
+
this.renderer.options = this.options;
|
|
21012
|
+
this.renderer.parser = this;
|
|
21013
|
+
this.textRenderer = new _TextRenderer();
|
|
21014
|
+
}
|
|
21015
|
+
/**
|
|
21016
|
+
* Static Parse Method
|
|
21017
|
+
*/
|
|
21018
|
+
static parse(tokens, options2) {
|
|
21019
|
+
const parser2 = new __Parser(options2);
|
|
21020
|
+
return parser2.parse(tokens);
|
|
21021
|
+
}
|
|
21022
|
+
/**
|
|
21023
|
+
* Static Parse Inline Method
|
|
21024
|
+
*/
|
|
21025
|
+
static parseInline(tokens, options2) {
|
|
21026
|
+
const parser2 = new __Parser(options2);
|
|
21027
|
+
return parser2.parseInline(tokens);
|
|
21028
|
+
}
|
|
21029
|
+
/**
|
|
21030
|
+
* Parse Loop
|
|
21031
|
+
*/
|
|
21032
|
+
parse(tokens, top = true) {
|
|
21033
|
+
let out = "";
|
|
21034
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
21035
|
+
const anyToken = tokens[i];
|
|
21036
|
+
if (this.options.extensions?.renderers?.[anyToken.type]) {
|
|
21037
|
+
const genericToken = anyToken;
|
|
21038
|
+
const ret = this.options.extensions.renderers[genericToken.type].call({ parser: this }, genericToken);
|
|
21039
|
+
if (ret !== false || !["space", "hr", "heading", "code", "table", "blockquote", "list", "html", "paragraph", "text"].includes(genericToken.type)) {
|
|
21040
|
+
out += ret || "";
|
|
21041
|
+
continue;
|
|
21042
|
+
}
|
|
21043
|
+
}
|
|
21044
|
+
const token = anyToken;
|
|
21045
|
+
switch (token.type) {
|
|
21046
|
+
case "space": {
|
|
21047
|
+
out += this.renderer.space(token);
|
|
21048
|
+
continue;
|
|
21049
|
+
}
|
|
21050
|
+
case "hr": {
|
|
21051
|
+
out += this.renderer.hr(token);
|
|
21052
|
+
continue;
|
|
21053
|
+
}
|
|
21054
|
+
case "heading": {
|
|
21055
|
+
out += this.renderer.heading(token);
|
|
21056
|
+
continue;
|
|
21057
|
+
}
|
|
21058
|
+
case "code": {
|
|
21059
|
+
out += this.renderer.code(token);
|
|
21060
|
+
continue;
|
|
21061
|
+
}
|
|
21062
|
+
case "table": {
|
|
21063
|
+
out += this.renderer.table(token);
|
|
21064
|
+
continue;
|
|
21065
|
+
}
|
|
21066
|
+
case "blockquote": {
|
|
21067
|
+
out += this.renderer.blockquote(token);
|
|
21068
|
+
continue;
|
|
21069
|
+
}
|
|
21070
|
+
case "list": {
|
|
21071
|
+
out += this.renderer.list(token);
|
|
21072
|
+
continue;
|
|
21073
|
+
}
|
|
21074
|
+
case "html": {
|
|
21075
|
+
out += this.renderer.html(token);
|
|
21076
|
+
continue;
|
|
21077
|
+
}
|
|
21078
|
+
case "paragraph": {
|
|
21079
|
+
out += this.renderer.paragraph(token);
|
|
21080
|
+
continue;
|
|
21081
|
+
}
|
|
21082
|
+
case "text": {
|
|
21083
|
+
let textToken = token;
|
|
21084
|
+
let body = this.renderer.text(textToken);
|
|
21085
|
+
while (i + 1 < tokens.length && tokens[i + 1].type === "text") {
|
|
21086
|
+
textToken = tokens[++i];
|
|
21087
|
+
body += "\n" + this.renderer.text(textToken);
|
|
21088
|
+
}
|
|
21089
|
+
if (top) {
|
|
21090
|
+
out += this.renderer.paragraph({
|
|
21091
|
+
type: "paragraph",
|
|
21092
|
+
raw: body,
|
|
21093
|
+
text: body,
|
|
21094
|
+
tokens: [{ type: "text", raw: body, text: body, escaped: true }]
|
|
21095
|
+
});
|
|
21096
|
+
} else {
|
|
21097
|
+
out += body;
|
|
21098
|
+
}
|
|
21099
|
+
continue;
|
|
21100
|
+
}
|
|
21101
|
+
default: {
|
|
21102
|
+
const errMsg = 'Token with "' + token.type + '" type was not found.';
|
|
21103
|
+
if (this.options.silent) {
|
|
21104
|
+
console.error(errMsg);
|
|
21105
|
+
return "";
|
|
21106
|
+
} else {
|
|
21107
|
+
throw new Error(errMsg);
|
|
21108
|
+
}
|
|
21109
|
+
}
|
|
21110
|
+
}
|
|
21111
|
+
}
|
|
21112
|
+
return out;
|
|
21113
|
+
}
|
|
21114
|
+
/**
|
|
21115
|
+
* Parse Inline Tokens
|
|
21116
|
+
*/
|
|
21117
|
+
parseInline(tokens, renderer = this.renderer) {
|
|
21118
|
+
let out = "";
|
|
21119
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
21120
|
+
const anyToken = tokens[i];
|
|
21121
|
+
if (this.options.extensions?.renderers?.[anyToken.type]) {
|
|
21122
|
+
const ret = this.options.extensions.renderers[anyToken.type].call({ parser: this }, anyToken);
|
|
21123
|
+
if (ret !== false || !["escape", "html", "link", "image", "strong", "em", "codespan", "br", "del", "text"].includes(anyToken.type)) {
|
|
21124
|
+
out += ret || "";
|
|
21125
|
+
continue;
|
|
21126
|
+
}
|
|
21127
|
+
}
|
|
21128
|
+
const token = anyToken;
|
|
21129
|
+
switch (token.type) {
|
|
21130
|
+
case "escape": {
|
|
21131
|
+
out += renderer.text(token);
|
|
21132
|
+
break;
|
|
21133
|
+
}
|
|
21134
|
+
case "html": {
|
|
21135
|
+
out += renderer.html(token);
|
|
21136
|
+
break;
|
|
21137
|
+
}
|
|
21138
|
+
case "link": {
|
|
21139
|
+
out += renderer.link(token);
|
|
21140
|
+
break;
|
|
21141
|
+
}
|
|
21142
|
+
case "image": {
|
|
21143
|
+
out += renderer.image(token);
|
|
21144
|
+
break;
|
|
21145
|
+
}
|
|
21146
|
+
case "strong": {
|
|
21147
|
+
out += renderer.strong(token);
|
|
21148
|
+
break;
|
|
21149
|
+
}
|
|
21150
|
+
case "em": {
|
|
21151
|
+
out += renderer.em(token);
|
|
21152
|
+
break;
|
|
21153
|
+
}
|
|
21154
|
+
case "codespan": {
|
|
21155
|
+
out += renderer.codespan(token);
|
|
21156
|
+
break;
|
|
21157
|
+
}
|
|
21158
|
+
case "br": {
|
|
21159
|
+
out += renderer.br(token);
|
|
21160
|
+
break;
|
|
21161
|
+
}
|
|
21162
|
+
case "del": {
|
|
21163
|
+
out += renderer.del(token);
|
|
21164
|
+
break;
|
|
21165
|
+
}
|
|
21166
|
+
case "text": {
|
|
21167
|
+
out += renderer.text(token);
|
|
21168
|
+
break;
|
|
21169
|
+
}
|
|
21170
|
+
default: {
|
|
21171
|
+
const errMsg = 'Token with "' + token.type + '" type was not found.';
|
|
21172
|
+
if (this.options.silent) {
|
|
21173
|
+
console.error(errMsg);
|
|
21174
|
+
return "";
|
|
21175
|
+
} else {
|
|
21176
|
+
throw new Error(errMsg);
|
|
21177
|
+
}
|
|
21178
|
+
}
|
|
21179
|
+
}
|
|
19181
21180
|
}
|
|
19182
|
-
|
|
19183
|
-
if (tr.docChanged) {
|
|
19184
|
-
editor.view.dispatch(tr);
|
|
21181
|
+
return out;
|
|
19185
21182
|
}
|
|
19186
|
-
}
|
|
21183
|
+
};
|
|
19187
21184
|
|
|
19188
|
-
// src/
|
|
19189
|
-
var
|
|
19190
|
-
|
|
19191
|
-
|
|
19192
|
-
|
|
21185
|
+
// src/Hooks.ts
|
|
21186
|
+
var _Hooks = class {
|
|
21187
|
+
options;
|
|
21188
|
+
block;
|
|
21189
|
+
constructor(options2) {
|
|
21190
|
+
this.options = options2 || _defaults;
|
|
21191
|
+
}
|
|
21192
|
+
static passThroughHooks = /* @__PURE__ */ new Set([
|
|
21193
|
+
"preprocess",
|
|
21194
|
+
"postprocess",
|
|
21195
|
+
"processAllTokens"
|
|
21196
|
+
]);
|
|
21197
|
+
/**
|
|
21198
|
+
* Process markdown before marked
|
|
21199
|
+
*/
|
|
21200
|
+
preprocess(markdown) {
|
|
21201
|
+
return markdown;
|
|
19193
21202
|
}
|
|
19194
21203
|
/**
|
|
19195
|
-
*
|
|
19196
|
-
* @param config - Node configuration object or a function that returns a configuration object
|
|
21204
|
+
* Process HTML after marked is finished
|
|
19197
21205
|
*/
|
|
19198
|
-
|
|
19199
|
-
|
|
19200
|
-
return new _Node(resolvedConfig);
|
|
21206
|
+
postprocess(html2) {
|
|
21207
|
+
return html2;
|
|
19201
21208
|
}
|
|
19202
|
-
|
|
19203
|
-
|
|
21209
|
+
/**
|
|
21210
|
+
* Process all tokens before walk tokens
|
|
21211
|
+
*/
|
|
21212
|
+
processAllTokens(tokens) {
|
|
21213
|
+
return tokens;
|
|
19204
21214
|
}
|
|
19205
|
-
|
|
19206
|
-
|
|
19207
|
-
|
|
21215
|
+
/**
|
|
21216
|
+
* Provide function to tokenize markdown
|
|
21217
|
+
*/
|
|
21218
|
+
provideLexer() {
|
|
21219
|
+
return this.block ? _Lexer.lex : _Lexer.lexInline;
|
|
21220
|
+
}
|
|
21221
|
+
/**
|
|
21222
|
+
* Provide function to parse tokens
|
|
21223
|
+
*/
|
|
21224
|
+
provideParser() {
|
|
21225
|
+
return this.block ? _Parser.parse : _Parser.parseInline;
|
|
19208
21226
|
}
|
|
19209
21227
|
};
|
|
19210
21228
|
|
|
19211
|
-
// src/
|
|
19212
|
-
|
|
19213
|
-
|
|
19214
|
-
|
|
19215
|
-
|
|
19216
|
-
|
|
19217
|
-
|
|
19218
|
-
|
|
19219
|
-
|
|
19220
|
-
|
|
19221
|
-
|
|
19222
|
-
|
|
19223
|
-
|
|
19224
|
-
|
|
19225
|
-
|
|
19226
|
-
|
|
19227
|
-
|
|
19228
|
-
|
|
19229
|
-
|
|
19230
|
-
|
|
19231
|
-
|
|
19232
|
-
|
|
19233
|
-
|
|
21229
|
+
// src/Instance.ts
|
|
21230
|
+
var Marked = class {
|
|
21231
|
+
defaults = _getDefaults();
|
|
21232
|
+
options = this.setOptions;
|
|
21233
|
+
parse = this.parseMarkdown(true);
|
|
21234
|
+
parseInline = this.parseMarkdown(false);
|
|
21235
|
+
Parser = _Parser;
|
|
21236
|
+
Renderer = _Renderer;
|
|
21237
|
+
TextRenderer = _TextRenderer;
|
|
21238
|
+
Lexer = _Lexer;
|
|
21239
|
+
Tokenizer = _Tokenizer;
|
|
21240
|
+
Hooks = _Hooks;
|
|
21241
|
+
constructor(...args) {
|
|
21242
|
+
this.use(...args);
|
|
21243
|
+
}
|
|
21244
|
+
/**
|
|
21245
|
+
* Run callback for every token
|
|
21246
|
+
*/
|
|
21247
|
+
walkTokens(tokens, callback) {
|
|
21248
|
+
let values = [];
|
|
21249
|
+
for (const token of tokens) {
|
|
21250
|
+
values = values.concat(callback.call(this, token));
|
|
21251
|
+
switch (token.type) {
|
|
21252
|
+
case "table": {
|
|
21253
|
+
const tableToken = token;
|
|
21254
|
+
for (const cell of tableToken.header) {
|
|
21255
|
+
values = values.concat(this.walkTokens(cell.tokens, callback));
|
|
21256
|
+
}
|
|
21257
|
+
for (const row of tableToken.rows) {
|
|
21258
|
+
for (const cell of row) {
|
|
21259
|
+
values = values.concat(this.walkTokens(cell.tokens, callback));
|
|
21260
|
+
}
|
|
21261
|
+
}
|
|
21262
|
+
break;
|
|
19234
21263
|
}
|
|
19235
|
-
|
|
19236
|
-
|
|
21264
|
+
case "list": {
|
|
21265
|
+
const listToken = token;
|
|
21266
|
+
values = values.concat(this.walkTokens(listToken.items, callback));
|
|
21267
|
+
break;
|
|
19237
21268
|
}
|
|
19238
|
-
|
|
19239
|
-
|
|
21269
|
+
default: {
|
|
21270
|
+
const genericToken = token;
|
|
21271
|
+
if (this.defaults.extensions?.childTokens?.[genericToken.type]) {
|
|
21272
|
+
this.defaults.extensions.childTokens[genericToken.type].forEach((childTokens) => {
|
|
21273
|
+
const tokens2 = genericToken[childTokens].flat(Infinity);
|
|
21274
|
+
values = values.concat(this.walkTokens(tokens2, callback));
|
|
21275
|
+
});
|
|
21276
|
+
} else if (genericToken.tokens) {
|
|
21277
|
+
values = values.concat(this.walkTokens(genericToken.tokens, callback));
|
|
21278
|
+
}
|
|
19240
21279
|
}
|
|
19241
|
-
markEnd = range.from + startSpaces + captureGroup.length;
|
|
19242
|
-
tr.addMark(range.from + startSpaces, markEnd, config.type.create(attributes || {}));
|
|
19243
|
-
tr.removeStoredMark(config.type);
|
|
19244
21280
|
}
|
|
19245
21281
|
}
|
|
19246
|
-
|
|
19247
|
-
}
|
|
19248
|
-
|
|
19249
|
-
|
|
19250
|
-
|
|
19251
|
-
|
|
19252
|
-
|
|
19253
|
-
|
|
19254
|
-
|
|
19255
|
-
|
|
19256
|
-
|
|
19257
|
-
|
|
19258
|
-
|
|
21282
|
+
return values;
|
|
21283
|
+
}
|
|
21284
|
+
use(...args) {
|
|
21285
|
+
const extensions = this.defaults.extensions || { renderers: {}, childTokens: {} };
|
|
21286
|
+
args.forEach((pack) => {
|
|
21287
|
+
const opts = { ...pack };
|
|
21288
|
+
opts.async = this.defaults.async || opts.async || false;
|
|
21289
|
+
if (pack.extensions) {
|
|
21290
|
+
pack.extensions.forEach((ext) => {
|
|
21291
|
+
if (!ext.name) {
|
|
21292
|
+
throw new Error("extension name required");
|
|
21293
|
+
}
|
|
21294
|
+
if ("renderer" in ext) {
|
|
21295
|
+
const prevRenderer = extensions.renderers[ext.name];
|
|
21296
|
+
if (prevRenderer) {
|
|
21297
|
+
extensions.renderers[ext.name] = function(...args2) {
|
|
21298
|
+
let ret = ext.renderer.apply(this, args2);
|
|
21299
|
+
if (ret === false) {
|
|
21300
|
+
ret = prevRenderer.apply(this, args2);
|
|
21301
|
+
}
|
|
21302
|
+
return ret;
|
|
21303
|
+
};
|
|
21304
|
+
} else {
|
|
21305
|
+
extensions.renderers[ext.name] = ext.renderer;
|
|
21306
|
+
}
|
|
21307
|
+
}
|
|
21308
|
+
if ("tokenizer" in ext) {
|
|
21309
|
+
if (!ext.level || ext.level !== "block" && ext.level !== "inline") {
|
|
21310
|
+
throw new Error("extension level must be 'block' or 'inline'");
|
|
21311
|
+
}
|
|
21312
|
+
const extLevel = extensions[ext.level];
|
|
21313
|
+
if (extLevel) {
|
|
21314
|
+
extLevel.unshift(ext.tokenizer);
|
|
21315
|
+
} else {
|
|
21316
|
+
extensions[ext.level] = [ext.tokenizer];
|
|
21317
|
+
}
|
|
21318
|
+
if (ext.start) {
|
|
21319
|
+
if (ext.level === "block") {
|
|
21320
|
+
if (extensions.startBlock) {
|
|
21321
|
+
extensions.startBlock.push(ext.start);
|
|
21322
|
+
} else {
|
|
21323
|
+
extensions.startBlock = [ext.start];
|
|
21324
|
+
}
|
|
21325
|
+
} else if (ext.level === "inline") {
|
|
21326
|
+
if (extensions.startInline) {
|
|
21327
|
+
extensions.startInline.push(ext.start);
|
|
21328
|
+
} else {
|
|
21329
|
+
extensions.startInline = [ext.start];
|
|
21330
|
+
}
|
|
21331
|
+
}
|
|
21332
|
+
}
|
|
21333
|
+
}
|
|
21334
|
+
if ("childTokens" in ext && ext.childTokens) {
|
|
21335
|
+
extensions.childTokens[ext.name] = ext.childTokens;
|
|
21336
|
+
}
|
|
21337
|
+
});
|
|
21338
|
+
opts.extensions = extensions;
|
|
21339
|
+
}
|
|
21340
|
+
if (pack.renderer) {
|
|
21341
|
+
const renderer = this.defaults.renderer || new _Renderer(this.defaults);
|
|
21342
|
+
for (const prop in pack.renderer) {
|
|
21343
|
+
if (!(prop in renderer)) {
|
|
21344
|
+
throw new Error(`renderer '${prop}' does not exist`);
|
|
21345
|
+
}
|
|
21346
|
+
if (["options", "parser"].includes(prop)) {
|
|
21347
|
+
continue;
|
|
21348
|
+
}
|
|
21349
|
+
const rendererProp = prop;
|
|
21350
|
+
const rendererFunc = pack.renderer[rendererProp];
|
|
21351
|
+
const prevRenderer = renderer[rendererProp];
|
|
21352
|
+
renderer[rendererProp] = (...args2) => {
|
|
21353
|
+
let ret = rendererFunc.apply(renderer, args2);
|
|
21354
|
+
if (ret === false) {
|
|
21355
|
+
ret = prevRenderer.apply(renderer, args2);
|
|
21356
|
+
}
|
|
21357
|
+
return ret || "";
|
|
21358
|
+
};
|
|
21359
|
+
}
|
|
21360
|
+
opts.renderer = renderer;
|
|
21361
|
+
}
|
|
21362
|
+
if (pack.tokenizer) {
|
|
21363
|
+
const tokenizer = this.defaults.tokenizer || new _Tokenizer(this.defaults);
|
|
21364
|
+
for (const prop in pack.tokenizer) {
|
|
21365
|
+
if (!(prop in tokenizer)) {
|
|
21366
|
+
throw new Error(`tokenizer '${prop}' does not exist`);
|
|
21367
|
+
}
|
|
21368
|
+
if (["options", "rules", "lexer"].includes(prop)) {
|
|
21369
|
+
continue;
|
|
21370
|
+
}
|
|
21371
|
+
const tokenizerProp = prop;
|
|
21372
|
+
const tokenizerFunc = pack.tokenizer[tokenizerProp];
|
|
21373
|
+
const prevTokenizer = tokenizer[tokenizerProp];
|
|
21374
|
+
tokenizer[tokenizerProp] = (...args2) => {
|
|
21375
|
+
let ret = tokenizerFunc.apply(tokenizer, args2);
|
|
21376
|
+
if (ret === false) {
|
|
21377
|
+
ret = prevTokenizer.apply(tokenizer, args2);
|
|
21378
|
+
}
|
|
21379
|
+
return ret;
|
|
21380
|
+
};
|
|
21381
|
+
}
|
|
21382
|
+
opts.tokenizer = tokenizer;
|
|
21383
|
+
}
|
|
21384
|
+
if (pack.hooks) {
|
|
21385
|
+
const hooks = this.defaults.hooks || new _Hooks();
|
|
21386
|
+
for (const prop in pack.hooks) {
|
|
21387
|
+
if (!(prop in hooks)) {
|
|
21388
|
+
throw new Error(`hook '${prop}' does not exist`);
|
|
21389
|
+
}
|
|
21390
|
+
if (["options", "block"].includes(prop)) {
|
|
21391
|
+
continue;
|
|
21392
|
+
}
|
|
21393
|
+
const hooksProp = prop;
|
|
21394
|
+
const hooksFunc = pack.hooks[hooksProp];
|
|
21395
|
+
const prevHook = hooks[hooksProp];
|
|
21396
|
+
if (_Hooks.passThroughHooks.has(prop)) {
|
|
21397
|
+
hooks[hooksProp] = (arg) => {
|
|
21398
|
+
if (this.defaults.async) {
|
|
21399
|
+
return Promise.resolve(hooksFunc.call(hooks, arg)).then((ret2) => {
|
|
21400
|
+
return prevHook.call(hooks, ret2);
|
|
21401
|
+
});
|
|
21402
|
+
}
|
|
21403
|
+
const ret = hooksFunc.call(hooks, arg);
|
|
21404
|
+
return prevHook.call(hooks, ret);
|
|
21405
|
+
};
|
|
21406
|
+
} else {
|
|
21407
|
+
hooks[hooksProp] = (...args2) => {
|
|
21408
|
+
let ret = hooksFunc.apply(hooks, args2);
|
|
21409
|
+
if (ret === false) {
|
|
21410
|
+
ret = prevHook.apply(hooks, args2);
|
|
21411
|
+
}
|
|
21412
|
+
return ret;
|
|
21413
|
+
};
|
|
21414
|
+
}
|
|
21415
|
+
}
|
|
21416
|
+
opts.hooks = hooks;
|
|
21417
|
+
}
|
|
21418
|
+
if (pack.walkTokens) {
|
|
21419
|
+
const walkTokens2 = this.defaults.walkTokens;
|
|
21420
|
+
const packWalktokens = pack.walkTokens;
|
|
21421
|
+
opts.walkTokens = function(token) {
|
|
21422
|
+
let values = [];
|
|
21423
|
+
values.push(packWalktokens.call(this, token));
|
|
21424
|
+
if (walkTokens2) {
|
|
21425
|
+
values = values.concat(walkTokens2.call(this, token));
|
|
21426
|
+
}
|
|
21427
|
+
return values;
|
|
21428
|
+
};
|
|
21429
|
+
}
|
|
21430
|
+
this.defaults = { ...this.defaults, ...opts };
|
|
21431
|
+
});
|
|
21432
|
+
return this;
|
|
21433
|
+
}
|
|
21434
|
+
setOptions(opt) {
|
|
21435
|
+
this.defaults = { ...this.defaults, ...opt };
|
|
21436
|
+
return this;
|
|
21437
|
+
}
|
|
21438
|
+
lexer(src, options2) {
|
|
21439
|
+
return _Lexer.lex(src, options2 ?? this.defaults);
|
|
21440
|
+
}
|
|
21441
|
+
parser(tokens, options2) {
|
|
21442
|
+
return _Parser.parse(tokens, options2 ?? this.defaults);
|
|
21443
|
+
}
|
|
21444
|
+
parseMarkdown(blockType) {
|
|
21445
|
+
const parse2 = (src, options2) => {
|
|
21446
|
+
const origOpt = { ...options2 };
|
|
21447
|
+
const opt = { ...this.defaults, ...origOpt };
|
|
21448
|
+
const throwError = this.onError(!!opt.silent, !!opt.async);
|
|
21449
|
+
if (this.defaults.async === true && origOpt.async === false) {
|
|
21450
|
+
return throwError(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));
|
|
21451
|
+
}
|
|
21452
|
+
if (typeof src === "undefined" || src === null) {
|
|
21453
|
+
return throwError(new Error("marked(): input parameter is undefined or null"));
|
|
21454
|
+
}
|
|
21455
|
+
if (typeof src !== "string") {
|
|
21456
|
+
return throwError(new Error("marked(): input parameter is of type " + Object.prototype.toString.call(src) + ", string expected"));
|
|
21457
|
+
}
|
|
21458
|
+
if (opt.hooks) {
|
|
21459
|
+
opt.hooks.options = opt;
|
|
21460
|
+
opt.hooks.block = blockType;
|
|
21461
|
+
}
|
|
21462
|
+
const lexer2 = opt.hooks ? opt.hooks.provideLexer() : blockType ? _Lexer.lex : _Lexer.lexInline;
|
|
21463
|
+
const parser2 = opt.hooks ? opt.hooks.provideParser() : blockType ? _Parser.parse : _Parser.parseInline;
|
|
21464
|
+
if (opt.async) {
|
|
21465
|
+
return Promise.resolve(opt.hooks ? opt.hooks.preprocess(src) : src).then((src2) => lexer2(src2, opt)).then((tokens) => opt.hooks ? opt.hooks.processAllTokens(tokens) : tokens).then((tokens) => opt.walkTokens ? Promise.all(this.walkTokens(tokens, opt.walkTokens)).then(() => tokens) : tokens).then((tokens) => parser2(tokens, opt)).then((html2) => opt.hooks ? opt.hooks.postprocess(html2) : html2).catch(throwError);
|
|
21466
|
+
}
|
|
21467
|
+
try {
|
|
21468
|
+
if (opt.hooks) {
|
|
21469
|
+
src = opt.hooks.preprocess(src);
|
|
21470
|
+
}
|
|
21471
|
+
let tokens = lexer2(src, opt);
|
|
21472
|
+
if (opt.hooks) {
|
|
21473
|
+
tokens = opt.hooks.processAllTokens(tokens);
|
|
21474
|
+
}
|
|
21475
|
+
if (opt.walkTokens) {
|
|
21476
|
+
this.walkTokens(tokens, opt.walkTokens);
|
|
21477
|
+
}
|
|
21478
|
+
let html2 = parser2(tokens, opt);
|
|
21479
|
+
if (opt.hooks) {
|
|
21480
|
+
html2 = opt.hooks.postprocess(html2);
|
|
21481
|
+
}
|
|
21482
|
+
return html2;
|
|
21483
|
+
} catch (e) {
|
|
21484
|
+
return throwError(e);
|
|
21485
|
+
}
|
|
21486
|
+
};
|
|
21487
|
+
return parse2;
|
|
21488
|
+
}
|
|
21489
|
+
onError(silent, async) {
|
|
21490
|
+
return (e) => {
|
|
21491
|
+
e.message += "\nPlease report this to https://github.com/markedjs/marked.";
|
|
21492
|
+
if (silent) {
|
|
21493
|
+
const msg = "<p>An error occurred:</p><pre>" + escape2(e.message + "", true) + "</pre>";
|
|
21494
|
+
if (async) {
|
|
21495
|
+
return Promise.resolve(msg);
|
|
21496
|
+
}
|
|
21497
|
+
return msg;
|
|
21498
|
+
}
|
|
21499
|
+
if (async) {
|
|
21500
|
+
return Promise.reject(e);
|
|
21501
|
+
}
|
|
21502
|
+
throw e;
|
|
21503
|
+
};
|
|
21504
|
+
}
|
|
21505
|
+
};
|
|
19259
21506
|
|
|
19260
|
-
|
|
19261
|
-
|
|
19262
|
-
|
|
19263
|
-
|
|
19264
|
-
|
|
19265
|
-
|
|
19266
|
-
|
|
19267
|
-
|
|
19268
|
-
|
|
19269
|
-
|
|
19270
|
-
|
|
19271
|
-
|
|
19272
|
-
|
|
19273
|
-
|
|
19274
|
-
|
|
19275
|
-
|
|
19276
|
-
|
|
19277
|
-
|
|
19278
|
-
|
|
19279
|
-
|
|
19280
|
-
|
|
19281
|
-
|
|
19282
|
-
|
|
19283
|
-
|
|
19284
|
-
|
|
19285
|
-
|
|
19286
|
-
|
|
19287
|
-
|
|
19288
|
-
|
|
19289
|
-
|
|
19290
|
-
|
|
19291
|
-
|
|
19292
|
-
`)+r.raw,s.text+=`
|
|
19293
|
-
`+r.raw,this.inlineQueue.at(-1).src=s.text):this.tokens.links[r.tag]||(this.tokens.links[r.tag]={href:r.href,title:r.title},t.push(r));continue}if(r=this.tokenizer.table(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.lheading(e)){e=e.substring(r.raw.length),t.push(r);continue}let i=e;if(this.options.extensions?.startBlock){let s=1/0,o=e.slice(1),a;this.options.extensions.startBlock.forEach(l=>{a=l.call({lexer:this},o),typeof a=="number"&&a>=0&&(s=Math.min(s,a));}),s<1/0&&s>=0&&(i=e.substring(0,s+1));}if(this.state.top&&(r=this.tokenizer.paragraph(i))){let s=t.at(-1);n&&s?.type==="paragraph"?(s.raw+=(s.raw.endsWith(`
|
|
19294
|
-
`)?"":`
|
|
19295
|
-
`)+r.raw,s.text+=`
|
|
19296
|
-
`+r.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=s.text):t.push(r),n=i.length!==e.length,e=e.substring(r.raw.length);continue}if(r=this.tokenizer.text(e)){e=e.substring(r.raw.length);let s=t.at(-1);s?.type==="text"?(s.raw+=(s.raw.endsWith(`
|
|
19297
|
-
`)?"":`
|
|
19298
|
-
`)+r.raw,s.text+=`
|
|
19299
|
-
`+r.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=s.text):t.push(r);continue}if(e){let s="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(s);break}else throw new Error(s)}}return this.state.top=true,t}inline(e,t=[]){return this.inlineQueue.push({src:e,tokens:t}),t}inlineTokens(e,t=[]){let n=e,r=null;if(this.tokens.links){let o=Object.keys(this.tokens.links);if(o.length>0)for(;(r=this.tokenizer.rules.inline.reflinkSearch.exec(n))!=null;)o.includes(r[0].slice(r[0].lastIndexOf("[")+1,-1))&&(n=n.slice(0,r.index)+"["+"a".repeat(r[0].length-2)+"]"+n.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex));}for(;(r=this.tokenizer.rules.inline.anyPunctuation.exec(n))!=null;)n=n.slice(0,r.index)+"++"+n.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);for(;(r=this.tokenizer.rules.inline.blockSkip.exec(n))!=null;)n=n.slice(0,r.index)+"["+"a".repeat(r[0].length-2)+"]"+n.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);n=this.options.hooks?.emStrongMask?.call({lexer:this},n)??n;let i=false,s="";for(;e;){i||(s=""),i=false;let o;if(this.options.extensions?.inline?.some(l=>(o=l.call({lexer:this},e,t))?(e=e.substring(o.raw.length),t.push(o),true):false))continue;if(o=this.tokenizer.escape(e)){e=e.substring(o.raw.length),t.push(o);continue}if(o=this.tokenizer.tag(e)){e=e.substring(o.raw.length),t.push(o);continue}if(o=this.tokenizer.link(e)){e=e.substring(o.raw.length),t.push(o);continue}if(o=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(o.raw.length);let l=t.at(-1);o.type==="text"&&l?.type==="text"?(l.raw+=o.raw,l.text+=o.text):t.push(o);continue}if(o=this.tokenizer.emStrong(e,n,s)){e=e.substring(o.raw.length),t.push(o);continue}if(o=this.tokenizer.codespan(e)){e=e.substring(o.raw.length),t.push(o);continue}if(o=this.tokenizer.br(e)){e=e.substring(o.raw.length),t.push(o);continue}if(o=this.tokenizer.del(e)){e=e.substring(o.raw.length),t.push(o);continue}if(o=this.tokenizer.autolink(e)){e=e.substring(o.raw.length),t.push(o);continue}if(!this.state.inLink&&(o=this.tokenizer.url(e))){e=e.substring(o.raw.length),t.push(o);continue}let a=e;if(this.options.extensions?.startInline){let l=1/0,c=e.slice(1),p;this.options.extensions.startInline.forEach(g=>{p=g.call({lexer:this},c),typeof p=="number"&&p>=0&&(l=Math.min(l,p));}),l<1/0&&l>=0&&(a=e.substring(0,l+1));}if(o=this.tokenizer.inlineText(a)){e=e.substring(o.raw.length),o.raw.slice(-1)!=="_"&&(s=o.raw.slice(-1)),i=true;let l=t.at(-1);l?.type==="text"?(l.raw+=o.raw,l.text+=o.text):t.push(o);continue}if(e){let l="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(l);break}else throw new Error(l)}}return t}};var P=class{options;parser;constructor(e){this.options=e||T;}space(e){return ""}code({text:e,lang:t,escaped:n}){let r=(t||"").match(m.notSpaceStart)?.[0],i=e.replace(m.endingNewline,"")+`
|
|
19300
|
-
`;return r?'<pre><code class="language-'+w(r)+'">'+(n?i:w(i,true))+`</code></pre>
|
|
19301
|
-
`:"<pre><code>"+(n?i:w(i,true))+`</code></pre>
|
|
19302
|
-
`}blockquote({tokens:e}){return `<blockquote>
|
|
19303
|
-
${this.parser.parse(e)}</blockquote>
|
|
19304
|
-
`}html({text:e}){return e}def(e){return ""}heading({tokens:e,depth:t}){return `<h${t}>${this.parser.parseInline(e)}</h${t}>
|
|
19305
|
-
`}hr(e){return `<hr>
|
|
19306
|
-
`}list(e){let t=e.ordered,n=e.start,r="";for(let o=0;o<e.items.length;o++){let a=e.items[o];r+=this.listitem(a);}let i=t?"ol":"ul",s=t&&n!==1?' start="'+n+'"':"";return "<"+i+s+`>
|
|
19307
|
-
`+r+"</"+i+`>
|
|
19308
|
-
`}listitem(e){let t="";if(e.task){let n=this.checkbox({checked:!!e.checked});e.loose?e.tokens[0]?.type==="paragraph"?(e.tokens[0].text=n+" "+e.tokens[0].text,e.tokens[0].tokens&&e.tokens[0].tokens.length>0&&e.tokens[0].tokens[0].type==="text"&&(e.tokens[0].tokens[0].text=n+" "+w(e.tokens[0].tokens[0].text),e.tokens[0].tokens[0].escaped=true)):e.tokens.unshift({type:"text",raw:n+" ",text:n+" ",escaped:true}):t+=n+" ";}return t+=this.parser.parse(e.tokens,!!e.loose),`<li>${t}</li>
|
|
19309
|
-
`}checkbox({checked:e}){return "<input "+(e?'checked="" ':"")+'disabled="" type="checkbox">'}paragraph({tokens:e}){return `<p>${this.parser.parseInline(e)}</p>
|
|
19310
|
-
`}table(e){let t="",n="";for(let i=0;i<e.header.length;i++)n+=this.tablecell(e.header[i]);t+=this.tablerow({text:n});let r="";for(let i=0;i<e.rows.length;i++){let s=e.rows[i];n="";for(let o=0;o<s.length;o++)n+=this.tablecell(s[o]);r+=this.tablerow({text:n});}return r&&(r=`<tbody>${r}</tbody>`),`<table>
|
|
19311
|
-
<thead>
|
|
19312
|
-
`+t+`</thead>
|
|
19313
|
-
`+r+`</table>
|
|
19314
|
-
`}tablerow({text:e}){return `<tr>
|
|
19315
|
-
${e}</tr>
|
|
19316
|
-
`}tablecell(e){let t=this.parser.parseInline(e.tokens),n=e.header?"th":"td";return (e.align?`<${n} align="${e.align}">`:`<${n}>`)+t+`</${n}>
|
|
19317
|
-
`}strong({tokens:e}){return `<strong>${this.parser.parseInline(e)}</strong>`}em({tokens:e}){return `<em>${this.parser.parseInline(e)}</em>`}codespan({text:e}){return `<code>${w(e,true)}</code>`}br(e){return "<br>"}del({tokens:e}){return `<del>${this.parser.parseInline(e)}</del>`}link({href:e,title:t,tokens:n}){let r=this.parser.parseInline(n),i=J(e);if(i===null)return r;e=i;let s='<a href="'+e+'"';return t&&(s+=' title="'+w(t)+'"'),s+=">"+r+"</a>",s}image({href:e,title:t,text:n,tokens:r}){r&&(n=this.parser.parseInline(r,this.parser.textRenderer));let i=J(e);if(i===null)return w(n);e=i;let s=`<img src="${e}" alt="${n}"`;return t&&(s+=` title="${w(t)}"`),s+=">",s}text(e){return "tokens"in e&&e.tokens?this.parser.parseInline(e.tokens):"escaped"in e&&e.escaped?e.text:w(e.text)}};var $=class{strong({text:e}){return e}em({text:e}){return e}codespan({text:e}){return e}del({text:e}){return e}html({text:e}){return e}text({text:e}){return e}link({text:e}){return ""+e}image({text:e}){return ""+e}br(){return ""}};var b=class u{options;renderer;textRenderer;constructor(e){this.options=e||T,this.options.renderer=this.options.renderer||new P,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new $;}static parse(e,t){return new u(t).parse(e)}static parseInline(e,t){return new u(t).parseInline(e)}parse(e,t=true){let n="";for(let r=0;r<e.length;r++){let i=e[r];if(this.options.extensions?.renderers?.[i.type]){let o=i,a=this.options.extensions.renderers[o.type].call({parser:this},o);if(a!==false||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(o.type)){n+=a||"";continue}}let s=i;switch(s.type){case "space":{n+=this.renderer.space(s);continue}case "hr":{n+=this.renderer.hr(s);continue}case "heading":{n+=this.renderer.heading(s);continue}case "code":{n+=this.renderer.code(s);continue}case "table":{n+=this.renderer.table(s);continue}case "blockquote":{n+=this.renderer.blockquote(s);continue}case "list":{n+=this.renderer.list(s);continue}case "html":{n+=this.renderer.html(s);continue}case "def":{n+=this.renderer.def(s);continue}case "paragraph":{n+=this.renderer.paragraph(s);continue}case "text":{let o=s,a=this.renderer.text(o);for(;r+1<e.length&&e[r+1].type==="text";)o=e[++r],a+=`
|
|
19318
|
-
`+this.renderer.text(o);t?n+=this.renderer.paragraph({type:"paragraph",raw:a,text:a,tokens:[{type:"text",raw:a,text:a,escaped:true}]}):n+=a;continue}default:{let o='Token with "'+s.type+'" type was not found.';if(this.options.silent)return console.error(o),"";throw new Error(o)}}}return n}parseInline(e,t=this.renderer){let n="";for(let r=0;r<e.length;r++){let i=e[r];if(this.options.extensions?.renderers?.[i.type]){let o=this.options.extensions.renderers[i.type].call({parser:this},i);if(o!==false||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(i.type)){n+=o||"";continue}}let s=i;switch(s.type){case "escape":{n+=t.text(s);break}case "html":{n+=t.html(s);break}case "link":{n+=t.link(s);break}case "image":{n+=t.image(s);break}case "strong":{n+=t.strong(s);break}case "em":{n+=t.em(s);break}case "codespan":{n+=t.codespan(s);break}case "br":{n+=t.br(s);break}case "del":{n+=t.del(s);break}case "text":{n+=t.text(s);break}default:{let o='Token with "'+s.type+'" type was not found.';if(this.options.silent)return console.error(o),"";throw new Error(o)}}}return n}};var S=class{options;block;constructor(e){this.options=e||T;}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(e){return e}postprocess(e){return e}processAllTokens(e){return e}emStrongMask(e){return e}provideLexer(){return this.block?x.lex:x.lexInline}provideParser(){return this.block?b.parse:b.parseInline}};var B=class{defaults=L();options=this.setOptions;parse=this.parseMarkdown(true);parseInline=this.parseMarkdown(false);Parser=b;Renderer=P;TextRenderer=$;Lexer=x;Tokenizer=y;Hooks=S;constructor(...e){this.use(...e);}walkTokens(e,t){let n=[];for(let r of e)switch(n=n.concat(t.call(this,r)),r.type){case "table":{let i=r;for(let s of i.header)n=n.concat(this.walkTokens(s.tokens,t));for(let s of i.rows)for(let o of s)n=n.concat(this.walkTokens(o.tokens,t));break}case "list":{let i=r;n=n.concat(this.walkTokens(i.items,t));break}default:{let i=r;this.defaults.extensions?.childTokens?.[i.type]?this.defaults.extensions.childTokens[i.type].forEach(s=>{let o=i[s].flat(1/0);n=n.concat(this.walkTokens(o,t));}):i.tokens&&(n=n.concat(this.walkTokens(i.tokens,t)));}}return n}use(...e){let t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.forEach(n=>{let r={...n};if(r.async=this.defaults.async||r.async||false,n.extensions&&(n.extensions.forEach(i=>{if(!i.name)throw new Error("extension name required");if("renderer"in i){let s=t.renderers[i.name];s?t.renderers[i.name]=function(...o){let a=i.renderer.apply(this,o);return a===false&&(a=s.apply(this,o)),a}:t.renderers[i.name]=i.renderer;}if("tokenizer"in i){if(!i.level||i.level!=="block"&&i.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");let s=t[i.level];s?s.unshift(i.tokenizer):t[i.level]=[i.tokenizer],i.start&&(i.level==="block"?t.startBlock?t.startBlock.push(i.start):t.startBlock=[i.start]:i.level==="inline"&&(t.startInline?t.startInline.push(i.start):t.startInline=[i.start]));}"childTokens"in i&&i.childTokens&&(t.childTokens[i.name]=i.childTokens);}),r.extensions=t),n.renderer){let i=this.defaults.renderer||new P(this.defaults);for(let s in n.renderer){if(!(s in i))throw new Error(`renderer '${s}' does not exist`);if(["options","parser"].includes(s))continue;let o=s,a=n.renderer[o],l=i[o];i[o]=(...c)=>{let p=a.apply(i,c);return p===false&&(p=l.apply(i,c)),p||""};}r.renderer=i;}if(n.tokenizer){let i=this.defaults.tokenizer||new y(this.defaults);for(let s in n.tokenizer){if(!(s in i))throw new Error(`tokenizer '${s}' does not exist`);if(["options","rules","lexer"].includes(s))continue;let o=s,a=n.tokenizer[o],l=i[o];i[o]=(...c)=>{let p=a.apply(i,c);return p===false&&(p=l.apply(i,c)),p};}r.tokenizer=i;}if(n.hooks){let i=this.defaults.hooks||new S;for(let s in n.hooks){if(!(s in i))throw new Error(`hook '${s}' does not exist`);if(["options","block"].includes(s))continue;let o=s,a=n.hooks[o],l=i[o];S.passThroughHooks.has(s)?i[o]=c=>{if(this.defaults.async&&S.passThroughHooksRespectAsync.has(s))return (async()=>{let g=await a.call(i,c);return l.call(i,g)})();let p=a.call(i,c);return l.call(i,p)}:i[o]=(...c)=>{if(this.defaults.async)return (async()=>{let g=await a.apply(i,c);return g===false&&(g=await l.apply(i,c)),g})();let p=a.apply(i,c);return p===false&&(p=l.apply(i,c)),p};}r.hooks=i;}if(n.walkTokens){let i=this.defaults.walkTokens,s=n.walkTokens;r.walkTokens=function(o){let a=[];return a.push(s.call(this,o)),i&&(a=a.concat(i.call(this,o))),a};}this.defaults={...this.defaults,...r};}),this}setOptions(e){return this.defaults={...this.defaults,...e},this}lexer(e,t){return x.lex(e,t??this.defaults)}parser(e,t){return b.parse(e,t??this.defaults)}parseMarkdown(e){return (n,r)=>{let i={...r},s={...this.defaults,...i},o=this.onError(!!s.silent,!!s.async);if(this.defaults.async===true&&i.async===false)return o(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof n>"u"||n===null)return o(new Error("marked(): input parameter is undefined or null"));if(typeof n!="string")return o(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(n)+", string expected"));if(s.hooks&&(s.hooks.options=s,s.hooks.block=e),s.async)return (async()=>{let a=s.hooks?await s.hooks.preprocess(n):n,c=await(s.hooks?await s.hooks.provideLexer():e?x.lex:x.lexInline)(a,s),p=s.hooks?await s.hooks.processAllTokens(c):c;s.walkTokens&&await Promise.all(this.walkTokens(p,s.walkTokens));let h=await(s.hooks?await s.hooks.provideParser():e?b.parse:b.parseInline)(p,s);return s.hooks?await s.hooks.postprocess(h):h})().catch(o);try{s.hooks&&(n=s.hooks.preprocess(n));let l=(s.hooks?s.hooks.provideLexer():e?x.lex:x.lexInline)(n,s);s.hooks&&(l=s.hooks.processAllTokens(l)),s.walkTokens&&this.walkTokens(l,s.walkTokens);let p=(s.hooks?s.hooks.provideParser():e?b.parse:b.parseInline)(l,s);return s.hooks&&(p=s.hooks.postprocess(p)),p}catch(a){return o(a)}}}onError(e,t){return n=>{if(n.message+=`
|
|
19319
|
-
Please report this to https://github.com/markedjs/marked.`,e){let r="<p>An error occurred:</p><pre>"+w(n.message+"",true)+"</pre>";return t?Promise.resolve(r):r}if(t)return Promise.reject(n);throw n}}};var _=new B;function k(u,e){return _.parse(u,e)}k.options=k.setOptions=function(u){return _.setOptions(u),k.defaults=_.defaults,G(k.defaults),k};k.getDefaults=L;k.defaults=T;k.use=function(...u){return _.use(...u),k.defaults=_.defaults,G(k.defaults),k};k.walkTokens=function(u,e){return _.walkTokens(u,e)};k.parseInline=_.parseInline;k.Parser=b;k.parser=b.parse;k.Renderer=P;k.TextRenderer=$;k.Lexer=x;k.lexer=x.lex;k.Tokenizer=y;k.Hooks=S;k.parse=k;
|
|
21507
|
+
// src/marked.ts
|
|
21508
|
+
var markedInstance = new Marked();
|
|
21509
|
+
function marked(src, opt) {
|
|
21510
|
+
return markedInstance.parse(src, opt);
|
|
21511
|
+
}
|
|
21512
|
+
marked.options = marked.setOptions = function(options2) {
|
|
21513
|
+
markedInstance.setOptions(options2);
|
|
21514
|
+
marked.defaults = markedInstance.defaults;
|
|
21515
|
+
changeDefaults(marked.defaults);
|
|
21516
|
+
return marked;
|
|
21517
|
+
};
|
|
21518
|
+
marked.getDefaults = _getDefaults;
|
|
21519
|
+
marked.defaults = _defaults;
|
|
21520
|
+
marked.use = function(...args) {
|
|
21521
|
+
markedInstance.use(...args);
|
|
21522
|
+
marked.defaults = markedInstance.defaults;
|
|
21523
|
+
changeDefaults(marked.defaults);
|
|
21524
|
+
return marked;
|
|
21525
|
+
};
|
|
21526
|
+
marked.walkTokens = function(tokens, callback) {
|
|
21527
|
+
return markedInstance.walkTokens(tokens, callback);
|
|
21528
|
+
};
|
|
21529
|
+
marked.parseInline = markedInstance.parseInline;
|
|
21530
|
+
marked.Parser = _Parser;
|
|
21531
|
+
marked.parser = _Parser.parse;
|
|
21532
|
+
marked.Renderer = _Renderer;
|
|
21533
|
+
marked.TextRenderer = _TextRenderer;
|
|
21534
|
+
marked.Lexer = _Lexer;
|
|
21535
|
+
marked.lexer = _Lexer.lex;
|
|
21536
|
+
marked.Tokenizer = _Tokenizer;
|
|
21537
|
+
marked.Hooks = _Hooks;
|
|
21538
|
+
marked.parse = marked;
|
|
19320
21539
|
|
|
19321
21540
|
// src/Extension.ts
|
|
19322
21541
|
|
|
@@ -19333,7 +21552,7 @@ function findMarksToClose(activeMarks, currentMarks) {
|
|
|
19333
21552
|
marksToClose.push(markType);
|
|
19334
21553
|
}
|
|
19335
21554
|
});
|
|
19336
|
-
return marksToClose
|
|
21555
|
+
return marksToClose;
|
|
19337
21556
|
}
|
|
19338
21557
|
function findMarksToOpen(activeMarks, currentMarks) {
|
|
19339
21558
|
const marksToOpen = [];
|
|
@@ -19361,7 +21580,7 @@ function findMarksToCloseAtEnd(activeMarks, currentMarks, nextNode, markSetsEqua
|
|
|
19361
21580
|
marksToCloseAtEnd.push(...Array.from(activeMarks.keys()));
|
|
19362
21581
|
}
|
|
19363
21582
|
}
|
|
19364
|
-
return marksToCloseAtEnd
|
|
21583
|
+
return marksToCloseAtEnd;
|
|
19365
21584
|
}
|
|
19366
21585
|
function closeMarksBeforeNode(activeMarks, getMarkClosing) {
|
|
19367
21586
|
let beforeMarkdown = "";
|
|
@@ -19386,6 +21605,14 @@ function reopenMarksAfterNode(marksToReopen, activeMarks, getMarkOpening) {
|
|
|
19386
21605
|
});
|
|
19387
21606
|
return afterMarkdown;
|
|
19388
21607
|
}
|
|
21608
|
+
function isTaskItem(item) {
|
|
21609
|
+
const raw = item.raw || item.text || "";
|
|
21610
|
+
const match = raw.match(/^(\s*)[-+*]\s+\[([ xX])\]\s+/);
|
|
21611
|
+
if (match) {
|
|
21612
|
+
return { isTask: true, checked: match[2].toLowerCase() === "x", indentLevel: match[1].length };
|
|
21613
|
+
}
|
|
21614
|
+
return { isTask: false, indentLevel: 0 };
|
|
21615
|
+
}
|
|
19389
21616
|
function assumeContentType(content, contentType) {
|
|
19390
21617
|
if (typeof content !== "string") {
|
|
19391
21618
|
return "json";
|
|
@@ -19407,7 +21634,7 @@ var MarkdownManager = class {
|
|
|
19407
21634
|
this.extensions = [];
|
|
19408
21635
|
this.lastParseResult = null;
|
|
19409
21636
|
var _a, _b, _c, _d, _e;
|
|
19410
|
-
this.markedInstance = (_a = options == null ? void 0 : options.marked) != null ? _a :
|
|
21637
|
+
this.markedInstance = (_a = options == null ? void 0 : options.marked) != null ? _a : marked;
|
|
19411
21638
|
this.lexer = new this.markedInstance.Lexer();
|
|
19412
21639
|
this.indentStyle = (_c = (_b = options == null ? void 0 : options.indentation) == null ? void 0 : _b.style) != null ? _c : "space";
|
|
19413
21640
|
this.indentSize = (_e = (_d = options == null ? void 0 : options.indentation) == null ? void 0 : _d.size) != null ? _e : 2;
|
|
@@ -19595,6 +21822,127 @@ var MarkdownManager = class {
|
|
|
19595
21822
|
* Parse a single token into Tiptap JSON using the appropriate registered handler.
|
|
19596
21823
|
*/
|
|
19597
21824
|
parseToken(token) {
|
|
21825
|
+
if (!token.type) {
|
|
21826
|
+
return null;
|
|
21827
|
+
}
|
|
21828
|
+
if (token.type === "list") {
|
|
21829
|
+
return this.parseListToken(token);
|
|
21830
|
+
}
|
|
21831
|
+
const handlers = this.getHandlersForToken(token.type);
|
|
21832
|
+
const helpers = this.createParseHelpers();
|
|
21833
|
+
const result = handlers.find((handler) => {
|
|
21834
|
+
if (!handler.parseMarkdown) {
|
|
21835
|
+
return false;
|
|
21836
|
+
}
|
|
21837
|
+
const parseResult = handler.parseMarkdown(token, helpers);
|
|
21838
|
+
const normalized = this.normalizeParseResult(parseResult);
|
|
21839
|
+
if (normalized && (!Array.isArray(normalized) || normalized.length > 0)) {
|
|
21840
|
+
this.lastParseResult = normalized;
|
|
21841
|
+
return true;
|
|
21842
|
+
}
|
|
21843
|
+
return false;
|
|
21844
|
+
});
|
|
21845
|
+
if (result && this.lastParseResult) {
|
|
21846
|
+
const toReturn = this.lastParseResult;
|
|
21847
|
+
this.lastParseResult = null;
|
|
21848
|
+
return toReturn;
|
|
21849
|
+
}
|
|
21850
|
+
return this.parseFallbackToken(token);
|
|
21851
|
+
}
|
|
21852
|
+
/**
|
|
21853
|
+
* Parse a list token, handling mixed bullet and task list items by splitting them into separate lists.
|
|
21854
|
+
* This ensures that consecutive task items and bullet items are grouped and parsed as separate list nodes.
|
|
21855
|
+
*
|
|
21856
|
+
* @param token The list token to parse
|
|
21857
|
+
* @returns Array of parsed list nodes, or null if parsing fails
|
|
21858
|
+
*/
|
|
21859
|
+
parseListToken(token) {
|
|
21860
|
+
if (!token.items || token.items.length === 0) {
|
|
21861
|
+
return this.parseTokenWithHandlers(token);
|
|
21862
|
+
}
|
|
21863
|
+
const hasTask = token.items.some((item) => isTaskItem(item).isTask);
|
|
21864
|
+
const hasNonTask = token.items.some((item) => !isTaskItem(item).isTask);
|
|
21865
|
+
if (!hasTask || !hasNonTask || this.getHandlersForToken("taskList").length === 0) {
|
|
21866
|
+
return this.parseTokenWithHandlers(token);
|
|
21867
|
+
}
|
|
21868
|
+
const groups = [];
|
|
21869
|
+
let currentGroup = [];
|
|
21870
|
+
let currentType = null;
|
|
21871
|
+
for (let i = 0; i < token.items.length; i += 1) {
|
|
21872
|
+
const item = token.items[i];
|
|
21873
|
+
const { isTask, checked, indentLevel } = isTaskItem(item);
|
|
21874
|
+
let processedItem = item;
|
|
21875
|
+
if (isTask) {
|
|
21876
|
+
const raw = item.raw || item.text || "";
|
|
21877
|
+
const lines = raw.split("\n");
|
|
21878
|
+
const firstLineMatch = lines[0].match(/^\s*[-+*]\s+\[([ xX])\]\s+(.*)$/);
|
|
21879
|
+
const mainContent = firstLineMatch ? firstLineMatch[2] : "";
|
|
21880
|
+
let nestedTokens = [];
|
|
21881
|
+
if (lines.length > 1) {
|
|
21882
|
+
const nestedRaw = lines.slice(1).join("\n");
|
|
21883
|
+
if (nestedRaw.trim()) {
|
|
21884
|
+
const nestedLines = lines.slice(1);
|
|
21885
|
+
const nonEmptyLines = nestedLines.filter((line) => line.trim());
|
|
21886
|
+
if (nonEmptyLines.length > 0) {
|
|
21887
|
+
const minIndent = Math.min(...nonEmptyLines.map((line) => line.length - line.trimStart().length));
|
|
21888
|
+
const trimmedLines = nestedLines.map((line) => {
|
|
21889
|
+
if (!line.trim()) {
|
|
21890
|
+
return "";
|
|
21891
|
+
}
|
|
21892
|
+
return line.slice(minIndent);
|
|
21893
|
+
});
|
|
21894
|
+
const nestedContent = trimmedLines.join("\n").trim();
|
|
21895
|
+
if (nestedContent) {
|
|
21896
|
+
nestedTokens = this.markedInstance.lexer(`${nestedContent}
|
|
21897
|
+
`);
|
|
21898
|
+
}
|
|
21899
|
+
}
|
|
21900
|
+
}
|
|
21901
|
+
}
|
|
21902
|
+
processedItem = {
|
|
21903
|
+
type: "taskItem",
|
|
21904
|
+
raw: "",
|
|
21905
|
+
mainContent,
|
|
21906
|
+
indentLevel,
|
|
21907
|
+
checked: checked != null ? checked : false,
|
|
21908
|
+
text: mainContent,
|
|
21909
|
+
tokens: this.lexer.inlineTokens(mainContent),
|
|
21910
|
+
nestedTokens
|
|
21911
|
+
};
|
|
21912
|
+
}
|
|
21913
|
+
const itemType = isTask ? "taskList" : "list";
|
|
21914
|
+
if (currentType !== itemType) {
|
|
21915
|
+
if (currentGroup.length > 0) {
|
|
21916
|
+
groups.push({ type: currentType, items: currentGroup });
|
|
21917
|
+
}
|
|
21918
|
+
currentGroup = [processedItem];
|
|
21919
|
+
currentType = itemType;
|
|
21920
|
+
} else {
|
|
21921
|
+
currentGroup.push(processedItem);
|
|
21922
|
+
}
|
|
21923
|
+
}
|
|
21924
|
+
if (currentGroup.length > 0) {
|
|
21925
|
+
groups.push({ type: currentType, items: currentGroup });
|
|
21926
|
+
}
|
|
21927
|
+
const results = [];
|
|
21928
|
+
for (let i = 0; i < groups.length; i += 1) {
|
|
21929
|
+
const group = groups[i];
|
|
21930
|
+
const subToken = { ...token, type: group.type, items: group.items };
|
|
21931
|
+
const parsed = this.parseToken(subToken);
|
|
21932
|
+
if (parsed) {
|
|
21933
|
+
if (Array.isArray(parsed)) {
|
|
21934
|
+
results.push(...parsed);
|
|
21935
|
+
} else {
|
|
21936
|
+
results.push(parsed);
|
|
21937
|
+
}
|
|
21938
|
+
}
|
|
21939
|
+
}
|
|
21940
|
+
return results.length > 0 ? results : null;
|
|
21941
|
+
}
|
|
21942
|
+
/**
|
|
21943
|
+
* Parse a token using registered handlers (extracted for reuse).
|
|
21944
|
+
*/
|
|
21945
|
+
parseTokenWithHandlers(token) {
|
|
19598
21946
|
if (!token.type) {
|
|
19599
21947
|
return null;
|
|
19600
21948
|
}
|
|
@@ -19620,7 +21968,8 @@ var MarkdownManager = class {
|
|
|
19620
21968
|
return this.parseFallbackToken(token);
|
|
19621
21969
|
}
|
|
19622
21970
|
/**
|
|
19623
|
-
*
|
|
21971
|
+
* Creates helper functions for parsing markdown tokens.
|
|
21972
|
+
* @returns An object containing helper functions for parsing.
|
|
19624
21973
|
*/
|
|
19625
21974
|
createParseHelpers() {
|
|
19626
21975
|
return {
|
|
@@ -19652,18 +22001,75 @@ var MarkdownManager = class {
|
|
|
19652
22001
|
})
|
|
19653
22002
|
};
|
|
19654
22003
|
}
|
|
22004
|
+
/**
|
|
22005
|
+
* Escape special regex characters in a string.
|
|
22006
|
+
*/
|
|
22007
|
+
escapeRegex(str) {
|
|
22008
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
22009
|
+
}
|
|
19655
22010
|
/**
|
|
19656
22011
|
* Parse inline tokens (bold, italic, links, etc.) into text nodes with marks.
|
|
19657
22012
|
* This is the complex part that handles mark nesting and boundaries.
|
|
19658
22013
|
*/
|
|
19659
22014
|
parseInlineTokens(tokens) {
|
|
22015
|
+
var _a, _b, _c, _d;
|
|
19660
22016
|
const result = [];
|
|
19661
|
-
tokens.
|
|
22017
|
+
for (let i = 0; i < tokens.length; i += 1) {
|
|
22018
|
+
const token = tokens[i];
|
|
19662
22019
|
if (token.type === "text") {
|
|
19663
22020
|
result.push({
|
|
19664
22021
|
type: "text",
|
|
19665
22022
|
text: token.text || ""
|
|
19666
22023
|
});
|
|
22024
|
+
} else if (token.type === "html") {
|
|
22025
|
+
const raw = ((_b = (_a = token.raw) != null ? _a : token.text) != null ? _b : "").toString();
|
|
22026
|
+
const isClosing = /^<\/[\s]*[\w-]+/i.test(raw);
|
|
22027
|
+
const openMatch = raw.match(/^<[\s]*([\w-]+)(\s|>|\/|$)/i);
|
|
22028
|
+
if (!isClosing && openMatch && !/\/>$/.test(raw)) {
|
|
22029
|
+
const tagName = openMatch[1];
|
|
22030
|
+
const escapedTagName = this.escapeRegex(tagName);
|
|
22031
|
+
const closingRegex = new RegExp(`^<\\/\\s*${escapedTagName}\\b`, "i");
|
|
22032
|
+
let foundIndex = -1;
|
|
22033
|
+
const parts = [raw];
|
|
22034
|
+
for (let j = i + 1; j < tokens.length; j += 1) {
|
|
22035
|
+
const t = tokens[j];
|
|
22036
|
+
const tRaw = ((_d = (_c = t.raw) != null ? _c : t.text) != null ? _d : "").toString();
|
|
22037
|
+
parts.push(tRaw);
|
|
22038
|
+
if (t.type === "html" && closingRegex.test(tRaw)) {
|
|
22039
|
+
foundIndex = j;
|
|
22040
|
+
break;
|
|
22041
|
+
}
|
|
22042
|
+
}
|
|
22043
|
+
if (foundIndex !== -1) {
|
|
22044
|
+
const mergedRaw = parts.join("");
|
|
22045
|
+
const mergedToken = {
|
|
22046
|
+
type: "html",
|
|
22047
|
+
raw: mergedRaw,
|
|
22048
|
+
text: mergedRaw,
|
|
22049
|
+
block: false
|
|
22050
|
+
};
|
|
22051
|
+
const parsed = this.parseHTMLToken(mergedToken);
|
|
22052
|
+
if (parsed) {
|
|
22053
|
+
const normalized = this.normalizeParseResult(parsed);
|
|
22054
|
+
if (Array.isArray(normalized)) {
|
|
22055
|
+
result.push(...normalized);
|
|
22056
|
+
} else if (normalized) {
|
|
22057
|
+
result.push(normalized);
|
|
22058
|
+
}
|
|
22059
|
+
}
|
|
22060
|
+
i = foundIndex;
|
|
22061
|
+
continue;
|
|
22062
|
+
}
|
|
22063
|
+
}
|
|
22064
|
+
const parsedSingle = this.parseHTMLToken(token);
|
|
22065
|
+
if (parsedSingle) {
|
|
22066
|
+
const normalized = this.normalizeParseResult(parsedSingle);
|
|
22067
|
+
if (Array.isArray(normalized)) {
|
|
22068
|
+
result.push(...normalized);
|
|
22069
|
+
} else if (normalized) {
|
|
22070
|
+
result.push(normalized);
|
|
22071
|
+
}
|
|
22072
|
+
}
|
|
19667
22073
|
} else if (token.type) {
|
|
19668
22074
|
const markHandler = this.getHandlerForToken(token.type);
|
|
19669
22075
|
if (markHandler && markHandler.parseMarkdown) {
|
|
@@ -19684,7 +22090,7 @@ var MarkdownManager = class {
|
|
|
19684
22090
|
result.push(...this.parseInlineTokens(token.tokens));
|
|
19685
22091
|
}
|
|
19686
22092
|
}
|
|
19687
|
-
}
|
|
22093
|
+
}
|
|
19688
22094
|
return result;
|
|
19689
22095
|
}
|
|
19690
22096
|
/**
|
|
@@ -19879,7 +22285,7 @@ var MarkdownManager = class {
|
|
|
19879
22285
|
const marksToReopen = new Map(activeMarks);
|
|
19880
22286
|
const beforeMarkdown = closeMarksBeforeNode(activeMarks, this.getMarkClosing.bind(this));
|
|
19881
22287
|
const nodeContent = this.renderNodeToMarkdown(node, parentNode, i, level);
|
|
19882
|
-
const afterMarkdown = reopenMarksAfterNode(marksToReopen, activeMarks, this.getMarkOpening.bind(this));
|
|
22288
|
+
const afterMarkdown = node.type === "hardBreak" ? "" : reopenMarksAfterNode(marksToReopen, activeMarks, this.getMarkOpening.bind(this));
|
|
19883
22289
|
result.push(beforeMarkdown + nodeContent + afterMarkdown);
|
|
19884
22290
|
}
|
|
19885
22291
|
});
|
|
@@ -20096,14 +22502,22 @@ var Blockquote = Node3.create({
|
|
|
20096
22502
|
if (!node.content) {
|
|
20097
22503
|
return "";
|
|
20098
22504
|
}
|
|
20099
|
-
const
|
|
22505
|
+
const prefix = ">";
|
|
22506
|
+
const result = [];
|
|
20100
22507
|
node.content.forEach((child) => {
|
|
20101
|
-
const
|
|
20102
|
-
const
|
|
20103
|
-
lines.
|
|
22508
|
+
const childContent = h.renderChildren([child]);
|
|
22509
|
+
const lines = childContent.split("\n");
|
|
22510
|
+
const linesWithPrefix = lines.map((line) => {
|
|
22511
|
+
if (line.trim() === "") {
|
|
22512
|
+
return prefix;
|
|
22513
|
+
}
|
|
22514
|
+
return `${prefix} ${line}`;
|
|
22515
|
+
});
|
|
22516
|
+
result.push(linesWithPrefix.join("\n"));
|
|
20104
22517
|
});
|
|
20105
|
-
|
|
20106
|
-
|
|
22518
|
+
return result.join(`
|
|
22519
|
+
${prefix}
|
|
22520
|
+
`);
|
|
20107
22521
|
},
|
|
20108
22522
|
addCommands() {
|
|
20109
22523
|
return {
|
|
@@ -20631,8 +23045,8 @@ var HardBreak = Node3.create({
|
|
|
20631
23045
|
renderText() {
|
|
20632
23046
|
return "\n";
|
|
20633
23047
|
},
|
|
20634
|
-
renderMarkdown: (
|
|
20635
|
-
|
|
23048
|
+
renderMarkdown: () => `
|
|
23049
|
+
`,
|
|
20636
23050
|
parseMarkdown: () => {
|
|
20637
23051
|
return {
|
|
20638
23052
|
type: "hardBreak"
|
|
@@ -25573,6 +27987,9 @@ var TrailingNode = Extension.create({
|
|
|
25573
27987
|
if (!tr.docChanged) {
|
|
25574
27988
|
return value;
|
|
25575
27989
|
}
|
|
27990
|
+
if (tr.getMeta("__uniqueIDTransaction")) {
|
|
27991
|
+
return value;
|
|
27992
|
+
}
|
|
25576
27993
|
const lastNode = tr.doc.lastChild;
|
|
25577
27994
|
return !nodeEqualsType({ node: lastNode, types: disabledNodes });
|
|
25578
27995
|
}
|