@syntrologie/runtime-sdk 2.7.0 → 2.8.0-canary.10
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/CAPABILITIES.md +23 -1
- package/dist/{chunk-UUFNSBJN.js → chunk-UH5R7GWH.js} +262 -140
- package/dist/chunk-UH5R7GWH.js.map +7 -0
- package/dist/components/TileIcon.d.ts +2 -2
- package/dist/components/emojiToIcon.d.ts +24 -0
- package/dist/index.js +2271 -54
- package/dist/index.js.map +4 -4
- package/dist/react.js +1 -1
- package/dist/smart-canvas.esm.js +113 -47
- package/dist/smart-canvas.esm.js.map +4 -4
- package/dist/smart-canvas.js +3395 -939
- package/dist/smart-canvas.js.map +4 -4
- package/dist/smart-canvas.min.js +113 -47
- package/dist/smart-canvas.min.js.map +4 -4
- package/dist/version.d.ts +1 -1
- package/package.json +7 -7
- package/schema/canvas-config.schema.json +100 -2
- package/dist/chunk-UUFNSBJN.js.map +0 -7
package/dist/index.js
CHANGED
|
@@ -100,7 +100,7 @@ import {
|
|
|
100
100
|
validateAction,
|
|
101
101
|
validateActions,
|
|
102
102
|
widgetRegistry
|
|
103
|
-
} from "./chunk-
|
|
103
|
+
} from "./chunk-UH5R7GWH.js";
|
|
104
104
|
import {
|
|
105
105
|
AddClassZ,
|
|
106
106
|
AnchorIdZ,
|
|
@@ -160,6 +160,7 @@ import {
|
|
|
160
160
|
StateEqualsConditionZ,
|
|
161
161
|
TriggerWhenZ,
|
|
162
162
|
ViewportConditionZ,
|
|
163
|
+
__publicField,
|
|
163
164
|
decisionSchemas,
|
|
164
165
|
validateActivationConfig,
|
|
165
166
|
validateCondition,
|
|
@@ -256,8 +257,8 @@ var nextId = 0;
|
|
|
256
257
|
function generateId() {
|
|
257
258
|
return `msg-${Date.now()}-${++nextId}`;
|
|
258
259
|
}
|
|
259
|
-
function useChat(
|
|
260
|
-
const { backendUrl, tileId, runtime: runtime7, greeting, maxHistory = 20, mlflowRunId, config } =
|
|
260
|
+
function useChat(options2) {
|
|
261
|
+
const { backendUrl, tileId, runtime: runtime7, greeting, maxHistory = 20, mlflowRunId, config } = options2;
|
|
261
262
|
const [messages, setMessages] = useState(() => {
|
|
262
263
|
if (greeting) {
|
|
263
264
|
return [
|
|
@@ -275,7 +276,7 @@ function useChat(options) {
|
|
|
275
276
|
const [error, setError] = useState(null);
|
|
276
277
|
const batchHandleRef = useRef(null);
|
|
277
278
|
const send = useCallback(async (text) => {
|
|
278
|
-
var
|
|
279
|
+
var _a2;
|
|
279
280
|
const trimmed = text.trim();
|
|
280
281
|
if (!trimmed)
|
|
281
282
|
return;
|
|
@@ -309,7 +310,7 @@ function useChat(options) {
|
|
|
309
310
|
};
|
|
310
311
|
setMessages((prev) => [...prev, assistantMessage]);
|
|
311
312
|
if (actions.length > 0) {
|
|
312
|
-
if ((
|
|
313
|
+
if ((_a2 = batchHandleRef.current) == null ? void 0 : _a2.isApplied()) {
|
|
313
314
|
await batchHandleRef.current.revertAll();
|
|
314
315
|
}
|
|
315
316
|
batchHandleRef.current = await runtime7.actions.applyBatch(actions);
|
|
@@ -327,10 +328,10 @@ function useChat(options) {
|
|
|
327
328
|
}
|
|
328
329
|
}, [backendUrl, messages, maxHistory, mlflowRunId, config, runtime7, tileId]);
|
|
329
330
|
const clearMessages = useCallback(() => {
|
|
330
|
-
var
|
|
331
|
+
var _a2;
|
|
331
332
|
setMessages([]);
|
|
332
333
|
setError(null);
|
|
333
|
-
if ((
|
|
334
|
+
if ((_a2 = batchHandleRef.current) == null ? void 0 : _a2.isApplied()) {
|
|
334
335
|
batchHandleRef.current.revertAll();
|
|
335
336
|
batchHandleRef.current = null;
|
|
336
337
|
}
|
|
@@ -538,7 +539,7 @@ function resolveItem(store, itemId, itemQuestion) {
|
|
|
538
539
|
throw new Error("FAQ item not found");
|
|
539
540
|
}
|
|
540
541
|
async function executeScrollToFaq(action, context, store) {
|
|
541
|
-
var
|
|
542
|
+
var _a2;
|
|
542
543
|
const item = resolveItem(store, action.itemId, action.itemQuestion);
|
|
543
544
|
const { id } = item.config;
|
|
544
545
|
if (action.expand !== false) {
|
|
@@ -547,7 +548,7 @@ async function executeScrollToFaq(action, context, store) {
|
|
|
547
548
|
const el = document.querySelector(`[data-faq-item-id="${id}"]`);
|
|
548
549
|
if (el) {
|
|
549
550
|
el.scrollIntoView({
|
|
550
|
-
behavior: (
|
|
551
|
+
behavior: (_a2 = action.behavior) != null ? _a2 : "smooth"
|
|
551
552
|
});
|
|
552
553
|
}
|
|
553
554
|
context.publishEvent("faq:scroll_to", { itemId: id });
|
|
@@ -557,10 +558,10 @@ async function executeScrollToFaq(action, context, store) {
|
|
|
557
558
|
};
|
|
558
559
|
}
|
|
559
560
|
async function executeToggleFaqItem(action, context, store) {
|
|
560
|
-
var
|
|
561
|
+
var _a2;
|
|
561
562
|
const item = resolveItem(store, action.itemId, action.itemQuestion);
|
|
562
563
|
const { id } = item.config;
|
|
563
|
-
const desiredState = (
|
|
564
|
+
const desiredState = (_a2 = action.state) != null ? _a2 : "toggle";
|
|
564
565
|
let newState;
|
|
565
566
|
switch (desiredState) {
|
|
566
567
|
case "open":
|
|
@@ -585,10 +586,10 @@ async function executeToggleFaqItem(action, context, store) {
|
|
|
585
586
|
};
|
|
586
587
|
}
|
|
587
588
|
async function executeUpdateFaq(action, context, store) {
|
|
588
|
-
var
|
|
589
|
+
var _a2, _b, _c;
|
|
589
590
|
switch (action.operation) {
|
|
590
591
|
case "add": {
|
|
591
|
-
const items = (
|
|
592
|
+
const items = (_a2 = action.items) != null ? _a2 : [];
|
|
592
593
|
const position = action.position === "prepend" ? "prepend" : "append";
|
|
593
594
|
store.addItems(items, position);
|
|
594
595
|
break;
|
|
@@ -629,8 +630,2157 @@ var executorDefinitions = [
|
|
|
629
630
|
|
|
630
631
|
// ../adaptives/adaptive-faq/dist/FAQWidget.js
|
|
631
632
|
import { jsx as _jsx2, jsxs as _jsxs2 } from "react/jsx-runtime";
|
|
633
|
+
|
|
634
|
+
// ../../node_modules/marked/lib/marked.esm.js
|
|
635
|
+
function _getDefaults() {
|
|
636
|
+
return {
|
|
637
|
+
async: false,
|
|
638
|
+
breaks: false,
|
|
639
|
+
extensions: null,
|
|
640
|
+
gfm: true,
|
|
641
|
+
hooks: null,
|
|
642
|
+
pedantic: false,
|
|
643
|
+
renderer: null,
|
|
644
|
+
silent: false,
|
|
645
|
+
tokenizer: null,
|
|
646
|
+
walkTokens: null
|
|
647
|
+
};
|
|
648
|
+
}
|
|
649
|
+
var _defaults = _getDefaults();
|
|
650
|
+
function changeDefaults(newDefaults) {
|
|
651
|
+
_defaults = newDefaults;
|
|
652
|
+
}
|
|
653
|
+
var noopTest = { exec: () => null };
|
|
654
|
+
function edit(regex, opt = "") {
|
|
655
|
+
let source = typeof regex === "string" ? regex : regex.source;
|
|
656
|
+
const obj = {
|
|
657
|
+
replace: (name, val) => {
|
|
658
|
+
let valSource = typeof val === "string" ? val : val.source;
|
|
659
|
+
valSource = valSource.replace(other.caret, "$1");
|
|
660
|
+
source = source.replace(name, valSource);
|
|
661
|
+
return obj;
|
|
662
|
+
},
|
|
663
|
+
getRegex: () => {
|
|
664
|
+
return new RegExp(source, opt);
|
|
665
|
+
}
|
|
666
|
+
};
|
|
667
|
+
return obj;
|
|
668
|
+
}
|
|
669
|
+
var other = {
|
|
670
|
+
codeRemoveIndent: /^(?: {1,4}| {0,3}\t)/gm,
|
|
671
|
+
outputLinkReplace: /\\([\[\]])/g,
|
|
672
|
+
indentCodeCompensation: /^(\s+)(?:```)/,
|
|
673
|
+
beginningSpace: /^\s+/,
|
|
674
|
+
endingHash: /#$/,
|
|
675
|
+
startingSpaceChar: /^ /,
|
|
676
|
+
endingSpaceChar: / $/,
|
|
677
|
+
nonSpaceChar: /[^ ]/,
|
|
678
|
+
newLineCharGlobal: /\n/g,
|
|
679
|
+
tabCharGlobal: /\t/g,
|
|
680
|
+
multipleSpaceGlobal: /\s+/g,
|
|
681
|
+
blankLine: /^[ \t]*$/,
|
|
682
|
+
doubleBlankLine: /\n[ \t]*\n[ \t]*$/,
|
|
683
|
+
blockquoteStart: /^ {0,3}>/,
|
|
684
|
+
blockquoteSetextReplace: /\n {0,3}((?:=+|-+) *)(?=\n|$)/g,
|
|
685
|
+
blockquoteSetextReplace2: /^ {0,3}>[ \t]?/gm,
|
|
686
|
+
listReplaceTabs: /^\t+/,
|
|
687
|
+
listReplaceNesting: /^ {1,4}(?=( {4})*[^ ])/g,
|
|
688
|
+
listIsTask: /^\[[ xX]\] /,
|
|
689
|
+
listReplaceTask: /^\[[ xX]\] +/,
|
|
690
|
+
anyLine: /\n.*\n/,
|
|
691
|
+
hrefBrackets: /^<(.*)>$/,
|
|
692
|
+
tableDelimiter: /[:|]/,
|
|
693
|
+
tableAlignChars: /^\||\| *$/g,
|
|
694
|
+
tableRowBlankLine: /\n[ \t]*$/,
|
|
695
|
+
tableAlignRight: /^ *-+: *$/,
|
|
696
|
+
tableAlignCenter: /^ *:-+: *$/,
|
|
697
|
+
tableAlignLeft: /^ *:-+ *$/,
|
|
698
|
+
startATag: /^<a /i,
|
|
699
|
+
endATag: /^<\/a>/i,
|
|
700
|
+
startPreScriptTag: /^<(pre|code|kbd|script)(\s|>)/i,
|
|
701
|
+
endPreScriptTag: /^<\/(pre|code|kbd|script)(\s|>)/i,
|
|
702
|
+
startAngleBracket: /^</,
|
|
703
|
+
endAngleBracket: />$/,
|
|
704
|
+
pedanticHrefTitle: /^([^'"]*[^\s])\s+(['"])(.*)\2/,
|
|
705
|
+
unicodeAlphaNumeric: /[\p{L}\p{N}]/u,
|
|
706
|
+
escapeTest: /[&<>"']/,
|
|
707
|
+
escapeReplace: /[&<>"']/g,
|
|
708
|
+
escapeTestNoEncode: /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,
|
|
709
|
+
escapeReplaceNoEncode: /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,
|
|
710
|
+
unescapeTest: /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig,
|
|
711
|
+
caret: /(^|[^\[])\^/g,
|
|
712
|
+
percentDecode: /%25/g,
|
|
713
|
+
findPipe: /\|/g,
|
|
714
|
+
splitPipe: / \|/,
|
|
715
|
+
slashPipe: /\\\|/g,
|
|
716
|
+
carriageReturn: /\r\n|\r/g,
|
|
717
|
+
spaceLine: /^ +$/gm,
|
|
718
|
+
notSpaceStart: /^\S*/,
|
|
719
|
+
endingNewline: /\n$/,
|
|
720
|
+
listItemRegex: (bull) => new RegExp(`^( {0,3}${bull})((?:[ ][^\\n]*)?(?:\\n|$))`),
|
|
721
|
+
nextBulletRegex: (indent) => new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),
|
|
722
|
+
hrRegex: (indent) => new RegExp(`^ {0,${Math.min(3, indent - 1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),
|
|
723
|
+
fencesBeginRegex: (indent) => new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:\`\`\`|~~~)`),
|
|
724
|
+
headingBeginRegex: (indent) => new RegExp(`^ {0,${Math.min(3, indent - 1)}}#`),
|
|
725
|
+
htmlBeginRegex: (indent) => new RegExp(`^ {0,${Math.min(3, indent - 1)}}<(?:[a-z].*>|!--)`, "i")
|
|
726
|
+
};
|
|
727
|
+
var newline = /^(?:[ \t]*(?:\n|$))+/;
|
|
728
|
+
var blockCode = /^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/;
|
|
729
|
+
var fences = /^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/;
|
|
730
|
+
var hr = /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/;
|
|
731
|
+
var heading = /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/;
|
|
732
|
+
var bullet = /(?:[*+-]|\d{1,9}[.)])/;
|
|
733
|
+
var lheadingCore = /^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/;
|
|
734
|
+
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();
|
|
735
|
+
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();
|
|
736
|
+
var _paragraph = /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/;
|
|
737
|
+
var blockText = /^[^\n]+/;
|
|
738
|
+
var _blockLabel = /(?!\s*\])(?:\\.|[^\[\]\\])+/;
|
|
739
|
+
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();
|
|
740
|
+
var list = edit(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g, bullet).getRegex();
|
|
741
|
+
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";
|
|
742
|
+
var _comment = /<!--(?:-?>|[\s\S]*?(?:-->|$))/;
|
|
743
|
+
var html = edit(
|
|
744
|
+
"^ {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|$))",
|
|
745
|
+
"i"
|
|
746
|
+
).replace("comment", _comment).replace("tag", _tag).replace("attribute", / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex();
|
|
747
|
+
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();
|
|
748
|
+
var blockquote = edit(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph", paragraph).getRegex();
|
|
749
|
+
var blockNormal = {
|
|
750
|
+
blockquote,
|
|
751
|
+
code: blockCode,
|
|
752
|
+
def,
|
|
753
|
+
fences,
|
|
754
|
+
heading,
|
|
755
|
+
hr,
|
|
756
|
+
html,
|
|
757
|
+
lheading,
|
|
758
|
+
list,
|
|
759
|
+
newline,
|
|
760
|
+
paragraph,
|
|
761
|
+
table: noopTest,
|
|
762
|
+
text: blockText
|
|
763
|
+
};
|
|
764
|
+
var gfmTable = edit(
|
|
765
|
+
"^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)"
|
|
766
|
+
).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();
|
|
767
|
+
var blockGfm = {
|
|
768
|
+
...blockNormal,
|
|
769
|
+
lheading: lheadingGfm,
|
|
770
|
+
table: gfmTable,
|
|
771
|
+
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()
|
|
772
|
+
};
|
|
773
|
+
var blockPedantic = {
|
|
774
|
+
...blockNormal,
|
|
775
|
+
html: edit(
|
|
776
|
+
`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`
|
|
777
|
+
).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(),
|
|
778
|
+
def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,
|
|
779
|
+
heading: /^(#{1,6})(.*)(?:\n+|$)/,
|
|
780
|
+
fences: noopTest,
|
|
781
|
+
// fences not supported
|
|
782
|
+
lheading: /^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,
|
|
783
|
+
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()
|
|
784
|
+
};
|
|
785
|
+
var escape = /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/;
|
|
786
|
+
var inlineCode = /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/;
|
|
787
|
+
var br = /^( {2,}|\\)\n(?!\s*$)/;
|
|
788
|
+
var inlineText = /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/;
|
|
789
|
+
var _punctuation = /[\p{P}\p{S}]/u;
|
|
790
|
+
var _punctuationOrSpace = /[\s\p{P}\p{S}]/u;
|
|
791
|
+
var _notPunctuationOrSpace = /[^\s\p{P}\p{S}]/u;
|
|
792
|
+
var punctuation = edit(/^((?![*_])punctSpace)/, "u").replace(/punctSpace/g, _punctuationOrSpace).getRegex();
|
|
793
|
+
var _punctuationGfmStrongEm = /(?!~)[\p{P}\p{S}]/u;
|
|
794
|
+
var _punctuationOrSpaceGfmStrongEm = /(?!~)[\s\p{P}\p{S}]/u;
|
|
795
|
+
var _notPunctuationOrSpaceGfmStrongEm = /(?:[^\s\p{P}\p{S}]|~)/u;
|
|
796
|
+
var blockSkip = /\[[^[\]]*?\]\((?:\\.|[^\\\(\)]|\((?:\\.|[^\\\(\)])*\))*\)|`[^`]*?`|<[^<>]*?>/g;
|
|
797
|
+
var emStrongLDelimCore = /^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/;
|
|
798
|
+
var emStrongLDelim = edit(emStrongLDelimCore, "u").replace(/punct/g, _punctuation).getRegex();
|
|
799
|
+
var emStrongLDelimGfm = edit(emStrongLDelimCore, "u").replace(/punct/g, _punctuationGfmStrongEm).getRegex();
|
|
800
|
+
var emStrongRDelimAstCore = "^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)";
|
|
801
|
+
var emStrongRDelimAst = edit(emStrongRDelimAstCore, "gu").replace(/notPunctSpace/g, _notPunctuationOrSpace).replace(/punctSpace/g, _punctuationOrSpace).replace(/punct/g, _punctuation).getRegex();
|
|
802
|
+
var emStrongRDelimAstGfm = edit(emStrongRDelimAstCore, "gu").replace(/notPunctSpace/g, _notPunctuationOrSpaceGfmStrongEm).replace(/punctSpace/g, _punctuationOrSpaceGfmStrongEm).replace(/punct/g, _punctuationGfmStrongEm).getRegex();
|
|
803
|
+
var emStrongRDelimUnd = edit(
|
|
804
|
+
"^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)",
|
|
805
|
+
"gu"
|
|
806
|
+
).replace(/notPunctSpace/g, _notPunctuationOrSpace).replace(/punctSpace/g, _punctuationOrSpace).replace(/punct/g, _punctuation).getRegex();
|
|
807
|
+
var anyPunctuation = edit(/\\(punct)/, "gu").replace(/punct/g, _punctuation).getRegex();
|
|
808
|
+
var autolink = 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();
|
|
809
|
+
var _inlineComment = edit(_comment).replace("(?:-->|$)", "-->").getRegex();
|
|
810
|
+
var tag = edit(
|
|
811
|
+
"^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>"
|
|
812
|
+
).replace("comment", _inlineComment).replace("attribute", /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex();
|
|
813
|
+
var _inlineLabel = /(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/;
|
|
814
|
+
var link = edit(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label", _inlineLabel).replace("href", /<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title", /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex();
|
|
815
|
+
var reflink = edit(/^!?\[(label)\]\[(ref)\]/).replace("label", _inlineLabel).replace("ref", _blockLabel).getRegex();
|
|
816
|
+
var nolink = edit(/^!?\[(ref)\](?:\[\])?/).replace("ref", _blockLabel).getRegex();
|
|
817
|
+
var reflinkSearch = edit("reflink|nolink(?!\\()", "g").replace("reflink", reflink).replace("nolink", nolink).getRegex();
|
|
818
|
+
var inlineNormal = {
|
|
819
|
+
_backpedal: noopTest,
|
|
820
|
+
// only used for GFM url
|
|
821
|
+
anyPunctuation,
|
|
822
|
+
autolink,
|
|
823
|
+
blockSkip,
|
|
824
|
+
br,
|
|
825
|
+
code: inlineCode,
|
|
826
|
+
del: noopTest,
|
|
827
|
+
emStrongLDelim,
|
|
828
|
+
emStrongRDelimAst,
|
|
829
|
+
emStrongRDelimUnd,
|
|
830
|
+
escape,
|
|
831
|
+
link,
|
|
832
|
+
nolink,
|
|
833
|
+
punctuation,
|
|
834
|
+
reflink,
|
|
835
|
+
reflinkSearch,
|
|
836
|
+
tag,
|
|
837
|
+
text: inlineText,
|
|
838
|
+
url: noopTest
|
|
839
|
+
};
|
|
840
|
+
var inlinePedantic = {
|
|
841
|
+
...inlineNormal,
|
|
842
|
+
link: edit(/^!?\[(label)\]\((.*?)\)/).replace("label", _inlineLabel).getRegex(),
|
|
843
|
+
reflink: edit(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label", _inlineLabel).getRegex()
|
|
844
|
+
};
|
|
845
|
+
var inlineGfm = {
|
|
846
|
+
...inlineNormal,
|
|
847
|
+
emStrongRDelimAst: emStrongRDelimAstGfm,
|
|
848
|
+
emStrongLDelim: emStrongLDelimGfm,
|
|
849
|
+
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(),
|
|
850
|
+
_backpedal: /(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,
|
|
851
|
+
del: /^(~~?)(?=[^\s~])((?:\\.|[^\\])*?(?:\\.|[^\s~\\]))\1(?=[^~]|$)/,
|
|
852
|
+
text: /^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/
|
|
853
|
+
};
|
|
854
|
+
var inlineBreaks = {
|
|
855
|
+
...inlineGfm,
|
|
856
|
+
br: edit(br).replace("{2,}", "*").getRegex(),
|
|
857
|
+
text: edit(inlineGfm.text).replace("\\b_", "\\b_| {2,}\\n").replace(/\{2,\}/g, "*").getRegex()
|
|
858
|
+
};
|
|
859
|
+
var block = {
|
|
860
|
+
normal: blockNormal,
|
|
861
|
+
gfm: blockGfm,
|
|
862
|
+
pedantic: blockPedantic
|
|
863
|
+
};
|
|
864
|
+
var inline = {
|
|
865
|
+
normal: inlineNormal,
|
|
866
|
+
gfm: inlineGfm,
|
|
867
|
+
breaks: inlineBreaks,
|
|
868
|
+
pedantic: inlinePedantic
|
|
869
|
+
};
|
|
870
|
+
var escapeReplacements = {
|
|
871
|
+
"&": "&",
|
|
872
|
+
"<": "<",
|
|
873
|
+
">": ">",
|
|
874
|
+
'"': """,
|
|
875
|
+
"'": "'"
|
|
876
|
+
};
|
|
877
|
+
var getEscapeReplacement = (ch) => escapeReplacements[ch];
|
|
878
|
+
function escape2(html2, encode) {
|
|
879
|
+
if (encode) {
|
|
880
|
+
if (other.escapeTest.test(html2)) {
|
|
881
|
+
return html2.replace(other.escapeReplace, getEscapeReplacement);
|
|
882
|
+
}
|
|
883
|
+
} else {
|
|
884
|
+
if (other.escapeTestNoEncode.test(html2)) {
|
|
885
|
+
return html2.replace(other.escapeReplaceNoEncode, getEscapeReplacement);
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
return html2;
|
|
889
|
+
}
|
|
890
|
+
function cleanUrl(href) {
|
|
891
|
+
try {
|
|
892
|
+
href = encodeURI(href).replace(other.percentDecode, "%");
|
|
893
|
+
} catch {
|
|
894
|
+
return null;
|
|
895
|
+
}
|
|
896
|
+
return href;
|
|
897
|
+
}
|
|
898
|
+
function splitCells(tableRow, count) {
|
|
899
|
+
var _a2;
|
|
900
|
+
const row = tableRow.replace(other.findPipe, (match, offset, str) => {
|
|
901
|
+
let escaped = false;
|
|
902
|
+
let curr = offset;
|
|
903
|
+
while (--curr >= 0 && str[curr] === "\\") escaped = !escaped;
|
|
904
|
+
if (escaped) {
|
|
905
|
+
return "|";
|
|
906
|
+
} else {
|
|
907
|
+
return " |";
|
|
908
|
+
}
|
|
909
|
+
}), cells = row.split(other.splitPipe);
|
|
910
|
+
let i = 0;
|
|
911
|
+
if (!cells[0].trim()) {
|
|
912
|
+
cells.shift();
|
|
913
|
+
}
|
|
914
|
+
if (cells.length > 0 && !((_a2 = cells.at(-1)) == null ? void 0 : _a2.trim())) {
|
|
915
|
+
cells.pop();
|
|
916
|
+
}
|
|
917
|
+
if (count) {
|
|
918
|
+
if (cells.length > count) {
|
|
919
|
+
cells.splice(count);
|
|
920
|
+
} else {
|
|
921
|
+
while (cells.length < count) cells.push("");
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
for (; i < cells.length; i++) {
|
|
925
|
+
cells[i] = cells[i].trim().replace(other.slashPipe, "|");
|
|
926
|
+
}
|
|
927
|
+
return cells;
|
|
928
|
+
}
|
|
929
|
+
function rtrim(str, c, invert) {
|
|
930
|
+
const l = str.length;
|
|
931
|
+
if (l === 0) {
|
|
932
|
+
return "";
|
|
933
|
+
}
|
|
934
|
+
let suffLen = 0;
|
|
935
|
+
while (suffLen < l) {
|
|
936
|
+
const currChar = str.charAt(l - suffLen - 1);
|
|
937
|
+
if (currChar === c && !invert) {
|
|
938
|
+
suffLen++;
|
|
939
|
+
} else if (currChar !== c && invert) {
|
|
940
|
+
suffLen++;
|
|
941
|
+
} else {
|
|
942
|
+
break;
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
return str.slice(0, l - suffLen);
|
|
946
|
+
}
|
|
947
|
+
function findClosingBracket(str, b) {
|
|
948
|
+
if (str.indexOf(b[1]) === -1) {
|
|
949
|
+
return -1;
|
|
950
|
+
}
|
|
951
|
+
let level = 0;
|
|
952
|
+
for (let i = 0; i < str.length; i++) {
|
|
953
|
+
if (str[i] === "\\") {
|
|
954
|
+
i++;
|
|
955
|
+
} else if (str[i] === b[0]) {
|
|
956
|
+
level++;
|
|
957
|
+
} else if (str[i] === b[1]) {
|
|
958
|
+
level--;
|
|
959
|
+
if (level < 0) {
|
|
960
|
+
return i;
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
if (level > 0) {
|
|
965
|
+
return -2;
|
|
966
|
+
}
|
|
967
|
+
return -1;
|
|
968
|
+
}
|
|
969
|
+
function outputLink(cap, link2, raw, lexer2, rules) {
|
|
970
|
+
const href = link2.href;
|
|
971
|
+
const title = link2.title || null;
|
|
972
|
+
const text = cap[1].replace(rules.other.outputLinkReplace, "$1");
|
|
973
|
+
lexer2.state.inLink = true;
|
|
974
|
+
const token = {
|
|
975
|
+
type: cap[0].charAt(0) === "!" ? "image" : "link",
|
|
976
|
+
raw,
|
|
977
|
+
href,
|
|
978
|
+
title,
|
|
979
|
+
text,
|
|
980
|
+
tokens: lexer2.inlineTokens(text)
|
|
981
|
+
};
|
|
982
|
+
lexer2.state.inLink = false;
|
|
983
|
+
return token;
|
|
984
|
+
}
|
|
985
|
+
function indentCodeCompensation(raw, text, rules) {
|
|
986
|
+
const matchIndentToCode = raw.match(rules.other.indentCodeCompensation);
|
|
987
|
+
if (matchIndentToCode === null) {
|
|
988
|
+
return text;
|
|
989
|
+
}
|
|
990
|
+
const indentToCode = matchIndentToCode[1];
|
|
991
|
+
return text.split("\n").map((node) => {
|
|
992
|
+
const matchIndentInNode = node.match(rules.other.beginningSpace);
|
|
993
|
+
if (matchIndentInNode === null) {
|
|
994
|
+
return node;
|
|
995
|
+
}
|
|
996
|
+
const [indentInNode] = matchIndentInNode;
|
|
997
|
+
if (indentInNode.length >= indentToCode.length) {
|
|
998
|
+
return node.slice(indentToCode.length);
|
|
999
|
+
}
|
|
1000
|
+
return node;
|
|
1001
|
+
}).join("\n");
|
|
1002
|
+
}
|
|
1003
|
+
var _Tokenizer = class {
|
|
1004
|
+
// set by the lexer
|
|
1005
|
+
constructor(options2) {
|
|
1006
|
+
__publicField(this, "options");
|
|
1007
|
+
__publicField(this, "rules");
|
|
1008
|
+
// set by the lexer
|
|
1009
|
+
__publicField(this, "lexer");
|
|
1010
|
+
this.options = options2 || _defaults;
|
|
1011
|
+
}
|
|
1012
|
+
space(src) {
|
|
1013
|
+
const cap = this.rules.block.newline.exec(src);
|
|
1014
|
+
if (cap && cap[0].length > 0) {
|
|
1015
|
+
return {
|
|
1016
|
+
type: "space",
|
|
1017
|
+
raw: cap[0]
|
|
1018
|
+
};
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
code(src) {
|
|
1022
|
+
const cap = this.rules.block.code.exec(src);
|
|
1023
|
+
if (cap) {
|
|
1024
|
+
const text = cap[0].replace(this.rules.other.codeRemoveIndent, "");
|
|
1025
|
+
return {
|
|
1026
|
+
type: "code",
|
|
1027
|
+
raw: cap[0],
|
|
1028
|
+
codeBlockStyle: "indented",
|
|
1029
|
+
text: !this.options.pedantic ? rtrim(text, "\n") : text
|
|
1030
|
+
};
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
fences(src) {
|
|
1034
|
+
const cap = this.rules.block.fences.exec(src);
|
|
1035
|
+
if (cap) {
|
|
1036
|
+
const raw = cap[0];
|
|
1037
|
+
const text = indentCodeCompensation(raw, cap[3] || "", this.rules);
|
|
1038
|
+
return {
|
|
1039
|
+
type: "code",
|
|
1040
|
+
raw,
|
|
1041
|
+
lang: cap[2] ? cap[2].trim().replace(this.rules.inline.anyPunctuation, "$1") : cap[2],
|
|
1042
|
+
text
|
|
1043
|
+
};
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
heading(src) {
|
|
1047
|
+
const cap = this.rules.block.heading.exec(src);
|
|
1048
|
+
if (cap) {
|
|
1049
|
+
let text = cap[2].trim();
|
|
1050
|
+
if (this.rules.other.endingHash.test(text)) {
|
|
1051
|
+
const trimmed = rtrim(text, "#");
|
|
1052
|
+
if (this.options.pedantic) {
|
|
1053
|
+
text = trimmed.trim();
|
|
1054
|
+
} else if (!trimmed || this.rules.other.endingSpaceChar.test(trimmed)) {
|
|
1055
|
+
text = trimmed.trim();
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
return {
|
|
1059
|
+
type: "heading",
|
|
1060
|
+
raw: cap[0],
|
|
1061
|
+
depth: cap[1].length,
|
|
1062
|
+
text,
|
|
1063
|
+
tokens: this.lexer.inline(text)
|
|
1064
|
+
};
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
hr(src) {
|
|
1068
|
+
const cap = this.rules.block.hr.exec(src);
|
|
1069
|
+
if (cap) {
|
|
1070
|
+
return {
|
|
1071
|
+
type: "hr",
|
|
1072
|
+
raw: rtrim(cap[0], "\n")
|
|
1073
|
+
};
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
blockquote(src) {
|
|
1077
|
+
const cap = this.rules.block.blockquote.exec(src);
|
|
1078
|
+
if (cap) {
|
|
1079
|
+
let lines = rtrim(cap[0], "\n").split("\n");
|
|
1080
|
+
let raw = "";
|
|
1081
|
+
let text = "";
|
|
1082
|
+
const tokens = [];
|
|
1083
|
+
while (lines.length > 0) {
|
|
1084
|
+
let inBlockquote = false;
|
|
1085
|
+
const currentLines = [];
|
|
1086
|
+
let i;
|
|
1087
|
+
for (i = 0; i < lines.length; i++) {
|
|
1088
|
+
if (this.rules.other.blockquoteStart.test(lines[i])) {
|
|
1089
|
+
currentLines.push(lines[i]);
|
|
1090
|
+
inBlockquote = true;
|
|
1091
|
+
} else if (!inBlockquote) {
|
|
1092
|
+
currentLines.push(lines[i]);
|
|
1093
|
+
} else {
|
|
1094
|
+
break;
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
lines = lines.slice(i);
|
|
1098
|
+
const currentRaw = currentLines.join("\n");
|
|
1099
|
+
const currentText = currentRaw.replace(this.rules.other.blockquoteSetextReplace, "\n $1").replace(this.rules.other.blockquoteSetextReplace2, "");
|
|
1100
|
+
raw = raw ? `${raw}
|
|
1101
|
+
${currentRaw}` : currentRaw;
|
|
1102
|
+
text = text ? `${text}
|
|
1103
|
+
${currentText}` : currentText;
|
|
1104
|
+
const top = this.lexer.state.top;
|
|
1105
|
+
this.lexer.state.top = true;
|
|
1106
|
+
this.lexer.blockTokens(currentText, tokens, true);
|
|
1107
|
+
this.lexer.state.top = top;
|
|
1108
|
+
if (lines.length === 0) {
|
|
1109
|
+
break;
|
|
1110
|
+
}
|
|
1111
|
+
const lastToken = tokens.at(-1);
|
|
1112
|
+
if ((lastToken == null ? void 0 : lastToken.type) === "code") {
|
|
1113
|
+
break;
|
|
1114
|
+
} else if ((lastToken == null ? void 0 : lastToken.type) === "blockquote") {
|
|
1115
|
+
const oldToken = lastToken;
|
|
1116
|
+
const newText = oldToken.raw + "\n" + lines.join("\n");
|
|
1117
|
+
const newToken = this.blockquote(newText);
|
|
1118
|
+
tokens[tokens.length - 1] = newToken;
|
|
1119
|
+
raw = raw.substring(0, raw.length - oldToken.raw.length) + newToken.raw;
|
|
1120
|
+
text = text.substring(0, text.length - oldToken.text.length) + newToken.text;
|
|
1121
|
+
break;
|
|
1122
|
+
} else if ((lastToken == null ? void 0 : lastToken.type) === "list") {
|
|
1123
|
+
const oldToken = lastToken;
|
|
1124
|
+
const newText = oldToken.raw + "\n" + lines.join("\n");
|
|
1125
|
+
const newToken = this.list(newText);
|
|
1126
|
+
tokens[tokens.length - 1] = newToken;
|
|
1127
|
+
raw = raw.substring(0, raw.length - lastToken.raw.length) + newToken.raw;
|
|
1128
|
+
text = text.substring(0, text.length - oldToken.raw.length) + newToken.raw;
|
|
1129
|
+
lines = newText.substring(tokens.at(-1).raw.length).split("\n");
|
|
1130
|
+
continue;
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
return {
|
|
1134
|
+
type: "blockquote",
|
|
1135
|
+
raw,
|
|
1136
|
+
tokens,
|
|
1137
|
+
text
|
|
1138
|
+
};
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
list(src) {
|
|
1142
|
+
let cap = this.rules.block.list.exec(src);
|
|
1143
|
+
if (cap) {
|
|
1144
|
+
let bull = cap[1].trim();
|
|
1145
|
+
const isordered = bull.length > 1;
|
|
1146
|
+
const list2 = {
|
|
1147
|
+
type: "list",
|
|
1148
|
+
raw: "",
|
|
1149
|
+
ordered: isordered,
|
|
1150
|
+
start: isordered ? +bull.slice(0, -1) : "",
|
|
1151
|
+
loose: false,
|
|
1152
|
+
items: []
|
|
1153
|
+
};
|
|
1154
|
+
bull = isordered ? `\\d{1,9}\\${bull.slice(-1)}` : `\\${bull}`;
|
|
1155
|
+
if (this.options.pedantic) {
|
|
1156
|
+
bull = isordered ? bull : "[*+-]";
|
|
1157
|
+
}
|
|
1158
|
+
const itemRegex = this.rules.other.listItemRegex(bull);
|
|
1159
|
+
let endsWithBlankLine = false;
|
|
1160
|
+
while (src) {
|
|
1161
|
+
let endEarly = false;
|
|
1162
|
+
let raw = "";
|
|
1163
|
+
let itemContents = "";
|
|
1164
|
+
if (!(cap = itemRegex.exec(src))) {
|
|
1165
|
+
break;
|
|
1166
|
+
}
|
|
1167
|
+
if (this.rules.block.hr.test(src)) {
|
|
1168
|
+
break;
|
|
1169
|
+
}
|
|
1170
|
+
raw = cap[0];
|
|
1171
|
+
src = src.substring(raw.length);
|
|
1172
|
+
let line = cap[2].split("\n", 1)[0].replace(this.rules.other.listReplaceTabs, (t) => " ".repeat(3 * t.length));
|
|
1173
|
+
let nextLine = src.split("\n", 1)[0];
|
|
1174
|
+
let blankLine = !line.trim();
|
|
1175
|
+
let indent = 0;
|
|
1176
|
+
if (this.options.pedantic) {
|
|
1177
|
+
indent = 2;
|
|
1178
|
+
itemContents = line.trimStart();
|
|
1179
|
+
} else if (blankLine) {
|
|
1180
|
+
indent = cap[1].length + 1;
|
|
1181
|
+
} else {
|
|
1182
|
+
indent = cap[2].search(this.rules.other.nonSpaceChar);
|
|
1183
|
+
indent = indent > 4 ? 1 : indent;
|
|
1184
|
+
itemContents = line.slice(indent);
|
|
1185
|
+
indent += cap[1].length;
|
|
1186
|
+
}
|
|
1187
|
+
if (blankLine && this.rules.other.blankLine.test(nextLine)) {
|
|
1188
|
+
raw += nextLine + "\n";
|
|
1189
|
+
src = src.substring(nextLine.length + 1);
|
|
1190
|
+
endEarly = true;
|
|
1191
|
+
}
|
|
1192
|
+
if (!endEarly) {
|
|
1193
|
+
const nextBulletRegex = this.rules.other.nextBulletRegex(indent);
|
|
1194
|
+
const hrRegex = this.rules.other.hrRegex(indent);
|
|
1195
|
+
const fencesBeginRegex = this.rules.other.fencesBeginRegex(indent);
|
|
1196
|
+
const headingBeginRegex = this.rules.other.headingBeginRegex(indent);
|
|
1197
|
+
const htmlBeginRegex = this.rules.other.htmlBeginRegex(indent);
|
|
1198
|
+
while (src) {
|
|
1199
|
+
const rawLine = src.split("\n", 1)[0];
|
|
1200
|
+
let nextLineWithoutTabs;
|
|
1201
|
+
nextLine = rawLine;
|
|
1202
|
+
if (this.options.pedantic) {
|
|
1203
|
+
nextLine = nextLine.replace(this.rules.other.listReplaceNesting, " ");
|
|
1204
|
+
nextLineWithoutTabs = nextLine;
|
|
1205
|
+
} else {
|
|
1206
|
+
nextLineWithoutTabs = nextLine.replace(this.rules.other.tabCharGlobal, " ");
|
|
1207
|
+
}
|
|
1208
|
+
if (fencesBeginRegex.test(nextLine)) {
|
|
1209
|
+
break;
|
|
1210
|
+
}
|
|
1211
|
+
if (headingBeginRegex.test(nextLine)) {
|
|
1212
|
+
break;
|
|
1213
|
+
}
|
|
1214
|
+
if (htmlBeginRegex.test(nextLine)) {
|
|
1215
|
+
break;
|
|
1216
|
+
}
|
|
1217
|
+
if (nextBulletRegex.test(nextLine)) {
|
|
1218
|
+
break;
|
|
1219
|
+
}
|
|
1220
|
+
if (hrRegex.test(nextLine)) {
|
|
1221
|
+
break;
|
|
1222
|
+
}
|
|
1223
|
+
if (nextLineWithoutTabs.search(this.rules.other.nonSpaceChar) >= indent || !nextLine.trim()) {
|
|
1224
|
+
itemContents += "\n" + nextLineWithoutTabs.slice(indent);
|
|
1225
|
+
} else {
|
|
1226
|
+
if (blankLine) {
|
|
1227
|
+
break;
|
|
1228
|
+
}
|
|
1229
|
+
if (line.replace(this.rules.other.tabCharGlobal, " ").search(this.rules.other.nonSpaceChar) >= 4) {
|
|
1230
|
+
break;
|
|
1231
|
+
}
|
|
1232
|
+
if (fencesBeginRegex.test(line)) {
|
|
1233
|
+
break;
|
|
1234
|
+
}
|
|
1235
|
+
if (headingBeginRegex.test(line)) {
|
|
1236
|
+
break;
|
|
1237
|
+
}
|
|
1238
|
+
if (hrRegex.test(line)) {
|
|
1239
|
+
break;
|
|
1240
|
+
}
|
|
1241
|
+
itemContents += "\n" + nextLine;
|
|
1242
|
+
}
|
|
1243
|
+
if (!blankLine && !nextLine.trim()) {
|
|
1244
|
+
blankLine = true;
|
|
1245
|
+
}
|
|
1246
|
+
raw += rawLine + "\n";
|
|
1247
|
+
src = src.substring(rawLine.length + 1);
|
|
1248
|
+
line = nextLineWithoutTabs.slice(indent);
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
if (!list2.loose) {
|
|
1252
|
+
if (endsWithBlankLine) {
|
|
1253
|
+
list2.loose = true;
|
|
1254
|
+
} else if (this.rules.other.doubleBlankLine.test(raw)) {
|
|
1255
|
+
endsWithBlankLine = true;
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
let istask = null;
|
|
1259
|
+
let ischecked;
|
|
1260
|
+
if (this.options.gfm) {
|
|
1261
|
+
istask = this.rules.other.listIsTask.exec(itemContents);
|
|
1262
|
+
if (istask) {
|
|
1263
|
+
ischecked = istask[0] !== "[ ] ";
|
|
1264
|
+
itemContents = itemContents.replace(this.rules.other.listReplaceTask, "");
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
list2.items.push({
|
|
1268
|
+
type: "list_item",
|
|
1269
|
+
raw,
|
|
1270
|
+
task: !!istask,
|
|
1271
|
+
checked: ischecked,
|
|
1272
|
+
loose: false,
|
|
1273
|
+
text: itemContents,
|
|
1274
|
+
tokens: []
|
|
1275
|
+
});
|
|
1276
|
+
list2.raw += raw;
|
|
1277
|
+
}
|
|
1278
|
+
const lastItem = list2.items.at(-1);
|
|
1279
|
+
if (lastItem) {
|
|
1280
|
+
lastItem.raw = lastItem.raw.trimEnd();
|
|
1281
|
+
lastItem.text = lastItem.text.trimEnd();
|
|
1282
|
+
} else {
|
|
1283
|
+
return;
|
|
1284
|
+
}
|
|
1285
|
+
list2.raw = list2.raw.trimEnd();
|
|
1286
|
+
for (let i = 0; i < list2.items.length; i++) {
|
|
1287
|
+
this.lexer.state.top = false;
|
|
1288
|
+
list2.items[i].tokens = this.lexer.blockTokens(list2.items[i].text, []);
|
|
1289
|
+
if (!list2.loose) {
|
|
1290
|
+
const spacers = list2.items[i].tokens.filter((t) => t.type === "space");
|
|
1291
|
+
const hasMultipleLineBreaks = spacers.length > 0 && spacers.some((t) => this.rules.other.anyLine.test(t.raw));
|
|
1292
|
+
list2.loose = hasMultipleLineBreaks;
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
if (list2.loose) {
|
|
1296
|
+
for (let i = 0; i < list2.items.length; i++) {
|
|
1297
|
+
list2.items[i].loose = true;
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
return list2;
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
html(src) {
|
|
1304
|
+
const cap = this.rules.block.html.exec(src);
|
|
1305
|
+
if (cap) {
|
|
1306
|
+
const token = {
|
|
1307
|
+
type: "html",
|
|
1308
|
+
block: true,
|
|
1309
|
+
raw: cap[0],
|
|
1310
|
+
pre: cap[1] === "pre" || cap[1] === "script" || cap[1] === "style",
|
|
1311
|
+
text: cap[0]
|
|
1312
|
+
};
|
|
1313
|
+
return token;
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
def(src) {
|
|
1317
|
+
const cap = this.rules.block.def.exec(src);
|
|
1318
|
+
if (cap) {
|
|
1319
|
+
const tag2 = cap[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal, " ");
|
|
1320
|
+
const href = cap[2] ? cap[2].replace(this.rules.other.hrefBrackets, "$1").replace(this.rules.inline.anyPunctuation, "$1") : "";
|
|
1321
|
+
const title = cap[3] ? cap[3].substring(1, cap[3].length - 1).replace(this.rules.inline.anyPunctuation, "$1") : cap[3];
|
|
1322
|
+
return {
|
|
1323
|
+
type: "def",
|
|
1324
|
+
tag: tag2,
|
|
1325
|
+
raw: cap[0],
|
|
1326
|
+
href,
|
|
1327
|
+
title
|
|
1328
|
+
};
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
table(src) {
|
|
1332
|
+
var _a2;
|
|
1333
|
+
const cap = this.rules.block.table.exec(src);
|
|
1334
|
+
if (!cap) {
|
|
1335
|
+
return;
|
|
1336
|
+
}
|
|
1337
|
+
if (!this.rules.other.tableDelimiter.test(cap[2])) {
|
|
1338
|
+
return;
|
|
1339
|
+
}
|
|
1340
|
+
const headers = splitCells(cap[1]);
|
|
1341
|
+
const aligns = cap[2].replace(this.rules.other.tableAlignChars, "").split("|");
|
|
1342
|
+
const rows = ((_a2 = cap[3]) == null ? void 0 : _a2.trim()) ? cap[3].replace(this.rules.other.tableRowBlankLine, "").split("\n") : [];
|
|
1343
|
+
const item = {
|
|
1344
|
+
type: "table",
|
|
1345
|
+
raw: cap[0],
|
|
1346
|
+
header: [],
|
|
1347
|
+
align: [],
|
|
1348
|
+
rows: []
|
|
1349
|
+
};
|
|
1350
|
+
if (headers.length !== aligns.length) {
|
|
1351
|
+
return;
|
|
1352
|
+
}
|
|
1353
|
+
for (const align of aligns) {
|
|
1354
|
+
if (this.rules.other.tableAlignRight.test(align)) {
|
|
1355
|
+
item.align.push("right");
|
|
1356
|
+
} else if (this.rules.other.tableAlignCenter.test(align)) {
|
|
1357
|
+
item.align.push("center");
|
|
1358
|
+
} else if (this.rules.other.tableAlignLeft.test(align)) {
|
|
1359
|
+
item.align.push("left");
|
|
1360
|
+
} else {
|
|
1361
|
+
item.align.push(null);
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
1364
|
+
for (let i = 0; i < headers.length; i++) {
|
|
1365
|
+
item.header.push({
|
|
1366
|
+
text: headers[i],
|
|
1367
|
+
tokens: this.lexer.inline(headers[i]),
|
|
1368
|
+
header: true,
|
|
1369
|
+
align: item.align[i]
|
|
1370
|
+
});
|
|
1371
|
+
}
|
|
1372
|
+
for (const row of rows) {
|
|
1373
|
+
item.rows.push(splitCells(row, item.header.length).map((cell, i) => {
|
|
1374
|
+
return {
|
|
1375
|
+
text: cell,
|
|
1376
|
+
tokens: this.lexer.inline(cell),
|
|
1377
|
+
header: false,
|
|
1378
|
+
align: item.align[i]
|
|
1379
|
+
};
|
|
1380
|
+
}));
|
|
1381
|
+
}
|
|
1382
|
+
return item;
|
|
1383
|
+
}
|
|
1384
|
+
lheading(src) {
|
|
1385
|
+
const cap = this.rules.block.lheading.exec(src);
|
|
1386
|
+
if (cap) {
|
|
1387
|
+
return {
|
|
1388
|
+
type: "heading",
|
|
1389
|
+
raw: cap[0],
|
|
1390
|
+
depth: cap[2].charAt(0) === "=" ? 1 : 2,
|
|
1391
|
+
text: cap[1],
|
|
1392
|
+
tokens: this.lexer.inline(cap[1])
|
|
1393
|
+
};
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
paragraph(src) {
|
|
1397
|
+
const cap = this.rules.block.paragraph.exec(src);
|
|
1398
|
+
if (cap) {
|
|
1399
|
+
const text = cap[1].charAt(cap[1].length - 1) === "\n" ? cap[1].slice(0, -1) : cap[1];
|
|
1400
|
+
return {
|
|
1401
|
+
type: "paragraph",
|
|
1402
|
+
raw: cap[0],
|
|
1403
|
+
text,
|
|
1404
|
+
tokens: this.lexer.inline(text)
|
|
1405
|
+
};
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
text(src) {
|
|
1409
|
+
const cap = this.rules.block.text.exec(src);
|
|
1410
|
+
if (cap) {
|
|
1411
|
+
return {
|
|
1412
|
+
type: "text",
|
|
1413
|
+
raw: cap[0],
|
|
1414
|
+
text: cap[0],
|
|
1415
|
+
tokens: this.lexer.inline(cap[0])
|
|
1416
|
+
};
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1419
|
+
escape(src) {
|
|
1420
|
+
const cap = this.rules.inline.escape.exec(src);
|
|
1421
|
+
if (cap) {
|
|
1422
|
+
return {
|
|
1423
|
+
type: "escape",
|
|
1424
|
+
raw: cap[0],
|
|
1425
|
+
text: cap[1]
|
|
1426
|
+
};
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1429
|
+
tag(src) {
|
|
1430
|
+
const cap = this.rules.inline.tag.exec(src);
|
|
1431
|
+
if (cap) {
|
|
1432
|
+
if (!this.lexer.state.inLink && this.rules.other.startATag.test(cap[0])) {
|
|
1433
|
+
this.lexer.state.inLink = true;
|
|
1434
|
+
} else if (this.lexer.state.inLink && this.rules.other.endATag.test(cap[0])) {
|
|
1435
|
+
this.lexer.state.inLink = false;
|
|
1436
|
+
}
|
|
1437
|
+
if (!this.lexer.state.inRawBlock && this.rules.other.startPreScriptTag.test(cap[0])) {
|
|
1438
|
+
this.lexer.state.inRawBlock = true;
|
|
1439
|
+
} else if (this.lexer.state.inRawBlock && this.rules.other.endPreScriptTag.test(cap[0])) {
|
|
1440
|
+
this.lexer.state.inRawBlock = false;
|
|
1441
|
+
}
|
|
1442
|
+
return {
|
|
1443
|
+
type: "html",
|
|
1444
|
+
raw: cap[0],
|
|
1445
|
+
inLink: this.lexer.state.inLink,
|
|
1446
|
+
inRawBlock: this.lexer.state.inRawBlock,
|
|
1447
|
+
block: false,
|
|
1448
|
+
text: cap[0]
|
|
1449
|
+
};
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
link(src) {
|
|
1453
|
+
const cap = this.rules.inline.link.exec(src);
|
|
1454
|
+
if (cap) {
|
|
1455
|
+
const trimmedUrl = cap[2].trim();
|
|
1456
|
+
if (!this.options.pedantic && this.rules.other.startAngleBracket.test(trimmedUrl)) {
|
|
1457
|
+
if (!this.rules.other.endAngleBracket.test(trimmedUrl)) {
|
|
1458
|
+
return;
|
|
1459
|
+
}
|
|
1460
|
+
const rtrimSlash = rtrim(trimmedUrl.slice(0, -1), "\\");
|
|
1461
|
+
if ((trimmedUrl.length - rtrimSlash.length) % 2 === 0) {
|
|
1462
|
+
return;
|
|
1463
|
+
}
|
|
1464
|
+
} else {
|
|
1465
|
+
const lastParenIndex = findClosingBracket(cap[2], "()");
|
|
1466
|
+
if (lastParenIndex === -2) {
|
|
1467
|
+
return;
|
|
1468
|
+
}
|
|
1469
|
+
if (lastParenIndex > -1) {
|
|
1470
|
+
const start = cap[0].indexOf("!") === 0 ? 5 : 4;
|
|
1471
|
+
const linkLen = start + cap[1].length + lastParenIndex;
|
|
1472
|
+
cap[2] = cap[2].substring(0, lastParenIndex);
|
|
1473
|
+
cap[0] = cap[0].substring(0, linkLen).trim();
|
|
1474
|
+
cap[3] = "";
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
let href = cap[2];
|
|
1478
|
+
let title = "";
|
|
1479
|
+
if (this.options.pedantic) {
|
|
1480
|
+
const link2 = this.rules.other.pedanticHrefTitle.exec(href);
|
|
1481
|
+
if (link2) {
|
|
1482
|
+
href = link2[1];
|
|
1483
|
+
title = link2[3];
|
|
1484
|
+
}
|
|
1485
|
+
} else {
|
|
1486
|
+
title = cap[3] ? cap[3].slice(1, -1) : "";
|
|
1487
|
+
}
|
|
1488
|
+
href = href.trim();
|
|
1489
|
+
if (this.rules.other.startAngleBracket.test(href)) {
|
|
1490
|
+
if (this.options.pedantic && !this.rules.other.endAngleBracket.test(trimmedUrl)) {
|
|
1491
|
+
href = href.slice(1);
|
|
1492
|
+
} else {
|
|
1493
|
+
href = href.slice(1, -1);
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
return outputLink(cap, {
|
|
1497
|
+
href: href ? href.replace(this.rules.inline.anyPunctuation, "$1") : href,
|
|
1498
|
+
title: title ? title.replace(this.rules.inline.anyPunctuation, "$1") : title
|
|
1499
|
+
}, cap[0], this.lexer, this.rules);
|
|
1500
|
+
}
|
|
1501
|
+
}
|
|
1502
|
+
reflink(src, links) {
|
|
1503
|
+
let cap;
|
|
1504
|
+
if ((cap = this.rules.inline.reflink.exec(src)) || (cap = this.rules.inline.nolink.exec(src))) {
|
|
1505
|
+
const linkString = (cap[2] || cap[1]).replace(this.rules.other.multipleSpaceGlobal, " ");
|
|
1506
|
+
const link2 = links[linkString.toLowerCase()];
|
|
1507
|
+
if (!link2) {
|
|
1508
|
+
const text = cap[0].charAt(0);
|
|
1509
|
+
return {
|
|
1510
|
+
type: "text",
|
|
1511
|
+
raw: text,
|
|
1512
|
+
text
|
|
1513
|
+
};
|
|
1514
|
+
}
|
|
1515
|
+
return outputLink(cap, link2, cap[0], this.lexer, this.rules);
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
emStrong(src, maskedSrc, prevChar = "") {
|
|
1519
|
+
let match = this.rules.inline.emStrongLDelim.exec(src);
|
|
1520
|
+
if (!match) return;
|
|
1521
|
+
if (match[3] && prevChar.match(this.rules.other.unicodeAlphaNumeric)) return;
|
|
1522
|
+
const nextChar = match[1] || match[2] || "";
|
|
1523
|
+
if (!nextChar || !prevChar || this.rules.inline.punctuation.exec(prevChar)) {
|
|
1524
|
+
const lLength = [...match[0]].length - 1;
|
|
1525
|
+
let rDelim, rLength, delimTotal = lLength, midDelimTotal = 0;
|
|
1526
|
+
const endReg = match[0][0] === "*" ? this.rules.inline.emStrongRDelimAst : this.rules.inline.emStrongRDelimUnd;
|
|
1527
|
+
endReg.lastIndex = 0;
|
|
1528
|
+
maskedSrc = maskedSrc.slice(-1 * src.length + lLength);
|
|
1529
|
+
while ((match = endReg.exec(maskedSrc)) != null) {
|
|
1530
|
+
rDelim = match[1] || match[2] || match[3] || match[4] || match[5] || match[6];
|
|
1531
|
+
if (!rDelim) continue;
|
|
1532
|
+
rLength = [...rDelim].length;
|
|
1533
|
+
if (match[3] || match[4]) {
|
|
1534
|
+
delimTotal += rLength;
|
|
1535
|
+
continue;
|
|
1536
|
+
} else if (match[5] || match[6]) {
|
|
1537
|
+
if (lLength % 3 && !((lLength + rLength) % 3)) {
|
|
1538
|
+
midDelimTotal += rLength;
|
|
1539
|
+
continue;
|
|
1540
|
+
}
|
|
1541
|
+
}
|
|
1542
|
+
delimTotal -= rLength;
|
|
1543
|
+
if (delimTotal > 0) continue;
|
|
1544
|
+
rLength = Math.min(rLength, rLength + delimTotal + midDelimTotal);
|
|
1545
|
+
const lastCharLength = [...match[0]][0].length;
|
|
1546
|
+
const raw = src.slice(0, lLength + match.index + lastCharLength + rLength);
|
|
1547
|
+
if (Math.min(lLength, rLength) % 2) {
|
|
1548
|
+
const text2 = raw.slice(1, -1);
|
|
1549
|
+
return {
|
|
1550
|
+
type: "em",
|
|
1551
|
+
raw,
|
|
1552
|
+
text: text2,
|
|
1553
|
+
tokens: this.lexer.inlineTokens(text2)
|
|
1554
|
+
};
|
|
1555
|
+
}
|
|
1556
|
+
const text = raw.slice(2, -2);
|
|
1557
|
+
return {
|
|
1558
|
+
type: "strong",
|
|
1559
|
+
raw,
|
|
1560
|
+
text,
|
|
1561
|
+
tokens: this.lexer.inlineTokens(text)
|
|
1562
|
+
};
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
}
|
|
1566
|
+
codespan(src) {
|
|
1567
|
+
const cap = this.rules.inline.code.exec(src);
|
|
1568
|
+
if (cap) {
|
|
1569
|
+
let text = cap[2].replace(this.rules.other.newLineCharGlobal, " ");
|
|
1570
|
+
const hasNonSpaceChars = this.rules.other.nonSpaceChar.test(text);
|
|
1571
|
+
const hasSpaceCharsOnBothEnds = this.rules.other.startingSpaceChar.test(text) && this.rules.other.endingSpaceChar.test(text);
|
|
1572
|
+
if (hasNonSpaceChars && hasSpaceCharsOnBothEnds) {
|
|
1573
|
+
text = text.substring(1, text.length - 1);
|
|
1574
|
+
}
|
|
1575
|
+
return {
|
|
1576
|
+
type: "codespan",
|
|
1577
|
+
raw: cap[0],
|
|
1578
|
+
text
|
|
1579
|
+
};
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
br(src) {
|
|
1583
|
+
const cap = this.rules.inline.br.exec(src);
|
|
1584
|
+
if (cap) {
|
|
1585
|
+
return {
|
|
1586
|
+
type: "br",
|
|
1587
|
+
raw: cap[0]
|
|
1588
|
+
};
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
del(src) {
|
|
1592
|
+
const cap = this.rules.inline.del.exec(src);
|
|
1593
|
+
if (cap) {
|
|
1594
|
+
return {
|
|
1595
|
+
type: "del",
|
|
1596
|
+
raw: cap[0],
|
|
1597
|
+
text: cap[2],
|
|
1598
|
+
tokens: this.lexer.inlineTokens(cap[2])
|
|
1599
|
+
};
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
autolink(src) {
|
|
1603
|
+
const cap = this.rules.inline.autolink.exec(src);
|
|
1604
|
+
if (cap) {
|
|
1605
|
+
let text, href;
|
|
1606
|
+
if (cap[2] === "@") {
|
|
1607
|
+
text = cap[1];
|
|
1608
|
+
href = "mailto:" + text;
|
|
1609
|
+
} else {
|
|
1610
|
+
text = cap[1];
|
|
1611
|
+
href = text;
|
|
1612
|
+
}
|
|
1613
|
+
return {
|
|
1614
|
+
type: "link",
|
|
1615
|
+
raw: cap[0],
|
|
1616
|
+
text,
|
|
1617
|
+
href,
|
|
1618
|
+
tokens: [
|
|
1619
|
+
{
|
|
1620
|
+
type: "text",
|
|
1621
|
+
raw: text,
|
|
1622
|
+
text
|
|
1623
|
+
}
|
|
1624
|
+
]
|
|
1625
|
+
};
|
|
1626
|
+
}
|
|
1627
|
+
}
|
|
1628
|
+
url(src) {
|
|
1629
|
+
var _a2, _b;
|
|
1630
|
+
let cap;
|
|
1631
|
+
if (cap = this.rules.inline.url.exec(src)) {
|
|
1632
|
+
let text, href;
|
|
1633
|
+
if (cap[2] === "@") {
|
|
1634
|
+
text = cap[0];
|
|
1635
|
+
href = "mailto:" + text;
|
|
1636
|
+
} else {
|
|
1637
|
+
let prevCapZero;
|
|
1638
|
+
do {
|
|
1639
|
+
prevCapZero = cap[0];
|
|
1640
|
+
cap[0] = (_b = (_a2 = this.rules.inline._backpedal.exec(cap[0])) == null ? void 0 : _a2[0]) != null ? _b : "";
|
|
1641
|
+
} while (prevCapZero !== cap[0]);
|
|
1642
|
+
text = cap[0];
|
|
1643
|
+
if (cap[1] === "www.") {
|
|
1644
|
+
href = "http://" + cap[0];
|
|
1645
|
+
} else {
|
|
1646
|
+
href = cap[0];
|
|
1647
|
+
}
|
|
1648
|
+
}
|
|
1649
|
+
return {
|
|
1650
|
+
type: "link",
|
|
1651
|
+
raw: cap[0],
|
|
1652
|
+
text,
|
|
1653
|
+
href,
|
|
1654
|
+
tokens: [
|
|
1655
|
+
{
|
|
1656
|
+
type: "text",
|
|
1657
|
+
raw: text,
|
|
1658
|
+
text
|
|
1659
|
+
}
|
|
1660
|
+
]
|
|
1661
|
+
};
|
|
1662
|
+
}
|
|
1663
|
+
}
|
|
1664
|
+
inlineText(src) {
|
|
1665
|
+
const cap = this.rules.inline.text.exec(src);
|
|
1666
|
+
if (cap) {
|
|
1667
|
+
const escaped = this.lexer.state.inRawBlock;
|
|
1668
|
+
return {
|
|
1669
|
+
type: "text",
|
|
1670
|
+
raw: cap[0],
|
|
1671
|
+
text: cap[0],
|
|
1672
|
+
escaped
|
|
1673
|
+
};
|
|
1674
|
+
}
|
|
1675
|
+
}
|
|
1676
|
+
};
|
|
1677
|
+
var _Lexer = class __Lexer {
|
|
1678
|
+
constructor(options2) {
|
|
1679
|
+
__publicField(this, "tokens");
|
|
1680
|
+
__publicField(this, "options");
|
|
1681
|
+
__publicField(this, "state");
|
|
1682
|
+
__publicField(this, "tokenizer");
|
|
1683
|
+
__publicField(this, "inlineQueue");
|
|
1684
|
+
this.tokens = [];
|
|
1685
|
+
this.tokens.links = /* @__PURE__ */ Object.create(null);
|
|
1686
|
+
this.options = options2 || _defaults;
|
|
1687
|
+
this.options.tokenizer = this.options.tokenizer || new _Tokenizer();
|
|
1688
|
+
this.tokenizer = this.options.tokenizer;
|
|
1689
|
+
this.tokenizer.options = this.options;
|
|
1690
|
+
this.tokenizer.lexer = this;
|
|
1691
|
+
this.inlineQueue = [];
|
|
1692
|
+
this.state = {
|
|
1693
|
+
inLink: false,
|
|
1694
|
+
inRawBlock: false,
|
|
1695
|
+
top: true
|
|
1696
|
+
};
|
|
1697
|
+
const rules = {
|
|
1698
|
+
other,
|
|
1699
|
+
block: block.normal,
|
|
1700
|
+
inline: inline.normal
|
|
1701
|
+
};
|
|
1702
|
+
if (this.options.pedantic) {
|
|
1703
|
+
rules.block = block.pedantic;
|
|
1704
|
+
rules.inline = inline.pedantic;
|
|
1705
|
+
} else if (this.options.gfm) {
|
|
1706
|
+
rules.block = block.gfm;
|
|
1707
|
+
if (this.options.breaks) {
|
|
1708
|
+
rules.inline = inline.breaks;
|
|
1709
|
+
} else {
|
|
1710
|
+
rules.inline = inline.gfm;
|
|
1711
|
+
}
|
|
1712
|
+
}
|
|
1713
|
+
this.tokenizer.rules = rules;
|
|
1714
|
+
}
|
|
1715
|
+
/**
|
|
1716
|
+
* Expose Rules
|
|
1717
|
+
*/
|
|
1718
|
+
static get rules() {
|
|
1719
|
+
return {
|
|
1720
|
+
block,
|
|
1721
|
+
inline
|
|
1722
|
+
};
|
|
1723
|
+
}
|
|
1724
|
+
/**
|
|
1725
|
+
* Static Lex Method
|
|
1726
|
+
*/
|
|
1727
|
+
static lex(src, options2) {
|
|
1728
|
+
const lexer2 = new __Lexer(options2);
|
|
1729
|
+
return lexer2.lex(src);
|
|
1730
|
+
}
|
|
1731
|
+
/**
|
|
1732
|
+
* Static Lex Inline Method
|
|
1733
|
+
*/
|
|
1734
|
+
static lexInline(src, options2) {
|
|
1735
|
+
const lexer2 = new __Lexer(options2);
|
|
1736
|
+
return lexer2.inlineTokens(src);
|
|
1737
|
+
}
|
|
1738
|
+
/**
|
|
1739
|
+
* Preprocessing
|
|
1740
|
+
*/
|
|
1741
|
+
lex(src) {
|
|
1742
|
+
src = src.replace(other.carriageReturn, "\n");
|
|
1743
|
+
this.blockTokens(src, this.tokens);
|
|
1744
|
+
for (let i = 0; i < this.inlineQueue.length; i++) {
|
|
1745
|
+
const next = this.inlineQueue[i];
|
|
1746
|
+
this.inlineTokens(next.src, next.tokens);
|
|
1747
|
+
}
|
|
1748
|
+
this.inlineQueue = [];
|
|
1749
|
+
return this.tokens;
|
|
1750
|
+
}
|
|
1751
|
+
blockTokens(src, tokens = [], lastParagraphClipped = false) {
|
|
1752
|
+
var _a2, _b, _c;
|
|
1753
|
+
if (this.options.pedantic) {
|
|
1754
|
+
src = src.replace(other.tabCharGlobal, " ").replace(other.spaceLine, "");
|
|
1755
|
+
}
|
|
1756
|
+
while (src) {
|
|
1757
|
+
let token;
|
|
1758
|
+
if ((_b = (_a2 = this.options.extensions) == null ? void 0 : _a2.block) == null ? void 0 : _b.some((extTokenizer) => {
|
|
1759
|
+
if (token = extTokenizer.call({ lexer: this }, src, tokens)) {
|
|
1760
|
+
src = src.substring(token.raw.length);
|
|
1761
|
+
tokens.push(token);
|
|
1762
|
+
return true;
|
|
1763
|
+
}
|
|
1764
|
+
return false;
|
|
1765
|
+
})) {
|
|
1766
|
+
continue;
|
|
1767
|
+
}
|
|
1768
|
+
if (token = this.tokenizer.space(src)) {
|
|
1769
|
+
src = src.substring(token.raw.length);
|
|
1770
|
+
const lastToken = tokens.at(-1);
|
|
1771
|
+
if (token.raw.length === 1 && lastToken !== void 0) {
|
|
1772
|
+
lastToken.raw += "\n";
|
|
1773
|
+
} else {
|
|
1774
|
+
tokens.push(token);
|
|
1775
|
+
}
|
|
1776
|
+
continue;
|
|
1777
|
+
}
|
|
1778
|
+
if (token = this.tokenizer.code(src)) {
|
|
1779
|
+
src = src.substring(token.raw.length);
|
|
1780
|
+
const lastToken = tokens.at(-1);
|
|
1781
|
+
if ((lastToken == null ? void 0 : lastToken.type) === "paragraph" || (lastToken == null ? void 0 : lastToken.type) === "text") {
|
|
1782
|
+
lastToken.raw += "\n" + token.raw;
|
|
1783
|
+
lastToken.text += "\n" + token.text;
|
|
1784
|
+
this.inlineQueue.at(-1).src = lastToken.text;
|
|
1785
|
+
} else {
|
|
1786
|
+
tokens.push(token);
|
|
1787
|
+
}
|
|
1788
|
+
continue;
|
|
1789
|
+
}
|
|
1790
|
+
if (token = this.tokenizer.fences(src)) {
|
|
1791
|
+
src = src.substring(token.raw.length);
|
|
1792
|
+
tokens.push(token);
|
|
1793
|
+
continue;
|
|
1794
|
+
}
|
|
1795
|
+
if (token = this.tokenizer.heading(src)) {
|
|
1796
|
+
src = src.substring(token.raw.length);
|
|
1797
|
+
tokens.push(token);
|
|
1798
|
+
continue;
|
|
1799
|
+
}
|
|
1800
|
+
if (token = this.tokenizer.hr(src)) {
|
|
1801
|
+
src = src.substring(token.raw.length);
|
|
1802
|
+
tokens.push(token);
|
|
1803
|
+
continue;
|
|
1804
|
+
}
|
|
1805
|
+
if (token = this.tokenizer.blockquote(src)) {
|
|
1806
|
+
src = src.substring(token.raw.length);
|
|
1807
|
+
tokens.push(token);
|
|
1808
|
+
continue;
|
|
1809
|
+
}
|
|
1810
|
+
if (token = this.tokenizer.list(src)) {
|
|
1811
|
+
src = src.substring(token.raw.length);
|
|
1812
|
+
tokens.push(token);
|
|
1813
|
+
continue;
|
|
1814
|
+
}
|
|
1815
|
+
if (token = this.tokenizer.html(src)) {
|
|
1816
|
+
src = src.substring(token.raw.length);
|
|
1817
|
+
tokens.push(token);
|
|
1818
|
+
continue;
|
|
1819
|
+
}
|
|
1820
|
+
if (token = this.tokenizer.def(src)) {
|
|
1821
|
+
src = src.substring(token.raw.length);
|
|
1822
|
+
const lastToken = tokens.at(-1);
|
|
1823
|
+
if ((lastToken == null ? void 0 : lastToken.type) === "paragraph" || (lastToken == null ? void 0 : lastToken.type) === "text") {
|
|
1824
|
+
lastToken.raw += "\n" + token.raw;
|
|
1825
|
+
lastToken.text += "\n" + token.raw;
|
|
1826
|
+
this.inlineQueue.at(-1).src = lastToken.text;
|
|
1827
|
+
} else if (!this.tokens.links[token.tag]) {
|
|
1828
|
+
this.tokens.links[token.tag] = {
|
|
1829
|
+
href: token.href,
|
|
1830
|
+
title: token.title
|
|
1831
|
+
};
|
|
1832
|
+
}
|
|
1833
|
+
continue;
|
|
1834
|
+
}
|
|
1835
|
+
if (token = this.tokenizer.table(src)) {
|
|
1836
|
+
src = src.substring(token.raw.length);
|
|
1837
|
+
tokens.push(token);
|
|
1838
|
+
continue;
|
|
1839
|
+
}
|
|
1840
|
+
if (token = this.tokenizer.lheading(src)) {
|
|
1841
|
+
src = src.substring(token.raw.length);
|
|
1842
|
+
tokens.push(token);
|
|
1843
|
+
continue;
|
|
1844
|
+
}
|
|
1845
|
+
let cutSrc = src;
|
|
1846
|
+
if ((_c = this.options.extensions) == null ? void 0 : _c.startBlock) {
|
|
1847
|
+
let startIndex = Infinity;
|
|
1848
|
+
const tempSrc = src.slice(1);
|
|
1849
|
+
let tempStart;
|
|
1850
|
+
this.options.extensions.startBlock.forEach((getStartIndex) => {
|
|
1851
|
+
tempStart = getStartIndex.call({ lexer: this }, tempSrc);
|
|
1852
|
+
if (typeof tempStart === "number" && tempStart >= 0) {
|
|
1853
|
+
startIndex = Math.min(startIndex, tempStart);
|
|
1854
|
+
}
|
|
1855
|
+
});
|
|
1856
|
+
if (startIndex < Infinity && startIndex >= 0) {
|
|
1857
|
+
cutSrc = src.substring(0, startIndex + 1);
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1860
|
+
if (this.state.top && (token = this.tokenizer.paragraph(cutSrc))) {
|
|
1861
|
+
const lastToken = tokens.at(-1);
|
|
1862
|
+
if (lastParagraphClipped && (lastToken == null ? void 0 : lastToken.type) === "paragraph") {
|
|
1863
|
+
lastToken.raw += "\n" + token.raw;
|
|
1864
|
+
lastToken.text += "\n" + token.text;
|
|
1865
|
+
this.inlineQueue.pop();
|
|
1866
|
+
this.inlineQueue.at(-1).src = lastToken.text;
|
|
1867
|
+
} else {
|
|
1868
|
+
tokens.push(token);
|
|
1869
|
+
}
|
|
1870
|
+
lastParagraphClipped = cutSrc.length !== src.length;
|
|
1871
|
+
src = src.substring(token.raw.length);
|
|
1872
|
+
continue;
|
|
1873
|
+
}
|
|
1874
|
+
if (token = this.tokenizer.text(src)) {
|
|
1875
|
+
src = src.substring(token.raw.length);
|
|
1876
|
+
const lastToken = tokens.at(-1);
|
|
1877
|
+
if ((lastToken == null ? void 0 : lastToken.type) === "text") {
|
|
1878
|
+
lastToken.raw += "\n" + token.raw;
|
|
1879
|
+
lastToken.text += "\n" + token.text;
|
|
1880
|
+
this.inlineQueue.pop();
|
|
1881
|
+
this.inlineQueue.at(-1).src = lastToken.text;
|
|
1882
|
+
} else {
|
|
1883
|
+
tokens.push(token);
|
|
1884
|
+
}
|
|
1885
|
+
continue;
|
|
1886
|
+
}
|
|
1887
|
+
if (src) {
|
|
1888
|
+
const errMsg = "Infinite loop on byte: " + src.charCodeAt(0);
|
|
1889
|
+
if (this.options.silent) {
|
|
1890
|
+
console.error(errMsg);
|
|
1891
|
+
break;
|
|
1892
|
+
} else {
|
|
1893
|
+
throw new Error(errMsg);
|
|
1894
|
+
}
|
|
1895
|
+
}
|
|
1896
|
+
}
|
|
1897
|
+
this.state.top = true;
|
|
1898
|
+
return tokens;
|
|
1899
|
+
}
|
|
1900
|
+
inline(src, tokens = []) {
|
|
1901
|
+
this.inlineQueue.push({ src, tokens });
|
|
1902
|
+
return tokens;
|
|
1903
|
+
}
|
|
1904
|
+
/**
|
|
1905
|
+
* Lexing/Compiling
|
|
1906
|
+
*/
|
|
1907
|
+
inlineTokens(src, tokens = []) {
|
|
1908
|
+
var _a2, _b, _c;
|
|
1909
|
+
let maskedSrc = src;
|
|
1910
|
+
let match = null;
|
|
1911
|
+
if (this.tokens.links) {
|
|
1912
|
+
const links = Object.keys(this.tokens.links);
|
|
1913
|
+
if (links.length > 0) {
|
|
1914
|
+
while ((match = this.tokenizer.rules.inline.reflinkSearch.exec(maskedSrc)) != null) {
|
|
1915
|
+
if (links.includes(match[0].slice(match[0].lastIndexOf("[") + 1, -1))) {
|
|
1916
|
+
maskedSrc = maskedSrc.slice(0, match.index) + "[" + "a".repeat(match[0].length - 2) + "]" + maskedSrc.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex);
|
|
1917
|
+
}
|
|
1918
|
+
}
|
|
1919
|
+
}
|
|
1920
|
+
}
|
|
1921
|
+
while ((match = this.tokenizer.rules.inline.anyPunctuation.exec(maskedSrc)) != null) {
|
|
1922
|
+
maskedSrc = maskedSrc.slice(0, match.index) + "++" + maskedSrc.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);
|
|
1923
|
+
}
|
|
1924
|
+
while ((match = this.tokenizer.rules.inline.blockSkip.exec(maskedSrc)) != null) {
|
|
1925
|
+
maskedSrc = maskedSrc.slice(0, match.index) + "[" + "a".repeat(match[0].length - 2) + "]" + maskedSrc.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
|
|
1926
|
+
}
|
|
1927
|
+
let keepPrevChar = false;
|
|
1928
|
+
let prevChar = "";
|
|
1929
|
+
while (src) {
|
|
1930
|
+
if (!keepPrevChar) {
|
|
1931
|
+
prevChar = "";
|
|
1932
|
+
}
|
|
1933
|
+
keepPrevChar = false;
|
|
1934
|
+
let token;
|
|
1935
|
+
if ((_b = (_a2 = this.options.extensions) == null ? void 0 : _a2.inline) == null ? void 0 : _b.some((extTokenizer) => {
|
|
1936
|
+
if (token = extTokenizer.call({ lexer: this }, src, tokens)) {
|
|
1937
|
+
src = src.substring(token.raw.length);
|
|
1938
|
+
tokens.push(token);
|
|
1939
|
+
return true;
|
|
1940
|
+
}
|
|
1941
|
+
return false;
|
|
1942
|
+
})) {
|
|
1943
|
+
continue;
|
|
1944
|
+
}
|
|
1945
|
+
if (token = this.tokenizer.escape(src)) {
|
|
1946
|
+
src = src.substring(token.raw.length);
|
|
1947
|
+
tokens.push(token);
|
|
1948
|
+
continue;
|
|
1949
|
+
}
|
|
1950
|
+
if (token = this.tokenizer.tag(src)) {
|
|
1951
|
+
src = src.substring(token.raw.length);
|
|
1952
|
+
tokens.push(token);
|
|
1953
|
+
continue;
|
|
1954
|
+
}
|
|
1955
|
+
if (token = this.tokenizer.link(src)) {
|
|
1956
|
+
src = src.substring(token.raw.length);
|
|
1957
|
+
tokens.push(token);
|
|
1958
|
+
continue;
|
|
1959
|
+
}
|
|
1960
|
+
if (token = this.tokenizer.reflink(src, this.tokens.links)) {
|
|
1961
|
+
src = src.substring(token.raw.length);
|
|
1962
|
+
const lastToken = tokens.at(-1);
|
|
1963
|
+
if (token.type === "text" && (lastToken == null ? void 0 : lastToken.type) === "text") {
|
|
1964
|
+
lastToken.raw += token.raw;
|
|
1965
|
+
lastToken.text += token.text;
|
|
1966
|
+
} else {
|
|
1967
|
+
tokens.push(token);
|
|
1968
|
+
}
|
|
1969
|
+
continue;
|
|
1970
|
+
}
|
|
1971
|
+
if (token = this.tokenizer.emStrong(src, maskedSrc, prevChar)) {
|
|
1972
|
+
src = src.substring(token.raw.length);
|
|
1973
|
+
tokens.push(token);
|
|
1974
|
+
continue;
|
|
1975
|
+
}
|
|
1976
|
+
if (token = this.tokenizer.codespan(src)) {
|
|
1977
|
+
src = src.substring(token.raw.length);
|
|
1978
|
+
tokens.push(token);
|
|
1979
|
+
continue;
|
|
1980
|
+
}
|
|
1981
|
+
if (token = this.tokenizer.br(src)) {
|
|
1982
|
+
src = src.substring(token.raw.length);
|
|
1983
|
+
tokens.push(token);
|
|
1984
|
+
continue;
|
|
1985
|
+
}
|
|
1986
|
+
if (token = this.tokenizer.del(src)) {
|
|
1987
|
+
src = src.substring(token.raw.length);
|
|
1988
|
+
tokens.push(token);
|
|
1989
|
+
continue;
|
|
1990
|
+
}
|
|
1991
|
+
if (token = this.tokenizer.autolink(src)) {
|
|
1992
|
+
src = src.substring(token.raw.length);
|
|
1993
|
+
tokens.push(token);
|
|
1994
|
+
continue;
|
|
1995
|
+
}
|
|
1996
|
+
if (!this.state.inLink && (token = this.tokenizer.url(src))) {
|
|
1997
|
+
src = src.substring(token.raw.length);
|
|
1998
|
+
tokens.push(token);
|
|
1999
|
+
continue;
|
|
2000
|
+
}
|
|
2001
|
+
let cutSrc = src;
|
|
2002
|
+
if ((_c = this.options.extensions) == null ? void 0 : _c.startInline) {
|
|
2003
|
+
let startIndex = Infinity;
|
|
2004
|
+
const tempSrc = src.slice(1);
|
|
2005
|
+
let tempStart;
|
|
2006
|
+
this.options.extensions.startInline.forEach((getStartIndex) => {
|
|
2007
|
+
tempStart = getStartIndex.call({ lexer: this }, tempSrc);
|
|
2008
|
+
if (typeof tempStart === "number" && tempStart >= 0) {
|
|
2009
|
+
startIndex = Math.min(startIndex, tempStart);
|
|
2010
|
+
}
|
|
2011
|
+
});
|
|
2012
|
+
if (startIndex < Infinity && startIndex >= 0) {
|
|
2013
|
+
cutSrc = src.substring(0, startIndex + 1);
|
|
2014
|
+
}
|
|
2015
|
+
}
|
|
2016
|
+
if (token = this.tokenizer.inlineText(cutSrc)) {
|
|
2017
|
+
src = src.substring(token.raw.length);
|
|
2018
|
+
if (token.raw.slice(-1) !== "_") {
|
|
2019
|
+
prevChar = token.raw.slice(-1);
|
|
2020
|
+
}
|
|
2021
|
+
keepPrevChar = true;
|
|
2022
|
+
const lastToken = tokens.at(-1);
|
|
2023
|
+
if ((lastToken == null ? void 0 : lastToken.type) === "text") {
|
|
2024
|
+
lastToken.raw += token.raw;
|
|
2025
|
+
lastToken.text += token.text;
|
|
2026
|
+
} else {
|
|
2027
|
+
tokens.push(token);
|
|
2028
|
+
}
|
|
2029
|
+
continue;
|
|
2030
|
+
}
|
|
2031
|
+
if (src) {
|
|
2032
|
+
const errMsg = "Infinite loop on byte: " + src.charCodeAt(0);
|
|
2033
|
+
if (this.options.silent) {
|
|
2034
|
+
console.error(errMsg);
|
|
2035
|
+
break;
|
|
2036
|
+
} else {
|
|
2037
|
+
throw new Error(errMsg);
|
|
2038
|
+
}
|
|
2039
|
+
}
|
|
2040
|
+
}
|
|
2041
|
+
return tokens;
|
|
2042
|
+
}
|
|
2043
|
+
};
|
|
2044
|
+
var _Renderer = class {
|
|
2045
|
+
// set by the parser
|
|
2046
|
+
constructor(options2) {
|
|
2047
|
+
__publicField(this, "options");
|
|
2048
|
+
__publicField(this, "parser");
|
|
2049
|
+
this.options = options2 || _defaults;
|
|
2050
|
+
}
|
|
2051
|
+
space(token) {
|
|
2052
|
+
return "";
|
|
2053
|
+
}
|
|
2054
|
+
code({ text, lang, escaped }) {
|
|
2055
|
+
var _a2;
|
|
2056
|
+
const langString = (_a2 = (lang || "").match(other.notSpaceStart)) == null ? void 0 : _a2[0];
|
|
2057
|
+
const code = text.replace(other.endingNewline, "") + "\n";
|
|
2058
|
+
if (!langString) {
|
|
2059
|
+
return "<pre><code>" + (escaped ? code : escape2(code, true)) + "</code></pre>\n";
|
|
2060
|
+
}
|
|
2061
|
+
return '<pre><code class="language-' + escape2(langString) + '">' + (escaped ? code : escape2(code, true)) + "</code></pre>\n";
|
|
2062
|
+
}
|
|
2063
|
+
blockquote({ tokens }) {
|
|
2064
|
+
const body = this.parser.parse(tokens);
|
|
2065
|
+
return `<blockquote>
|
|
2066
|
+
${body}</blockquote>
|
|
2067
|
+
`;
|
|
2068
|
+
}
|
|
2069
|
+
html({ text }) {
|
|
2070
|
+
return text;
|
|
2071
|
+
}
|
|
2072
|
+
heading({ tokens, depth }) {
|
|
2073
|
+
return `<h${depth}>${this.parser.parseInline(tokens)}</h${depth}>
|
|
2074
|
+
`;
|
|
2075
|
+
}
|
|
2076
|
+
hr(token) {
|
|
2077
|
+
return "<hr>\n";
|
|
2078
|
+
}
|
|
2079
|
+
list(token) {
|
|
2080
|
+
const ordered = token.ordered;
|
|
2081
|
+
const start = token.start;
|
|
2082
|
+
let body = "";
|
|
2083
|
+
for (let j = 0; j < token.items.length; j++) {
|
|
2084
|
+
const item = token.items[j];
|
|
2085
|
+
body += this.listitem(item);
|
|
2086
|
+
}
|
|
2087
|
+
const type = ordered ? "ol" : "ul";
|
|
2088
|
+
const startAttr = ordered && start !== 1 ? ' start="' + start + '"' : "";
|
|
2089
|
+
return "<" + type + startAttr + ">\n" + body + "</" + type + ">\n";
|
|
2090
|
+
}
|
|
2091
|
+
listitem(item) {
|
|
2092
|
+
var _a2;
|
|
2093
|
+
let itemBody = "";
|
|
2094
|
+
if (item.task) {
|
|
2095
|
+
const checkbox = this.checkbox({ checked: !!item.checked });
|
|
2096
|
+
if (item.loose) {
|
|
2097
|
+
if (((_a2 = item.tokens[0]) == null ? void 0 : _a2.type) === "paragraph") {
|
|
2098
|
+
item.tokens[0].text = checkbox + " " + item.tokens[0].text;
|
|
2099
|
+
if (item.tokens[0].tokens && item.tokens[0].tokens.length > 0 && item.tokens[0].tokens[0].type === "text") {
|
|
2100
|
+
item.tokens[0].tokens[0].text = checkbox + " " + escape2(item.tokens[0].tokens[0].text);
|
|
2101
|
+
item.tokens[0].tokens[0].escaped = true;
|
|
2102
|
+
}
|
|
2103
|
+
} else {
|
|
2104
|
+
item.tokens.unshift({
|
|
2105
|
+
type: "text",
|
|
2106
|
+
raw: checkbox + " ",
|
|
2107
|
+
text: checkbox + " ",
|
|
2108
|
+
escaped: true
|
|
2109
|
+
});
|
|
2110
|
+
}
|
|
2111
|
+
} else {
|
|
2112
|
+
itemBody += checkbox + " ";
|
|
2113
|
+
}
|
|
2114
|
+
}
|
|
2115
|
+
itemBody += this.parser.parse(item.tokens, !!item.loose);
|
|
2116
|
+
return `<li>${itemBody}</li>
|
|
2117
|
+
`;
|
|
2118
|
+
}
|
|
2119
|
+
checkbox({ checked }) {
|
|
2120
|
+
return "<input " + (checked ? 'checked="" ' : "") + 'disabled="" type="checkbox">';
|
|
2121
|
+
}
|
|
2122
|
+
paragraph({ tokens }) {
|
|
2123
|
+
return `<p>${this.parser.parseInline(tokens)}</p>
|
|
2124
|
+
`;
|
|
2125
|
+
}
|
|
2126
|
+
table(token) {
|
|
2127
|
+
let header = "";
|
|
2128
|
+
let cell = "";
|
|
2129
|
+
for (let j = 0; j < token.header.length; j++) {
|
|
2130
|
+
cell += this.tablecell(token.header[j]);
|
|
2131
|
+
}
|
|
2132
|
+
header += this.tablerow({ text: cell });
|
|
2133
|
+
let body = "";
|
|
2134
|
+
for (let j = 0; j < token.rows.length; j++) {
|
|
2135
|
+
const row = token.rows[j];
|
|
2136
|
+
cell = "";
|
|
2137
|
+
for (let k = 0; k < row.length; k++) {
|
|
2138
|
+
cell += this.tablecell(row[k]);
|
|
2139
|
+
}
|
|
2140
|
+
body += this.tablerow({ text: cell });
|
|
2141
|
+
}
|
|
2142
|
+
if (body) body = `<tbody>${body}</tbody>`;
|
|
2143
|
+
return "<table>\n<thead>\n" + header + "</thead>\n" + body + "</table>\n";
|
|
2144
|
+
}
|
|
2145
|
+
tablerow({ text }) {
|
|
2146
|
+
return `<tr>
|
|
2147
|
+
${text}</tr>
|
|
2148
|
+
`;
|
|
2149
|
+
}
|
|
2150
|
+
tablecell(token) {
|
|
2151
|
+
const content = this.parser.parseInline(token.tokens);
|
|
2152
|
+
const type = token.header ? "th" : "td";
|
|
2153
|
+
const tag2 = token.align ? `<${type} align="${token.align}">` : `<${type}>`;
|
|
2154
|
+
return tag2 + content + `</${type}>
|
|
2155
|
+
`;
|
|
2156
|
+
}
|
|
2157
|
+
/**
|
|
2158
|
+
* span level renderer
|
|
2159
|
+
*/
|
|
2160
|
+
strong({ tokens }) {
|
|
2161
|
+
return `<strong>${this.parser.parseInline(tokens)}</strong>`;
|
|
2162
|
+
}
|
|
2163
|
+
em({ tokens }) {
|
|
2164
|
+
return `<em>${this.parser.parseInline(tokens)}</em>`;
|
|
2165
|
+
}
|
|
2166
|
+
codespan({ text }) {
|
|
2167
|
+
return `<code>${escape2(text, true)}</code>`;
|
|
2168
|
+
}
|
|
2169
|
+
br(token) {
|
|
2170
|
+
return "<br>";
|
|
2171
|
+
}
|
|
2172
|
+
del({ tokens }) {
|
|
2173
|
+
return `<del>${this.parser.parseInline(tokens)}</del>`;
|
|
2174
|
+
}
|
|
2175
|
+
link({ href, title, tokens }) {
|
|
2176
|
+
const text = this.parser.parseInline(tokens);
|
|
2177
|
+
const cleanHref = cleanUrl(href);
|
|
2178
|
+
if (cleanHref === null) {
|
|
2179
|
+
return text;
|
|
2180
|
+
}
|
|
2181
|
+
href = cleanHref;
|
|
2182
|
+
let out = '<a href="' + href + '"';
|
|
2183
|
+
if (title) {
|
|
2184
|
+
out += ' title="' + escape2(title) + '"';
|
|
2185
|
+
}
|
|
2186
|
+
out += ">" + text + "</a>";
|
|
2187
|
+
return out;
|
|
2188
|
+
}
|
|
2189
|
+
image({ href, title, text, tokens }) {
|
|
2190
|
+
if (tokens) {
|
|
2191
|
+
text = this.parser.parseInline(tokens, this.parser.textRenderer);
|
|
2192
|
+
}
|
|
2193
|
+
const cleanHref = cleanUrl(href);
|
|
2194
|
+
if (cleanHref === null) {
|
|
2195
|
+
return escape2(text);
|
|
2196
|
+
}
|
|
2197
|
+
href = cleanHref;
|
|
2198
|
+
let out = `<img src="${href}" alt="${text}"`;
|
|
2199
|
+
if (title) {
|
|
2200
|
+
out += ` title="${escape2(title)}"`;
|
|
2201
|
+
}
|
|
2202
|
+
out += ">";
|
|
2203
|
+
return out;
|
|
2204
|
+
}
|
|
2205
|
+
text(token) {
|
|
2206
|
+
return "tokens" in token && token.tokens ? this.parser.parseInline(token.tokens) : "escaped" in token && token.escaped ? token.text : escape2(token.text);
|
|
2207
|
+
}
|
|
2208
|
+
};
|
|
2209
|
+
var _TextRenderer = class {
|
|
2210
|
+
// no need for block level renderers
|
|
2211
|
+
strong({ text }) {
|
|
2212
|
+
return text;
|
|
2213
|
+
}
|
|
2214
|
+
em({ text }) {
|
|
2215
|
+
return text;
|
|
2216
|
+
}
|
|
2217
|
+
codespan({ text }) {
|
|
2218
|
+
return text;
|
|
2219
|
+
}
|
|
2220
|
+
del({ text }) {
|
|
2221
|
+
return text;
|
|
2222
|
+
}
|
|
2223
|
+
html({ text }) {
|
|
2224
|
+
return text;
|
|
2225
|
+
}
|
|
2226
|
+
text({ text }) {
|
|
2227
|
+
return text;
|
|
2228
|
+
}
|
|
2229
|
+
link({ text }) {
|
|
2230
|
+
return "" + text;
|
|
2231
|
+
}
|
|
2232
|
+
image({ text }) {
|
|
2233
|
+
return "" + text;
|
|
2234
|
+
}
|
|
2235
|
+
br() {
|
|
2236
|
+
return "";
|
|
2237
|
+
}
|
|
2238
|
+
};
|
|
2239
|
+
var _Parser = class __Parser {
|
|
2240
|
+
constructor(options2) {
|
|
2241
|
+
__publicField(this, "options");
|
|
2242
|
+
__publicField(this, "renderer");
|
|
2243
|
+
__publicField(this, "textRenderer");
|
|
2244
|
+
this.options = options2 || _defaults;
|
|
2245
|
+
this.options.renderer = this.options.renderer || new _Renderer();
|
|
2246
|
+
this.renderer = this.options.renderer;
|
|
2247
|
+
this.renderer.options = this.options;
|
|
2248
|
+
this.renderer.parser = this;
|
|
2249
|
+
this.textRenderer = new _TextRenderer();
|
|
2250
|
+
}
|
|
2251
|
+
/**
|
|
2252
|
+
* Static Parse Method
|
|
2253
|
+
*/
|
|
2254
|
+
static parse(tokens, options2) {
|
|
2255
|
+
const parser2 = new __Parser(options2);
|
|
2256
|
+
return parser2.parse(tokens);
|
|
2257
|
+
}
|
|
2258
|
+
/**
|
|
2259
|
+
* Static Parse Inline Method
|
|
2260
|
+
*/
|
|
2261
|
+
static parseInline(tokens, options2) {
|
|
2262
|
+
const parser2 = new __Parser(options2);
|
|
2263
|
+
return parser2.parseInline(tokens);
|
|
2264
|
+
}
|
|
2265
|
+
/**
|
|
2266
|
+
* Parse Loop
|
|
2267
|
+
*/
|
|
2268
|
+
parse(tokens, top = true) {
|
|
2269
|
+
var _a2, _b;
|
|
2270
|
+
let out = "";
|
|
2271
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
2272
|
+
const anyToken = tokens[i];
|
|
2273
|
+
if ((_b = (_a2 = this.options.extensions) == null ? void 0 : _a2.renderers) == null ? void 0 : _b[anyToken.type]) {
|
|
2274
|
+
const genericToken = anyToken;
|
|
2275
|
+
const ret = this.options.extensions.renderers[genericToken.type].call({ parser: this }, genericToken);
|
|
2276
|
+
if (ret !== false || !["space", "hr", "heading", "code", "table", "blockquote", "list", "html", "paragraph", "text"].includes(genericToken.type)) {
|
|
2277
|
+
out += ret || "";
|
|
2278
|
+
continue;
|
|
2279
|
+
}
|
|
2280
|
+
}
|
|
2281
|
+
const token = anyToken;
|
|
2282
|
+
switch (token.type) {
|
|
2283
|
+
case "space": {
|
|
2284
|
+
out += this.renderer.space(token);
|
|
2285
|
+
continue;
|
|
2286
|
+
}
|
|
2287
|
+
case "hr": {
|
|
2288
|
+
out += this.renderer.hr(token);
|
|
2289
|
+
continue;
|
|
2290
|
+
}
|
|
2291
|
+
case "heading": {
|
|
2292
|
+
out += this.renderer.heading(token);
|
|
2293
|
+
continue;
|
|
2294
|
+
}
|
|
2295
|
+
case "code": {
|
|
2296
|
+
out += this.renderer.code(token);
|
|
2297
|
+
continue;
|
|
2298
|
+
}
|
|
2299
|
+
case "table": {
|
|
2300
|
+
out += this.renderer.table(token);
|
|
2301
|
+
continue;
|
|
2302
|
+
}
|
|
2303
|
+
case "blockquote": {
|
|
2304
|
+
out += this.renderer.blockquote(token);
|
|
2305
|
+
continue;
|
|
2306
|
+
}
|
|
2307
|
+
case "list": {
|
|
2308
|
+
out += this.renderer.list(token);
|
|
2309
|
+
continue;
|
|
2310
|
+
}
|
|
2311
|
+
case "html": {
|
|
2312
|
+
out += this.renderer.html(token);
|
|
2313
|
+
continue;
|
|
2314
|
+
}
|
|
2315
|
+
case "paragraph": {
|
|
2316
|
+
out += this.renderer.paragraph(token);
|
|
2317
|
+
continue;
|
|
2318
|
+
}
|
|
2319
|
+
case "text": {
|
|
2320
|
+
let textToken = token;
|
|
2321
|
+
let body = this.renderer.text(textToken);
|
|
2322
|
+
while (i + 1 < tokens.length && tokens[i + 1].type === "text") {
|
|
2323
|
+
textToken = tokens[++i];
|
|
2324
|
+
body += "\n" + this.renderer.text(textToken);
|
|
2325
|
+
}
|
|
2326
|
+
if (top) {
|
|
2327
|
+
out += this.renderer.paragraph({
|
|
2328
|
+
type: "paragraph",
|
|
2329
|
+
raw: body,
|
|
2330
|
+
text: body,
|
|
2331
|
+
tokens: [{ type: "text", raw: body, text: body, escaped: true }]
|
|
2332
|
+
});
|
|
2333
|
+
} else {
|
|
2334
|
+
out += body;
|
|
2335
|
+
}
|
|
2336
|
+
continue;
|
|
2337
|
+
}
|
|
2338
|
+
default: {
|
|
2339
|
+
const errMsg = 'Token with "' + token.type + '" type was not found.';
|
|
2340
|
+
if (this.options.silent) {
|
|
2341
|
+
console.error(errMsg);
|
|
2342
|
+
return "";
|
|
2343
|
+
} else {
|
|
2344
|
+
throw new Error(errMsg);
|
|
2345
|
+
}
|
|
2346
|
+
}
|
|
2347
|
+
}
|
|
2348
|
+
}
|
|
2349
|
+
return out;
|
|
2350
|
+
}
|
|
2351
|
+
/**
|
|
2352
|
+
* Parse Inline Tokens
|
|
2353
|
+
*/
|
|
2354
|
+
parseInline(tokens, renderer = this.renderer) {
|
|
2355
|
+
var _a2, _b;
|
|
2356
|
+
let out = "";
|
|
2357
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
2358
|
+
const anyToken = tokens[i];
|
|
2359
|
+
if ((_b = (_a2 = this.options.extensions) == null ? void 0 : _a2.renderers) == null ? void 0 : _b[anyToken.type]) {
|
|
2360
|
+
const ret = this.options.extensions.renderers[anyToken.type].call({ parser: this }, anyToken);
|
|
2361
|
+
if (ret !== false || !["escape", "html", "link", "image", "strong", "em", "codespan", "br", "del", "text"].includes(anyToken.type)) {
|
|
2362
|
+
out += ret || "";
|
|
2363
|
+
continue;
|
|
2364
|
+
}
|
|
2365
|
+
}
|
|
2366
|
+
const token = anyToken;
|
|
2367
|
+
switch (token.type) {
|
|
2368
|
+
case "escape": {
|
|
2369
|
+
out += renderer.text(token);
|
|
2370
|
+
break;
|
|
2371
|
+
}
|
|
2372
|
+
case "html": {
|
|
2373
|
+
out += renderer.html(token);
|
|
2374
|
+
break;
|
|
2375
|
+
}
|
|
2376
|
+
case "link": {
|
|
2377
|
+
out += renderer.link(token);
|
|
2378
|
+
break;
|
|
2379
|
+
}
|
|
2380
|
+
case "image": {
|
|
2381
|
+
out += renderer.image(token);
|
|
2382
|
+
break;
|
|
2383
|
+
}
|
|
2384
|
+
case "strong": {
|
|
2385
|
+
out += renderer.strong(token);
|
|
2386
|
+
break;
|
|
2387
|
+
}
|
|
2388
|
+
case "em": {
|
|
2389
|
+
out += renderer.em(token);
|
|
2390
|
+
break;
|
|
2391
|
+
}
|
|
2392
|
+
case "codespan": {
|
|
2393
|
+
out += renderer.codespan(token);
|
|
2394
|
+
break;
|
|
2395
|
+
}
|
|
2396
|
+
case "br": {
|
|
2397
|
+
out += renderer.br(token);
|
|
2398
|
+
break;
|
|
2399
|
+
}
|
|
2400
|
+
case "del": {
|
|
2401
|
+
out += renderer.del(token);
|
|
2402
|
+
break;
|
|
2403
|
+
}
|
|
2404
|
+
case "text": {
|
|
2405
|
+
out += renderer.text(token);
|
|
2406
|
+
break;
|
|
2407
|
+
}
|
|
2408
|
+
default: {
|
|
2409
|
+
const errMsg = 'Token with "' + token.type + '" type was not found.';
|
|
2410
|
+
if (this.options.silent) {
|
|
2411
|
+
console.error(errMsg);
|
|
2412
|
+
return "";
|
|
2413
|
+
} else {
|
|
2414
|
+
throw new Error(errMsg);
|
|
2415
|
+
}
|
|
2416
|
+
}
|
|
2417
|
+
}
|
|
2418
|
+
}
|
|
2419
|
+
return out;
|
|
2420
|
+
}
|
|
2421
|
+
};
|
|
2422
|
+
var _a;
|
|
2423
|
+
var _Hooks = (_a = class {
|
|
2424
|
+
constructor(options2) {
|
|
2425
|
+
__publicField(this, "options");
|
|
2426
|
+
__publicField(this, "block");
|
|
2427
|
+
this.options = options2 || _defaults;
|
|
2428
|
+
}
|
|
2429
|
+
/**
|
|
2430
|
+
* Process markdown before marked
|
|
2431
|
+
*/
|
|
2432
|
+
preprocess(markdown) {
|
|
2433
|
+
return markdown;
|
|
2434
|
+
}
|
|
2435
|
+
/**
|
|
2436
|
+
* Process HTML after marked is finished
|
|
2437
|
+
*/
|
|
2438
|
+
postprocess(html2) {
|
|
2439
|
+
return html2;
|
|
2440
|
+
}
|
|
2441
|
+
/**
|
|
2442
|
+
* Process all tokens before walk tokens
|
|
2443
|
+
*/
|
|
2444
|
+
processAllTokens(tokens) {
|
|
2445
|
+
return tokens;
|
|
2446
|
+
}
|
|
2447
|
+
/**
|
|
2448
|
+
* Provide function to tokenize markdown
|
|
2449
|
+
*/
|
|
2450
|
+
provideLexer() {
|
|
2451
|
+
return this.block ? _Lexer.lex : _Lexer.lexInline;
|
|
2452
|
+
}
|
|
2453
|
+
/**
|
|
2454
|
+
* Provide function to parse tokens
|
|
2455
|
+
*/
|
|
2456
|
+
provideParser() {
|
|
2457
|
+
return this.block ? _Parser.parse : _Parser.parseInline;
|
|
2458
|
+
}
|
|
2459
|
+
}, __publicField(_a, "passThroughHooks", /* @__PURE__ */ new Set([
|
|
2460
|
+
"preprocess",
|
|
2461
|
+
"postprocess",
|
|
2462
|
+
"processAllTokens"
|
|
2463
|
+
])), _a);
|
|
2464
|
+
var Marked = class {
|
|
2465
|
+
constructor(...args) {
|
|
2466
|
+
__publicField(this, "defaults", _getDefaults());
|
|
2467
|
+
__publicField(this, "options", this.setOptions);
|
|
2468
|
+
__publicField(this, "parse", this.parseMarkdown(true));
|
|
2469
|
+
__publicField(this, "parseInline", this.parseMarkdown(false));
|
|
2470
|
+
__publicField(this, "Parser", _Parser);
|
|
2471
|
+
__publicField(this, "Renderer", _Renderer);
|
|
2472
|
+
__publicField(this, "TextRenderer", _TextRenderer);
|
|
2473
|
+
__publicField(this, "Lexer", _Lexer);
|
|
2474
|
+
__publicField(this, "Tokenizer", _Tokenizer);
|
|
2475
|
+
__publicField(this, "Hooks", _Hooks);
|
|
2476
|
+
this.use(...args);
|
|
2477
|
+
}
|
|
2478
|
+
/**
|
|
2479
|
+
* Run callback for every token
|
|
2480
|
+
*/
|
|
2481
|
+
walkTokens(tokens, callback) {
|
|
2482
|
+
var _a2, _b;
|
|
2483
|
+
let values = [];
|
|
2484
|
+
for (const token of tokens) {
|
|
2485
|
+
values = values.concat(callback.call(this, token));
|
|
2486
|
+
switch (token.type) {
|
|
2487
|
+
case "table": {
|
|
2488
|
+
const tableToken = token;
|
|
2489
|
+
for (const cell of tableToken.header) {
|
|
2490
|
+
values = values.concat(this.walkTokens(cell.tokens, callback));
|
|
2491
|
+
}
|
|
2492
|
+
for (const row of tableToken.rows) {
|
|
2493
|
+
for (const cell of row) {
|
|
2494
|
+
values = values.concat(this.walkTokens(cell.tokens, callback));
|
|
2495
|
+
}
|
|
2496
|
+
}
|
|
2497
|
+
break;
|
|
2498
|
+
}
|
|
2499
|
+
case "list": {
|
|
2500
|
+
const listToken = token;
|
|
2501
|
+
values = values.concat(this.walkTokens(listToken.items, callback));
|
|
2502
|
+
break;
|
|
2503
|
+
}
|
|
2504
|
+
default: {
|
|
2505
|
+
const genericToken = token;
|
|
2506
|
+
if ((_b = (_a2 = this.defaults.extensions) == null ? void 0 : _a2.childTokens) == null ? void 0 : _b[genericToken.type]) {
|
|
2507
|
+
this.defaults.extensions.childTokens[genericToken.type].forEach((childTokens) => {
|
|
2508
|
+
const tokens2 = genericToken[childTokens].flat(Infinity);
|
|
2509
|
+
values = values.concat(this.walkTokens(tokens2, callback));
|
|
2510
|
+
});
|
|
2511
|
+
} else if (genericToken.tokens) {
|
|
2512
|
+
values = values.concat(this.walkTokens(genericToken.tokens, callback));
|
|
2513
|
+
}
|
|
2514
|
+
}
|
|
2515
|
+
}
|
|
2516
|
+
}
|
|
2517
|
+
return values;
|
|
2518
|
+
}
|
|
2519
|
+
use(...args) {
|
|
2520
|
+
const extensions = this.defaults.extensions || { renderers: {}, childTokens: {} };
|
|
2521
|
+
args.forEach((pack) => {
|
|
2522
|
+
const opts = { ...pack };
|
|
2523
|
+
opts.async = this.defaults.async || opts.async || false;
|
|
2524
|
+
if (pack.extensions) {
|
|
2525
|
+
pack.extensions.forEach((ext) => {
|
|
2526
|
+
if (!ext.name) {
|
|
2527
|
+
throw new Error("extension name required");
|
|
2528
|
+
}
|
|
2529
|
+
if ("renderer" in ext) {
|
|
2530
|
+
const prevRenderer = extensions.renderers[ext.name];
|
|
2531
|
+
if (prevRenderer) {
|
|
2532
|
+
extensions.renderers[ext.name] = function(...args2) {
|
|
2533
|
+
let ret = ext.renderer.apply(this, args2);
|
|
2534
|
+
if (ret === false) {
|
|
2535
|
+
ret = prevRenderer.apply(this, args2);
|
|
2536
|
+
}
|
|
2537
|
+
return ret;
|
|
2538
|
+
};
|
|
2539
|
+
} else {
|
|
2540
|
+
extensions.renderers[ext.name] = ext.renderer;
|
|
2541
|
+
}
|
|
2542
|
+
}
|
|
2543
|
+
if ("tokenizer" in ext) {
|
|
2544
|
+
if (!ext.level || ext.level !== "block" && ext.level !== "inline") {
|
|
2545
|
+
throw new Error("extension level must be 'block' or 'inline'");
|
|
2546
|
+
}
|
|
2547
|
+
const extLevel = extensions[ext.level];
|
|
2548
|
+
if (extLevel) {
|
|
2549
|
+
extLevel.unshift(ext.tokenizer);
|
|
2550
|
+
} else {
|
|
2551
|
+
extensions[ext.level] = [ext.tokenizer];
|
|
2552
|
+
}
|
|
2553
|
+
if (ext.start) {
|
|
2554
|
+
if (ext.level === "block") {
|
|
2555
|
+
if (extensions.startBlock) {
|
|
2556
|
+
extensions.startBlock.push(ext.start);
|
|
2557
|
+
} else {
|
|
2558
|
+
extensions.startBlock = [ext.start];
|
|
2559
|
+
}
|
|
2560
|
+
} else if (ext.level === "inline") {
|
|
2561
|
+
if (extensions.startInline) {
|
|
2562
|
+
extensions.startInline.push(ext.start);
|
|
2563
|
+
} else {
|
|
2564
|
+
extensions.startInline = [ext.start];
|
|
2565
|
+
}
|
|
2566
|
+
}
|
|
2567
|
+
}
|
|
2568
|
+
}
|
|
2569
|
+
if ("childTokens" in ext && ext.childTokens) {
|
|
2570
|
+
extensions.childTokens[ext.name] = ext.childTokens;
|
|
2571
|
+
}
|
|
2572
|
+
});
|
|
2573
|
+
opts.extensions = extensions;
|
|
2574
|
+
}
|
|
2575
|
+
if (pack.renderer) {
|
|
2576
|
+
const renderer = this.defaults.renderer || new _Renderer(this.defaults);
|
|
2577
|
+
for (const prop in pack.renderer) {
|
|
2578
|
+
if (!(prop in renderer)) {
|
|
2579
|
+
throw new Error(`renderer '${prop}' does not exist`);
|
|
2580
|
+
}
|
|
2581
|
+
if (["options", "parser"].includes(prop)) {
|
|
2582
|
+
continue;
|
|
2583
|
+
}
|
|
2584
|
+
const rendererProp = prop;
|
|
2585
|
+
const rendererFunc = pack.renderer[rendererProp];
|
|
2586
|
+
const prevRenderer = renderer[rendererProp];
|
|
2587
|
+
renderer[rendererProp] = (...args2) => {
|
|
2588
|
+
let ret = rendererFunc.apply(renderer, args2);
|
|
2589
|
+
if (ret === false) {
|
|
2590
|
+
ret = prevRenderer.apply(renderer, args2);
|
|
2591
|
+
}
|
|
2592
|
+
return ret || "";
|
|
2593
|
+
};
|
|
2594
|
+
}
|
|
2595
|
+
opts.renderer = renderer;
|
|
2596
|
+
}
|
|
2597
|
+
if (pack.tokenizer) {
|
|
2598
|
+
const tokenizer = this.defaults.tokenizer || new _Tokenizer(this.defaults);
|
|
2599
|
+
for (const prop in pack.tokenizer) {
|
|
2600
|
+
if (!(prop in tokenizer)) {
|
|
2601
|
+
throw new Error(`tokenizer '${prop}' does not exist`);
|
|
2602
|
+
}
|
|
2603
|
+
if (["options", "rules", "lexer"].includes(prop)) {
|
|
2604
|
+
continue;
|
|
2605
|
+
}
|
|
2606
|
+
const tokenizerProp = prop;
|
|
2607
|
+
const tokenizerFunc = pack.tokenizer[tokenizerProp];
|
|
2608
|
+
const prevTokenizer = tokenizer[tokenizerProp];
|
|
2609
|
+
tokenizer[tokenizerProp] = (...args2) => {
|
|
2610
|
+
let ret = tokenizerFunc.apply(tokenizer, args2);
|
|
2611
|
+
if (ret === false) {
|
|
2612
|
+
ret = prevTokenizer.apply(tokenizer, args2);
|
|
2613
|
+
}
|
|
2614
|
+
return ret;
|
|
2615
|
+
};
|
|
2616
|
+
}
|
|
2617
|
+
opts.tokenizer = tokenizer;
|
|
2618
|
+
}
|
|
2619
|
+
if (pack.hooks) {
|
|
2620
|
+
const hooks = this.defaults.hooks || new _Hooks();
|
|
2621
|
+
for (const prop in pack.hooks) {
|
|
2622
|
+
if (!(prop in hooks)) {
|
|
2623
|
+
throw new Error(`hook '${prop}' does not exist`);
|
|
2624
|
+
}
|
|
2625
|
+
if (["options", "block"].includes(prop)) {
|
|
2626
|
+
continue;
|
|
2627
|
+
}
|
|
2628
|
+
const hooksProp = prop;
|
|
2629
|
+
const hooksFunc = pack.hooks[hooksProp];
|
|
2630
|
+
const prevHook = hooks[hooksProp];
|
|
2631
|
+
if (_Hooks.passThroughHooks.has(prop)) {
|
|
2632
|
+
hooks[hooksProp] = (arg) => {
|
|
2633
|
+
if (this.defaults.async) {
|
|
2634
|
+
return Promise.resolve(hooksFunc.call(hooks, arg)).then((ret2) => {
|
|
2635
|
+
return prevHook.call(hooks, ret2);
|
|
2636
|
+
});
|
|
2637
|
+
}
|
|
2638
|
+
const ret = hooksFunc.call(hooks, arg);
|
|
2639
|
+
return prevHook.call(hooks, ret);
|
|
2640
|
+
};
|
|
2641
|
+
} else {
|
|
2642
|
+
hooks[hooksProp] = (...args2) => {
|
|
2643
|
+
let ret = hooksFunc.apply(hooks, args2);
|
|
2644
|
+
if (ret === false) {
|
|
2645
|
+
ret = prevHook.apply(hooks, args2);
|
|
2646
|
+
}
|
|
2647
|
+
return ret;
|
|
2648
|
+
};
|
|
2649
|
+
}
|
|
2650
|
+
}
|
|
2651
|
+
opts.hooks = hooks;
|
|
2652
|
+
}
|
|
2653
|
+
if (pack.walkTokens) {
|
|
2654
|
+
const walkTokens2 = this.defaults.walkTokens;
|
|
2655
|
+
const packWalktokens = pack.walkTokens;
|
|
2656
|
+
opts.walkTokens = function(token) {
|
|
2657
|
+
let values = [];
|
|
2658
|
+
values.push(packWalktokens.call(this, token));
|
|
2659
|
+
if (walkTokens2) {
|
|
2660
|
+
values = values.concat(walkTokens2.call(this, token));
|
|
2661
|
+
}
|
|
2662
|
+
return values;
|
|
2663
|
+
};
|
|
2664
|
+
}
|
|
2665
|
+
this.defaults = { ...this.defaults, ...opts };
|
|
2666
|
+
});
|
|
2667
|
+
return this;
|
|
2668
|
+
}
|
|
2669
|
+
setOptions(opt) {
|
|
2670
|
+
this.defaults = { ...this.defaults, ...opt };
|
|
2671
|
+
return this;
|
|
2672
|
+
}
|
|
2673
|
+
lexer(src, options2) {
|
|
2674
|
+
return _Lexer.lex(src, options2 != null ? options2 : this.defaults);
|
|
2675
|
+
}
|
|
2676
|
+
parser(tokens, options2) {
|
|
2677
|
+
return _Parser.parse(tokens, options2 != null ? options2 : this.defaults);
|
|
2678
|
+
}
|
|
2679
|
+
parseMarkdown(blockType) {
|
|
2680
|
+
const parse2 = (src, options2) => {
|
|
2681
|
+
const origOpt = { ...options2 };
|
|
2682
|
+
const opt = { ...this.defaults, ...origOpt };
|
|
2683
|
+
const throwError = this.onError(!!opt.silent, !!opt.async);
|
|
2684
|
+
if (this.defaults.async === true && origOpt.async === false) {
|
|
2685
|
+
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."));
|
|
2686
|
+
}
|
|
2687
|
+
if (typeof src === "undefined" || src === null) {
|
|
2688
|
+
return throwError(new Error("marked(): input parameter is undefined or null"));
|
|
2689
|
+
}
|
|
2690
|
+
if (typeof src !== "string") {
|
|
2691
|
+
return throwError(new Error("marked(): input parameter is of type " + Object.prototype.toString.call(src) + ", string expected"));
|
|
2692
|
+
}
|
|
2693
|
+
if (opt.hooks) {
|
|
2694
|
+
opt.hooks.options = opt;
|
|
2695
|
+
opt.hooks.block = blockType;
|
|
2696
|
+
}
|
|
2697
|
+
const lexer2 = opt.hooks ? opt.hooks.provideLexer() : blockType ? _Lexer.lex : _Lexer.lexInline;
|
|
2698
|
+
const parser2 = opt.hooks ? opt.hooks.provideParser() : blockType ? _Parser.parse : _Parser.parseInline;
|
|
2699
|
+
if (opt.async) {
|
|
2700
|
+
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);
|
|
2701
|
+
}
|
|
2702
|
+
try {
|
|
2703
|
+
if (opt.hooks) {
|
|
2704
|
+
src = opt.hooks.preprocess(src);
|
|
2705
|
+
}
|
|
2706
|
+
let tokens = lexer2(src, opt);
|
|
2707
|
+
if (opt.hooks) {
|
|
2708
|
+
tokens = opt.hooks.processAllTokens(tokens);
|
|
2709
|
+
}
|
|
2710
|
+
if (opt.walkTokens) {
|
|
2711
|
+
this.walkTokens(tokens, opt.walkTokens);
|
|
2712
|
+
}
|
|
2713
|
+
let html2 = parser2(tokens, opt);
|
|
2714
|
+
if (opt.hooks) {
|
|
2715
|
+
html2 = opt.hooks.postprocess(html2);
|
|
2716
|
+
}
|
|
2717
|
+
return html2;
|
|
2718
|
+
} catch (e) {
|
|
2719
|
+
return throwError(e);
|
|
2720
|
+
}
|
|
2721
|
+
};
|
|
2722
|
+
return parse2;
|
|
2723
|
+
}
|
|
2724
|
+
onError(silent, async) {
|
|
2725
|
+
return (e) => {
|
|
2726
|
+
e.message += "\nPlease report this to https://github.com/markedjs/marked.";
|
|
2727
|
+
if (silent) {
|
|
2728
|
+
const msg = "<p>An error occurred:</p><pre>" + escape2(e.message + "", true) + "</pre>";
|
|
2729
|
+
if (async) {
|
|
2730
|
+
return Promise.resolve(msg);
|
|
2731
|
+
}
|
|
2732
|
+
return msg;
|
|
2733
|
+
}
|
|
2734
|
+
if (async) {
|
|
2735
|
+
return Promise.reject(e);
|
|
2736
|
+
}
|
|
2737
|
+
throw e;
|
|
2738
|
+
};
|
|
2739
|
+
}
|
|
2740
|
+
};
|
|
2741
|
+
var markedInstance = new Marked();
|
|
2742
|
+
function marked(src, opt) {
|
|
2743
|
+
return markedInstance.parse(src, opt);
|
|
2744
|
+
}
|
|
2745
|
+
marked.options = marked.setOptions = function(options2) {
|
|
2746
|
+
markedInstance.setOptions(options2);
|
|
2747
|
+
marked.defaults = markedInstance.defaults;
|
|
2748
|
+
changeDefaults(marked.defaults);
|
|
2749
|
+
return marked;
|
|
2750
|
+
};
|
|
2751
|
+
marked.getDefaults = _getDefaults;
|
|
2752
|
+
marked.defaults = _defaults;
|
|
2753
|
+
marked.use = function(...args) {
|
|
2754
|
+
markedInstance.use(...args);
|
|
2755
|
+
marked.defaults = markedInstance.defaults;
|
|
2756
|
+
changeDefaults(marked.defaults);
|
|
2757
|
+
return marked;
|
|
2758
|
+
};
|
|
2759
|
+
marked.walkTokens = function(tokens, callback) {
|
|
2760
|
+
return markedInstance.walkTokens(tokens, callback);
|
|
2761
|
+
};
|
|
2762
|
+
marked.parseInline = markedInstance.parseInline;
|
|
2763
|
+
marked.Parser = _Parser;
|
|
2764
|
+
marked.parser = _Parser.parse;
|
|
2765
|
+
marked.Renderer = _Renderer;
|
|
2766
|
+
marked.TextRenderer = _TextRenderer;
|
|
2767
|
+
marked.Lexer = _Lexer;
|
|
2768
|
+
marked.lexer = _Lexer.lex;
|
|
2769
|
+
marked.Tokenizer = _Tokenizer;
|
|
2770
|
+
marked.Hooks = _Hooks;
|
|
2771
|
+
marked.parse = marked;
|
|
2772
|
+
var options = marked.options;
|
|
2773
|
+
var setOptions = marked.setOptions;
|
|
2774
|
+
var use = marked.use;
|
|
2775
|
+
var walkTokens = marked.walkTokens;
|
|
2776
|
+
var parseInline = marked.parseInline;
|
|
2777
|
+
var parser = _Parser.parse;
|
|
2778
|
+
var lexer = _Lexer.lex;
|
|
2779
|
+
|
|
2780
|
+
// ../adaptives/adaptive-faq/dist/FAQWidget.js
|
|
632
2781
|
import React2, { useCallback as useCallback2, useEffect as useEffect2, useMemo, useReducer, useState as useState2 } from "react";
|
|
633
2782
|
import { createRoot as createRoot2 } from "react-dom/client";
|
|
2783
|
+
var marked2 = new Marked({ async: false, gfm: true, breaks: true });
|
|
634
2784
|
function getAnswerText(answer) {
|
|
635
2785
|
if (typeof answer === "string")
|
|
636
2786
|
return answer;
|
|
@@ -645,7 +2795,11 @@ function renderAnswer(answer) {
|
|
|
645
2795
|
if (answer.type === "rich") {
|
|
646
2796
|
return _jsx2("div", { style: { margin: 0 }, dangerouslySetInnerHTML: { __html: answer.html } });
|
|
647
2797
|
}
|
|
648
|
-
|
|
2798
|
+
const html2 = marked2.parse(answer.content);
|
|
2799
|
+
return (
|
|
2800
|
+
// biome-ignore lint/security/noDangerouslySetInnerHtml: markdown content is CMS/config content, not user-controlled input
|
|
2801
|
+
_jsx2("div", { style: { margin: 0 }, "data-faq-markdown": "", dangerouslySetInnerHTML: { __html: html2 } })
|
|
2802
|
+
);
|
|
649
2803
|
}
|
|
650
2804
|
function resolveFeedbackConfig(feedback) {
|
|
651
2805
|
if (!feedback)
|
|
@@ -774,7 +2928,10 @@ var themeStyles = {
|
|
|
774
2928
|
},
|
|
775
2929
|
item: {
|
|
776
2930
|
backgroundColor: "var(--sc-content-background)",
|
|
777
|
-
|
|
2931
|
+
borderTop: "var(--sc-content-border)",
|
|
2932
|
+
borderRight: "var(--sc-content-border)",
|
|
2933
|
+
borderBottom: "var(--sc-content-border)",
|
|
2934
|
+
borderLeft: "var(--sc-content-border)"
|
|
778
2935
|
},
|
|
779
2936
|
itemExpanded: {
|
|
780
2937
|
boxShadow: "0 4px 12px rgba(0, 0, 0, 0.08)"
|
|
@@ -813,7 +2970,10 @@ var themeStyles = {
|
|
|
813
2970
|
},
|
|
814
2971
|
item: {
|
|
815
2972
|
backgroundColor: "var(--sc-content-background)",
|
|
816
|
-
|
|
2973
|
+
borderTop: "var(--sc-content-border)",
|
|
2974
|
+
borderRight: "var(--sc-content-border)",
|
|
2975
|
+
borderBottom: "var(--sc-content-border)",
|
|
2976
|
+
borderLeft: "var(--sc-content-border)"
|
|
817
2977
|
},
|
|
818
2978
|
itemExpanded: {
|
|
819
2979
|
boxShadow: "0 4px 12px rgba(0, 0, 0, 0.15)"
|
|
@@ -898,8 +3058,8 @@ function FAQWidget({ config, runtime: runtime7, instanceId }) {
|
|
|
898
3058
|
return unsubscribe;
|
|
899
3059
|
}, [runtime7.context]);
|
|
900
3060
|
useEffect2(() => {
|
|
901
|
-
var
|
|
902
|
-
if (!((
|
|
3061
|
+
var _a2;
|
|
3062
|
+
if (!((_a2 = runtime7.accumulator) == null ? void 0 : _a2.subscribe))
|
|
903
3063
|
return;
|
|
904
3064
|
return runtime7.accumulator.subscribe(() => {
|
|
905
3065
|
forceUpdate();
|
|
@@ -911,8 +3071,8 @@ function FAQWidget({ config, runtime: runtime7, instanceId }) {
|
|
|
911
3071
|
if (runtime7.events.getRecent) {
|
|
912
3072
|
const recentEvents = runtime7.events.getRecent({ patterns: ["^action\\.tooltip_cta_clicked$", "^action\\.modal_cta_clicked$"] }, 10);
|
|
913
3073
|
const pendingEvent = recentEvents.filter((e) => {
|
|
914
|
-
var
|
|
915
|
-
const actionId = (
|
|
3074
|
+
var _a2;
|
|
3075
|
+
const actionId = (_a2 = e.props) == null ? void 0 : _a2.actionId;
|
|
916
3076
|
return typeof actionId === "string" && actionId.startsWith("faq:open:");
|
|
917
3077
|
}).pop();
|
|
918
3078
|
if (pendingEvent && Date.now() - pendingEvent.ts < 1e4) {
|
|
@@ -926,8 +3086,8 @@ function FAQWidget({ config, runtime: runtime7, instanceId }) {
|
|
|
926
3086
|
}
|
|
927
3087
|
}
|
|
928
3088
|
const unsubscribe = runtime7.events.subscribe({ patterns: ["^action\\.tooltip_cta_clicked$", "^action\\.modal_cta_clicked$"] }, (event) => {
|
|
929
|
-
var
|
|
930
|
-
const actionId = (
|
|
3089
|
+
var _a2;
|
|
3090
|
+
const actionId = (_a2 = event.props) == null ? void 0 : _a2.actionId;
|
|
931
3091
|
if (typeof actionId !== "string" || !actionId.startsWith("faq:open:"))
|
|
932
3092
|
return;
|
|
933
3093
|
const questionId = actionId.replace("faq:open:", "");
|
|
@@ -945,8 +3105,8 @@ function FAQWidget({ config, runtime: runtime7, instanceId }) {
|
|
|
945
3105
|
if (!runtime7.events.subscribe)
|
|
946
3106
|
return;
|
|
947
3107
|
const handleDeepLink = (event) => {
|
|
948
|
-
var
|
|
949
|
-
const tileId = (
|
|
3108
|
+
var _a2, _b;
|
|
3109
|
+
const tileId = (_a2 = event.props) == null ? void 0 : _a2.tileId;
|
|
950
3110
|
const itemId = (_b = event.props) == null ? void 0 : _b.itemId;
|
|
951
3111
|
if (tileId !== instanceId)
|
|
952
3112
|
return;
|
|
@@ -964,8 +3124,8 @@ function FAQWidget({ config, runtime: runtime7, instanceId }) {
|
|
|
964
3124
|
if (runtime7.events.getRecent) {
|
|
965
3125
|
const recent = runtime7.events.getRecent({ names: ["notification.deep_link"] }, 5);
|
|
966
3126
|
const pending = recent.filter((e) => {
|
|
967
|
-
var
|
|
968
|
-
return ((
|
|
3127
|
+
var _a2, _b;
|
|
3128
|
+
return ((_a2 = e.props) == null ? void 0 : _a2.tileId) === instanceId && ((_b = e.props) == null ? void 0 : _b.itemId);
|
|
969
3129
|
}).pop();
|
|
970
3130
|
if (pending && Date.now() - pending.ts < 1e4) {
|
|
971
3131
|
handleDeepLink(pending);
|
|
@@ -983,8 +3143,8 @@ function FAQWidget({ config, runtime: runtime7, instanceId }) {
|
|
|
983
3143
|
const orderedQuestions = useMemo(() => {
|
|
984
3144
|
if (config.ordering === "priority") {
|
|
985
3145
|
return [...visibleQuestions].sort((a, b) => {
|
|
986
|
-
var
|
|
987
|
-
return ((
|
|
3146
|
+
var _a2, _b;
|
|
3147
|
+
return ((_a2 = b.config.priority) != null ? _a2 : 0) - ((_b = a.config.priority) != null ? _b : 0);
|
|
988
3148
|
});
|
|
989
3149
|
}
|
|
990
3150
|
return visibleQuestions;
|
|
@@ -995,8 +3155,8 @@ function FAQWidget({ config, runtime: runtime7, instanceId }) {
|
|
|
995
3155
|
}
|
|
996
3156
|
const query = searchQuery.toLowerCase();
|
|
997
3157
|
return orderedQuestions.filter((q) => {
|
|
998
|
-
var
|
|
999
|
-
return q.config.question.toLowerCase().includes(query) || getAnswerText(q.config.answer).toLowerCase().includes(query) || ((
|
|
3158
|
+
var _a2;
|
|
3159
|
+
return q.config.question.toLowerCase().includes(query) || getAnswerText(q.config.answer).toLowerCase().includes(query) || ((_a2 = q.config.category) == null ? void 0 : _a2.toLowerCase().includes(query));
|
|
1000
3160
|
});
|
|
1001
3161
|
}, [orderedQuestions, searchQuery, config.searchable]);
|
|
1002
3162
|
const categoryGroups = useMemo(() => {
|
|
@@ -1012,11 +3172,11 @@ function FAQWidget({ config, runtime: runtime7, instanceId }) {
|
|
|
1012
3172
|
}, [filteredQuestions]);
|
|
1013
3173
|
const hasCategories = useMemo(() => filteredQuestions.some((q) => q.config.category), [filteredQuestions]);
|
|
1014
3174
|
const resolvedTheme = useMemo(() => {
|
|
1015
|
-
var
|
|
3175
|
+
var _a2;
|
|
1016
3176
|
if (config.theme && config.theme !== "auto")
|
|
1017
3177
|
return config.theme;
|
|
1018
3178
|
if (typeof window !== "undefined") {
|
|
1019
|
-
return ((
|
|
3179
|
+
return ((_a2 = window.matchMedia) == null ? void 0 : _a2.call(window, "(prefers-color-scheme: dark)").matches) ? "dark" : "light";
|
|
1020
3180
|
}
|
|
1021
3181
|
return "light";
|
|
1022
3182
|
}, [config.theme]);
|
|
@@ -1144,8 +3304,8 @@ var runtime4 = {
|
|
|
1144
3304
|
* and publishes faq:question_revealed when triggerWhen transitions false → true.
|
|
1145
3305
|
*/
|
|
1146
3306
|
notifyWatchers(props) {
|
|
1147
|
-
var
|
|
1148
|
-
const actions = (
|
|
3307
|
+
var _a2;
|
|
3308
|
+
const actions = (_a2 = props.actions) != null ? _a2 : [];
|
|
1149
3309
|
return actions.filter((a) => a.notify && a.triggerWhen).map((a) => ({
|
|
1150
3310
|
id: `faq:${a.config.id}`,
|
|
1151
3311
|
strategy: a.triggerWhen,
|
|
@@ -1209,6 +3369,21 @@ var runtime5 = {
|
|
|
1209
3369
|
import { jsx as _jsx3, jsxs as _jsxs3 } from "react/jsx-runtime";
|
|
1210
3370
|
import React3, { useCallback as useCallback3, useEffect as useEffect3, useMemo as useMemo2, useReducer as useReducer2, useState as useState3 } from "react";
|
|
1211
3371
|
import { createRoot as createRoot3 } from "react-dom/client";
|
|
3372
|
+
var EMOJI_SVG_MAP = {
|
|
3373
|
+
"\u{1F4B5}": '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="20" height="12" x="2" y="6" rx="2"/><circle cx="12" cy="12" r="2"/><path d="M6 12h.01M18 12h.01"/></svg>',
|
|
3374
|
+
"\u{1F3DB}\uFE0F": '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="3" x2="21" y1="22" y2="22"/><line x1="6" x2="6" y1="18" y2="11"/><line x1="10" x2="10" y1="18" y2="11"/><line x1="14" x2="14" y1="18" y2="11"/><line x1="18" x2="18" y1="18" y2="11"/><polygon points="12 2 20 7 4 7"/></svg>',
|
|
3375
|
+
"\u23ED\uFE0F": '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="5 4 15 12 5 20 5 4"/><line x1="19" x2="19" y1="5" y2="19"/></svg>',
|
|
3376
|
+
"\u27A1\uFE0F": '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12h14"/><path d="m12 5 7 7-7 7"/></svg>',
|
|
3377
|
+
"\u{1F4A1}": '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5.7.7 1.3 1.5 1.5 2.5"/><path d="M9 18h6"/><path d="M10 22h4"/></svg>',
|
|
3378
|
+
"\u{1F4B0}": '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="20" height="12" x="2" y="6" rx="2"/><circle cx="12" cy="12" r="2"/><path d="M6 12h.01M18 12h.01"/></svg>',
|
|
3379
|
+
"\u{1F4CB}": '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="8" height="4" x="8" y="2" rx="1" ry="1"/><path d="M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2"/><path d="M12 11h4"/><path d="M12 16h4"/><path d="M8 11h.01"/><path d="M8 16h.01"/></svg>',
|
|
3380
|
+
"\u2705": '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/><path d="m9 11 3 3L22 4"/></svg>',
|
|
3381
|
+
"\u26A0\uFE0F": '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3"/><path d="M12 9v4"/><path d="M12 17h.01"/></svg>'
|
|
3382
|
+
};
|
|
3383
|
+
function renderIcon(emoji) {
|
|
3384
|
+
var _a2;
|
|
3385
|
+
return (_a2 = EMOJI_SVG_MAP[emoji]) != null ? _a2 : escapeHtml(emoji);
|
|
3386
|
+
}
|
|
1212
3387
|
function escapeHtml(str) {
|
|
1213
3388
|
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
1214
3389
|
}
|
|
@@ -1358,10 +3533,29 @@ var themeStyles2 = {
|
|
|
1358
3533
|
}
|
|
1359
3534
|
}
|
|
1360
3535
|
};
|
|
1361
|
-
function
|
|
3536
|
+
function routeMatchesCurrent(routes) {
|
|
3537
|
+
if (typeof window === "undefined")
|
|
3538
|
+
return false;
|
|
3539
|
+
const current = window.location.pathname;
|
|
3540
|
+
return routes.some((route) => {
|
|
3541
|
+
const routePath = route.split("?")[0].split("#")[0];
|
|
3542
|
+
if (routePath.endsWith("/**")) {
|
|
3543
|
+
return current.startsWith(routePath.slice(0, -3));
|
|
3544
|
+
}
|
|
3545
|
+
return current === routePath;
|
|
3546
|
+
});
|
|
3547
|
+
}
|
|
3548
|
+
function pulseElement(el) {
|
|
3549
|
+
const keyframes = [
|
|
3550
|
+
{ boxShadow: "0 0 0 0 rgba(13, 148, 136, 0.5)" },
|
|
3551
|
+
{ boxShadow: "0 0 0 8px rgba(13, 148, 136, 0)" }
|
|
3552
|
+
];
|
|
3553
|
+
el.animate(keyframes, { duration: 600, iterations: 3, easing: "ease-out" });
|
|
3554
|
+
}
|
|
3555
|
+
function NavTipItem({ item, isExpanded, isLast, onToggle, onNavigate, onFocusAnchor, theme }) {
|
|
1362
3556
|
const [isHovered, setIsHovered] = useState3(false);
|
|
1363
3557
|
const colors = themeStyles2[theme];
|
|
1364
|
-
const { title, description, href, icon, external } = item.config;
|
|
3558
|
+
const { title, description, href, icon, external, anchor } = item.config;
|
|
1365
3559
|
const itemStyle = {
|
|
1366
3560
|
...baseStyles2.item,
|
|
1367
3561
|
...colors.item,
|
|
@@ -1383,14 +3577,22 @@ function NavTipItem({ item, isExpanded, isLast, onToggle, onNavigate, theme }) {
|
|
|
1383
3577
|
maxHeight: isExpanded ? "500px" : "0",
|
|
1384
3578
|
paddingBottom: isExpanded ? "16px" : "0"
|
|
1385
3579
|
};
|
|
3580
|
+
const effectiveHref = anchor ? Array.isArray(anchor.route) ? anchor.route[0] : anchor.route : href;
|
|
3581
|
+
const isSamePage = anchor ? routeMatchesCurrent(Array.isArray(anchor.route) ? anchor.route : [anchor.route]) : effectiveHref ? routeMatchesCurrent([effectiveHref]) : false;
|
|
3582
|
+
const hasSelector = (anchor == null ? void 0 : anchor.selector) && anchor.selector !== "*";
|
|
3583
|
+
const isFocusAction = isSamePage && hasSelector;
|
|
3584
|
+
const hasAction = !!effectiveHref || isFocusAction;
|
|
1386
3585
|
const handleLinkClick = (e) => {
|
|
1387
3586
|
e.preventDefault();
|
|
1388
3587
|
e.stopPropagation();
|
|
1389
|
-
if (
|
|
1390
|
-
|
|
3588
|
+
if (isFocusAction && anchor) {
|
|
3589
|
+
onFocusAnchor(anchor);
|
|
3590
|
+
} else if (effectiveHref) {
|
|
3591
|
+
onNavigate(effectiveHref, external != null ? external : false);
|
|
1391
3592
|
}
|
|
1392
3593
|
};
|
|
1393
|
-
|
|
3594
|
+
const ctaLabel = isFocusAction ? `Focus \u2192` : external ? `Go \u2197` : `Go \u2192`;
|
|
3595
|
+
return _jsxs3("div", { style: itemStyle, "data-nav-tip-id": item.config.id, children: [_jsxs3("button", { type: "button", style: headerStyle, onClick: onToggle, onMouseEnter: () => setIsHovered(true), onMouseLeave: () => setIsHovered(false), "aria-expanded": isExpanded, children: [icon && _jsx3("span", { style: baseStyles2.icon, dangerouslySetInnerHTML: { __html: renderIcon(icon) } }), _jsx3("span", { children: title }), _jsx3("span", { style: chevronStyle, children: "\u203A" })] }), _jsxs3("div", { style: bodyStyle, "aria-hidden": !isExpanded, children: [_jsx3("p", { style: baseStyles2.description, children: description }), hasAction && _jsx3("a", { href: effectiveHref || "#", onClick: handleLinkClick, style: { ...baseStyles2.linkButton, ...colors.linkButton }, target: external ? "_blank" : void 0, rel: external ? "noopener noreferrer" : void 0, children: ctaLabel })] })] });
|
|
1394
3596
|
}
|
|
1395
3597
|
function NavWidget({ config, runtime: runtime7, instanceId }) {
|
|
1396
3598
|
const [renderTick, forceUpdate] = useReducer2((x) => x + 1, 0);
|
|
@@ -1402,8 +3604,8 @@ function NavWidget({ config, runtime: runtime7, instanceId }) {
|
|
|
1402
3604
|
return unsubscribe;
|
|
1403
3605
|
}, [runtime7.context]);
|
|
1404
3606
|
useEffect3(() => {
|
|
1405
|
-
var
|
|
1406
|
-
if (!((
|
|
3607
|
+
var _a2;
|
|
3608
|
+
if (!((_a2 = runtime7.accumulator) == null ? void 0 : _a2.subscribe))
|
|
1407
3609
|
return;
|
|
1408
3610
|
return runtime7.accumulator.subscribe(() => {
|
|
1409
3611
|
forceUpdate();
|
|
@@ -1432,11 +3634,11 @@ function NavWidget({ config, runtime: runtime7, instanceId }) {
|
|
|
1432
3634
|
}, [visibleTips]);
|
|
1433
3635
|
const hasCategories = useMemo2(() => visibleTips.some((t) => t.config.category), [visibleTips]);
|
|
1434
3636
|
const resolvedTheme = useMemo2(() => {
|
|
1435
|
-
var
|
|
3637
|
+
var _a2;
|
|
1436
3638
|
if (config.theme && config.theme !== "auto")
|
|
1437
3639
|
return config.theme;
|
|
1438
3640
|
if (typeof window !== "undefined") {
|
|
1439
|
-
return ((
|
|
3641
|
+
return ((_a2 = window.matchMedia) == null ? void 0 : _a2.call(window, "(prefers-color-scheme: dark)").matches) ? "dark" : "light";
|
|
1440
3642
|
}
|
|
1441
3643
|
return "light";
|
|
1442
3644
|
}, [config.theme]);
|
|
@@ -1489,9 +3691,24 @@ function NavWidget({ config, runtime: runtime7, instanceId }) {
|
|
|
1489
3691
|
} else {
|
|
1490
3692
|
const url = new URL(href, window.location.origin);
|
|
1491
3693
|
url.search = window.location.search;
|
|
1492
|
-
window.
|
|
3694
|
+
window.history.pushState(null, "", url.toString());
|
|
3695
|
+
window.dispatchEvent(new PopStateEvent("popstate"));
|
|
1493
3696
|
}
|
|
1494
3697
|
}, [runtime7.events, instanceId]);
|
|
3698
|
+
const handleFocusAnchor = useCallback3((anchor) => {
|
|
3699
|
+
const el = document.querySelector(anchor.selector);
|
|
3700
|
+
if (!(el instanceof HTMLElement))
|
|
3701
|
+
return;
|
|
3702
|
+
runtime7.events.publish("nav:tip_focused", {
|
|
3703
|
+
instanceId,
|
|
3704
|
+
selector: anchor.selector,
|
|
3705
|
+
route: anchor.route,
|
|
3706
|
+
timestamp: Date.now()
|
|
3707
|
+
});
|
|
3708
|
+
el.scrollIntoView({ behavior: "smooth", block: "center" });
|
|
3709
|
+
pulseElement(el);
|
|
3710
|
+
setTimeout(() => el.focus(), 400);
|
|
3711
|
+
}, [runtime7.events, instanceId]);
|
|
1495
3712
|
const containerStyle = {
|
|
1496
3713
|
...baseStyles2.container,
|
|
1497
3714
|
...themeStyles2[resolvedTheme].container
|
|
@@ -1504,7 +3721,7 @@ function NavWidget({ config, runtime: runtime7, instanceId }) {
|
|
|
1504
3721
|
...baseStyles2.emptyState,
|
|
1505
3722
|
...themeStyles2[resolvedTheme].emptyState
|
|
1506
3723
|
};
|
|
1507
|
-
const renderItems = (items) => items.map((tip, index) => _jsx3(NavTipItem, { item: tip, isExpanded: expandedIds.has(tip.config.id), isLast: index === items.length - 1, onToggle: () => handleToggle(tip.config.id), onNavigate: handleNavigate, theme: resolvedTheme }, tip.config.id));
|
|
3724
|
+
const renderItems = (items) => items.map((tip, index) => _jsx3(NavTipItem, { item: tip, isExpanded: expandedIds.has(tip.config.id), isLast: index === items.length - 1, onToggle: () => handleToggle(tip.config.id), onNavigate: handleNavigate, onFocusAnchor: handleFocusAnchor, theme: resolvedTheme }, tip.config.id));
|
|
1508
3725
|
if (visibleTips.length === 0) {
|
|
1509
3726
|
return _jsx3("div", { style: containerStyle, "data-adaptive-id": instanceId, "data-adaptive-type": "adaptive-nav", children: _jsx3("div", { style: emptyStateStyle, children: "You're all set for now! We'll share helpful tips here when they're relevant to what you're doing." }) });
|
|
1510
3727
|
}
|
|
@@ -1533,7 +3750,7 @@ var NavMountableWidget = {
|
|
|
1533
3750
|
<div style="font-family: system-ui; max-width: 100%;">
|
|
1534
3751
|
${tips.map((tip) => `
|
|
1535
3752
|
<div style="margin-bottom: 4px; padding: 12px 16px; background: ${slateGrey[12]}; border-radius: 8px;">
|
|
1536
|
-
${tip.config.icon ? `<span>${
|
|
3753
|
+
${tip.config.icon ? `<span>${renderIcon(tip.config.icon)}</span> ` : ""}<strong>${escapeHtml(tip.config.title)}</strong>
|
|
1537
3754
|
<p style="margin-top: 8px; color: ${slateGrey[6]}; font-size: 13px;">${escapeHtml(tip.config.description)}</p>
|
|
1538
3755
|
${tip.config.href ? `<a href="${escapeHtml(tip.config.href)}" style="color: ${purple[2]}; font-size: 13px;">Go →</a>` : ""}
|
|
1539
3756
|
</div>
|
|
@@ -1548,7 +3765,7 @@ var NavMountableWidget = {
|
|
|
1548
3765
|
|
|
1549
3766
|
// ../adaptives/adaptive-nav/dist/runtime.js
|
|
1550
3767
|
var executeScrollTo = async (action, context) => {
|
|
1551
|
-
var
|
|
3768
|
+
var _a2, _b, _c, _d;
|
|
1552
3769
|
const anchorEl = context.resolveAnchor(action.anchorId);
|
|
1553
3770
|
if (!anchorEl) {
|
|
1554
3771
|
console.error(`[adaptive-nav] Anchor not found for scrollTo, skipping: ${action.anchorId.selector}`);
|
|
@@ -1556,7 +3773,7 @@ var executeScrollTo = async (action, context) => {
|
|
|
1556
3773
|
} };
|
|
1557
3774
|
}
|
|
1558
3775
|
anchorEl.scrollIntoView({
|
|
1559
|
-
behavior: (
|
|
3776
|
+
behavior: (_a2 = action.behavior) != null ? _a2 : "smooth",
|
|
1560
3777
|
block: (_b = action.block) != null ? _b : "center",
|
|
1561
3778
|
inline: (_c = action.inline) != null ? _c : "nearest"
|
|
1562
3779
|
});
|
|
@@ -1580,12 +3797,12 @@ function isSameOrigin(url) {
|
|
|
1580
3797
|
}
|
|
1581
3798
|
}
|
|
1582
3799
|
var executeNavigate = async (action, context) => {
|
|
1583
|
-
var
|
|
3800
|
+
var _a2;
|
|
1584
3801
|
const url = action.url.trim();
|
|
1585
3802
|
if (url.toLowerCase().startsWith("javascript:")) {
|
|
1586
3803
|
throw new Error("javascript: URLs are not allowed");
|
|
1587
3804
|
}
|
|
1588
|
-
const target = (
|
|
3805
|
+
const target = (_a2 = action.target) != null ? _a2 : "_self";
|
|
1589
3806
|
context.publishEvent("action.applied", {
|
|
1590
3807
|
id: context.generateId(),
|
|
1591
3808
|
kind: "navigation:navigate",
|
|
@@ -1638,8 +3855,8 @@ var runtime6 = {
|
|
|
1638
3855
|
* and publishes nav:tip_revealed when triggerWhen transitions false → true.
|
|
1639
3856
|
*/
|
|
1640
3857
|
notifyWatchers(props) {
|
|
1641
|
-
var
|
|
1642
|
-
const actions = (
|
|
3858
|
+
var _a2;
|
|
3859
|
+
const actions = (_a2 = props.actions) != null ? _a2 : [];
|
|
1643
3860
|
return actions.filter((a) => a.notify && a.triggerWhen).map((a) => ({
|
|
1644
3861
|
id: `nav:${a.config.id}`,
|
|
1645
3862
|
strategy: a.triggerWhen,
|
|
@@ -1688,8 +3905,8 @@ function TileWheel({ tiles, intervalMs = 7e3, telemetry }) {
|
|
|
1688
3905
|
const [index, setIndex] = useState4(0);
|
|
1689
3906
|
const ordered = useMemo3(
|
|
1690
3907
|
() => [...tiles].sort((a, b) => {
|
|
1691
|
-
var
|
|
1692
|
-
return ((
|
|
3908
|
+
var _a2, _b;
|
|
3909
|
+
return ((_a2 = a.priority) != null ? _a2 : 0) - ((_b = b.priority) != null ? _b : 0);
|
|
1693
3910
|
}),
|
|
1694
3911
|
[tiles]
|
|
1695
3912
|
);
|