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