stream-markdown-parser 0.0.38 → 0.0.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +279 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -73,6 +73,11 @@ interface HtmlInlineNode extends BaseNode {
|
|
|
73
73
|
tag?: string;
|
|
74
74
|
content: string;
|
|
75
75
|
children: ParsedNode[];
|
|
76
|
+
/**
|
|
77
|
+
* True when the parser auto-appended a closing tag for streaming stability.
|
|
78
|
+
* The original source is still incomplete (no explicit close typed yet).
|
|
79
|
+
*/
|
|
80
|
+
autoClosed?: boolean;
|
|
76
81
|
}
|
|
77
82
|
interface InlineCodeNode extends BaseNode {
|
|
78
83
|
type: 'inline_code';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/factory.ts","../src/types.ts","../src/parser/inline-parsers/index.ts","../src/parser/index.ts","../src/config.ts","../src/findMatchingClose.ts","../src/parser/inline-parsers/fence-parser.ts","../src/plugins/containers.ts","../src/plugins/isMathLike.ts","../src/plugins/math.ts","../src/index.ts"],"sourcesContent":[],"mappings":";;;UAYiB,cAAA,SAAuB;sBAClB;;EADL,gBAAA,CAAe,EAAA,OAAA;;;;ECVf,CAAA;AAQjB;;;UARiB,QAAA;;EDUA,GAAA,EAAA,MAAA;;;;ACVjB;AAQiB,UAAA,QAAA,SAAiB,QAAQ,CAAA;EAMzB,IAAA,EAAA,MAAA;EAOA,OAAA,EAAA,MAAA;EAMA,MAAA,CAAA,EAAA,OAAW;AAM5B;AAQiB,UA3BA,WAAA,SAAoB,QA2BC,CAAA;EAKrB,IAAA,EAAA,SAAA;EAiBA,KAAA,EAAA,MAAA;EAOA,IAAA,EAAA,MAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/factory.ts","../src/types.ts","../src/parser/inline-parsers/index.ts","../src/parser/index.ts","../src/config.ts","../src/findMatchingClose.ts","../src/parser/inline-parsers/fence-parser.ts","../src/plugins/containers.ts","../src/plugins/isMathLike.ts","../src/plugins/math.ts","../src/index.ts"],"sourcesContent":[],"mappings":";;;UAYiB,cAAA,SAAuB;sBAClB;;EADL,gBAAA,CAAe,EAAA,OAAA;;;;ECVf,CAAA;AAQjB;;;UARiB,QAAA;;EDUA,GAAA,EAAA,MAAA;;;;ACVjB;AAQiB,UAAA,QAAA,SAAiB,QAAQ,CAAA;EAMzB,IAAA,EAAA,MAAA;EAOA,OAAA,EAAA,MAAA;EAMA,MAAA,CAAA,EAAA,OAAW;AAM5B;AAQiB,UA3BA,WAAA,SAAoB,QA2BC,CAAA;EAKrB,IAAA,EAAA,SAAA;EAiBA,KAAA,EAAA,MAAA;EAOA,IAAA,EAAA,MAAA;EAYA,QAAA,EAhEL,UAgEoB,EAAA;AAKhC;AAQiB,UA1EA,aAAA,SAAsB,QA0EI,CAAA;EAO1B,IAAA,EAAA,WAAA;EAIA,QAAA,EAnFL,UAmFqB,EAAA;EASrB,aAAA,CAAA,EAAA,OAAc;AAS1B;AAKiB,UAtGA,UAAA,SAAmB,QAsGT,CAAA;EAEjB,IAAA,EAAA,QAAA;EACF,QAAA,EAvGI,UAuGJ,EAAA;EAH2B,OAAA,CAAA,EAAA,MAAA;;AAMlB,UAtGA,QAAA,SAAiB,QAwGzB,CAAA;EAGQ,IAAA,EAAA,MAAA;EAOA,OAAA,EAAA,OAAA;EAKA,KAAA,CAAA,EAAA,MAAA;EAET,KAAA,EApHC,YAoHD,EAAA;;AAFoC,UA/G3B,YAAA,SAAqB,QA+GM,CAAA;EAAQ,IAAA,EAAA,WAAA;EAMnC,QAAA,EAnHL,UAmHkB,EAAA;AAM9B;AAKiB,UA3HA,aAAA,SAAsB,QA2Ha,CAAA;EAKnC,IAAA,EAAA,YAAe;EAOf,QA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AAFyB,iBGrGnB,qBAAA,CHqGmB,IAAA,EGrGS,WHqGT,GAAA,SAAA,CAAA,EAAA,IAAA;;;iBInInB,iBAAA;;;iBCoCA,eAAA,QAAuB,gBAAgB;;;iBCjCvC,eAAA,KAAoB;;;cCHvB;cAoBA;iBA6BG,UAAA;;;cChCH;iBA4JG,6BAAA,mBAAgD;iBA2EhD,SAAA,KAAc,yBAAuB;;;AT5OpC,iBUSD,sBAAA,CVTwB,MAAM,EAAA,OAAA,CAAA,EAAA,IAAA;iBUa9B,8BAAA,CAAA;ATwCC,UShBA,kBAAA,SAA2B,cTgBG,CAAA;EAO9B,MAAA,CAAA,EStBN,KTsBM,CAAA,OAAe,CAAA;EAYf,KAAA,CAAA,ESjCP,KTiCO,CAAA,CAAA,EAAe,ESjCX,UTiCmB,EAAA,GAAA,IAAQ,CAAA;EAK/B;AAQjB;AAOA;AAIA;EASY,IAAA,CAAA,EAAA,CAAA,CAAA,GAAA,EAAA,MAAc,EAAA,GAAA,MAOf,CAAA,GSpE0B,MToElB,CAAA,MAAA,EAAA,MAAA,CAAA;AAEnB;AAKiB,iBSxED,WAAA,CTwEW,KAAA,CAAA,EAAA,MAAA,EAAA,OAAA,CAAA,ESxEkD,kBTwElD,CAAA,ESxEyE,UTwEzE"}
|
package/dist/index.js
CHANGED
|
@@ -6820,7 +6820,260 @@ const VOID_TAGS$2 = new Set([
|
|
|
6820
6820
|
"track",
|
|
6821
6821
|
"wbr"
|
|
6822
6822
|
]);
|
|
6823
|
+
const COMMON_HTML_TAGS = new Set([
|
|
6824
|
+
...Array.from(VOID_TAGS$2),
|
|
6825
|
+
"a",
|
|
6826
|
+
"abbr",
|
|
6827
|
+
"b",
|
|
6828
|
+
"bdi",
|
|
6829
|
+
"bdo",
|
|
6830
|
+
"button",
|
|
6831
|
+
"cite",
|
|
6832
|
+
"code",
|
|
6833
|
+
"data",
|
|
6834
|
+
"del",
|
|
6835
|
+
"dfn",
|
|
6836
|
+
"em",
|
|
6837
|
+
"i",
|
|
6838
|
+
"img",
|
|
6839
|
+
"input",
|
|
6840
|
+
"ins",
|
|
6841
|
+
"kbd",
|
|
6842
|
+
"label",
|
|
6843
|
+
"mark",
|
|
6844
|
+
"q",
|
|
6845
|
+
"s",
|
|
6846
|
+
"samp",
|
|
6847
|
+
"small",
|
|
6848
|
+
"span",
|
|
6849
|
+
"strong",
|
|
6850
|
+
"sub",
|
|
6851
|
+
"sup",
|
|
6852
|
+
"time",
|
|
6853
|
+
"u",
|
|
6854
|
+
"var",
|
|
6855
|
+
"article",
|
|
6856
|
+
"aside",
|
|
6857
|
+
"blockquote",
|
|
6858
|
+
"div",
|
|
6859
|
+
"details",
|
|
6860
|
+
"figcaption",
|
|
6861
|
+
"figure",
|
|
6862
|
+
"footer",
|
|
6863
|
+
"header",
|
|
6864
|
+
"h1",
|
|
6865
|
+
"h2",
|
|
6866
|
+
"h3",
|
|
6867
|
+
"h4",
|
|
6868
|
+
"h5",
|
|
6869
|
+
"h6",
|
|
6870
|
+
"li",
|
|
6871
|
+
"main",
|
|
6872
|
+
"nav",
|
|
6873
|
+
"ol",
|
|
6874
|
+
"p",
|
|
6875
|
+
"pre",
|
|
6876
|
+
"section",
|
|
6877
|
+
"summary",
|
|
6878
|
+
"table",
|
|
6879
|
+
"tbody",
|
|
6880
|
+
"td",
|
|
6881
|
+
"th",
|
|
6882
|
+
"thead",
|
|
6883
|
+
"tr",
|
|
6884
|
+
"ul",
|
|
6885
|
+
"svg",
|
|
6886
|
+
"g",
|
|
6887
|
+
"path"
|
|
6888
|
+
]);
|
|
6889
|
+
const OPEN_TAG_RE = /<([A-Z][\w-]*)(?=[\s/>]|$)/gi;
|
|
6890
|
+
const CLOSE_TAG_RE = /<\/\s*([A-Z][\w-]*)(?=[\s/>]|$)/gi;
|
|
6891
|
+
const FULL_TAG_RE = /^<\s*(?:\/\s*)?([A-Z][\w-]*)(?:\s[^>]*?)?\/?>/i;
|
|
6892
|
+
function tokenToRaw$1(token) {
|
|
6893
|
+
const shape = token;
|
|
6894
|
+
return String(shape.raw ?? shape.content ?? shape.markup ?? "");
|
|
6895
|
+
}
|
|
6896
|
+
function isCommonHtmlTagOrPrefix(tag) {
|
|
6897
|
+
if (COMMON_HTML_TAGS.has(tag)) return true;
|
|
6898
|
+
for (const common of COMMON_HTML_TAGS) if (common.startsWith(tag)) return true;
|
|
6899
|
+
return false;
|
|
6900
|
+
}
|
|
6901
|
+
function findFirstIncompleteTag(content) {
|
|
6902
|
+
let first = null;
|
|
6903
|
+
for (const m of content.matchAll(OPEN_TAG_RE)) {
|
|
6904
|
+
const idx = m.index ?? -1;
|
|
6905
|
+
if (idx < 0) continue;
|
|
6906
|
+
const tag = (m[1] ?? "").toLowerCase();
|
|
6907
|
+
if (!COMMON_HTML_TAGS.has(tag)) continue;
|
|
6908
|
+
if (content.slice(idx).includes(">")) continue;
|
|
6909
|
+
if (!first || idx < first.index) first = {
|
|
6910
|
+
index: idx,
|
|
6911
|
+
tag,
|
|
6912
|
+
closing: false
|
|
6913
|
+
};
|
|
6914
|
+
}
|
|
6915
|
+
for (const m of content.matchAll(CLOSE_TAG_RE)) {
|
|
6916
|
+
const idx = m.index ?? -1;
|
|
6917
|
+
if (idx < 0) continue;
|
|
6918
|
+
const tag = (m[1] ?? "").toLowerCase();
|
|
6919
|
+
if (!isCommonHtmlTagOrPrefix(tag)) continue;
|
|
6920
|
+
if (content.slice(idx).includes(">")) continue;
|
|
6921
|
+
if (!first || idx < first.index) first = {
|
|
6922
|
+
index: idx,
|
|
6923
|
+
tag,
|
|
6924
|
+
closing: true
|
|
6925
|
+
};
|
|
6926
|
+
}
|
|
6927
|
+
const bareClose = /<\/\s*$/.exec(content);
|
|
6928
|
+
if (bareClose && typeof bareClose.index === "number") {
|
|
6929
|
+
const idx = bareClose.index;
|
|
6930
|
+
if (!content.slice(idx).includes(">") && (!first || idx < first.index)) first = {
|
|
6931
|
+
index: idx,
|
|
6932
|
+
tag: "",
|
|
6933
|
+
closing: true
|
|
6934
|
+
};
|
|
6935
|
+
}
|
|
6936
|
+
const bareOpen = /<\s*$/.exec(content);
|
|
6937
|
+
if (bareOpen && typeof bareOpen.index === "number") {
|
|
6938
|
+
const idx = bareOpen.index;
|
|
6939
|
+
const rest = content.slice(idx);
|
|
6940
|
+
if (!rest.startsWith("</") && !rest.includes(">") && (!first || idx < first.index)) first = {
|
|
6941
|
+
index: idx,
|
|
6942
|
+
tag: "",
|
|
6943
|
+
closing: false
|
|
6944
|
+
};
|
|
6945
|
+
}
|
|
6946
|
+
return first;
|
|
6947
|
+
}
|
|
6948
|
+
function splitTextToken(token, content) {
|
|
6949
|
+
const t = token;
|
|
6950
|
+
return Object.assign(Object.create(Object.getPrototypeOf(t)), t, {
|
|
6951
|
+
type: "text",
|
|
6952
|
+
content,
|
|
6953
|
+
raw: content
|
|
6954
|
+
});
|
|
6955
|
+
}
|
|
6956
|
+
function fixStreamingHtmlInlineChildren(children) {
|
|
6957
|
+
if (!children.length) return { children };
|
|
6958
|
+
const out = [];
|
|
6959
|
+
let pending = null;
|
|
6960
|
+
let pendingAtEnd = null;
|
|
6961
|
+
function pushTextPart(text$1, baseToken) {
|
|
6962
|
+
if (!text$1) return;
|
|
6963
|
+
if (baseToken) out.push(splitTextToken(baseToken, text$1));
|
|
6964
|
+
else out.push({
|
|
6965
|
+
type: "text",
|
|
6966
|
+
content: text$1,
|
|
6967
|
+
raw: text$1
|
|
6968
|
+
});
|
|
6969
|
+
}
|
|
6970
|
+
function splitCompleteHtmlFromText(chunk, baseToken) {
|
|
6971
|
+
let cursor = 0;
|
|
6972
|
+
while (cursor < chunk.length) {
|
|
6973
|
+
const lt = chunk.indexOf("<", cursor);
|
|
6974
|
+
if (lt === -1) {
|
|
6975
|
+
pushTextPart(chunk.slice(cursor), baseToken);
|
|
6976
|
+
break;
|
|
6977
|
+
}
|
|
6978
|
+
pushTextPart(chunk.slice(cursor, lt), baseToken);
|
|
6979
|
+
const fullMatch = chunk.slice(lt).match(FULL_TAG_RE);
|
|
6980
|
+
if (!fullMatch) {
|
|
6981
|
+
pushTextPart("<", baseToken);
|
|
6982
|
+
cursor = lt + 1;
|
|
6983
|
+
continue;
|
|
6984
|
+
}
|
|
6985
|
+
const tagText = fullMatch[0];
|
|
6986
|
+
const tagName = (fullMatch[1] ?? "").toLowerCase();
|
|
6987
|
+
if (COMMON_HTML_TAGS.has(tagName)) out.push({
|
|
6988
|
+
type: "html_inline",
|
|
6989
|
+
tag: "",
|
|
6990
|
+
content: tagText,
|
|
6991
|
+
raw: tagText
|
|
6992
|
+
});
|
|
6993
|
+
else pushTextPart(tagText, baseToken);
|
|
6994
|
+
cursor = lt + tagText.length;
|
|
6995
|
+
}
|
|
6996
|
+
}
|
|
6997
|
+
function processTextChunk(chunk, baseToken) {
|
|
6998
|
+
if (!chunk) return;
|
|
6999
|
+
const match = findFirstIncompleteTag(chunk);
|
|
7000
|
+
if (!match) {
|
|
7001
|
+
splitCompleteHtmlFromText(chunk, baseToken);
|
|
7002
|
+
return;
|
|
7003
|
+
}
|
|
7004
|
+
const before = chunk.slice(0, match.index);
|
|
7005
|
+
if (before) splitCompleteHtmlFromText(before, baseToken);
|
|
7006
|
+
pending = {
|
|
7007
|
+
tag: match.tag,
|
|
7008
|
+
buffer: chunk.slice(match.index),
|
|
7009
|
+
closing: match.closing
|
|
7010
|
+
};
|
|
7011
|
+
pendingAtEnd = pending.buffer;
|
|
7012
|
+
}
|
|
7013
|
+
for (const child of children) {
|
|
7014
|
+
if (pending) {
|
|
7015
|
+
pending.buffer += tokenToRaw$1(child);
|
|
7016
|
+
pendingAtEnd = pending.buffer;
|
|
7017
|
+
const closeIdx = pending.buffer.indexOf(">");
|
|
7018
|
+
if (closeIdx === -1) continue;
|
|
7019
|
+
const tagChunk = pending.buffer.slice(0, closeIdx + 1);
|
|
7020
|
+
const afterChunk = pending.buffer.slice(closeIdx + 1);
|
|
7021
|
+
out.push({
|
|
7022
|
+
type: "html_inline",
|
|
7023
|
+
tag: "",
|
|
7024
|
+
content: tagChunk,
|
|
7025
|
+
raw: tagChunk
|
|
7026
|
+
});
|
|
7027
|
+
pending = null;
|
|
7028
|
+
pendingAtEnd = null;
|
|
7029
|
+
if (afterChunk) processTextChunk(afterChunk);
|
|
7030
|
+
continue;
|
|
7031
|
+
}
|
|
7032
|
+
if (child.type === "text") {
|
|
7033
|
+
const content = String(child.content ?? "");
|
|
7034
|
+
if (!content.includes("<")) {
|
|
7035
|
+
out.push(child);
|
|
7036
|
+
continue;
|
|
7037
|
+
}
|
|
7038
|
+
processTextChunk(content, child);
|
|
7039
|
+
continue;
|
|
7040
|
+
}
|
|
7041
|
+
out.push(child);
|
|
7042
|
+
}
|
|
7043
|
+
return {
|
|
7044
|
+
children: out,
|
|
7045
|
+
pendingBuffer: pendingAtEnd ?? void 0
|
|
7046
|
+
};
|
|
7047
|
+
}
|
|
6823
7048
|
function applyFixHtmlInlineTokens(md) {
|
|
7049
|
+
md.core.ruler.after("inline", "fix_html_inline_streaming", (state) => {
|
|
7050
|
+
const toks = state.tokens ?? [];
|
|
7051
|
+
for (const t of toks) {
|
|
7052
|
+
const tok = t;
|
|
7053
|
+
if (tok.type !== "inline" || !Array.isArray(tok.children)) continue;
|
|
7054
|
+
const originalContent = String(tok.content ?? "");
|
|
7055
|
+
const sourceChildren = tok.children.length ? tok.children : originalContent.includes("<") ? [{
|
|
7056
|
+
type: "text",
|
|
7057
|
+
content: originalContent,
|
|
7058
|
+
raw: originalContent
|
|
7059
|
+
}] : null;
|
|
7060
|
+
if (!sourceChildren) continue;
|
|
7061
|
+
try {
|
|
7062
|
+
const fixed = fixStreamingHtmlInlineChildren(sourceChildren);
|
|
7063
|
+
tok.children = fixed.children;
|
|
7064
|
+
if (fixed.pendingBuffer) {
|
|
7065
|
+
const idx = originalContent.lastIndexOf(fixed.pendingBuffer);
|
|
7066
|
+
if (idx !== -1) {
|
|
7067
|
+
const trimmed = originalContent.slice(0, idx);
|
|
7068
|
+
tok.content = trimmed;
|
|
7069
|
+
if (typeof tok.raw === "string") tok.raw = trimmed;
|
|
7070
|
+
}
|
|
7071
|
+
}
|
|
7072
|
+
} catch (e) {
|
|
7073
|
+
console.error("[applyFixHtmlInlineTokens] failed to fix streaming html inline", e);
|
|
7074
|
+
}
|
|
7075
|
+
}
|
|
7076
|
+
});
|
|
6824
7077
|
md.core.ruler.push("fix_html_inline_tokens", (state) => {
|
|
6825
7078
|
const toks = state.tokens ?? [];
|
|
6826
7079
|
const tagStack = [];
|
|
@@ -7918,6 +8171,12 @@ function normalizeStandaloneBackslashT(s, opts) {
|
|
|
7918
8171
|
result = result.replace(ESCAPED_MKATWX_COMMANDS, "$1\\$2");
|
|
7919
8172
|
return result;
|
|
7920
8173
|
}
|
|
8174
|
+
function isPlainBracketMathLike(content) {
|
|
8175
|
+
const stripped = content.trim();
|
|
8176
|
+
if (!isMathLike(stripped)) return false;
|
|
8177
|
+
if (!(/\\[a-z]+/i.test(stripped) || /\d/.test(stripped) || /[=+*/^<>]|\\times|\\pm|\\cdot|\\le|\\ge|\\neq/.test(stripped) || /[_^]/.test(stripped)) && /\s-\s/.test(stripped)) return false;
|
|
8178
|
+
return true;
|
|
8179
|
+
}
|
|
7921
8180
|
function applyMath(md, mathOpts) {
|
|
7922
8181
|
const mathInline = (state, silent) => {
|
|
7923
8182
|
const s = state;
|
|
@@ -8109,7 +8368,8 @@ function applyMath(md, mathOpts) {
|
|
|
8109
8368
|
if (lineText.replace("\\", "").startsWith("[") && !lineText.includes("](")) {
|
|
8110
8369
|
const closeIndex = lineText.indexOf("]");
|
|
8111
8370
|
if (lineText.slice(closeIndex).trim() !== "]") continue;
|
|
8112
|
-
|
|
8371
|
+
const inner = lineText.slice(open.length, closeIndex);
|
|
8372
|
+
if (open === "[" ? isPlainBracketMathLike(inner) : isMathLike(inner)) {
|
|
8113
8373
|
matched = true;
|
|
8114
8374
|
openDelim = open;
|
|
8115
8375
|
closeDelim = close;
|
|
@@ -8180,7 +8440,7 @@ function applyMath(md, mathOpts) {
|
|
|
8180
8440
|
}
|
|
8181
8441
|
}
|
|
8182
8442
|
if (strict && !found) return false;
|
|
8183
|
-
if (!isMathLike(content)) return false;
|
|
8443
|
+
if (!(openDelim === "[" ? isPlainBracketMathLike(content) : isMathLike(content))) return false;
|
|
8184
8444
|
const token = s.push("math_block", "math", 0);
|
|
8185
8445
|
token.content = normalizeStandaloneBackslashT(content);
|
|
8186
8446
|
token.markup = openDelim === "$$" ? "$$" : openDelim === "[" ? "[]" : "\\[\\]";
|
|
@@ -8475,10 +8735,10 @@ function collectHtmlFragment(tokens, startIndex, tag) {
|
|
|
8475
8735
|
fragmentTokens.push(...innerTokens, tokens[closingIndex]);
|
|
8476
8736
|
nextIndex = closingIndex + 1;
|
|
8477
8737
|
closed = true;
|
|
8478
|
-
} else
|
|
8479
|
-
innerTokens =
|
|
8480
|
-
fragmentTokens.push(
|
|
8481
|
-
nextIndex =
|
|
8738
|
+
} else {
|
|
8739
|
+
innerTokens = tokens.slice(startIndex + 1);
|
|
8740
|
+
if (innerTokens.length) fragmentTokens.push(...innerTokens);
|
|
8741
|
+
nextIndex = tokens.length;
|
|
8482
8742
|
}
|
|
8483
8743
|
return {
|
|
8484
8744
|
closed,
|
|
@@ -8546,13 +8806,23 @@ function parseHtmlInlineCodeToken(token, tokens, i, parseInlineTokens$1, raw, pP
|
|
|
8546
8806
|
raw: fragment.html
|
|
8547
8807
|
}, fragment.nextIndex];
|
|
8548
8808
|
const children = fragment.innerTokens.length ? parseInlineTokens$1(fragment.innerTokens, raw, pPreToken, options) : [];
|
|
8809
|
+
let content = fragment.html || code$1;
|
|
8810
|
+
let loading = !fragment.closed;
|
|
8811
|
+
let autoClosed = false;
|
|
8812
|
+
if (!fragment.closed) {
|
|
8813
|
+
const closeTag = `</${tag}>`;
|
|
8814
|
+
if (!content.toLowerCase().includes(closeTag.toLowerCase())) content += closeTag;
|
|
8815
|
+
autoClosed = true;
|
|
8816
|
+
loading = true;
|
|
8817
|
+
}
|
|
8549
8818
|
return [{
|
|
8550
8819
|
type: "html_inline",
|
|
8551
8820
|
tag,
|
|
8552
|
-
content
|
|
8821
|
+
content,
|
|
8553
8822
|
children,
|
|
8554
|
-
raw:
|
|
8555
|
-
loading
|
|
8823
|
+
raw: content,
|
|
8824
|
+
loading,
|
|
8825
|
+
autoClosed
|
|
8556
8826
|
}, fragment.nextIndex];
|
|
8557
8827
|
}
|
|
8558
8828
|
|