@aiderdesk/aiderdesk 0.61.0-dev → 0.61.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/renderer/assets/__vite-browser-external-2447137e-DYxpcVy9.js +4 -0
- package/out/renderer/assets/{_baseUniq-Z8t1Ab1g.js → _baseUniq-BPF2Herp.js} +21 -197
- package/out/renderer/assets/{arc-CwESpVYE.js → arc-DfPLteHF.js} +1 -1
- package/out/renderer/assets/{architectureDiagram-2XIMDMQ5-C490EQr5.js → architectureDiagram-Q4EWVU46-Bw0u-sSH.js} +34 -20
- package/out/renderer/assets/{blockDiagram-WCTKOSBZ-DbHssxrQ.js → blockDiagram-DXYQGD6D-CkfB9if8.js} +21 -8
- package/out/renderer/assets/{c4Diagram-IC4MRINW-BxE3GUKu.js → c4Diagram-AHTNJAMY-DweK9Liz.js} +31 -35
- package/out/renderer/assets/{channel-C9hJq_Xr.js → channel-C5wwrRof.js} +1 -1
- package/out/renderer/assets/{chunk-4BX2VUAB-ChcKNpL6.js → chunk-4BX2VUAB-0KM14cFd.js} +1 -1
- package/out/renderer/assets/{chunk-WL4C6EOR-vhby2fZi.js → chunk-4TB4RGXK-CmVtCVL4.js} +121 -82
- package/out/renderer/assets/{chunk-55IACEB6-oLT9lXTt.js → chunk-55IACEB6-BzVYZvBM.js} +1 -1
- package/out/renderer/assets/{chunk-KX2RTZJC-D32tV7H-.js → chunk-EDXVE4YY-BryQl5Kv.js} +1 -1
- package/out/renderer/assets/{chunk-FMBD7UC4-B5k8rETe.js → chunk-FMBD7UC4-CRiLea_e.js} +1 -1
- package/out/renderer/assets/{chunk-NQ4KR5QH-Bmqo2FpL.js → chunk-OYMX7WX6-Cpi4N3NO.js} +32 -15
- package/out/renderer/assets/{chunk-QZHKN3VN-8BpGifjS.js → chunk-QZHKN3VN-BT8kABWC.js} +1 -1
- package/out/renderer/assets/{chunk-JSJVCQXG-DtjSx6Cj.js → chunk-YZCP3GAM-OLZV_Sef.js} +1 -1
- package/out/renderer/assets/{classDiagram-VBA2DB6C-BxRSSb9e.js → classDiagram-6PBFFD2Q-VdE6G90i.js} +6 -6
- package/out/renderer/assets/{classDiagram-v2-RAHNMMFH-BxRSSb9e.js → classDiagram-v2-HSJHXN6E-VdE6G90i.js} +6 -6
- package/out/renderer/assets/{clone-D9a-uIZa.js → clone-DwQZ86nS.js} +1 -1
- package/out/renderer/assets/{cose-bilkent-S5V4N54A-CUqqQ-6R.js → cose-bilkent-S5V4N54A-BEcAKM9H.js} +1 -1
- package/out/renderer/assets/{dagre-KLK3FWXG-ORIwMMhq.js → dagre-KV5264BT-BcFQYL1M.js} +6 -6
- package/out/renderer/assets/diagram-5BDNPKRD-GrUNdC1u.js +171 -0
- package/out/renderer/assets/{diagram-E7M64L7V-bS9HcoDQ.js → diagram-G4DWMVQ6-CG4S-ov5.js} +15 -13
- package/out/renderer/assets/{diagram-IFDJBPK2-BRlTIR0J.js → diagram-MMDJMWI5-9ogY3MRC.js} +5 -6
- package/out/renderer/assets/{diagram-P4PSJMXO-jsjGwH-p.js → diagram-TYMM5635-Ck7mI1bS.js} +5 -6
- package/out/renderer/assets/{erDiagram-INFDFZHY-DGlgjHOQ.js → erDiagram-SMLLAGMA-Dvf_c-7M.js} +81 -35
- package/out/renderer/assets/{flowDiagram-PKNHOUZH-CzLC87bM.js → flowDiagram-DWJPFMVM-CPDjOXYp.js} +27 -45
- package/out/renderer/assets/{ganttDiagram-A5KZAMGK-BbDv36wT.js → ganttDiagram-T4ZO3ILL-B4dJrK-3.js} +17 -8
- package/out/renderer/assets/{gitGraphDiagram-K3NZZRJ6-CBQnBjEi.js → gitGraphDiagram-UUTBAWPF-De2eCfMN.js} +244 -67
- package/out/renderer/assets/{graph-Dl5N6maZ.js → graph-BFn23kR_.js} +175 -3
- package/out/renderer/assets/{index-MDHavDF9.js → index-BL-57WPa.js} +15877 -20787
- package/out/renderer/assets/{index-CDCy_DhA.css → index-BkntVzTm.css} +114 -301
- package/out/renderer/assets/{infoDiagram-LFFYTUFH-GtEDBEmz.js → infoDiagram-42DDH7IO-BIt9B6mQ.js} +5 -6
- package/out/renderer/assets/{ishikawaDiagram-PHBUUO56-Uj90gr3I.js → ishikawaDiagram-UXIWVN3A-CXZs0KGV.js} +3 -3
- package/out/renderer/assets/{journeyDiagram-4ABVD52K-DekFuOwS.js → journeyDiagram-VCZTEJTY-B-EXuj5b.js} +14 -13
- package/out/renderer/assets/{kanban-definition-K7BYSVSG-Hfz2L6NS.js → kanban-definition-6JOO6SKY-ByvN0qaD.js} +5 -2
- package/out/renderer/assets/{layout-B9K2VT39.js → layout-BpybWUv6.js} +117 -4
- package/out/renderer/assets/min-DB8ixvoT.js +41 -0
- package/out/renderer/assets/{mindmap-definition-YRQLILUH-DDcS7_GH.js → mindmap-definition-QFDTVHPH-Do-I-At8.js} +69 -13
- package/out/renderer/assets/{pieDiagram-SKSYHLDU-DwjEcJ0Q.js → pieDiagram-DEJITSTG-Cnpf6Gt6.js} +20 -13
- package/out/renderer/assets/{quadrantDiagram-337W2JSQ-CpGqN7vo.js → quadrantDiagram-34T5L4WZ-VcOb1qLd.js} +1 -1
- package/out/renderer/assets/{requirementDiagram-Z7DCOOCP-qDRUf1ip.js → requirementDiagram-MS252O5E-VJs9Hpaw.js} +42 -11
- package/out/renderer/assets/{sankeyDiagram-WA2Y5GQK-DRKS8C1H.js → sankeyDiagram-XADWPNL6-BoXxgLvi.js} +1 -1
- package/out/renderer/assets/{sequenceDiagram-2WXFIKYE-DhVN2ug2.js → sequenceDiagram-FGHM5R23-b69hQjSp.js} +446 -220
- package/out/renderer/assets/{stateDiagram-RAJIS63D-BpP4eSqu.js → stateDiagram-FHFEXIEX-BK7E-REm.js} +10 -9
- package/out/renderer/assets/{stateDiagram-v2-FVOUBMTO-B_qQJqra.js → stateDiagram-v2-QKLJ7IA2-Cd2wfCQu.js} +4 -4
- package/out/renderer/assets/{timeline-definition-YZTLITO2-UoWXE_76.js → timeline-definition-GMOUNBTQ-Bl-MTfK5.js} +445 -71
- package/out/renderer/assets/{vennDiagram-LZ73GAT5-Dp1FZ609.js → vennDiagram-DHZGUBPP-DNmr1k2L.js} +1 -1
- package/out/renderer/assets/{treemap-KZPCXAKY-W2a2L6ff.js → wardley-RL74JXVD-DTbxPMj9.js} +1474 -977
- package/out/renderer/assets/wardleyDiagram-NUSXRM2D-BWw08wtD.js +901 -0
- package/out/renderer/assets/{xychartDiagram-JWTSCODW-CTzYHTbD.js → xychartDiagram-5P7HB3ND-EEYPnLDT.js} +20 -4
- package/out/renderer/index.html +3 -3
- package/out/renderer/progress.html +212 -62
- package/out/resources/mcp-server/aider-desk-mcp-server.js +642 -402
- package/out/runner.js +976 -386
- package/package.json +2 -3
- package/out/renderer/assets/_basePickBy-BWoXHZ8Z.js +0 -161
- package/out/renderer/assets/apl-fqmucPXA.js +0 -140
- package/out/renderer/assets/asciiarmor-DucZyvP0.js +0 -56
- package/out/renderer/assets/asn1-BnOEsgAm.js +0 -144
- package/out/renderer/assets/asterisk-QAlztEwS.js +0 -345
- package/out/renderer/assets/brainfuck-DZVCuF_t.js +0 -53
- package/out/renderer/assets/clike-xqXYL6ge.js +0 -805
- package/out/renderer/assets/clojure-BhXMqnxz.js +0 -849
- package/out/renderer/assets/cmake-BGaNd9E7.js +0 -71
- package/out/renderer/assets/cobol-4yqQntpt.js +0 -120
- package/out/renderer/assets/coffeescript-D2dXvhEc.js +0 -308
- package/out/renderer/assets/commonlisp-CF_VNHQR.js +0 -130
- package/out/renderer/assets/crystal-DyuLTqLs.js +0 -398
- package/out/renderer/assets/css-c-jst79C.js +0 -1783
- package/out/renderer/assets/cypher-Dlu_3r4V.js +0 -121
- package/out/renderer/assets/d-UURgV0Ux.js +0 -179
- package/out/renderer/assets/diff-B_Bi2Crb.js +0 -25
- package/out/renderer/assets/dockerfile-Bvk733Ga.js +0 -201
- package/out/renderer/assets/dtd-Dy74G54E.js +0 -114
- package/out/renderer/assets/dylan-TSb-Nfix.js +0 -314
- package/out/renderer/assets/ebnf-4fKAGW3a.js +0 -140
- package/out/renderer/assets/ecl-B59qGGVg.js +0 -178
- package/out/renderer/assets/eiffel-Dze7nlu3.js +0 -134
- package/out/renderer/assets/elm-DG7jkhNZ.js +0 -176
- package/out/renderer/assets/erlang-BO6gOnGA.js +0 -674
- package/out/renderer/assets/factor-CMxFHDqz.js +0 -65
- package/out/renderer/assets/fcl-CDDUNjTj.js +0 -141
- package/out/renderer/assets/forth-B9D2JCeE.js +0 -116
- package/out/renderer/assets/fortran-CAG2BFbe.js +0 -467
- package/out/renderer/assets/gas-d3KEcW3x.js +0 -294
- package/out/renderer/assets/gherkin-DhZlEZiy.js +0 -115
- package/out/renderer/assets/groovy-CpwJiBl7.js +0 -223
- package/out/renderer/assets/haskell-ySd-OUo8.js +0 -459
- package/out/renderer/assets/haxe-7MlzfeYV.js +0 -514
- package/out/renderer/assets/http-BqypyemW.js +0 -79
- package/out/renderer/assets/idl-4HIGJlDI.js +0 -985
- package/out/renderer/assets/index-6qedlt0q.js +0 -689
- package/out/renderer/assets/index-86jDpUJn.js +0 -385
- package/out/renderer/assets/index-BRjO8ber.js +0 -332
- package/out/renderer/assets/index-BVgw7j0d.js +0 -312
- package/out/renderer/assets/index-BhkyI1q3.js +0 -642
- package/out/renderer/assets/index-BqrmLPkg.js +0 -82
- package/out/renderer/assets/index-BuPbw4xM.js +0 -178
- package/out/renderer/assets/index-CTO-LPBg.js +0 -311
- package/out/renderer/assets/index-CTO4SzlI.js +0 -97
- package/out/renderer/assets/index-CZ9IQK_0.js +0 -2488
- package/out/renderer/assets/index-CZxsVxBZ.js +0 -1765
- package/out/renderer/assets/index-DIXV-3Xn.js +0 -406
- package/out/renderer/assets/index-DNzOtZX5.js +0 -61
- package/out/renderer/assets/index-DZtJe7oC.js +0 -1019
- package/out/renderer/assets/index-DaWjZz_g.js +0 -291
- package/out/renderer/assets/index-De056HHR.js +0 -151
- package/out/renderer/assets/index-Dk3wSDSN.js +0 -117
- package/out/renderer/assets/index-Dy4VRsnA.js +0 -1041
- package/out/renderer/assets/index-FnnayPBc.js +0 -82
- package/out/renderer/assets/index-MZb_zy6R.js +0 -704
- package/out/renderer/assets/index-chzQl8rJ.js +0 -157
- package/out/renderer/assets/index-s-Owx3Pm.js +0 -327
- package/out/renderer/assets/javascript-C_OHM9hj.js +0 -994
- package/out/renderer/assets/julia-Bs6JJhYG.js +0 -407
- package/out/renderer/assets/livescript-DmzgM3Yt.js +0 -296
- package/out/renderer/assets/lua-8cJgIlqe.js +0 -256
- package/out/renderer/assets/mathematica-DNLOL9PQ.js +0 -110
- package/out/renderer/assets/mbox-Ga7d4MMN.js +0 -117
- package/out/renderer/assets/mirc-Dma3B8rS.js +0 -107
- package/out/renderer/assets/mllike-DHn7xckP.js +0 -334
- package/out/renderer/assets/modelica-0d55jYY0.js +0 -147
- package/out/renderer/assets/mscgen-DdqZYINH.js +0 -135
- package/out/renderer/assets/mumps-Btr8VblO.js +0 -93
- package/out/renderer/assets/nginx-DTDtBDVN.js +0 -141
- package/out/renderer/assets/nsis-3zG7tgur.js +0 -62
- package/out/renderer/assets/ntriples-CvgOYMpL.js +0 -153
- package/out/renderer/assets/octave-DYBj3-tl.js +0 -200
- package/out/renderer/assets/oz-R_e8WMIi.js +0 -231
- package/out/renderer/assets/pascal-GD8iposT.js +0 -105
- package/out/renderer/assets/perl-DL9mHpoi.js +0 -1105
- package/out/renderer/assets/pig-C_4T4YIV.js +0 -101
- package/out/renderer/assets/powershell-B0suO7Vd.js +0 -328
- package/out/renderer/assets/properties-BR-vP1aU.js +0 -58
- package/out/renderer/assets/protobuf-BxgpyhoW.js +0 -77
- package/out/renderer/assets/pug-CTXt1f8z.js +0 -405
- package/out/renderer/assets/puppet-Bdao66PW.js +0 -137
- package/out/renderer/assets/python-CvWbmiX4.js +0 -427
- package/out/renderer/assets/q-CrbCVq4a.js +0 -131
- package/out/renderer/assets/r-V7nswm59.js +0 -170
- package/out/renderer/assets/rpm-C-DLY-If.js +0 -109
- package/out/renderer/assets/ruby-JDKLJNK0.js +0 -330
- package/out/renderer/assets/sas-D2UG-yhZ.js +0 -207
- package/out/renderer/assets/scheme-BKzrkGJD.js +0 -222
- package/out/renderer/assets/shell-BlsXDxCn.js +0 -222
- package/out/renderer/assets/sieve-CjwBwOY5.js +0 -135
- package/out/renderer/assets/simple-mode-DMneyfDu.js +0 -130
- package/out/renderer/assets/smalltalk-BOIGQuhN.js +0 -121
- package/out/renderer/assets/solr-CwD7U71z.js +0 -69
- package/out/renderer/assets/sparql-DYskk2vE.js +0 -249
- package/out/renderer/assets/spreadsheet-Bgtt3oLP.js +0 -87
- package/out/renderer/assets/sql-BSrOzCRI.js +0 -354
- package/out/renderer/assets/stex-B6LNC55o.js +0 -231
- package/out/renderer/assets/stylus-BkS-boTH.js +0 -565
- package/out/renderer/assets/swift-FRZi1uvB.js +0 -291
- package/out/renderer/assets/tcl-CUcaCdmq.js +0 -114
- package/out/renderer/assets/textile-BnFpjsrl.js +0 -414
- package/out/renderer/assets/tiddlywiki-CjprD-Qp.js +0 -218
- package/out/renderer/assets/tiki-DK9DOeWn.js +0 -268
- package/out/renderer/assets/toml-BOuWGMcf.js +0 -76
- package/out/renderer/assets/troff-E1bJ0PPL.js +0 -61
- package/out/renderer/assets/ttcn-cfg-Dc39-fIP.js +0 -133
- package/out/renderer/assets/ttcn-tKd4HLu4.js +0 -192
- package/out/renderer/assets/turtle-Dq7-1WAf.js +0 -124
- package/out/renderer/assets/vb-Dp90gtsv.js +0 -196
- package/out/renderer/assets/vbscript-CI6_mxxU.js +0 -479
- package/out/renderer/assets/velocity-BwIZK1TH.js +0 -149
- package/out/renderer/assets/verilog-DDCYnHN8.js +0 -430
- package/out/renderer/assets/vhdl-DCkMIyT9.js +0 -158
- package/out/renderer/assets/webidl-BTLTThCm.js +0 -204
- package/out/renderer/assets/xquery-BrBUuxMR.js +0 -525
- package/out/renderer/assets/yacas-b5lAVEIl.js +0 -130
- package/out/renderer/assets/z80-BZV19vqv.js +0 -93
- package/scripts/download-uv.mjs +0 -147
- /package/patches/{ai+5.0.161.patch → ai+5.0.167.patch} +0 -0
|
@@ -1,2488 +0,0 @@
|
|
|
1
|
-
import { aI as Parser, aK as NodeType, aM as NodeProp, b4 as Tag, aJ as NodeSet, aD as styleTags, aN as Tree, aR as parseMixed, aE as tags, aH as syntaxTree, aQ as EditorSelection, b5 as countColumn, az as LanguageSupport, b6 as Prec, b7 as keymap, aP as EditorView, b8 as Language, b9 as indentUnit, ba as foldService, b3 as defineLanguageFacet, bb as CompletionContext, bc as EditorState, aC as foldNodeProp, aA as indentNodeProp, bd as languageDataProp, be as LanguageDescription, bf as ParseContext } from "./index-MDHavDF9.js";
|
|
2
|
-
import { html, htmlCompletionSource } from "./index-Dy4VRsnA.js";
|
|
3
|
-
import "./index-CZxsVxBZ.js";
|
|
4
|
-
import "./index-DZtJe7oC.js";
|
|
5
|
-
import "./index-BhkyI1q3.js";
|
|
6
|
-
class CompositeBlock {
|
|
7
|
-
static create(type, value, from, parentHash, end) {
|
|
8
|
-
let hash = parentHash + (parentHash << 8) + type + (value << 4) | 0;
|
|
9
|
-
return new CompositeBlock(type, value, from, hash, end, [], []);
|
|
10
|
-
}
|
|
11
|
-
constructor(type, value, from, hash, end, children, positions) {
|
|
12
|
-
this.type = type;
|
|
13
|
-
this.value = value;
|
|
14
|
-
this.from = from;
|
|
15
|
-
this.hash = hash;
|
|
16
|
-
this.end = end;
|
|
17
|
-
this.children = children;
|
|
18
|
-
this.positions = positions;
|
|
19
|
-
this.hashProp = [[NodeProp.contextHash, hash]];
|
|
20
|
-
}
|
|
21
|
-
addChild(child, pos) {
|
|
22
|
-
if (child.prop(NodeProp.contextHash) != this.hash)
|
|
23
|
-
child = new Tree(child.type, child.children, child.positions, child.length, this.hashProp);
|
|
24
|
-
this.children.push(child);
|
|
25
|
-
this.positions.push(pos);
|
|
26
|
-
}
|
|
27
|
-
toTree(nodeSet, end = this.end) {
|
|
28
|
-
let last = this.children.length - 1;
|
|
29
|
-
if (last >= 0)
|
|
30
|
-
end = Math.max(end, this.positions[last] + this.children[last].length + this.from);
|
|
31
|
-
return new Tree(nodeSet.types[this.type], this.children, this.positions, end - this.from).balance({
|
|
32
|
-
makeTree: (children, positions, length) => new Tree(NodeType.none, children, positions, length, this.hashProp)
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
var Type;
|
|
37
|
-
(function(Type2) {
|
|
38
|
-
Type2[Type2["Document"] = 1] = "Document";
|
|
39
|
-
Type2[Type2["CodeBlock"] = 2] = "CodeBlock";
|
|
40
|
-
Type2[Type2["FencedCode"] = 3] = "FencedCode";
|
|
41
|
-
Type2[Type2["Blockquote"] = 4] = "Blockquote";
|
|
42
|
-
Type2[Type2["HorizontalRule"] = 5] = "HorizontalRule";
|
|
43
|
-
Type2[Type2["BulletList"] = 6] = "BulletList";
|
|
44
|
-
Type2[Type2["OrderedList"] = 7] = "OrderedList";
|
|
45
|
-
Type2[Type2["ListItem"] = 8] = "ListItem";
|
|
46
|
-
Type2[Type2["ATXHeading1"] = 9] = "ATXHeading1";
|
|
47
|
-
Type2[Type2["ATXHeading2"] = 10] = "ATXHeading2";
|
|
48
|
-
Type2[Type2["ATXHeading3"] = 11] = "ATXHeading3";
|
|
49
|
-
Type2[Type2["ATXHeading4"] = 12] = "ATXHeading4";
|
|
50
|
-
Type2[Type2["ATXHeading5"] = 13] = "ATXHeading5";
|
|
51
|
-
Type2[Type2["ATXHeading6"] = 14] = "ATXHeading6";
|
|
52
|
-
Type2[Type2["SetextHeading1"] = 15] = "SetextHeading1";
|
|
53
|
-
Type2[Type2["SetextHeading2"] = 16] = "SetextHeading2";
|
|
54
|
-
Type2[Type2["HTMLBlock"] = 17] = "HTMLBlock";
|
|
55
|
-
Type2[Type2["LinkReference"] = 18] = "LinkReference";
|
|
56
|
-
Type2[Type2["Paragraph"] = 19] = "Paragraph";
|
|
57
|
-
Type2[Type2["CommentBlock"] = 20] = "CommentBlock";
|
|
58
|
-
Type2[Type2["ProcessingInstructionBlock"] = 21] = "ProcessingInstructionBlock";
|
|
59
|
-
Type2[Type2["Escape"] = 22] = "Escape";
|
|
60
|
-
Type2[Type2["Entity"] = 23] = "Entity";
|
|
61
|
-
Type2[Type2["HardBreak"] = 24] = "HardBreak";
|
|
62
|
-
Type2[Type2["Emphasis"] = 25] = "Emphasis";
|
|
63
|
-
Type2[Type2["StrongEmphasis"] = 26] = "StrongEmphasis";
|
|
64
|
-
Type2[Type2["Link"] = 27] = "Link";
|
|
65
|
-
Type2[Type2["Image"] = 28] = "Image";
|
|
66
|
-
Type2[Type2["InlineCode"] = 29] = "InlineCode";
|
|
67
|
-
Type2[Type2["HTMLTag"] = 30] = "HTMLTag";
|
|
68
|
-
Type2[Type2["Comment"] = 31] = "Comment";
|
|
69
|
-
Type2[Type2["ProcessingInstruction"] = 32] = "ProcessingInstruction";
|
|
70
|
-
Type2[Type2["Autolink"] = 33] = "Autolink";
|
|
71
|
-
Type2[Type2["HeaderMark"] = 34] = "HeaderMark";
|
|
72
|
-
Type2[Type2["QuoteMark"] = 35] = "QuoteMark";
|
|
73
|
-
Type2[Type2["ListMark"] = 36] = "ListMark";
|
|
74
|
-
Type2[Type2["LinkMark"] = 37] = "LinkMark";
|
|
75
|
-
Type2[Type2["EmphasisMark"] = 38] = "EmphasisMark";
|
|
76
|
-
Type2[Type2["CodeMark"] = 39] = "CodeMark";
|
|
77
|
-
Type2[Type2["CodeText"] = 40] = "CodeText";
|
|
78
|
-
Type2[Type2["CodeInfo"] = 41] = "CodeInfo";
|
|
79
|
-
Type2[Type2["LinkTitle"] = 42] = "LinkTitle";
|
|
80
|
-
Type2[Type2["LinkLabel"] = 43] = "LinkLabel";
|
|
81
|
-
Type2[Type2["URL"] = 44] = "URL";
|
|
82
|
-
})(Type || (Type = {}));
|
|
83
|
-
class LeafBlock {
|
|
84
|
-
/**
|
|
85
|
-
@internal
|
|
86
|
-
*/
|
|
87
|
-
constructor(start, content) {
|
|
88
|
-
this.start = start;
|
|
89
|
-
this.content = content;
|
|
90
|
-
this.marks = [];
|
|
91
|
-
this.parsers = [];
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
class Line {
|
|
95
|
-
constructor() {
|
|
96
|
-
this.text = "";
|
|
97
|
-
this.baseIndent = 0;
|
|
98
|
-
this.basePos = 0;
|
|
99
|
-
this.depth = 0;
|
|
100
|
-
this.markers = [];
|
|
101
|
-
this.pos = 0;
|
|
102
|
-
this.indent = 0;
|
|
103
|
-
this.next = -1;
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
@internal
|
|
107
|
-
*/
|
|
108
|
-
forward() {
|
|
109
|
-
if (this.basePos > this.pos)
|
|
110
|
-
this.forwardInner();
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
@internal
|
|
114
|
-
*/
|
|
115
|
-
forwardInner() {
|
|
116
|
-
let newPos = this.skipSpace(this.basePos);
|
|
117
|
-
this.indent = this.countIndent(newPos, this.pos, this.indent);
|
|
118
|
-
this.pos = newPos;
|
|
119
|
-
this.next = newPos == this.text.length ? -1 : this.text.charCodeAt(newPos);
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
Skip whitespace after the given position, return the position of
|
|
123
|
-
the next non-space character or the end of the line if there's
|
|
124
|
-
only space after `from`.
|
|
125
|
-
*/
|
|
126
|
-
skipSpace(from) {
|
|
127
|
-
return skipSpace(this.text, from);
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
@internal
|
|
131
|
-
*/
|
|
132
|
-
reset(text) {
|
|
133
|
-
this.text = text;
|
|
134
|
-
this.baseIndent = this.basePos = this.pos = this.indent = 0;
|
|
135
|
-
this.forwardInner();
|
|
136
|
-
this.depth = 1;
|
|
137
|
-
while (this.markers.length)
|
|
138
|
-
this.markers.pop();
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
Move the line's base position forward to the given position.
|
|
142
|
-
This should only be called by composite [block
|
|
143
|
-
parsers](#BlockParser.parse) or [markup skipping
|
|
144
|
-
functions](#NodeSpec.composite).
|
|
145
|
-
*/
|
|
146
|
-
moveBase(to) {
|
|
147
|
-
this.basePos = to;
|
|
148
|
-
this.baseIndent = this.countIndent(to, this.pos, this.indent);
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
Move the line's base position forward to the given _column_.
|
|
152
|
-
*/
|
|
153
|
-
moveBaseColumn(indent) {
|
|
154
|
-
this.baseIndent = indent;
|
|
155
|
-
this.basePos = this.findColumn(indent);
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
Store a composite-block-level marker. Should be called from
|
|
159
|
-
[markup skipping functions](#NodeSpec.composite) when they
|
|
160
|
-
consume any non-whitespace characters.
|
|
161
|
-
*/
|
|
162
|
-
addMarker(elt2) {
|
|
163
|
-
this.markers.push(elt2);
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
Find the column position at `to`, optionally starting at a given
|
|
167
|
-
position and column.
|
|
168
|
-
*/
|
|
169
|
-
countIndent(to, from = 0, indent = 0) {
|
|
170
|
-
for (let i = from; i < to; i++)
|
|
171
|
-
indent += this.text.charCodeAt(i) == 9 ? 4 - indent % 4 : 1;
|
|
172
|
-
return indent;
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
Find the position corresponding to the given column.
|
|
176
|
-
*/
|
|
177
|
-
findColumn(goal) {
|
|
178
|
-
let i = 0;
|
|
179
|
-
for (let indent = 0; i < this.text.length && indent < goal; i++)
|
|
180
|
-
indent += this.text.charCodeAt(i) == 9 ? 4 - indent % 4 : 1;
|
|
181
|
-
return i;
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
@internal
|
|
185
|
-
*/
|
|
186
|
-
scrub() {
|
|
187
|
-
if (!this.baseIndent)
|
|
188
|
-
return this.text;
|
|
189
|
-
let result = "";
|
|
190
|
-
for (let i = 0; i < this.basePos; i++)
|
|
191
|
-
result += " ";
|
|
192
|
-
return result + this.text.slice(this.basePos);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
function skipForList(bl, cx, line) {
|
|
196
|
-
if (line.pos == line.text.length || bl != cx.block && line.indent >= cx.stack[line.depth + 1].value + line.baseIndent)
|
|
197
|
-
return true;
|
|
198
|
-
if (line.indent >= line.baseIndent + 4)
|
|
199
|
-
return false;
|
|
200
|
-
let size = (bl.type == Type.OrderedList ? isOrderedList : isBulletList)(line, cx, false);
|
|
201
|
-
return size > 0 && (bl.type != Type.BulletList || isHorizontalRule(line, cx, false) < 0) && line.text.charCodeAt(line.pos + size - 1) == bl.value;
|
|
202
|
-
}
|
|
203
|
-
const DefaultSkipMarkup = {
|
|
204
|
-
[Type.Blockquote](bl, cx, line) {
|
|
205
|
-
if (line.next != 62)
|
|
206
|
-
return false;
|
|
207
|
-
line.markers.push(elt(Type.QuoteMark, cx.lineStart + line.pos, cx.lineStart + line.pos + 1));
|
|
208
|
-
line.moveBase(line.pos + (space(line.text.charCodeAt(line.pos + 1)) ? 2 : 1));
|
|
209
|
-
bl.end = cx.lineStart + line.text.length;
|
|
210
|
-
return true;
|
|
211
|
-
},
|
|
212
|
-
[Type.ListItem](bl, _cx, line) {
|
|
213
|
-
if (line.indent < line.baseIndent + bl.value && line.next > -1)
|
|
214
|
-
return false;
|
|
215
|
-
line.moveBaseColumn(line.baseIndent + bl.value);
|
|
216
|
-
return true;
|
|
217
|
-
},
|
|
218
|
-
[Type.OrderedList]: skipForList,
|
|
219
|
-
[Type.BulletList]: skipForList,
|
|
220
|
-
[Type.Document]() {
|
|
221
|
-
return true;
|
|
222
|
-
}
|
|
223
|
-
};
|
|
224
|
-
function space(ch) {
|
|
225
|
-
return ch == 32 || ch == 9 || ch == 10 || ch == 13;
|
|
226
|
-
}
|
|
227
|
-
function skipSpace(line, i = 0) {
|
|
228
|
-
while (i < line.length && space(line.charCodeAt(i)))
|
|
229
|
-
i++;
|
|
230
|
-
return i;
|
|
231
|
-
}
|
|
232
|
-
function skipSpaceBack(line, i, to) {
|
|
233
|
-
while (i > to && space(line.charCodeAt(i - 1)))
|
|
234
|
-
i--;
|
|
235
|
-
return i;
|
|
236
|
-
}
|
|
237
|
-
function isFencedCode(line) {
|
|
238
|
-
if (line.next != 96 && line.next != 126)
|
|
239
|
-
return -1;
|
|
240
|
-
let pos = line.pos + 1;
|
|
241
|
-
while (pos < line.text.length && line.text.charCodeAt(pos) == line.next)
|
|
242
|
-
pos++;
|
|
243
|
-
if (pos < line.pos + 3)
|
|
244
|
-
return -1;
|
|
245
|
-
if (line.next == 96) {
|
|
246
|
-
for (let i = pos; i < line.text.length; i++)
|
|
247
|
-
if (line.text.charCodeAt(i) == 96)
|
|
248
|
-
return -1;
|
|
249
|
-
}
|
|
250
|
-
return pos;
|
|
251
|
-
}
|
|
252
|
-
function isBlockquote(line) {
|
|
253
|
-
return line.next != 62 ? -1 : line.text.charCodeAt(line.pos + 1) == 32 ? 2 : 1;
|
|
254
|
-
}
|
|
255
|
-
function isHorizontalRule(line, cx, breaking) {
|
|
256
|
-
if (line.next != 42 && line.next != 45 && line.next != 95)
|
|
257
|
-
return -1;
|
|
258
|
-
let count2 = 1;
|
|
259
|
-
for (let pos = line.pos + 1; pos < line.text.length; pos++) {
|
|
260
|
-
let ch = line.text.charCodeAt(pos);
|
|
261
|
-
if (ch == line.next)
|
|
262
|
-
count2++;
|
|
263
|
-
else if (!space(ch))
|
|
264
|
-
return -1;
|
|
265
|
-
}
|
|
266
|
-
if (breaking && line.next == 45 && isSetextUnderline(line) > -1 && line.depth == cx.stack.length && cx.parser.leafBlockParsers.indexOf(DefaultLeafBlocks.SetextHeading) > -1)
|
|
267
|
-
return -1;
|
|
268
|
-
return count2 < 3 ? -1 : 1;
|
|
269
|
-
}
|
|
270
|
-
function inList(cx, type) {
|
|
271
|
-
for (let i = cx.stack.length - 1; i >= 0; i--)
|
|
272
|
-
if (cx.stack[i].type == type)
|
|
273
|
-
return true;
|
|
274
|
-
return false;
|
|
275
|
-
}
|
|
276
|
-
function isBulletList(line, cx, breaking) {
|
|
277
|
-
return (line.next == 45 || line.next == 43 || line.next == 42) && (line.pos == line.text.length - 1 || space(line.text.charCodeAt(line.pos + 1))) && (!breaking || inList(cx, Type.BulletList) || line.skipSpace(line.pos + 2) < line.text.length) ? 1 : -1;
|
|
278
|
-
}
|
|
279
|
-
function isOrderedList(line, cx, breaking) {
|
|
280
|
-
let pos = line.pos, next = line.next;
|
|
281
|
-
for (; ; ) {
|
|
282
|
-
if (next >= 48 && next <= 57)
|
|
283
|
-
pos++;
|
|
284
|
-
else
|
|
285
|
-
break;
|
|
286
|
-
if (pos == line.text.length)
|
|
287
|
-
return -1;
|
|
288
|
-
next = line.text.charCodeAt(pos);
|
|
289
|
-
}
|
|
290
|
-
if (pos == line.pos || pos > line.pos + 9 || next != 46 && next != 41 || pos < line.text.length - 1 && !space(line.text.charCodeAt(pos + 1)) || breaking && !inList(cx, Type.OrderedList) && (line.skipSpace(pos + 1) == line.text.length || pos > line.pos + 1 || line.next != 49))
|
|
291
|
-
return -1;
|
|
292
|
-
return pos + 1 - line.pos;
|
|
293
|
-
}
|
|
294
|
-
function isAtxHeading(line) {
|
|
295
|
-
if (line.next != 35)
|
|
296
|
-
return -1;
|
|
297
|
-
let pos = line.pos + 1;
|
|
298
|
-
while (pos < line.text.length && line.text.charCodeAt(pos) == 35)
|
|
299
|
-
pos++;
|
|
300
|
-
if (pos < line.text.length && line.text.charCodeAt(pos) != 32)
|
|
301
|
-
return -1;
|
|
302
|
-
let size = pos - line.pos;
|
|
303
|
-
return size > 6 ? -1 : size;
|
|
304
|
-
}
|
|
305
|
-
function isSetextUnderline(line) {
|
|
306
|
-
if (line.next != 45 && line.next != 61 || line.indent >= line.baseIndent + 4)
|
|
307
|
-
return -1;
|
|
308
|
-
let pos = line.pos + 1;
|
|
309
|
-
while (pos < line.text.length && line.text.charCodeAt(pos) == line.next)
|
|
310
|
-
pos++;
|
|
311
|
-
let end = pos;
|
|
312
|
-
while (pos < line.text.length && space(line.text.charCodeAt(pos)))
|
|
313
|
-
pos++;
|
|
314
|
-
return pos == line.text.length ? end : -1;
|
|
315
|
-
}
|
|
316
|
-
const EmptyLine = /^[ \t]*$/, CommentEnd = /-->/, ProcessingEnd = /\?>/;
|
|
317
|
-
const HTMLBlockStyle = [
|
|
318
|
-
[/^<(?:script|pre|style)(?:\s|>|$)/i, /<\/(?:script|pre|style)>/i],
|
|
319
|
-
[/^\s*<!--/, CommentEnd],
|
|
320
|
-
[/^\s*<\?/, ProcessingEnd],
|
|
321
|
-
[/^\s*<![A-Z]/, />/],
|
|
322
|
-
[/^\s*<!\[CDATA\[/, /\]\]>/],
|
|
323
|
-
[/^\s*<\/?(?: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|h1|h2|h3|h4|h5|h6|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|nav|noframes|ol|optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul)(?:\s|\/?>|$)/i, EmptyLine],
|
|
324
|
-
[/^\s*(?:<\/[a-z][\w-]*\s*>|<[a-z][\w-]*(\s+[a-z:_][\w-.]*(?:\s*=\s*(?:[^\s"'=<>`]+|'[^']*'|"[^"]*"))?)*\s*>)\s*$/i, EmptyLine]
|
|
325
|
-
];
|
|
326
|
-
function isHTMLBlock(line, _cx, breaking) {
|
|
327
|
-
if (line.next != 60)
|
|
328
|
-
return -1;
|
|
329
|
-
let rest = line.text.slice(line.pos);
|
|
330
|
-
for (let i = 0, e = HTMLBlockStyle.length - (breaking ? 1 : 0); i < e; i++)
|
|
331
|
-
if (HTMLBlockStyle[i][0].test(rest))
|
|
332
|
-
return i;
|
|
333
|
-
return -1;
|
|
334
|
-
}
|
|
335
|
-
function getListIndent(line, pos) {
|
|
336
|
-
let indentAfter = line.countIndent(pos, line.pos, line.indent);
|
|
337
|
-
let indented = line.countIndent(line.skipSpace(pos), pos, indentAfter);
|
|
338
|
-
return indented >= indentAfter + 5 ? indentAfter + 1 : indented;
|
|
339
|
-
}
|
|
340
|
-
function addCodeText(marks, from, to) {
|
|
341
|
-
let last = marks.length - 1;
|
|
342
|
-
if (last >= 0 && marks[last].to == from && marks[last].type == Type.CodeText)
|
|
343
|
-
marks[last].to = to;
|
|
344
|
-
else
|
|
345
|
-
marks.push(elt(Type.CodeText, from, to));
|
|
346
|
-
}
|
|
347
|
-
const DefaultBlockParsers = {
|
|
348
|
-
LinkReference: void 0,
|
|
349
|
-
IndentedCode(cx, line) {
|
|
350
|
-
let base = line.baseIndent + 4;
|
|
351
|
-
if (line.indent < base)
|
|
352
|
-
return false;
|
|
353
|
-
let start = line.findColumn(base);
|
|
354
|
-
let from = cx.lineStart + start, to = cx.lineStart + line.text.length;
|
|
355
|
-
let marks = [], pendingMarks = [];
|
|
356
|
-
addCodeText(marks, from, to);
|
|
357
|
-
while (cx.nextLine() && line.depth >= cx.stack.length) {
|
|
358
|
-
if (line.pos == line.text.length) {
|
|
359
|
-
addCodeText(pendingMarks, cx.lineStart - 1, cx.lineStart);
|
|
360
|
-
for (let m of line.markers)
|
|
361
|
-
pendingMarks.push(m);
|
|
362
|
-
} else if (line.indent < base) {
|
|
363
|
-
break;
|
|
364
|
-
} else {
|
|
365
|
-
if (pendingMarks.length) {
|
|
366
|
-
for (let m of pendingMarks) {
|
|
367
|
-
if (m.type == Type.CodeText)
|
|
368
|
-
addCodeText(marks, m.from, m.to);
|
|
369
|
-
else
|
|
370
|
-
marks.push(m);
|
|
371
|
-
}
|
|
372
|
-
pendingMarks = [];
|
|
373
|
-
}
|
|
374
|
-
addCodeText(marks, cx.lineStart - 1, cx.lineStart);
|
|
375
|
-
for (let m of line.markers)
|
|
376
|
-
marks.push(m);
|
|
377
|
-
to = cx.lineStart + line.text.length;
|
|
378
|
-
let codeStart = cx.lineStart + line.findColumn(line.baseIndent + 4);
|
|
379
|
-
if (codeStart < to)
|
|
380
|
-
addCodeText(marks, codeStart, to);
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
if (pendingMarks.length) {
|
|
384
|
-
pendingMarks = pendingMarks.filter((m) => m.type != Type.CodeText);
|
|
385
|
-
if (pendingMarks.length)
|
|
386
|
-
line.markers = pendingMarks.concat(line.markers);
|
|
387
|
-
}
|
|
388
|
-
cx.addNode(cx.buffer.writeElements(marks, -from).finish(Type.CodeBlock, to - from), from);
|
|
389
|
-
return true;
|
|
390
|
-
},
|
|
391
|
-
FencedCode(cx, line) {
|
|
392
|
-
let fenceEnd = isFencedCode(line);
|
|
393
|
-
if (fenceEnd < 0)
|
|
394
|
-
return false;
|
|
395
|
-
let from = cx.lineStart + line.pos, ch = line.next, len = fenceEnd - line.pos;
|
|
396
|
-
let infoFrom = line.skipSpace(fenceEnd), infoTo = skipSpaceBack(line.text, line.text.length, infoFrom);
|
|
397
|
-
let marks = [elt(Type.CodeMark, from, from + len)];
|
|
398
|
-
if (infoFrom < infoTo)
|
|
399
|
-
marks.push(elt(Type.CodeInfo, cx.lineStart + infoFrom, cx.lineStart + infoTo));
|
|
400
|
-
for (let first = true, empty = true, hasLine = false; cx.nextLine() && line.depth >= cx.stack.length; first = false) {
|
|
401
|
-
let i = line.pos;
|
|
402
|
-
if (line.indent - line.baseIndent < 4)
|
|
403
|
-
while (i < line.text.length && line.text.charCodeAt(i) == ch)
|
|
404
|
-
i++;
|
|
405
|
-
if (i - line.pos >= len && line.skipSpace(i) == line.text.length) {
|
|
406
|
-
for (let m of line.markers)
|
|
407
|
-
marks.push(m);
|
|
408
|
-
if (empty && hasLine)
|
|
409
|
-
addCodeText(marks, cx.lineStart - 1, cx.lineStart);
|
|
410
|
-
marks.push(elt(Type.CodeMark, cx.lineStart + line.pos, cx.lineStart + i));
|
|
411
|
-
cx.nextLine();
|
|
412
|
-
break;
|
|
413
|
-
} else {
|
|
414
|
-
hasLine = true;
|
|
415
|
-
if (!first) {
|
|
416
|
-
addCodeText(marks, cx.lineStart - 1, cx.lineStart);
|
|
417
|
-
empty = false;
|
|
418
|
-
}
|
|
419
|
-
for (let m of line.markers)
|
|
420
|
-
marks.push(m);
|
|
421
|
-
let textStart = cx.lineStart + line.basePos, textEnd = cx.lineStart + line.text.length;
|
|
422
|
-
if (textStart < textEnd) {
|
|
423
|
-
addCodeText(marks, textStart, textEnd);
|
|
424
|
-
empty = false;
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
cx.addNode(cx.buffer.writeElements(marks, -from).finish(Type.FencedCode, cx.prevLineEnd() - from), from);
|
|
429
|
-
return true;
|
|
430
|
-
},
|
|
431
|
-
Blockquote(cx, line) {
|
|
432
|
-
let size = isBlockquote(line);
|
|
433
|
-
if (size < 0)
|
|
434
|
-
return false;
|
|
435
|
-
cx.startContext(Type.Blockquote, line.pos);
|
|
436
|
-
cx.addNode(Type.QuoteMark, cx.lineStart + line.pos, cx.lineStart + line.pos + 1);
|
|
437
|
-
line.moveBase(line.pos + size);
|
|
438
|
-
return null;
|
|
439
|
-
},
|
|
440
|
-
HorizontalRule(cx, line) {
|
|
441
|
-
if (isHorizontalRule(line, cx, false) < 0)
|
|
442
|
-
return false;
|
|
443
|
-
let from = cx.lineStart + line.pos;
|
|
444
|
-
cx.nextLine();
|
|
445
|
-
cx.addNode(Type.HorizontalRule, from);
|
|
446
|
-
return true;
|
|
447
|
-
},
|
|
448
|
-
BulletList(cx, line) {
|
|
449
|
-
let size = isBulletList(line, cx, false);
|
|
450
|
-
if (size < 0)
|
|
451
|
-
return false;
|
|
452
|
-
if (cx.block.type != Type.BulletList)
|
|
453
|
-
cx.startContext(Type.BulletList, line.basePos, line.next);
|
|
454
|
-
let newBase = getListIndent(line, line.pos + 1);
|
|
455
|
-
cx.startContext(Type.ListItem, line.basePos, newBase - line.baseIndent);
|
|
456
|
-
cx.addNode(Type.ListMark, cx.lineStart + line.pos, cx.lineStart + line.pos + size);
|
|
457
|
-
line.moveBaseColumn(newBase);
|
|
458
|
-
return null;
|
|
459
|
-
},
|
|
460
|
-
OrderedList(cx, line) {
|
|
461
|
-
let size = isOrderedList(line, cx, false);
|
|
462
|
-
if (size < 0)
|
|
463
|
-
return false;
|
|
464
|
-
if (cx.block.type != Type.OrderedList)
|
|
465
|
-
cx.startContext(Type.OrderedList, line.basePos, line.text.charCodeAt(line.pos + size - 1));
|
|
466
|
-
let newBase = getListIndent(line, line.pos + size);
|
|
467
|
-
cx.startContext(Type.ListItem, line.basePos, newBase - line.baseIndent);
|
|
468
|
-
cx.addNode(Type.ListMark, cx.lineStart + line.pos, cx.lineStart + line.pos + size);
|
|
469
|
-
line.moveBaseColumn(newBase);
|
|
470
|
-
return null;
|
|
471
|
-
},
|
|
472
|
-
ATXHeading(cx, line) {
|
|
473
|
-
let size = isAtxHeading(line);
|
|
474
|
-
if (size < 0)
|
|
475
|
-
return false;
|
|
476
|
-
let off = line.pos, from = cx.lineStart + off;
|
|
477
|
-
let endOfSpace = skipSpaceBack(line.text, line.text.length, off), after = endOfSpace;
|
|
478
|
-
while (after > off && line.text.charCodeAt(after - 1) == line.next)
|
|
479
|
-
after--;
|
|
480
|
-
if (after == endOfSpace || after == off || !space(line.text.charCodeAt(after - 1)))
|
|
481
|
-
after = line.text.length;
|
|
482
|
-
let buf = cx.buffer.write(Type.HeaderMark, 0, size).writeElements(cx.parser.parseInline(line.text.slice(off + size + 1, after), from + size + 1), -from);
|
|
483
|
-
if (after < line.text.length)
|
|
484
|
-
buf.write(Type.HeaderMark, after - off, endOfSpace - off);
|
|
485
|
-
let node = buf.finish(Type.ATXHeading1 - 1 + size, line.text.length - off);
|
|
486
|
-
cx.nextLine();
|
|
487
|
-
cx.addNode(node, from);
|
|
488
|
-
return true;
|
|
489
|
-
},
|
|
490
|
-
HTMLBlock(cx, line) {
|
|
491
|
-
let type = isHTMLBlock(line, cx, false);
|
|
492
|
-
if (type < 0)
|
|
493
|
-
return false;
|
|
494
|
-
let from = cx.lineStart + line.pos, end = HTMLBlockStyle[type][1];
|
|
495
|
-
let marks = [], trailing = end != EmptyLine;
|
|
496
|
-
while (!end.test(line.text) && cx.nextLine()) {
|
|
497
|
-
if (line.depth < cx.stack.length) {
|
|
498
|
-
trailing = false;
|
|
499
|
-
break;
|
|
500
|
-
}
|
|
501
|
-
for (let m of line.markers)
|
|
502
|
-
marks.push(m);
|
|
503
|
-
}
|
|
504
|
-
if (trailing)
|
|
505
|
-
cx.nextLine();
|
|
506
|
-
let nodeType = end == CommentEnd ? Type.CommentBlock : end == ProcessingEnd ? Type.ProcessingInstructionBlock : Type.HTMLBlock;
|
|
507
|
-
let to = cx.prevLineEnd();
|
|
508
|
-
cx.addNode(cx.buffer.writeElements(marks, -from).finish(nodeType, to - from), from);
|
|
509
|
-
return true;
|
|
510
|
-
},
|
|
511
|
-
SetextHeading: void 0
|
|
512
|
-
// Specifies relative precedence for block-continue function
|
|
513
|
-
};
|
|
514
|
-
class LinkReferenceParser {
|
|
515
|
-
constructor(leaf) {
|
|
516
|
-
this.stage = 0;
|
|
517
|
-
this.elts = [];
|
|
518
|
-
this.pos = 0;
|
|
519
|
-
this.start = leaf.start;
|
|
520
|
-
this.advance(leaf.content);
|
|
521
|
-
}
|
|
522
|
-
nextLine(cx, line, leaf) {
|
|
523
|
-
if (this.stage == -1)
|
|
524
|
-
return false;
|
|
525
|
-
let content = leaf.content + "\n" + line.scrub();
|
|
526
|
-
let finish = this.advance(content);
|
|
527
|
-
if (finish > -1 && finish < content.length)
|
|
528
|
-
return this.complete(cx, leaf, finish);
|
|
529
|
-
return false;
|
|
530
|
-
}
|
|
531
|
-
finish(cx, leaf) {
|
|
532
|
-
if ((this.stage == 2 || this.stage == 3) && skipSpace(leaf.content, this.pos) == leaf.content.length)
|
|
533
|
-
return this.complete(cx, leaf, leaf.content.length);
|
|
534
|
-
return false;
|
|
535
|
-
}
|
|
536
|
-
complete(cx, leaf, len) {
|
|
537
|
-
cx.addLeafElement(leaf, elt(Type.LinkReference, this.start, this.start + len, this.elts));
|
|
538
|
-
return true;
|
|
539
|
-
}
|
|
540
|
-
nextStage(elt2) {
|
|
541
|
-
if (elt2) {
|
|
542
|
-
this.pos = elt2.to - this.start;
|
|
543
|
-
this.elts.push(elt2);
|
|
544
|
-
this.stage++;
|
|
545
|
-
return true;
|
|
546
|
-
}
|
|
547
|
-
if (elt2 === false)
|
|
548
|
-
this.stage = -1;
|
|
549
|
-
return false;
|
|
550
|
-
}
|
|
551
|
-
advance(content) {
|
|
552
|
-
for (; ; ) {
|
|
553
|
-
if (this.stage == -1) {
|
|
554
|
-
return -1;
|
|
555
|
-
} else if (this.stage == 0) {
|
|
556
|
-
if (!this.nextStage(parseLinkLabel(content, this.pos, this.start, true)))
|
|
557
|
-
return -1;
|
|
558
|
-
if (content.charCodeAt(this.pos) != 58)
|
|
559
|
-
return this.stage = -1;
|
|
560
|
-
this.elts.push(elt(Type.LinkMark, this.pos + this.start, this.pos + this.start + 1));
|
|
561
|
-
this.pos++;
|
|
562
|
-
} else if (this.stage == 1) {
|
|
563
|
-
if (!this.nextStage(parseURL(content, skipSpace(content, this.pos), this.start)))
|
|
564
|
-
return -1;
|
|
565
|
-
} else if (this.stage == 2) {
|
|
566
|
-
let skip = skipSpace(content, this.pos), end = 0;
|
|
567
|
-
if (skip > this.pos) {
|
|
568
|
-
let title = parseLinkTitle(content, skip, this.start);
|
|
569
|
-
if (title) {
|
|
570
|
-
let titleEnd = lineEnd(content, title.to - this.start);
|
|
571
|
-
if (titleEnd > 0) {
|
|
572
|
-
this.nextStage(title);
|
|
573
|
-
end = titleEnd;
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
if (!end)
|
|
578
|
-
end = lineEnd(content, this.pos);
|
|
579
|
-
return end > 0 && end < content.length ? end : -1;
|
|
580
|
-
} else {
|
|
581
|
-
return lineEnd(content, this.pos);
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
function lineEnd(text, pos) {
|
|
587
|
-
for (; pos < text.length; pos++) {
|
|
588
|
-
let next = text.charCodeAt(pos);
|
|
589
|
-
if (next == 10)
|
|
590
|
-
break;
|
|
591
|
-
if (!space(next))
|
|
592
|
-
return -1;
|
|
593
|
-
}
|
|
594
|
-
return pos;
|
|
595
|
-
}
|
|
596
|
-
class SetextHeadingParser {
|
|
597
|
-
nextLine(cx, line, leaf) {
|
|
598
|
-
let underline = line.depth < cx.stack.length ? -1 : isSetextUnderline(line);
|
|
599
|
-
let next = line.next;
|
|
600
|
-
if (underline < 0)
|
|
601
|
-
return false;
|
|
602
|
-
let underlineMark = elt(Type.HeaderMark, cx.lineStart + line.pos, cx.lineStart + underline);
|
|
603
|
-
cx.nextLine();
|
|
604
|
-
cx.addLeafElement(leaf, elt(next == 61 ? Type.SetextHeading1 : Type.SetextHeading2, leaf.start, cx.prevLineEnd(), [
|
|
605
|
-
...cx.parser.parseInline(leaf.content, leaf.start),
|
|
606
|
-
underlineMark
|
|
607
|
-
]));
|
|
608
|
-
return true;
|
|
609
|
-
}
|
|
610
|
-
finish() {
|
|
611
|
-
return false;
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
const DefaultLeafBlocks = {
|
|
615
|
-
LinkReference(_, leaf) {
|
|
616
|
-
return leaf.content.charCodeAt(0) == 91 ? new LinkReferenceParser(leaf) : null;
|
|
617
|
-
},
|
|
618
|
-
SetextHeading() {
|
|
619
|
-
return new SetextHeadingParser();
|
|
620
|
-
}
|
|
621
|
-
};
|
|
622
|
-
const DefaultEndLeaf = [
|
|
623
|
-
(_, line) => isAtxHeading(line) >= 0,
|
|
624
|
-
(_, line) => isFencedCode(line) >= 0,
|
|
625
|
-
(_, line) => isBlockquote(line) >= 0,
|
|
626
|
-
(p, line) => isBulletList(line, p, true) >= 0,
|
|
627
|
-
(p, line) => isOrderedList(line, p, true) >= 0,
|
|
628
|
-
(p, line) => isHorizontalRule(line, p, true) >= 0,
|
|
629
|
-
(p, line) => isHTMLBlock(line, p, true) >= 0
|
|
630
|
-
];
|
|
631
|
-
const scanLineResult = { text: "", end: 0 };
|
|
632
|
-
class BlockContext {
|
|
633
|
-
/**
|
|
634
|
-
@internal
|
|
635
|
-
*/
|
|
636
|
-
constructor(parser2, input, fragments, ranges) {
|
|
637
|
-
this.parser = parser2;
|
|
638
|
-
this.input = input;
|
|
639
|
-
this.ranges = ranges;
|
|
640
|
-
this.line = new Line();
|
|
641
|
-
this.atEnd = false;
|
|
642
|
-
this.reusePlaceholders = /* @__PURE__ */ new Map();
|
|
643
|
-
this.stoppedAt = null;
|
|
644
|
-
this.rangeI = 0;
|
|
645
|
-
this.to = ranges[ranges.length - 1].to;
|
|
646
|
-
this.lineStart = this.absoluteLineStart = this.absoluteLineEnd = ranges[0].from;
|
|
647
|
-
this.block = CompositeBlock.create(Type.Document, 0, this.lineStart, 0, 0);
|
|
648
|
-
this.stack = [this.block];
|
|
649
|
-
this.fragments = fragments.length ? new FragmentCursor(fragments, input) : null;
|
|
650
|
-
this.readLine();
|
|
651
|
-
}
|
|
652
|
-
get parsedPos() {
|
|
653
|
-
return this.absoluteLineStart;
|
|
654
|
-
}
|
|
655
|
-
advance() {
|
|
656
|
-
if (this.stoppedAt != null && this.absoluteLineStart > this.stoppedAt)
|
|
657
|
-
return this.finish();
|
|
658
|
-
let { line } = this;
|
|
659
|
-
for (; ; ) {
|
|
660
|
-
for (let markI = 0; ; ) {
|
|
661
|
-
let next = line.depth < this.stack.length ? this.stack[this.stack.length - 1] : null;
|
|
662
|
-
while (markI < line.markers.length && (!next || line.markers[markI].from < next.end)) {
|
|
663
|
-
let mark = line.markers[markI++];
|
|
664
|
-
this.addNode(mark.type, mark.from, mark.to);
|
|
665
|
-
}
|
|
666
|
-
if (!next)
|
|
667
|
-
break;
|
|
668
|
-
this.finishContext();
|
|
669
|
-
}
|
|
670
|
-
if (line.pos < line.text.length)
|
|
671
|
-
break;
|
|
672
|
-
if (!this.nextLine())
|
|
673
|
-
return this.finish();
|
|
674
|
-
}
|
|
675
|
-
if (this.fragments && this.reuseFragment(line.basePos))
|
|
676
|
-
return null;
|
|
677
|
-
start: for (; ; ) {
|
|
678
|
-
for (let type of this.parser.blockParsers)
|
|
679
|
-
if (type) {
|
|
680
|
-
let result = type(this, line);
|
|
681
|
-
if (result != false) {
|
|
682
|
-
if (result == true)
|
|
683
|
-
return null;
|
|
684
|
-
line.forward();
|
|
685
|
-
continue start;
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
break;
|
|
689
|
-
}
|
|
690
|
-
let leaf = new LeafBlock(this.lineStart + line.pos, line.text.slice(line.pos));
|
|
691
|
-
for (let parse of this.parser.leafBlockParsers)
|
|
692
|
-
if (parse) {
|
|
693
|
-
let parser2 = parse(this, leaf);
|
|
694
|
-
if (parser2)
|
|
695
|
-
leaf.parsers.push(parser2);
|
|
696
|
-
}
|
|
697
|
-
lines: while (this.nextLine()) {
|
|
698
|
-
if (line.pos == line.text.length)
|
|
699
|
-
break;
|
|
700
|
-
if (line.indent < line.baseIndent + 4) {
|
|
701
|
-
for (let stop of this.parser.endLeafBlock)
|
|
702
|
-
if (stop(this, line, leaf))
|
|
703
|
-
break lines;
|
|
704
|
-
}
|
|
705
|
-
for (let parser2 of leaf.parsers)
|
|
706
|
-
if (parser2.nextLine(this, line, leaf))
|
|
707
|
-
return null;
|
|
708
|
-
leaf.content += "\n" + line.scrub();
|
|
709
|
-
for (let m of line.markers)
|
|
710
|
-
leaf.marks.push(m);
|
|
711
|
-
}
|
|
712
|
-
this.finishLeaf(leaf);
|
|
713
|
-
return null;
|
|
714
|
-
}
|
|
715
|
-
stopAt(pos) {
|
|
716
|
-
if (this.stoppedAt != null && this.stoppedAt < pos)
|
|
717
|
-
throw new RangeError("Can't move stoppedAt forward");
|
|
718
|
-
this.stoppedAt = pos;
|
|
719
|
-
}
|
|
720
|
-
reuseFragment(start) {
|
|
721
|
-
if (!this.fragments.moveTo(this.absoluteLineStart + start, this.absoluteLineStart) || !this.fragments.matches(this.block.hash))
|
|
722
|
-
return false;
|
|
723
|
-
let taken = this.fragments.takeNodes(this);
|
|
724
|
-
if (!taken)
|
|
725
|
-
return false;
|
|
726
|
-
this.absoluteLineStart += taken;
|
|
727
|
-
this.lineStart = toRelative(this.absoluteLineStart, this.ranges);
|
|
728
|
-
this.moveRangeI();
|
|
729
|
-
if (this.absoluteLineStart < this.to) {
|
|
730
|
-
this.lineStart++;
|
|
731
|
-
this.absoluteLineStart++;
|
|
732
|
-
this.readLine();
|
|
733
|
-
} else {
|
|
734
|
-
this.atEnd = true;
|
|
735
|
-
this.readLine();
|
|
736
|
-
}
|
|
737
|
-
return true;
|
|
738
|
-
}
|
|
739
|
-
/**
|
|
740
|
-
The number of parent blocks surrounding the current block.
|
|
741
|
-
*/
|
|
742
|
-
get depth() {
|
|
743
|
-
return this.stack.length;
|
|
744
|
-
}
|
|
745
|
-
/**
|
|
746
|
-
Get the type of the parent block at the given depth. When no
|
|
747
|
-
depth is passed, return the type of the innermost parent.
|
|
748
|
-
*/
|
|
749
|
-
parentType(depth = this.depth - 1) {
|
|
750
|
-
return this.parser.nodeSet.types[this.stack[depth].type];
|
|
751
|
-
}
|
|
752
|
-
/**
|
|
753
|
-
Move to the next input line. This should only be called by
|
|
754
|
-
(non-composite) [block parsers](#BlockParser.parse) that consume
|
|
755
|
-
the line directly, or leaf block parser
|
|
756
|
-
[`nextLine`](#LeafBlockParser.nextLine) methods when they
|
|
757
|
-
consume the current line (and return true).
|
|
758
|
-
*/
|
|
759
|
-
nextLine() {
|
|
760
|
-
this.lineStart += this.line.text.length;
|
|
761
|
-
if (this.absoluteLineEnd >= this.to) {
|
|
762
|
-
this.absoluteLineStart = this.absoluteLineEnd;
|
|
763
|
-
this.atEnd = true;
|
|
764
|
-
this.readLine();
|
|
765
|
-
return false;
|
|
766
|
-
} else {
|
|
767
|
-
this.lineStart++;
|
|
768
|
-
this.absoluteLineStart = this.absoluteLineEnd + 1;
|
|
769
|
-
this.moveRangeI();
|
|
770
|
-
this.readLine();
|
|
771
|
-
return true;
|
|
772
|
-
}
|
|
773
|
-
}
|
|
774
|
-
/**
|
|
775
|
-
Retrieve the text of the line after the current one, without
|
|
776
|
-
actually moving the context's current line forward.
|
|
777
|
-
*/
|
|
778
|
-
peekLine() {
|
|
779
|
-
return this.scanLine(this.absoluteLineEnd + 1).text;
|
|
780
|
-
}
|
|
781
|
-
moveRangeI() {
|
|
782
|
-
while (this.rangeI < this.ranges.length - 1 && this.absoluteLineStart >= this.ranges[this.rangeI].to) {
|
|
783
|
-
this.rangeI++;
|
|
784
|
-
this.absoluteLineStart = Math.max(this.absoluteLineStart, this.ranges[this.rangeI].from);
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
/**
|
|
788
|
-
@internal
|
|
789
|
-
Collect the text for the next line.
|
|
790
|
-
*/
|
|
791
|
-
scanLine(start) {
|
|
792
|
-
let r = scanLineResult;
|
|
793
|
-
r.end = start;
|
|
794
|
-
if (start >= this.to) {
|
|
795
|
-
r.text = "";
|
|
796
|
-
} else {
|
|
797
|
-
r.text = this.lineChunkAt(start);
|
|
798
|
-
r.end += r.text.length;
|
|
799
|
-
if (this.ranges.length > 1) {
|
|
800
|
-
let textOffset = this.absoluteLineStart, rangeI = this.rangeI;
|
|
801
|
-
while (this.ranges[rangeI].to < r.end) {
|
|
802
|
-
rangeI++;
|
|
803
|
-
let nextFrom = this.ranges[rangeI].from;
|
|
804
|
-
let after = this.lineChunkAt(nextFrom);
|
|
805
|
-
r.end = nextFrom + after.length;
|
|
806
|
-
r.text = r.text.slice(0, this.ranges[rangeI - 1].to - textOffset) + after;
|
|
807
|
-
textOffset = r.end - r.text.length;
|
|
808
|
-
}
|
|
809
|
-
}
|
|
810
|
-
}
|
|
811
|
-
return r;
|
|
812
|
-
}
|
|
813
|
-
/**
|
|
814
|
-
@internal
|
|
815
|
-
Populate this.line with the content of the next line. Skip
|
|
816
|
-
leading characters covered by composite blocks.
|
|
817
|
-
*/
|
|
818
|
-
readLine() {
|
|
819
|
-
let { line } = this, { text, end } = this.scanLine(this.absoluteLineStart);
|
|
820
|
-
this.absoluteLineEnd = end;
|
|
821
|
-
line.reset(text);
|
|
822
|
-
for (; line.depth < this.stack.length; line.depth++) {
|
|
823
|
-
let cx = this.stack[line.depth], handler = this.parser.skipContextMarkup[cx.type];
|
|
824
|
-
if (!handler)
|
|
825
|
-
throw new Error("Unhandled block context " + Type[cx.type]);
|
|
826
|
-
let marks = this.line.markers.length;
|
|
827
|
-
if (!handler(cx, this, line)) {
|
|
828
|
-
if (this.line.markers.length > marks)
|
|
829
|
-
cx.end = this.line.markers[this.line.markers.length - 1].to;
|
|
830
|
-
line.forward();
|
|
831
|
-
break;
|
|
832
|
-
}
|
|
833
|
-
line.forward();
|
|
834
|
-
}
|
|
835
|
-
}
|
|
836
|
-
lineChunkAt(pos) {
|
|
837
|
-
let next = this.input.chunk(pos), text;
|
|
838
|
-
if (!this.input.lineChunks) {
|
|
839
|
-
let eol = next.indexOf("\n");
|
|
840
|
-
text = eol < 0 ? next : next.slice(0, eol);
|
|
841
|
-
} else {
|
|
842
|
-
text = next == "\n" ? "" : next;
|
|
843
|
-
}
|
|
844
|
-
return pos + text.length > this.to ? text.slice(0, this.to - pos) : text;
|
|
845
|
-
}
|
|
846
|
-
/**
|
|
847
|
-
The end position of the previous line.
|
|
848
|
-
*/
|
|
849
|
-
prevLineEnd() {
|
|
850
|
-
return this.atEnd ? this.lineStart : this.lineStart - 1;
|
|
851
|
-
}
|
|
852
|
-
/**
|
|
853
|
-
@internal
|
|
854
|
-
*/
|
|
855
|
-
startContext(type, start, value = 0) {
|
|
856
|
-
this.block = CompositeBlock.create(type, value, this.lineStart + start, this.block.hash, this.lineStart + this.line.text.length);
|
|
857
|
-
this.stack.push(this.block);
|
|
858
|
-
}
|
|
859
|
-
/**
|
|
860
|
-
Start a composite block. Should only be called from [block
|
|
861
|
-
parser functions](#BlockParser.parse) that return null.
|
|
862
|
-
*/
|
|
863
|
-
startComposite(type, start, value = 0) {
|
|
864
|
-
this.startContext(this.parser.getNodeType(type), start, value);
|
|
865
|
-
}
|
|
866
|
-
/**
|
|
867
|
-
@internal
|
|
868
|
-
*/
|
|
869
|
-
addNode(block, from, to) {
|
|
870
|
-
if (typeof block == "number")
|
|
871
|
-
block = new Tree(this.parser.nodeSet.types[block], none, none, (to !== null && to !== void 0 ? to : this.prevLineEnd()) - from);
|
|
872
|
-
this.block.addChild(block, from - this.block.from);
|
|
873
|
-
}
|
|
874
|
-
/**
|
|
875
|
-
Add a block element. Can be called by [block
|
|
876
|
-
parsers](#BlockParser.parse).
|
|
877
|
-
*/
|
|
878
|
-
addElement(elt2) {
|
|
879
|
-
this.block.addChild(elt2.toTree(this.parser.nodeSet), elt2.from - this.block.from);
|
|
880
|
-
}
|
|
881
|
-
/**
|
|
882
|
-
Add a block element from a [leaf parser](#LeafBlockParser). This
|
|
883
|
-
makes sure any extra composite block markup (such as blockquote
|
|
884
|
-
markers) inside the block are also added to the syntax tree.
|
|
885
|
-
*/
|
|
886
|
-
addLeafElement(leaf, elt2) {
|
|
887
|
-
this.addNode(this.buffer.writeElements(injectMarks(elt2.children, leaf.marks), -elt2.from).finish(elt2.type, elt2.to - elt2.from), elt2.from);
|
|
888
|
-
}
|
|
889
|
-
/**
|
|
890
|
-
@internal
|
|
891
|
-
*/
|
|
892
|
-
finishContext() {
|
|
893
|
-
let cx = this.stack.pop();
|
|
894
|
-
let top = this.stack[this.stack.length - 1];
|
|
895
|
-
top.addChild(cx.toTree(this.parser.nodeSet), cx.from - top.from);
|
|
896
|
-
this.block = top;
|
|
897
|
-
}
|
|
898
|
-
finish() {
|
|
899
|
-
while (this.stack.length > 1)
|
|
900
|
-
this.finishContext();
|
|
901
|
-
return this.addGaps(this.block.toTree(this.parser.nodeSet, this.lineStart));
|
|
902
|
-
}
|
|
903
|
-
addGaps(tree) {
|
|
904
|
-
return this.ranges.length > 1 ? injectGaps(this.ranges, 0, tree.topNode, this.ranges[0].from, this.reusePlaceholders) : tree;
|
|
905
|
-
}
|
|
906
|
-
/**
|
|
907
|
-
@internal
|
|
908
|
-
*/
|
|
909
|
-
finishLeaf(leaf) {
|
|
910
|
-
for (let parser2 of leaf.parsers)
|
|
911
|
-
if (parser2.finish(this, leaf))
|
|
912
|
-
return;
|
|
913
|
-
let inline = injectMarks(this.parser.parseInline(leaf.content, leaf.start), leaf.marks);
|
|
914
|
-
this.addNode(this.buffer.writeElements(inline, -leaf.start).finish(Type.Paragraph, leaf.content.length), leaf.start);
|
|
915
|
-
}
|
|
916
|
-
elt(type, from, to, children) {
|
|
917
|
-
if (typeof type == "string")
|
|
918
|
-
return elt(this.parser.getNodeType(type), from, to, children);
|
|
919
|
-
return new TreeElement(type, from);
|
|
920
|
-
}
|
|
921
|
-
/**
|
|
922
|
-
@internal
|
|
923
|
-
*/
|
|
924
|
-
get buffer() {
|
|
925
|
-
return new Buffer(this.parser.nodeSet);
|
|
926
|
-
}
|
|
927
|
-
}
|
|
928
|
-
function injectGaps(ranges, rangeI, tree, offset, dummies) {
|
|
929
|
-
let rangeEnd = ranges[rangeI].to;
|
|
930
|
-
let children = [], positions = [], start = tree.from + offset;
|
|
931
|
-
function movePastNext(upto, inclusive) {
|
|
932
|
-
while (inclusive ? upto >= rangeEnd : upto > rangeEnd) {
|
|
933
|
-
let size = ranges[rangeI + 1].from - rangeEnd;
|
|
934
|
-
offset += size;
|
|
935
|
-
upto += size;
|
|
936
|
-
rangeI++;
|
|
937
|
-
rangeEnd = ranges[rangeI].to;
|
|
938
|
-
}
|
|
939
|
-
}
|
|
940
|
-
for (let ch = tree.firstChild; ch; ch = ch.nextSibling) {
|
|
941
|
-
movePastNext(ch.from + offset, true);
|
|
942
|
-
let from = ch.from + offset, node, reuse = dummies.get(ch.tree);
|
|
943
|
-
if (reuse) {
|
|
944
|
-
node = reuse;
|
|
945
|
-
} else if (ch.to + offset > rangeEnd) {
|
|
946
|
-
node = injectGaps(ranges, rangeI, ch, offset, dummies);
|
|
947
|
-
movePastNext(ch.to + offset, false);
|
|
948
|
-
} else {
|
|
949
|
-
node = ch.toTree();
|
|
950
|
-
}
|
|
951
|
-
children.push(node);
|
|
952
|
-
positions.push(from - start);
|
|
953
|
-
}
|
|
954
|
-
movePastNext(tree.to + offset, false);
|
|
955
|
-
return new Tree(tree.type, children, positions, tree.to + offset - start, tree.tree ? tree.tree.propValues : void 0);
|
|
956
|
-
}
|
|
957
|
-
class MarkdownParser extends Parser {
|
|
958
|
-
/**
|
|
959
|
-
@internal
|
|
960
|
-
*/
|
|
961
|
-
constructor(nodeSet, blockParsers, leafBlockParsers, blockNames, endLeafBlock, skipContextMarkup, inlineParsers, inlineNames, wrappers) {
|
|
962
|
-
super();
|
|
963
|
-
this.nodeSet = nodeSet;
|
|
964
|
-
this.blockParsers = blockParsers;
|
|
965
|
-
this.leafBlockParsers = leafBlockParsers;
|
|
966
|
-
this.blockNames = blockNames;
|
|
967
|
-
this.endLeafBlock = endLeafBlock;
|
|
968
|
-
this.skipContextMarkup = skipContextMarkup;
|
|
969
|
-
this.inlineParsers = inlineParsers;
|
|
970
|
-
this.inlineNames = inlineNames;
|
|
971
|
-
this.wrappers = wrappers;
|
|
972
|
-
this.nodeTypes = /* @__PURE__ */ Object.create(null);
|
|
973
|
-
for (let t of nodeSet.types)
|
|
974
|
-
this.nodeTypes[t.name] = t.id;
|
|
975
|
-
}
|
|
976
|
-
createParse(input, fragments, ranges) {
|
|
977
|
-
let parse = new BlockContext(this, input, fragments, ranges);
|
|
978
|
-
for (let w of this.wrappers)
|
|
979
|
-
parse = w(parse, input, fragments, ranges);
|
|
980
|
-
return parse;
|
|
981
|
-
}
|
|
982
|
-
/**
|
|
983
|
-
Reconfigure the parser.
|
|
984
|
-
*/
|
|
985
|
-
configure(spec) {
|
|
986
|
-
let config = resolveConfig(spec);
|
|
987
|
-
if (!config)
|
|
988
|
-
return this;
|
|
989
|
-
let { nodeSet, skipContextMarkup } = this;
|
|
990
|
-
let blockParsers = this.blockParsers.slice(), leafBlockParsers = this.leafBlockParsers.slice(), blockNames = this.blockNames.slice(), inlineParsers = this.inlineParsers.slice(), inlineNames = this.inlineNames.slice(), endLeafBlock = this.endLeafBlock.slice(), wrappers = this.wrappers;
|
|
991
|
-
if (nonEmpty(config.defineNodes)) {
|
|
992
|
-
skipContextMarkup = Object.assign({}, skipContextMarkup);
|
|
993
|
-
let nodeTypes2 = nodeSet.types.slice(), styles;
|
|
994
|
-
for (let s of config.defineNodes) {
|
|
995
|
-
let { name, block, composite, style } = typeof s == "string" ? { name: s } : s;
|
|
996
|
-
if (nodeTypes2.some((t) => t.name == name))
|
|
997
|
-
continue;
|
|
998
|
-
if (composite)
|
|
999
|
-
skipContextMarkup[nodeTypes2.length] = (bl, cx, line) => composite(cx, line, bl.value);
|
|
1000
|
-
let id = nodeTypes2.length;
|
|
1001
|
-
let group = composite ? ["Block", "BlockContext"] : !block ? void 0 : id >= Type.ATXHeading1 && id <= Type.SetextHeading2 ? ["Block", "LeafBlock", "Heading"] : ["Block", "LeafBlock"];
|
|
1002
|
-
nodeTypes2.push(NodeType.define({
|
|
1003
|
-
id,
|
|
1004
|
-
name,
|
|
1005
|
-
props: group && [[NodeProp.group, group]]
|
|
1006
|
-
}));
|
|
1007
|
-
if (style) {
|
|
1008
|
-
if (!styles)
|
|
1009
|
-
styles = {};
|
|
1010
|
-
if (Array.isArray(style) || style instanceof Tag)
|
|
1011
|
-
styles[name] = style;
|
|
1012
|
-
else
|
|
1013
|
-
Object.assign(styles, style);
|
|
1014
|
-
}
|
|
1015
|
-
}
|
|
1016
|
-
nodeSet = new NodeSet(nodeTypes2);
|
|
1017
|
-
if (styles)
|
|
1018
|
-
nodeSet = nodeSet.extend(styleTags(styles));
|
|
1019
|
-
}
|
|
1020
|
-
if (nonEmpty(config.props))
|
|
1021
|
-
nodeSet = nodeSet.extend(...config.props);
|
|
1022
|
-
if (nonEmpty(config.remove)) {
|
|
1023
|
-
for (let rm of config.remove) {
|
|
1024
|
-
let block = this.blockNames.indexOf(rm), inline = this.inlineNames.indexOf(rm);
|
|
1025
|
-
if (block > -1)
|
|
1026
|
-
blockParsers[block] = leafBlockParsers[block] = void 0;
|
|
1027
|
-
if (inline > -1)
|
|
1028
|
-
inlineParsers[inline] = void 0;
|
|
1029
|
-
}
|
|
1030
|
-
}
|
|
1031
|
-
if (nonEmpty(config.parseBlock)) {
|
|
1032
|
-
for (let spec2 of config.parseBlock) {
|
|
1033
|
-
let found = blockNames.indexOf(spec2.name);
|
|
1034
|
-
if (found > -1) {
|
|
1035
|
-
blockParsers[found] = spec2.parse;
|
|
1036
|
-
leafBlockParsers[found] = spec2.leaf;
|
|
1037
|
-
} else {
|
|
1038
|
-
let pos = spec2.before ? findName(blockNames, spec2.before) : spec2.after ? findName(blockNames, spec2.after) + 1 : blockNames.length - 1;
|
|
1039
|
-
blockParsers.splice(pos, 0, spec2.parse);
|
|
1040
|
-
leafBlockParsers.splice(pos, 0, spec2.leaf);
|
|
1041
|
-
blockNames.splice(pos, 0, spec2.name);
|
|
1042
|
-
}
|
|
1043
|
-
if (spec2.endLeaf)
|
|
1044
|
-
endLeafBlock.push(spec2.endLeaf);
|
|
1045
|
-
}
|
|
1046
|
-
}
|
|
1047
|
-
if (nonEmpty(config.parseInline)) {
|
|
1048
|
-
for (let spec2 of config.parseInline) {
|
|
1049
|
-
let found = inlineNames.indexOf(spec2.name);
|
|
1050
|
-
if (found > -1) {
|
|
1051
|
-
inlineParsers[found] = spec2.parse;
|
|
1052
|
-
} else {
|
|
1053
|
-
let pos = spec2.before ? findName(inlineNames, spec2.before) : spec2.after ? findName(inlineNames, spec2.after) + 1 : inlineNames.length - 1;
|
|
1054
|
-
inlineParsers.splice(pos, 0, spec2.parse);
|
|
1055
|
-
inlineNames.splice(pos, 0, spec2.name);
|
|
1056
|
-
}
|
|
1057
|
-
}
|
|
1058
|
-
}
|
|
1059
|
-
if (config.wrap)
|
|
1060
|
-
wrappers = wrappers.concat(config.wrap);
|
|
1061
|
-
return new MarkdownParser(nodeSet, blockParsers, leafBlockParsers, blockNames, endLeafBlock, skipContextMarkup, inlineParsers, inlineNames, wrappers);
|
|
1062
|
-
}
|
|
1063
|
-
/**
|
|
1064
|
-
@internal
|
|
1065
|
-
*/
|
|
1066
|
-
getNodeType(name) {
|
|
1067
|
-
let found = this.nodeTypes[name];
|
|
1068
|
-
if (found == null)
|
|
1069
|
-
throw new RangeError(`Unknown node type '${name}'`);
|
|
1070
|
-
return found;
|
|
1071
|
-
}
|
|
1072
|
-
/**
|
|
1073
|
-
Parse the given piece of inline text at the given offset,
|
|
1074
|
-
returning an array of [`Element`](#Element) objects representing
|
|
1075
|
-
the inline content.
|
|
1076
|
-
*/
|
|
1077
|
-
parseInline(text, offset) {
|
|
1078
|
-
let cx = new InlineContext(this, text, offset);
|
|
1079
|
-
outer: for (let pos = offset; pos < cx.end; ) {
|
|
1080
|
-
let next = cx.char(pos);
|
|
1081
|
-
for (let token of this.inlineParsers)
|
|
1082
|
-
if (token) {
|
|
1083
|
-
let result = token(cx, next, pos);
|
|
1084
|
-
if (result >= 0) {
|
|
1085
|
-
pos = result;
|
|
1086
|
-
continue outer;
|
|
1087
|
-
}
|
|
1088
|
-
}
|
|
1089
|
-
pos++;
|
|
1090
|
-
}
|
|
1091
|
-
return cx.resolveMarkers(0);
|
|
1092
|
-
}
|
|
1093
|
-
}
|
|
1094
|
-
function nonEmpty(a) {
|
|
1095
|
-
return a != null && a.length > 0;
|
|
1096
|
-
}
|
|
1097
|
-
function resolveConfig(spec) {
|
|
1098
|
-
if (!Array.isArray(spec))
|
|
1099
|
-
return spec;
|
|
1100
|
-
if (spec.length == 0)
|
|
1101
|
-
return null;
|
|
1102
|
-
let conf = resolveConfig(spec[0]);
|
|
1103
|
-
if (spec.length == 1)
|
|
1104
|
-
return conf;
|
|
1105
|
-
let rest = resolveConfig(spec.slice(1));
|
|
1106
|
-
if (!rest || !conf)
|
|
1107
|
-
return conf || rest;
|
|
1108
|
-
let conc = (a, b) => (a || none).concat(b || none);
|
|
1109
|
-
let wrapA = conf.wrap, wrapB = rest.wrap;
|
|
1110
|
-
return {
|
|
1111
|
-
props: conc(conf.props, rest.props),
|
|
1112
|
-
defineNodes: conc(conf.defineNodes, rest.defineNodes),
|
|
1113
|
-
parseBlock: conc(conf.parseBlock, rest.parseBlock),
|
|
1114
|
-
parseInline: conc(conf.parseInline, rest.parseInline),
|
|
1115
|
-
remove: conc(conf.remove, rest.remove),
|
|
1116
|
-
wrap: !wrapA ? wrapB : !wrapB ? wrapA : (inner, input, fragments, ranges) => wrapA(wrapB(inner, input, fragments, ranges), input, fragments, ranges)
|
|
1117
|
-
};
|
|
1118
|
-
}
|
|
1119
|
-
function findName(names, name) {
|
|
1120
|
-
let found = names.indexOf(name);
|
|
1121
|
-
if (found < 0)
|
|
1122
|
-
throw new RangeError(`Position specified relative to unknown parser ${name}`);
|
|
1123
|
-
return found;
|
|
1124
|
-
}
|
|
1125
|
-
let nodeTypes = [NodeType.none];
|
|
1126
|
-
for (let i = 1, name; name = Type[i]; i++) {
|
|
1127
|
-
nodeTypes[i] = NodeType.define({
|
|
1128
|
-
id: i,
|
|
1129
|
-
name,
|
|
1130
|
-
props: i >= Type.Escape ? [] : [[NodeProp.group, i in DefaultSkipMarkup ? ["Block", "BlockContext"] : ["Block", "LeafBlock"]]],
|
|
1131
|
-
top: name == "Document"
|
|
1132
|
-
});
|
|
1133
|
-
}
|
|
1134
|
-
const none = [];
|
|
1135
|
-
class Buffer {
|
|
1136
|
-
constructor(nodeSet) {
|
|
1137
|
-
this.nodeSet = nodeSet;
|
|
1138
|
-
this.content = [];
|
|
1139
|
-
this.nodes = [];
|
|
1140
|
-
}
|
|
1141
|
-
write(type, from, to, children = 0) {
|
|
1142
|
-
this.content.push(type, from, to, 4 + children * 4);
|
|
1143
|
-
return this;
|
|
1144
|
-
}
|
|
1145
|
-
writeElements(elts, offset = 0) {
|
|
1146
|
-
for (let e of elts)
|
|
1147
|
-
e.writeTo(this, offset);
|
|
1148
|
-
return this;
|
|
1149
|
-
}
|
|
1150
|
-
finish(type, length) {
|
|
1151
|
-
return Tree.build({
|
|
1152
|
-
buffer: this.content,
|
|
1153
|
-
nodeSet: this.nodeSet,
|
|
1154
|
-
reused: this.nodes,
|
|
1155
|
-
topID: type,
|
|
1156
|
-
length
|
|
1157
|
-
});
|
|
1158
|
-
}
|
|
1159
|
-
}
|
|
1160
|
-
class Element {
|
|
1161
|
-
/**
|
|
1162
|
-
@internal
|
|
1163
|
-
*/
|
|
1164
|
-
constructor(type, from, to, children = none) {
|
|
1165
|
-
this.type = type;
|
|
1166
|
-
this.from = from;
|
|
1167
|
-
this.to = to;
|
|
1168
|
-
this.children = children;
|
|
1169
|
-
}
|
|
1170
|
-
/**
|
|
1171
|
-
@internal
|
|
1172
|
-
*/
|
|
1173
|
-
writeTo(buf, offset) {
|
|
1174
|
-
let startOff = buf.content.length;
|
|
1175
|
-
buf.writeElements(this.children, offset);
|
|
1176
|
-
buf.content.push(this.type, this.from + offset, this.to + offset, buf.content.length + 4 - startOff);
|
|
1177
|
-
}
|
|
1178
|
-
/**
|
|
1179
|
-
@internal
|
|
1180
|
-
*/
|
|
1181
|
-
toTree(nodeSet) {
|
|
1182
|
-
return new Buffer(nodeSet).writeElements(this.children, -this.from).finish(this.type, this.to - this.from);
|
|
1183
|
-
}
|
|
1184
|
-
}
|
|
1185
|
-
class TreeElement {
|
|
1186
|
-
constructor(tree, from) {
|
|
1187
|
-
this.tree = tree;
|
|
1188
|
-
this.from = from;
|
|
1189
|
-
}
|
|
1190
|
-
get to() {
|
|
1191
|
-
return this.from + this.tree.length;
|
|
1192
|
-
}
|
|
1193
|
-
get type() {
|
|
1194
|
-
return this.tree.type.id;
|
|
1195
|
-
}
|
|
1196
|
-
get children() {
|
|
1197
|
-
return none;
|
|
1198
|
-
}
|
|
1199
|
-
writeTo(buf, offset) {
|
|
1200
|
-
buf.nodes.push(this.tree);
|
|
1201
|
-
buf.content.push(buf.nodes.length - 1, this.from + offset, this.to + offset, -1);
|
|
1202
|
-
}
|
|
1203
|
-
toTree() {
|
|
1204
|
-
return this.tree;
|
|
1205
|
-
}
|
|
1206
|
-
}
|
|
1207
|
-
function elt(type, from, to, children) {
|
|
1208
|
-
return new Element(type, from, to, children);
|
|
1209
|
-
}
|
|
1210
|
-
const EmphasisUnderscore = { resolve: "Emphasis", mark: "EmphasisMark" };
|
|
1211
|
-
const EmphasisAsterisk = { resolve: "Emphasis", mark: "EmphasisMark" };
|
|
1212
|
-
const LinkStart = {}, ImageStart = {};
|
|
1213
|
-
class InlineDelimiter {
|
|
1214
|
-
constructor(type, from, to, side) {
|
|
1215
|
-
this.type = type;
|
|
1216
|
-
this.from = from;
|
|
1217
|
-
this.to = to;
|
|
1218
|
-
this.side = side;
|
|
1219
|
-
}
|
|
1220
|
-
}
|
|
1221
|
-
const Escapable = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";
|
|
1222
|
-
let Punctuation = /[!"#$%&'()*+,\-.\/:;<=>?@\[\\\]^_`{|}~\xA1\u2010-\u2027]/;
|
|
1223
|
-
try {
|
|
1224
|
-
Punctuation = new RegExp("[\\p{S}|\\p{P}]", "u");
|
|
1225
|
-
} catch (_) {
|
|
1226
|
-
}
|
|
1227
|
-
const DefaultInline = {
|
|
1228
|
-
Escape(cx, next, start) {
|
|
1229
|
-
if (next != 92 || start == cx.end - 1)
|
|
1230
|
-
return -1;
|
|
1231
|
-
let escaped = cx.char(start + 1);
|
|
1232
|
-
for (let i = 0; i < Escapable.length; i++)
|
|
1233
|
-
if (Escapable.charCodeAt(i) == escaped)
|
|
1234
|
-
return cx.append(elt(Type.Escape, start, start + 2));
|
|
1235
|
-
return -1;
|
|
1236
|
-
},
|
|
1237
|
-
Entity(cx, next, start) {
|
|
1238
|
-
if (next != 38)
|
|
1239
|
-
return -1;
|
|
1240
|
-
let m = /^(?:#\d+|#x[a-f\d]+|\w+);/i.exec(cx.slice(start + 1, start + 31));
|
|
1241
|
-
return m ? cx.append(elt(Type.Entity, start, start + 1 + m[0].length)) : -1;
|
|
1242
|
-
},
|
|
1243
|
-
InlineCode(cx, next, start) {
|
|
1244
|
-
if (next != 96 || start && cx.char(start - 1) == 96)
|
|
1245
|
-
return -1;
|
|
1246
|
-
let pos = start + 1;
|
|
1247
|
-
while (pos < cx.end && cx.char(pos) == 96)
|
|
1248
|
-
pos++;
|
|
1249
|
-
let size = pos - start, curSize = 0;
|
|
1250
|
-
for (; pos < cx.end; pos++) {
|
|
1251
|
-
if (cx.char(pos) == 96) {
|
|
1252
|
-
curSize++;
|
|
1253
|
-
if (curSize == size && cx.char(pos + 1) != 96)
|
|
1254
|
-
return cx.append(elt(Type.InlineCode, start, pos + 1, [
|
|
1255
|
-
elt(Type.CodeMark, start, start + size),
|
|
1256
|
-
elt(Type.CodeMark, pos + 1 - size, pos + 1)
|
|
1257
|
-
]));
|
|
1258
|
-
} else {
|
|
1259
|
-
curSize = 0;
|
|
1260
|
-
}
|
|
1261
|
-
}
|
|
1262
|
-
return -1;
|
|
1263
|
-
},
|
|
1264
|
-
HTMLTag(cx, next, start) {
|
|
1265
|
-
if (next != 60 || start == cx.end - 1)
|
|
1266
|
-
return -1;
|
|
1267
|
-
let after = cx.slice(start + 1, cx.end);
|
|
1268
|
-
let url = /^(?:[a-z][-\w+.]+:[^\s>]+|[a-z\d.!#$%&'*+/=?^_`{|}~-]+@[a-z\d](?:[a-z\d-]{0,61}[a-z\d])?(?:\.[a-z\d](?:[a-z\d-]{0,61}[a-z\d])?)*)>/i.exec(after);
|
|
1269
|
-
if (url) {
|
|
1270
|
-
return cx.append(elt(Type.Autolink, start, start + 1 + url[0].length, [
|
|
1271
|
-
elt(Type.LinkMark, start, start + 1),
|
|
1272
|
-
// url[0] includes the closing bracket, so exclude it from this slice
|
|
1273
|
-
elt(Type.URL, start + 1, start + url[0].length),
|
|
1274
|
-
elt(Type.LinkMark, start + url[0].length, start + 1 + url[0].length)
|
|
1275
|
-
]));
|
|
1276
|
-
}
|
|
1277
|
-
let comment = /^!--[^>](?:-[^-]|[^-])*?-->/i.exec(after);
|
|
1278
|
-
if (comment)
|
|
1279
|
-
return cx.append(elt(Type.Comment, start, start + 1 + comment[0].length));
|
|
1280
|
-
let procInst = /^\?[^]*?\?>/.exec(after);
|
|
1281
|
-
if (procInst)
|
|
1282
|
-
return cx.append(elt(Type.ProcessingInstruction, start, start + 1 + procInst[0].length));
|
|
1283
|
-
let m = /^(?:![A-Z][^]*?>|!\[CDATA\[[^]*?\]\]>|\/\s*[a-zA-Z][\w-]*\s*>|\s*[a-zA-Z][\w-]*(\s+[a-zA-Z:_][\w-.:]*(?:\s*=\s*(?:[^\s"'=<>`]+|'[^']*'|"[^"]*"))?)*\s*(\/\s*)?>)/.exec(after);
|
|
1284
|
-
if (!m)
|
|
1285
|
-
return -1;
|
|
1286
|
-
return cx.append(elt(Type.HTMLTag, start, start + 1 + m[0].length));
|
|
1287
|
-
},
|
|
1288
|
-
Emphasis(cx, next, start) {
|
|
1289
|
-
if (next != 95 && next != 42)
|
|
1290
|
-
return -1;
|
|
1291
|
-
let pos = start + 1;
|
|
1292
|
-
while (cx.char(pos) == next)
|
|
1293
|
-
pos++;
|
|
1294
|
-
let before = cx.slice(start - 1, start), after = cx.slice(pos, pos + 1);
|
|
1295
|
-
let pBefore = Punctuation.test(before), pAfter = Punctuation.test(after);
|
|
1296
|
-
let sBefore = /\s|^$/.test(before), sAfter = /\s|^$/.test(after);
|
|
1297
|
-
let leftFlanking = !sAfter && (!pAfter || sBefore || pBefore);
|
|
1298
|
-
let rightFlanking = !sBefore && (!pBefore || sAfter || pAfter);
|
|
1299
|
-
let canOpen = leftFlanking && (next == 42 || !rightFlanking || pBefore);
|
|
1300
|
-
let canClose = rightFlanking && (next == 42 || !leftFlanking || pAfter);
|
|
1301
|
-
return cx.append(new InlineDelimiter(next == 95 ? EmphasisUnderscore : EmphasisAsterisk, start, pos, (canOpen ? 1 : 0) | (canClose ? 2 : 0)));
|
|
1302
|
-
},
|
|
1303
|
-
HardBreak(cx, next, start) {
|
|
1304
|
-
if (next == 92 && cx.char(start + 1) == 10)
|
|
1305
|
-
return cx.append(elt(Type.HardBreak, start, start + 2));
|
|
1306
|
-
if (next == 32) {
|
|
1307
|
-
let pos = start + 1;
|
|
1308
|
-
while (cx.char(pos) == 32)
|
|
1309
|
-
pos++;
|
|
1310
|
-
if (cx.char(pos) == 10 && pos >= start + 2)
|
|
1311
|
-
return cx.append(elt(Type.HardBreak, start, pos + 1));
|
|
1312
|
-
}
|
|
1313
|
-
return -1;
|
|
1314
|
-
},
|
|
1315
|
-
Link(cx, next, start) {
|
|
1316
|
-
return next == 91 ? cx.append(new InlineDelimiter(
|
|
1317
|
-
LinkStart,
|
|
1318
|
-
start,
|
|
1319
|
-
start + 1,
|
|
1320
|
-
1
|
|
1321
|
-
/* Mark.Open */
|
|
1322
|
-
)) : -1;
|
|
1323
|
-
},
|
|
1324
|
-
Image(cx, next, start) {
|
|
1325
|
-
return next == 33 && cx.char(start + 1) == 91 ? cx.append(new InlineDelimiter(
|
|
1326
|
-
ImageStart,
|
|
1327
|
-
start,
|
|
1328
|
-
start + 2,
|
|
1329
|
-
1
|
|
1330
|
-
/* Mark.Open */
|
|
1331
|
-
)) : -1;
|
|
1332
|
-
},
|
|
1333
|
-
LinkEnd(cx, next, start) {
|
|
1334
|
-
if (next != 93)
|
|
1335
|
-
return -1;
|
|
1336
|
-
for (let i = cx.parts.length - 1; i >= 0; i--) {
|
|
1337
|
-
let part = cx.parts[i];
|
|
1338
|
-
if (part instanceof InlineDelimiter && (part.type == LinkStart || part.type == ImageStart)) {
|
|
1339
|
-
if (!part.side || cx.skipSpace(part.to) == start && !/[(\[]/.test(cx.slice(start + 1, start + 2))) {
|
|
1340
|
-
cx.parts[i] = null;
|
|
1341
|
-
return -1;
|
|
1342
|
-
}
|
|
1343
|
-
let content = cx.takeContent(i);
|
|
1344
|
-
let link = cx.parts[i] = finishLink(cx, content, part.type == LinkStart ? Type.Link : Type.Image, part.from, start + 1);
|
|
1345
|
-
if (part.type == LinkStart)
|
|
1346
|
-
for (let j = 0; j < i; j++) {
|
|
1347
|
-
let p = cx.parts[j];
|
|
1348
|
-
if (p instanceof InlineDelimiter && p.type == LinkStart)
|
|
1349
|
-
p.side = 0;
|
|
1350
|
-
}
|
|
1351
|
-
return link.to;
|
|
1352
|
-
}
|
|
1353
|
-
}
|
|
1354
|
-
return -1;
|
|
1355
|
-
}
|
|
1356
|
-
};
|
|
1357
|
-
function finishLink(cx, content, type, start, startPos) {
|
|
1358
|
-
let { text } = cx, next = cx.char(startPos), endPos = startPos;
|
|
1359
|
-
content.unshift(elt(Type.LinkMark, start, start + (type == Type.Image ? 2 : 1)));
|
|
1360
|
-
content.push(elt(Type.LinkMark, startPos - 1, startPos));
|
|
1361
|
-
if (next == 40) {
|
|
1362
|
-
let pos = cx.skipSpace(startPos + 1);
|
|
1363
|
-
let dest = parseURL(text, pos - cx.offset, cx.offset), title;
|
|
1364
|
-
if (dest) {
|
|
1365
|
-
pos = cx.skipSpace(dest.to);
|
|
1366
|
-
if (pos != dest.to) {
|
|
1367
|
-
title = parseLinkTitle(text, pos - cx.offset, cx.offset);
|
|
1368
|
-
if (title)
|
|
1369
|
-
pos = cx.skipSpace(title.to);
|
|
1370
|
-
}
|
|
1371
|
-
}
|
|
1372
|
-
if (cx.char(pos) == 41) {
|
|
1373
|
-
content.push(elt(Type.LinkMark, startPos, startPos + 1));
|
|
1374
|
-
endPos = pos + 1;
|
|
1375
|
-
if (dest)
|
|
1376
|
-
content.push(dest);
|
|
1377
|
-
if (title)
|
|
1378
|
-
content.push(title);
|
|
1379
|
-
content.push(elt(Type.LinkMark, pos, endPos));
|
|
1380
|
-
}
|
|
1381
|
-
} else if (next == 91) {
|
|
1382
|
-
let label = parseLinkLabel(text, startPos - cx.offset, cx.offset, false);
|
|
1383
|
-
if (label) {
|
|
1384
|
-
content.push(label);
|
|
1385
|
-
endPos = label.to;
|
|
1386
|
-
}
|
|
1387
|
-
}
|
|
1388
|
-
return elt(type, start, endPos, content);
|
|
1389
|
-
}
|
|
1390
|
-
function parseURL(text, start, offset) {
|
|
1391
|
-
let next = text.charCodeAt(start);
|
|
1392
|
-
if (next == 60) {
|
|
1393
|
-
for (let pos = start + 1; pos < text.length; pos++) {
|
|
1394
|
-
let ch = text.charCodeAt(pos);
|
|
1395
|
-
if (ch == 62)
|
|
1396
|
-
return elt(Type.URL, start + offset, pos + 1 + offset);
|
|
1397
|
-
if (ch == 60 || ch == 10)
|
|
1398
|
-
return false;
|
|
1399
|
-
}
|
|
1400
|
-
return null;
|
|
1401
|
-
} else {
|
|
1402
|
-
let depth = 0, pos = start;
|
|
1403
|
-
for (let escaped = false; pos < text.length; pos++) {
|
|
1404
|
-
let ch = text.charCodeAt(pos);
|
|
1405
|
-
if (space(ch)) {
|
|
1406
|
-
break;
|
|
1407
|
-
} else if (escaped) {
|
|
1408
|
-
escaped = false;
|
|
1409
|
-
} else if (ch == 40) {
|
|
1410
|
-
depth++;
|
|
1411
|
-
} else if (ch == 41) {
|
|
1412
|
-
if (!depth)
|
|
1413
|
-
break;
|
|
1414
|
-
depth--;
|
|
1415
|
-
} else if (ch == 92) {
|
|
1416
|
-
escaped = true;
|
|
1417
|
-
}
|
|
1418
|
-
}
|
|
1419
|
-
return pos > start ? elt(Type.URL, start + offset, pos + offset) : pos == text.length ? null : false;
|
|
1420
|
-
}
|
|
1421
|
-
}
|
|
1422
|
-
function parseLinkTitle(text, start, offset) {
|
|
1423
|
-
let next = text.charCodeAt(start);
|
|
1424
|
-
if (next != 39 && next != 34 && next != 40)
|
|
1425
|
-
return false;
|
|
1426
|
-
let end = next == 40 ? 41 : next;
|
|
1427
|
-
for (let pos = start + 1, escaped = false; pos < text.length; pos++) {
|
|
1428
|
-
let ch = text.charCodeAt(pos);
|
|
1429
|
-
if (escaped)
|
|
1430
|
-
escaped = false;
|
|
1431
|
-
else if (ch == end)
|
|
1432
|
-
return elt(Type.LinkTitle, start + offset, pos + 1 + offset);
|
|
1433
|
-
else if (ch == 92)
|
|
1434
|
-
escaped = true;
|
|
1435
|
-
}
|
|
1436
|
-
return null;
|
|
1437
|
-
}
|
|
1438
|
-
function parseLinkLabel(text, start, offset, requireNonWS) {
|
|
1439
|
-
for (let escaped = false, pos = start + 1, end = Math.min(text.length, pos + 999); pos < end; pos++) {
|
|
1440
|
-
let ch = text.charCodeAt(pos);
|
|
1441
|
-
if (escaped)
|
|
1442
|
-
escaped = false;
|
|
1443
|
-
else if (ch == 93)
|
|
1444
|
-
return requireNonWS ? false : elt(Type.LinkLabel, start + offset, pos + 1 + offset);
|
|
1445
|
-
else {
|
|
1446
|
-
if (requireNonWS && !space(ch))
|
|
1447
|
-
requireNonWS = false;
|
|
1448
|
-
if (ch == 91)
|
|
1449
|
-
return false;
|
|
1450
|
-
else if (ch == 92)
|
|
1451
|
-
escaped = true;
|
|
1452
|
-
}
|
|
1453
|
-
}
|
|
1454
|
-
return null;
|
|
1455
|
-
}
|
|
1456
|
-
class InlineContext {
|
|
1457
|
-
/**
|
|
1458
|
-
@internal
|
|
1459
|
-
*/
|
|
1460
|
-
constructor(parser2, text, offset) {
|
|
1461
|
-
this.parser = parser2;
|
|
1462
|
-
this.text = text;
|
|
1463
|
-
this.offset = offset;
|
|
1464
|
-
this.parts = [];
|
|
1465
|
-
}
|
|
1466
|
-
/**
|
|
1467
|
-
Get the character code at the given (document-relative)
|
|
1468
|
-
position.
|
|
1469
|
-
*/
|
|
1470
|
-
char(pos) {
|
|
1471
|
-
return pos >= this.end ? -1 : this.text.charCodeAt(pos - this.offset);
|
|
1472
|
-
}
|
|
1473
|
-
/**
|
|
1474
|
-
The position of the end of this inline section.
|
|
1475
|
-
*/
|
|
1476
|
-
get end() {
|
|
1477
|
-
return this.offset + this.text.length;
|
|
1478
|
-
}
|
|
1479
|
-
/**
|
|
1480
|
-
Get a substring of this inline section. Again uses
|
|
1481
|
-
document-relative positions.
|
|
1482
|
-
*/
|
|
1483
|
-
slice(from, to) {
|
|
1484
|
-
return this.text.slice(from - this.offset, to - this.offset);
|
|
1485
|
-
}
|
|
1486
|
-
/**
|
|
1487
|
-
@internal
|
|
1488
|
-
*/
|
|
1489
|
-
append(elt2) {
|
|
1490
|
-
this.parts.push(elt2);
|
|
1491
|
-
return elt2.to;
|
|
1492
|
-
}
|
|
1493
|
-
/**
|
|
1494
|
-
Add a [delimiter](#DelimiterType) at this given position. `open`
|
|
1495
|
-
and `close` indicate whether this delimiter is opening, closing,
|
|
1496
|
-
or both. Returns the end of the delimiter, for convenient
|
|
1497
|
-
returning from [parse functions](#InlineParser.parse).
|
|
1498
|
-
*/
|
|
1499
|
-
addDelimiter(type, from, to, open, close) {
|
|
1500
|
-
return this.append(new InlineDelimiter(type, from, to, (open ? 1 : 0) | (close ? 2 : 0)));
|
|
1501
|
-
}
|
|
1502
|
-
/**
|
|
1503
|
-
Returns true when there is an unmatched link or image opening
|
|
1504
|
-
token before the current position.
|
|
1505
|
-
*/
|
|
1506
|
-
get hasOpenLink() {
|
|
1507
|
-
for (let i = this.parts.length - 1; i >= 0; i--) {
|
|
1508
|
-
let part = this.parts[i];
|
|
1509
|
-
if (part instanceof InlineDelimiter && (part.type == LinkStart || part.type == ImageStart))
|
|
1510
|
-
return true;
|
|
1511
|
-
}
|
|
1512
|
-
return false;
|
|
1513
|
-
}
|
|
1514
|
-
/**
|
|
1515
|
-
Add an inline element. Returns the end of the element.
|
|
1516
|
-
*/
|
|
1517
|
-
addElement(elt2) {
|
|
1518
|
-
return this.append(elt2);
|
|
1519
|
-
}
|
|
1520
|
-
/**
|
|
1521
|
-
Resolve markers between this.parts.length and from, wrapping matched markers in the
|
|
1522
|
-
appropriate node and updating the content of this.parts. @internal
|
|
1523
|
-
*/
|
|
1524
|
-
resolveMarkers(from) {
|
|
1525
|
-
for (let i = from; i < this.parts.length; i++) {
|
|
1526
|
-
let close = this.parts[i];
|
|
1527
|
-
if (!(close instanceof InlineDelimiter && close.type.resolve && close.side & 2))
|
|
1528
|
-
continue;
|
|
1529
|
-
let emp = close.type == EmphasisUnderscore || close.type == EmphasisAsterisk;
|
|
1530
|
-
let closeSize = close.to - close.from;
|
|
1531
|
-
let open, j = i - 1;
|
|
1532
|
-
for (; j >= from; j--) {
|
|
1533
|
-
let part = this.parts[j];
|
|
1534
|
-
if (part instanceof InlineDelimiter && part.side & 1 && part.type == close.type && // Ignore emphasis delimiters where the character count doesn't match
|
|
1535
|
-
!(emp && (close.side & 1 || part.side & 2) && (part.to - part.from + closeSize) % 3 == 0 && ((part.to - part.from) % 3 || closeSize % 3))) {
|
|
1536
|
-
open = part;
|
|
1537
|
-
break;
|
|
1538
|
-
}
|
|
1539
|
-
}
|
|
1540
|
-
if (!open)
|
|
1541
|
-
continue;
|
|
1542
|
-
let type = close.type.resolve, content = [];
|
|
1543
|
-
let start = open.from, end = close.to;
|
|
1544
|
-
if (emp) {
|
|
1545
|
-
let size = Math.min(2, open.to - open.from, closeSize);
|
|
1546
|
-
start = open.to - size;
|
|
1547
|
-
end = close.from + size;
|
|
1548
|
-
type = size == 1 ? "Emphasis" : "StrongEmphasis";
|
|
1549
|
-
}
|
|
1550
|
-
if (open.type.mark)
|
|
1551
|
-
content.push(this.elt(open.type.mark, start, open.to));
|
|
1552
|
-
for (let k = j + 1; k < i; k++) {
|
|
1553
|
-
if (this.parts[k] instanceof Element)
|
|
1554
|
-
content.push(this.parts[k]);
|
|
1555
|
-
this.parts[k] = null;
|
|
1556
|
-
}
|
|
1557
|
-
if (close.type.mark)
|
|
1558
|
-
content.push(this.elt(close.type.mark, close.from, end));
|
|
1559
|
-
let element = this.elt(type, start, end, content);
|
|
1560
|
-
this.parts[j] = emp && open.from != start ? new InlineDelimiter(open.type, open.from, start, open.side) : null;
|
|
1561
|
-
let keep = this.parts[i] = emp && close.to != end ? new InlineDelimiter(close.type, end, close.to, close.side) : null;
|
|
1562
|
-
if (keep)
|
|
1563
|
-
this.parts.splice(i, 0, element);
|
|
1564
|
-
else
|
|
1565
|
-
this.parts[i] = element;
|
|
1566
|
-
}
|
|
1567
|
-
let result = [];
|
|
1568
|
-
for (let i = from; i < this.parts.length; i++) {
|
|
1569
|
-
let part = this.parts[i];
|
|
1570
|
-
if (part instanceof Element)
|
|
1571
|
-
result.push(part);
|
|
1572
|
-
}
|
|
1573
|
-
return result;
|
|
1574
|
-
}
|
|
1575
|
-
/**
|
|
1576
|
-
Find an opening delimiter of the given type. Returns `null` if
|
|
1577
|
-
no delimiter is found, or an index that can be passed to
|
|
1578
|
-
[`takeContent`](#InlineContext.takeContent) otherwise.
|
|
1579
|
-
*/
|
|
1580
|
-
findOpeningDelimiter(type) {
|
|
1581
|
-
for (let i = this.parts.length - 1; i >= 0; i--) {
|
|
1582
|
-
let part = this.parts[i];
|
|
1583
|
-
if (part instanceof InlineDelimiter && part.type == type && part.side & 1)
|
|
1584
|
-
return i;
|
|
1585
|
-
}
|
|
1586
|
-
return null;
|
|
1587
|
-
}
|
|
1588
|
-
/**
|
|
1589
|
-
Remove all inline elements and delimiters starting from the
|
|
1590
|
-
given index (which you should get from
|
|
1591
|
-
[`findOpeningDelimiter`](#InlineContext.findOpeningDelimiter),
|
|
1592
|
-
resolve delimiters inside of them, and return them as an array
|
|
1593
|
-
of elements.
|
|
1594
|
-
*/
|
|
1595
|
-
takeContent(startIndex) {
|
|
1596
|
-
let content = this.resolveMarkers(startIndex);
|
|
1597
|
-
this.parts.length = startIndex;
|
|
1598
|
-
return content;
|
|
1599
|
-
}
|
|
1600
|
-
/**
|
|
1601
|
-
Return the delimiter at the given index. Mostly useful to get
|
|
1602
|
-
additional info out of a delimiter index returned by
|
|
1603
|
-
[`findOpeningDelimiter`](#InlineContext.findOpeningDelimiter).
|
|
1604
|
-
Returns null if there is no delimiter at this index.
|
|
1605
|
-
*/
|
|
1606
|
-
getDelimiterAt(index) {
|
|
1607
|
-
let part = this.parts[index];
|
|
1608
|
-
return part instanceof InlineDelimiter ? part : null;
|
|
1609
|
-
}
|
|
1610
|
-
/**
|
|
1611
|
-
Skip space after the given (document) position, returning either
|
|
1612
|
-
the position of the next non-space character or the end of the
|
|
1613
|
-
section.
|
|
1614
|
-
*/
|
|
1615
|
-
skipSpace(from) {
|
|
1616
|
-
return skipSpace(this.text, from - this.offset) + this.offset;
|
|
1617
|
-
}
|
|
1618
|
-
elt(type, from, to, children) {
|
|
1619
|
-
if (typeof type == "string")
|
|
1620
|
-
return elt(this.parser.getNodeType(type), from, to, children);
|
|
1621
|
-
return new TreeElement(type, from);
|
|
1622
|
-
}
|
|
1623
|
-
}
|
|
1624
|
-
InlineContext.linkStart = LinkStart;
|
|
1625
|
-
InlineContext.imageStart = ImageStart;
|
|
1626
|
-
function injectMarks(elements, marks) {
|
|
1627
|
-
if (!marks.length)
|
|
1628
|
-
return elements;
|
|
1629
|
-
if (!elements.length)
|
|
1630
|
-
return marks;
|
|
1631
|
-
let elts = elements.slice(), eI = 0;
|
|
1632
|
-
for (let mark of marks) {
|
|
1633
|
-
while (eI < elts.length && elts[eI].to < mark.to)
|
|
1634
|
-
eI++;
|
|
1635
|
-
if (eI < elts.length && elts[eI].from < mark.from) {
|
|
1636
|
-
let e = elts[eI];
|
|
1637
|
-
if (e instanceof Element)
|
|
1638
|
-
elts[eI] = new Element(e.type, e.from, e.to, injectMarks(e.children, [mark]));
|
|
1639
|
-
} else {
|
|
1640
|
-
elts.splice(eI++, 0, mark);
|
|
1641
|
-
}
|
|
1642
|
-
}
|
|
1643
|
-
return elts;
|
|
1644
|
-
}
|
|
1645
|
-
const NotLast = [Type.CodeBlock, Type.ListItem, Type.OrderedList, Type.BulletList];
|
|
1646
|
-
class FragmentCursor {
|
|
1647
|
-
constructor(fragments, input) {
|
|
1648
|
-
this.fragments = fragments;
|
|
1649
|
-
this.input = input;
|
|
1650
|
-
this.i = 0;
|
|
1651
|
-
this.fragment = null;
|
|
1652
|
-
this.fragmentEnd = -1;
|
|
1653
|
-
this.cursor = null;
|
|
1654
|
-
if (fragments.length)
|
|
1655
|
-
this.fragment = fragments[this.i++];
|
|
1656
|
-
}
|
|
1657
|
-
nextFragment() {
|
|
1658
|
-
this.fragment = this.i < this.fragments.length ? this.fragments[this.i++] : null;
|
|
1659
|
-
this.cursor = null;
|
|
1660
|
-
this.fragmentEnd = -1;
|
|
1661
|
-
}
|
|
1662
|
-
moveTo(pos, lineStart) {
|
|
1663
|
-
while (this.fragment && this.fragment.to <= pos)
|
|
1664
|
-
this.nextFragment();
|
|
1665
|
-
if (!this.fragment || this.fragment.from > (pos ? pos - 1 : 0))
|
|
1666
|
-
return false;
|
|
1667
|
-
if (this.fragmentEnd < 0) {
|
|
1668
|
-
let end = this.fragment.to;
|
|
1669
|
-
while (end > 0 && this.input.read(end - 1, end) != "\n")
|
|
1670
|
-
end--;
|
|
1671
|
-
this.fragmentEnd = end ? end - 1 : 0;
|
|
1672
|
-
}
|
|
1673
|
-
let c = this.cursor;
|
|
1674
|
-
if (!c) {
|
|
1675
|
-
c = this.cursor = this.fragment.tree.cursor();
|
|
1676
|
-
c.firstChild();
|
|
1677
|
-
}
|
|
1678
|
-
let rPos = pos + this.fragment.offset;
|
|
1679
|
-
while (c.to <= rPos)
|
|
1680
|
-
if (!c.parent())
|
|
1681
|
-
return false;
|
|
1682
|
-
for (; ; ) {
|
|
1683
|
-
if (c.from >= rPos)
|
|
1684
|
-
return this.fragment.from <= lineStart;
|
|
1685
|
-
if (!c.childAfter(rPos))
|
|
1686
|
-
return false;
|
|
1687
|
-
}
|
|
1688
|
-
}
|
|
1689
|
-
matches(hash) {
|
|
1690
|
-
let tree = this.cursor.tree;
|
|
1691
|
-
return tree && tree.prop(NodeProp.contextHash) == hash;
|
|
1692
|
-
}
|
|
1693
|
-
takeNodes(cx) {
|
|
1694
|
-
let cur = this.cursor, off = this.fragment.offset, fragEnd = this.fragmentEnd - (this.fragment.openEnd ? 1 : 0);
|
|
1695
|
-
let start = cx.absoluteLineStart, end = start, blockI = cx.block.children.length;
|
|
1696
|
-
let prevEnd = end, prevI = blockI;
|
|
1697
|
-
for (; ; ) {
|
|
1698
|
-
if (cur.to - off > fragEnd) {
|
|
1699
|
-
if (cur.type.isAnonymous && cur.firstChild())
|
|
1700
|
-
continue;
|
|
1701
|
-
break;
|
|
1702
|
-
}
|
|
1703
|
-
let pos = toRelative(cur.from - off, cx.ranges);
|
|
1704
|
-
if (cur.to - off <= cx.ranges[cx.rangeI].to) {
|
|
1705
|
-
cx.addNode(cur.tree, pos);
|
|
1706
|
-
} else {
|
|
1707
|
-
let dummy = new Tree(cx.parser.nodeSet.types[Type.Paragraph], [], [], 0, cx.block.hashProp);
|
|
1708
|
-
cx.reusePlaceholders.set(dummy, cur.tree);
|
|
1709
|
-
cx.addNode(dummy, pos);
|
|
1710
|
-
}
|
|
1711
|
-
if (cur.type.is("Block")) {
|
|
1712
|
-
if (NotLast.indexOf(cur.type.id) < 0) {
|
|
1713
|
-
end = cur.to - off;
|
|
1714
|
-
blockI = cx.block.children.length;
|
|
1715
|
-
} else {
|
|
1716
|
-
end = prevEnd;
|
|
1717
|
-
blockI = prevI;
|
|
1718
|
-
}
|
|
1719
|
-
prevEnd = cur.to - off;
|
|
1720
|
-
prevI = cx.block.children.length;
|
|
1721
|
-
}
|
|
1722
|
-
if (!cur.nextSibling())
|
|
1723
|
-
break;
|
|
1724
|
-
}
|
|
1725
|
-
while (cx.block.children.length > blockI) {
|
|
1726
|
-
cx.block.children.pop();
|
|
1727
|
-
cx.block.positions.pop();
|
|
1728
|
-
}
|
|
1729
|
-
return end - start;
|
|
1730
|
-
}
|
|
1731
|
-
}
|
|
1732
|
-
function toRelative(abs, ranges) {
|
|
1733
|
-
let pos = abs;
|
|
1734
|
-
for (let i = 1; i < ranges.length; i++) {
|
|
1735
|
-
let gapFrom = ranges[i - 1].to, gapTo = ranges[i].from;
|
|
1736
|
-
if (gapFrom < abs)
|
|
1737
|
-
pos -= gapTo - gapFrom;
|
|
1738
|
-
}
|
|
1739
|
-
return pos;
|
|
1740
|
-
}
|
|
1741
|
-
const markdownHighlighting = styleTags({
|
|
1742
|
-
"Blockquote/...": tags.quote,
|
|
1743
|
-
HorizontalRule: tags.contentSeparator,
|
|
1744
|
-
"ATXHeading1/... SetextHeading1/...": tags.heading1,
|
|
1745
|
-
"ATXHeading2/... SetextHeading2/...": tags.heading2,
|
|
1746
|
-
"ATXHeading3/...": tags.heading3,
|
|
1747
|
-
"ATXHeading4/...": tags.heading4,
|
|
1748
|
-
"ATXHeading5/...": tags.heading5,
|
|
1749
|
-
"ATXHeading6/...": tags.heading6,
|
|
1750
|
-
"Comment CommentBlock": tags.comment,
|
|
1751
|
-
Escape: tags.escape,
|
|
1752
|
-
Entity: tags.character,
|
|
1753
|
-
"Emphasis/...": tags.emphasis,
|
|
1754
|
-
"StrongEmphasis/...": tags.strong,
|
|
1755
|
-
"Link/... Image/...": tags.link,
|
|
1756
|
-
"OrderedList/... BulletList/...": tags.list,
|
|
1757
|
-
"BlockQuote/...": tags.quote,
|
|
1758
|
-
"InlineCode CodeText": tags.monospace,
|
|
1759
|
-
"URL Autolink": tags.url,
|
|
1760
|
-
"HeaderMark HardBreak QuoteMark ListMark LinkMark EmphasisMark CodeMark": tags.processingInstruction,
|
|
1761
|
-
"CodeInfo LinkLabel": tags.labelName,
|
|
1762
|
-
LinkTitle: tags.string,
|
|
1763
|
-
Paragraph: tags.content
|
|
1764
|
-
});
|
|
1765
|
-
const parser = new MarkdownParser(new NodeSet(nodeTypes).extend(markdownHighlighting), Object.keys(DefaultBlockParsers).map((n) => DefaultBlockParsers[n]), Object.keys(DefaultBlockParsers).map((n) => DefaultLeafBlocks[n]), Object.keys(DefaultBlockParsers), DefaultEndLeaf, DefaultSkipMarkup, Object.keys(DefaultInline).map((n) => DefaultInline[n]), Object.keys(DefaultInline), []);
|
|
1766
|
-
function leftOverSpace(node, from, to) {
|
|
1767
|
-
let ranges = [];
|
|
1768
|
-
for (let n = node.firstChild, pos = from; ; n = n.nextSibling) {
|
|
1769
|
-
let nextPos = n ? n.from : to;
|
|
1770
|
-
if (nextPos > pos)
|
|
1771
|
-
ranges.push({ from: pos, to: nextPos });
|
|
1772
|
-
if (!n)
|
|
1773
|
-
break;
|
|
1774
|
-
pos = n.to;
|
|
1775
|
-
}
|
|
1776
|
-
return ranges;
|
|
1777
|
-
}
|
|
1778
|
-
function parseCode(config) {
|
|
1779
|
-
let { codeParser, htmlParser } = config;
|
|
1780
|
-
let wrap = parseMixed((node, input) => {
|
|
1781
|
-
let id = node.type.id;
|
|
1782
|
-
if (codeParser && (id == Type.CodeBlock || id == Type.FencedCode)) {
|
|
1783
|
-
let info = "";
|
|
1784
|
-
if (id == Type.FencedCode) {
|
|
1785
|
-
let infoNode = node.node.getChild(Type.CodeInfo);
|
|
1786
|
-
if (infoNode)
|
|
1787
|
-
info = input.read(infoNode.from, infoNode.to);
|
|
1788
|
-
}
|
|
1789
|
-
let parser2 = codeParser(info);
|
|
1790
|
-
if (parser2)
|
|
1791
|
-
return { parser: parser2, overlay: (node2) => node2.type.id == Type.CodeText, bracketed: id == Type.FencedCode };
|
|
1792
|
-
} else if (htmlParser && (id == Type.HTMLBlock || id == Type.HTMLTag || id == Type.CommentBlock)) {
|
|
1793
|
-
return { parser: htmlParser, overlay: leftOverSpace(node.node, node.from, node.to) };
|
|
1794
|
-
}
|
|
1795
|
-
return null;
|
|
1796
|
-
});
|
|
1797
|
-
return { wrap };
|
|
1798
|
-
}
|
|
1799
|
-
const StrikethroughDelim = { resolve: "Strikethrough", mark: "StrikethroughMark" };
|
|
1800
|
-
const Strikethrough = {
|
|
1801
|
-
defineNodes: [{
|
|
1802
|
-
name: "Strikethrough",
|
|
1803
|
-
style: { "Strikethrough/...": tags.strikethrough }
|
|
1804
|
-
}, {
|
|
1805
|
-
name: "StrikethroughMark",
|
|
1806
|
-
style: tags.processingInstruction
|
|
1807
|
-
}],
|
|
1808
|
-
parseInline: [{
|
|
1809
|
-
name: "Strikethrough",
|
|
1810
|
-
parse(cx, next, pos) {
|
|
1811
|
-
if (next != 126 || cx.char(pos + 1) != 126 || cx.char(pos + 2) == 126)
|
|
1812
|
-
return -1;
|
|
1813
|
-
let before = cx.slice(pos - 1, pos), after = cx.slice(pos + 2, pos + 3);
|
|
1814
|
-
let sBefore = /\s|^$/.test(before), sAfter = /\s|^$/.test(after);
|
|
1815
|
-
let pBefore = Punctuation.test(before), pAfter = Punctuation.test(after);
|
|
1816
|
-
return cx.addDelimiter(StrikethroughDelim, pos, pos + 2, !sAfter && (!pAfter || sBefore || pBefore), !sBefore && (!pBefore || sAfter || pAfter));
|
|
1817
|
-
},
|
|
1818
|
-
after: "Emphasis"
|
|
1819
|
-
}]
|
|
1820
|
-
};
|
|
1821
|
-
function parseRow(cx, line, startI = 0, elts, offset = 0) {
|
|
1822
|
-
let count2 = 0, first = true, cellStart = -1, cellEnd = -1, esc = false;
|
|
1823
|
-
let parseCell = () => {
|
|
1824
|
-
elts.push(cx.elt("TableCell", offset + cellStart, offset + cellEnd, cx.parser.parseInline(line.slice(cellStart, cellEnd), offset + cellStart)));
|
|
1825
|
-
};
|
|
1826
|
-
for (let i = startI; i < line.length; i++) {
|
|
1827
|
-
let next = line.charCodeAt(i);
|
|
1828
|
-
if (next == 124 && !esc) {
|
|
1829
|
-
if (!first || cellStart > -1)
|
|
1830
|
-
count2++;
|
|
1831
|
-
first = false;
|
|
1832
|
-
if (elts) {
|
|
1833
|
-
if (cellStart > -1)
|
|
1834
|
-
parseCell();
|
|
1835
|
-
elts.push(cx.elt("TableDelimiter", i + offset, i + offset + 1));
|
|
1836
|
-
}
|
|
1837
|
-
cellStart = cellEnd = -1;
|
|
1838
|
-
} else if (esc || next != 32 && next != 9) {
|
|
1839
|
-
if (cellStart < 0)
|
|
1840
|
-
cellStart = i;
|
|
1841
|
-
cellEnd = i + 1;
|
|
1842
|
-
}
|
|
1843
|
-
esc = !esc && next == 92;
|
|
1844
|
-
}
|
|
1845
|
-
if (cellStart > -1) {
|
|
1846
|
-
count2++;
|
|
1847
|
-
if (elts)
|
|
1848
|
-
parseCell();
|
|
1849
|
-
}
|
|
1850
|
-
return count2;
|
|
1851
|
-
}
|
|
1852
|
-
function hasPipe(str, start) {
|
|
1853
|
-
for (let i = start; i < str.length; i++) {
|
|
1854
|
-
let next = str.charCodeAt(i);
|
|
1855
|
-
if (next == 124)
|
|
1856
|
-
return true;
|
|
1857
|
-
if (next == 92)
|
|
1858
|
-
i++;
|
|
1859
|
-
}
|
|
1860
|
-
return false;
|
|
1861
|
-
}
|
|
1862
|
-
const delimiterLine = /^\|?(\s*:?-+:?\s*\|)+(\s*:?-+:?\s*)?$/;
|
|
1863
|
-
class TableParser {
|
|
1864
|
-
constructor() {
|
|
1865
|
-
this.rows = null;
|
|
1866
|
-
}
|
|
1867
|
-
nextLine(cx, line, leaf) {
|
|
1868
|
-
if (this.rows == null) {
|
|
1869
|
-
this.rows = false;
|
|
1870
|
-
let lineText;
|
|
1871
|
-
if ((line.next == 45 || line.next == 58 || line.next == 124) && delimiterLine.test(lineText = line.text.slice(line.pos))) {
|
|
1872
|
-
let firstRow = [], firstCount = parseRow(cx, leaf.content, 0, firstRow, leaf.start);
|
|
1873
|
-
if (firstCount == parseRow(cx, lineText, line.pos))
|
|
1874
|
-
this.rows = [
|
|
1875
|
-
cx.elt("TableHeader", leaf.start, leaf.start + leaf.content.length, firstRow),
|
|
1876
|
-
cx.elt("TableDelimiter", cx.lineStart + line.pos, cx.lineStart + line.text.length)
|
|
1877
|
-
];
|
|
1878
|
-
}
|
|
1879
|
-
} else if (this.rows) {
|
|
1880
|
-
let content = [];
|
|
1881
|
-
parseRow(cx, line.text, line.pos, content, cx.lineStart);
|
|
1882
|
-
this.rows.push(cx.elt("TableRow", cx.lineStart + line.pos, cx.lineStart + line.text.length, content));
|
|
1883
|
-
}
|
|
1884
|
-
return false;
|
|
1885
|
-
}
|
|
1886
|
-
finish(cx, leaf) {
|
|
1887
|
-
if (!this.rows)
|
|
1888
|
-
return false;
|
|
1889
|
-
cx.addLeafElement(leaf, cx.elt("Table", leaf.start, leaf.start + leaf.content.length, this.rows));
|
|
1890
|
-
return true;
|
|
1891
|
-
}
|
|
1892
|
-
}
|
|
1893
|
-
const Table = {
|
|
1894
|
-
defineNodes: [
|
|
1895
|
-
{ name: "Table", block: true },
|
|
1896
|
-
{ name: "TableHeader", style: { "TableHeader/...": tags.heading } },
|
|
1897
|
-
"TableRow",
|
|
1898
|
-
{ name: "TableCell", style: tags.content },
|
|
1899
|
-
{ name: "TableDelimiter", style: tags.processingInstruction }
|
|
1900
|
-
],
|
|
1901
|
-
parseBlock: [{
|
|
1902
|
-
name: "Table",
|
|
1903
|
-
leaf(_, leaf) {
|
|
1904
|
-
return hasPipe(leaf.content, 0) ? new TableParser() : null;
|
|
1905
|
-
},
|
|
1906
|
-
endLeaf(cx, line, leaf) {
|
|
1907
|
-
if (leaf.parsers.some((p) => p instanceof TableParser) || !hasPipe(line.text, line.basePos))
|
|
1908
|
-
return false;
|
|
1909
|
-
let next = cx.peekLine();
|
|
1910
|
-
return delimiterLine.test(next) && parseRow(cx, line.text, line.basePos) == parseRow(cx, next, line.basePos);
|
|
1911
|
-
},
|
|
1912
|
-
before: "SetextHeading"
|
|
1913
|
-
}]
|
|
1914
|
-
};
|
|
1915
|
-
class TaskParser {
|
|
1916
|
-
nextLine() {
|
|
1917
|
-
return false;
|
|
1918
|
-
}
|
|
1919
|
-
finish(cx, leaf) {
|
|
1920
|
-
cx.addLeafElement(leaf, cx.elt("Task", leaf.start, leaf.start + leaf.content.length, [
|
|
1921
|
-
cx.elt("TaskMarker", leaf.start, leaf.start + 3),
|
|
1922
|
-
...cx.parser.parseInline(leaf.content.slice(3), leaf.start + 3)
|
|
1923
|
-
]));
|
|
1924
|
-
return true;
|
|
1925
|
-
}
|
|
1926
|
-
}
|
|
1927
|
-
const TaskList = {
|
|
1928
|
-
defineNodes: [
|
|
1929
|
-
{ name: "Task", block: true, style: tags.list },
|
|
1930
|
-
{ name: "TaskMarker", style: tags.atom }
|
|
1931
|
-
],
|
|
1932
|
-
parseBlock: [{
|
|
1933
|
-
name: "TaskList",
|
|
1934
|
-
leaf(cx, leaf) {
|
|
1935
|
-
return /^\[[ xX]\][ \t]/.test(leaf.content) && cx.parentType().name == "ListItem" ? new TaskParser() : null;
|
|
1936
|
-
},
|
|
1937
|
-
after: "SetextHeading"
|
|
1938
|
-
}]
|
|
1939
|
-
};
|
|
1940
|
-
const autolinkRE = /(www\.)|(https?:\/\/)|([\w.+-]{1,100}@)|(mailto:|xmpp:)/gy;
|
|
1941
|
-
const urlRE = /[\w-]+(\.[\w-]+)+(\/[^\s<]*)?/gy;
|
|
1942
|
-
const lastTwoDomainWords = /[\w-]+\.[\w-]+($|\/)/;
|
|
1943
|
-
const emailRE = /[\w.+-]+@[\w-]+(\.[\w.-]+)+/gy;
|
|
1944
|
-
const xmppResourceRE = /\/[a-zA-Z\d@.]+/gy;
|
|
1945
|
-
function count(str, from, to, ch) {
|
|
1946
|
-
let result = 0;
|
|
1947
|
-
for (let i = from; i < to; i++)
|
|
1948
|
-
if (str[i] == ch)
|
|
1949
|
-
result++;
|
|
1950
|
-
return result;
|
|
1951
|
-
}
|
|
1952
|
-
function autolinkURLEnd(text, from) {
|
|
1953
|
-
urlRE.lastIndex = from;
|
|
1954
|
-
let m = urlRE.exec(text);
|
|
1955
|
-
if (!m || lastTwoDomainWords.exec(m[0])[0].indexOf("_") > -1)
|
|
1956
|
-
return -1;
|
|
1957
|
-
let end = from + m[0].length;
|
|
1958
|
-
for (; ; ) {
|
|
1959
|
-
let last = text[end - 1], m2;
|
|
1960
|
-
if (/[?!.,:*_~]/.test(last) || last == ")" && count(text, from, end, ")") > count(text, from, end, "("))
|
|
1961
|
-
end--;
|
|
1962
|
-
else if (last == ";" && (m2 = /&(?:#\d+|#x[a-f\d]+|\w+);$/.exec(text.slice(from, end))))
|
|
1963
|
-
end = from + m2.index;
|
|
1964
|
-
else
|
|
1965
|
-
break;
|
|
1966
|
-
}
|
|
1967
|
-
return end;
|
|
1968
|
-
}
|
|
1969
|
-
function autolinkEmailEnd(text, from) {
|
|
1970
|
-
emailRE.lastIndex = from;
|
|
1971
|
-
let m = emailRE.exec(text);
|
|
1972
|
-
if (!m)
|
|
1973
|
-
return -1;
|
|
1974
|
-
let last = m[0][m[0].length - 1];
|
|
1975
|
-
return last == "_" || last == "-" ? -1 : from + m[0].length - (last == "." ? 1 : 0);
|
|
1976
|
-
}
|
|
1977
|
-
const Autolink = {
|
|
1978
|
-
parseInline: [{
|
|
1979
|
-
name: "Autolink",
|
|
1980
|
-
parse(cx, next, absPos) {
|
|
1981
|
-
let pos = absPos - cx.offset;
|
|
1982
|
-
if (pos && /\w/.test(cx.text[pos - 1]))
|
|
1983
|
-
return -1;
|
|
1984
|
-
autolinkRE.lastIndex = pos;
|
|
1985
|
-
let m = autolinkRE.exec(cx.text), end = -1;
|
|
1986
|
-
if (!m)
|
|
1987
|
-
return -1;
|
|
1988
|
-
if (m[1] || m[2]) {
|
|
1989
|
-
end = autolinkURLEnd(cx.text, pos + m[0].length);
|
|
1990
|
-
if (end > -1 && cx.hasOpenLink) {
|
|
1991
|
-
let noBracket = /([^\[\]]|\[[^\]]*\])*/.exec(cx.text.slice(pos, end));
|
|
1992
|
-
end = pos + noBracket[0].length;
|
|
1993
|
-
}
|
|
1994
|
-
} else if (m[3]) {
|
|
1995
|
-
end = autolinkEmailEnd(cx.text, pos);
|
|
1996
|
-
} else {
|
|
1997
|
-
end = autolinkEmailEnd(cx.text, pos + m[0].length);
|
|
1998
|
-
if (end > -1 && m[0] == "xmpp:") {
|
|
1999
|
-
xmppResourceRE.lastIndex = end;
|
|
2000
|
-
m = xmppResourceRE.exec(cx.text);
|
|
2001
|
-
if (m)
|
|
2002
|
-
end = m.index + m[0].length;
|
|
2003
|
-
}
|
|
2004
|
-
}
|
|
2005
|
-
if (end < 0)
|
|
2006
|
-
return -1;
|
|
2007
|
-
cx.addElement(cx.elt("URL", absPos, end + cx.offset));
|
|
2008
|
-
return end + cx.offset;
|
|
2009
|
-
}
|
|
2010
|
-
}]
|
|
2011
|
-
};
|
|
2012
|
-
const GFM = [Table, TaskList, Strikethrough, Autolink];
|
|
2013
|
-
function parseSubSuper(ch, node, mark) {
|
|
2014
|
-
return (cx, next, pos) => {
|
|
2015
|
-
if (next != ch || cx.char(pos + 1) == ch)
|
|
2016
|
-
return -1;
|
|
2017
|
-
let elts = [cx.elt(mark, pos, pos + 1)];
|
|
2018
|
-
for (let i = pos + 1; i < cx.end; i++) {
|
|
2019
|
-
let next2 = cx.char(i);
|
|
2020
|
-
if (next2 == ch)
|
|
2021
|
-
return cx.addElement(cx.elt(node, pos, i + 1, elts.concat(cx.elt(mark, i, i + 1))));
|
|
2022
|
-
if (next2 == 92)
|
|
2023
|
-
elts.push(cx.elt("Escape", i, i++ + 2));
|
|
2024
|
-
if (space(next2))
|
|
2025
|
-
break;
|
|
2026
|
-
}
|
|
2027
|
-
return -1;
|
|
2028
|
-
};
|
|
2029
|
-
}
|
|
2030
|
-
const Superscript = {
|
|
2031
|
-
defineNodes: [
|
|
2032
|
-
{ name: "Superscript", style: tags.special(tags.content) },
|
|
2033
|
-
{ name: "SuperscriptMark", style: tags.processingInstruction }
|
|
2034
|
-
],
|
|
2035
|
-
parseInline: [{
|
|
2036
|
-
name: "Superscript",
|
|
2037
|
-
parse: parseSubSuper(94, "Superscript", "SuperscriptMark")
|
|
2038
|
-
}]
|
|
2039
|
-
};
|
|
2040
|
-
const Subscript = {
|
|
2041
|
-
defineNodes: [
|
|
2042
|
-
{ name: "Subscript", style: tags.special(tags.content) },
|
|
2043
|
-
{ name: "SubscriptMark", style: tags.processingInstruction }
|
|
2044
|
-
],
|
|
2045
|
-
parseInline: [{
|
|
2046
|
-
name: "Subscript",
|
|
2047
|
-
parse: parseSubSuper(126, "Subscript", "SubscriptMark")
|
|
2048
|
-
}]
|
|
2049
|
-
};
|
|
2050
|
-
const Emoji = {
|
|
2051
|
-
defineNodes: [{ name: "Emoji", style: tags.character }],
|
|
2052
|
-
parseInline: [{
|
|
2053
|
-
name: "Emoji",
|
|
2054
|
-
parse(cx, next, pos) {
|
|
2055
|
-
let match;
|
|
2056
|
-
if (next != 58 || !(match = /^[a-zA-Z_0-9]+:/.exec(cx.slice(pos + 1, cx.end))))
|
|
2057
|
-
return -1;
|
|
2058
|
-
return cx.addElement(cx.elt("Emoji", pos, pos + 1 + match[0].length));
|
|
2059
|
-
}
|
|
2060
|
-
}]
|
|
2061
|
-
};
|
|
2062
|
-
const data = /* @__PURE__ */ defineLanguageFacet({ commentTokens: { block: { open: "<!--", close: "-->" } } });
|
|
2063
|
-
const headingProp = /* @__PURE__ */ new NodeProp();
|
|
2064
|
-
const commonmark = /* @__PURE__ */ parser.configure({
|
|
2065
|
-
props: [
|
|
2066
|
-
/* @__PURE__ */ foldNodeProp.add((type) => {
|
|
2067
|
-
return !type.is("Block") || type.is("Document") || isHeading(type) != null || isList(type) ? void 0 : (tree, state) => ({ from: state.doc.lineAt(tree.from).to, to: tree.to });
|
|
2068
|
-
}),
|
|
2069
|
-
/* @__PURE__ */ headingProp.add(isHeading),
|
|
2070
|
-
/* @__PURE__ */ indentNodeProp.add({
|
|
2071
|
-
Document: () => null
|
|
2072
|
-
}),
|
|
2073
|
-
/* @__PURE__ */ languageDataProp.add({
|
|
2074
|
-
Document: data
|
|
2075
|
-
})
|
|
2076
|
-
]
|
|
2077
|
-
});
|
|
2078
|
-
function isHeading(type) {
|
|
2079
|
-
let match = /^(?:ATX|Setext)Heading(\d)$/.exec(type.name);
|
|
2080
|
-
return match ? +match[1] : void 0;
|
|
2081
|
-
}
|
|
2082
|
-
function isList(type) {
|
|
2083
|
-
return type.name == "OrderedList" || type.name == "BulletList";
|
|
2084
|
-
}
|
|
2085
|
-
function findSectionEnd(headerNode, level) {
|
|
2086
|
-
let last = headerNode;
|
|
2087
|
-
for (; ; ) {
|
|
2088
|
-
let next = last.nextSibling, heading;
|
|
2089
|
-
if (!next || (heading = isHeading(next.type)) != null && heading <= level)
|
|
2090
|
-
break;
|
|
2091
|
-
last = next;
|
|
2092
|
-
}
|
|
2093
|
-
return last.to;
|
|
2094
|
-
}
|
|
2095
|
-
const headerIndent = /* @__PURE__ */ foldService.of((state, start, end) => {
|
|
2096
|
-
for (let node = syntaxTree(state).resolveInner(end, -1); node; node = node.parent) {
|
|
2097
|
-
if (node.from < start)
|
|
2098
|
-
break;
|
|
2099
|
-
let heading = node.type.prop(headingProp);
|
|
2100
|
-
if (heading == null)
|
|
2101
|
-
continue;
|
|
2102
|
-
let upto = findSectionEnd(node, heading);
|
|
2103
|
-
if (upto > end)
|
|
2104
|
-
return { from: end, to: upto };
|
|
2105
|
-
}
|
|
2106
|
-
return null;
|
|
2107
|
-
});
|
|
2108
|
-
function mkLang(parser2) {
|
|
2109
|
-
return new Language(data, parser2, [], "markdown");
|
|
2110
|
-
}
|
|
2111
|
-
const commonmarkLanguage = /* @__PURE__ */ mkLang(commonmark);
|
|
2112
|
-
const extended = /* @__PURE__ */ commonmark.configure([GFM, Subscript, Superscript, Emoji, {
|
|
2113
|
-
props: [
|
|
2114
|
-
/* @__PURE__ */ foldNodeProp.add({
|
|
2115
|
-
Table: (tree, state) => ({ from: state.doc.lineAt(tree.from).to, to: tree.to })
|
|
2116
|
-
})
|
|
2117
|
-
]
|
|
2118
|
-
}]);
|
|
2119
|
-
const markdownLanguage = /* @__PURE__ */ mkLang(extended);
|
|
2120
|
-
function getCodeParser(languages, defaultLanguage) {
|
|
2121
|
-
return (info) => {
|
|
2122
|
-
if (info && languages) {
|
|
2123
|
-
let found = null;
|
|
2124
|
-
info = /\S*/.exec(info)[0];
|
|
2125
|
-
if (typeof languages == "function")
|
|
2126
|
-
found = languages(info);
|
|
2127
|
-
else
|
|
2128
|
-
found = LanguageDescription.matchLanguageName(languages, info, true);
|
|
2129
|
-
if (found instanceof LanguageDescription)
|
|
2130
|
-
return found.support ? found.support.language.parser : ParseContext.getSkippingParser(found.load());
|
|
2131
|
-
else if (found)
|
|
2132
|
-
return found.parser;
|
|
2133
|
-
}
|
|
2134
|
-
return defaultLanguage ? defaultLanguage.parser : null;
|
|
2135
|
-
};
|
|
2136
|
-
}
|
|
2137
|
-
class Context {
|
|
2138
|
-
constructor(node, from, to, spaceBefore, spaceAfter, type, item) {
|
|
2139
|
-
this.node = node;
|
|
2140
|
-
this.from = from;
|
|
2141
|
-
this.to = to;
|
|
2142
|
-
this.spaceBefore = spaceBefore;
|
|
2143
|
-
this.spaceAfter = spaceAfter;
|
|
2144
|
-
this.type = type;
|
|
2145
|
-
this.item = item;
|
|
2146
|
-
}
|
|
2147
|
-
blank(maxWidth, trailing = true) {
|
|
2148
|
-
let result = this.spaceBefore + (this.node.name == "Blockquote" ? ">" : "");
|
|
2149
|
-
if (maxWidth != null) {
|
|
2150
|
-
while (result.length < maxWidth)
|
|
2151
|
-
result += " ";
|
|
2152
|
-
return result;
|
|
2153
|
-
} else {
|
|
2154
|
-
for (let i = this.to - this.from - result.length - this.spaceAfter.length; i > 0; i--)
|
|
2155
|
-
result += " ";
|
|
2156
|
-
return result + (trailing ? this.spaceAfter : "");
|
|
2157
|
-
}
|
|
2158
|
-
}
|
|
2159
|
-
marker(doc, add) {
|
|
2160
|
-
let number = this.node.name == "OrderedList" ? String(+itemNumber(this.item, doc)[2] + add) : "";
|
|
2161
|
-
return this.spaceBefore + number + this.type + this.spaceAfter;
|
|
2162
|
-
}
|
|
2163
|
-
}
|
|
2164
|
-
function getContext(node, doc) {
|
|
2165
|
-
let nodes = [], context = [];
|
|
2166
|
-
for (let cur = node; cur; cur = cur.parent) {
|
|
2167
|
-
if (cur.name == "FencedCode")
|
|
2168
|
-
return context;
|
|
2169
|
-
if (cur.name == "ListItem" || cur.name == "Blockquote")
|
|
2170
|
-
nodes.push(cur);
|
|
2171
|
-
}
|
|
2172
|
-
for (let i = nodes.length - 1; i >= 0; i--) {
|
|
2173
|
-
let node2 = nodes[i], match;
|
|
2174
|
-
let line = doc.lineAt(node2.from), startPos = node2.from - line.from;
|
|
2175
|
-
if (node2.name == "Blockquote" && (match = /^ *>( ?)/.exec(line.text.slice(startPos)))) {
|
|
2176
|
-
context.push(new Context(node2, startPos, startPos + match[0].length, "", match[1], ">", null));
|
|
2177
|
-
} else if (node2.name == "ListItem" && node2.parent.name == "OrderedList" && (match = /^( *)\d+([.)])( *)/.exec(line.text.slice(startPos)))) {
|
|
2178
|
-
let after = match[3], len = match[0].length;
|
|
2179
|
-
if (after.length >= 4) {
|
|
2180
|
-
after = after.slice(0, after.length - 4);
|
|
2181
|
-
len -= 4;
|
|
2182
|
-
}
|
|
2183
|
-
context.push(new Context(node2.parent, startPos, startPos + len, match[1], after, match[2], node2));
|
|
2184
|
-
} else if (node2.name == "ListItem" && node2.parent.name == "BulletList" && (match = /^( *)([-+*])( {1,4}\[[ xX]\])?( +)/.exec(line.text.slice(startPos)))) {
|
|
2185
|
-
let after = match[4], len = match[0].length;
|
|
2186
|
-
if (after.length > 4) {
|
|
2187
|
-
after = after.slice(0, after.length - 4);
|
|
2188
|
-
len -= 4;
|
|
2189
|
-
}
|
|
2190
|
-
let type = match[2];
|
|
2191
|
-
if (match[3])
|
|
2192
|
-
type += match[3].replace(/[xX]/, " ");
|
|
2193
|
-
context.push(new Context(node2.parent, startPos, startPos + len, match[1], after, type, node2));
|
|
2194
|
-
}
|
|
2195
|
-
}
|
|
2196
|
-
return context;
|
|
2197
|
-
}
|
|
2198
|
-
function itemNumber(item, doc) {
|
|
2199
|
-
return /^(\s*)(\d+)(?=[.)])/.exec(doc.sliceString(item.from, item.from + 10));
|
|
2200
|
-
}
|
|
2201
|
-
function renumberList(after, doc, changes, offset = 0) {
|
|
2202
|
-
for (let prev = -1, node = after; ; ) {
|
|
2203
|
-
if (node.name == "ListItem") {
|
|
2204
|
-
let m = itemNumber(node, doc);
|
|
2205
|
-
let number = +m[2];
|
|
2206
|
-
if (prev >= 0) {
|
|
2207
|
-
if (number != prev + 1)
|
|
2208
|
-
return;
|
|
2209
|
-
changes.push({ from: node.from + m[1].length, to: node.from + m[0].length, insert: String(prev + 2 + offset) });
|
|
2210
|
-
}
|
|
2211
|
-
prev = number;
|
|
2212
|
-
}
|
|
2213
|
-
let next = node.nextSibling;
|
|
2214
|
-
if (!next)
|
|
2215
|
-
break;
|
|
2216
|
-
node = next;
|
|
2217
|
-
}
|
|
2218
|
-
}
|
|
2219
|
-
function normalizeIndent(content, state) {
|
|
2220
|
-
let blank = /^[ \t]*/.exec(content)[0].length;
|
|
2221
|
-
if (!blank || state.facet(indentUnit) != " ")
|
|
2222
|
-
return content;
|
|
2223
|
-
let col = countColumn(content, 4, blank);
|
|
2224
|
-
let space2 = "";
|
|
2225
|
-
for (let i = col; i > 0; ) {
|
|
2226
|
-
if (i >= 4) {
|
|
2227
|
-
space2 += " ";
|
|
2228
|
-
i -= 4;
|
|
2229
|
-
} else {
|
|
2230
|
-
space2 += " ";
|
|
2231
|
-
i--;
|
|
2232
|
-
}
|
|
2233
|
-
}
|
|
2234
|
-
return space2 + content.slice(blank);
|
|
2235
|
-
}
|
|
2236
|
-
const insertNewlineContinueMarkupCommand = (config = {}) => ({ state, dispatch }) => {
|
|
2237
|
-
let tree = syntaxTree(state), { doc } = state;
|
|
2238
|
-
let dont = null, changes = state.changeByRange((range) => {
|
|
2239
|
-
if (!range.empty || !markdownLanguage.isActiveAt(state, range.from, -1) && !markdownLanguage.isActiveAt(state, range.from, 1))
|
|
2240
|
-
return dont = { range };
|
|
2241
|
-
let pos = range.from, line = doc.lineAt(pos);
|
|
2242
|
-
let context = getContext(tree.resolveInner(pos, -1), doc);
|
|
2243
|
-
while (context.length && context[context.length - 1].from > pos - line.from)
|
|
2244
|
-
context.pop();
|
|
2245
|
-
if (!context.length)
|
|
2246
|
-
return dont = { range };
|
|
2247
|
-
let inner = context[context.length - 1];
|
|
2248
|
-
if (inner.to - inner.spaceAfter.length > pos - line.from)
|
|
2249
|
-
return dont = { range };
|
|
2250
|
-
let emptyLine = pos >= inner.to - inner.spaceAfter.length && !/\S/.test(line.text.slice(inner.to));
|
|
2251
|
-
if (inner.item && emptyLine) {
|
|
2252
|
-
let first = inner.node.firstChild, second = inner.node.getChild("ListItem", "ListItem");
|
|
2253
|
-
if (first.to >= pos || second && second.to < pos || line.from > 0 && !/[^\s>]/.test(doc.lineAt(line.from - 1).text) || config.nonTightLists === false) {
|
|
2254
|
-
let next = context.length > 1 ? context[context.length - 2] : null;
|
|
2255
|
-
let delTo, insert2 = "";
|
|
2256
|
-
if (next && next.item) {
|
|
2257
|
-
delTo = line.from + next.from;
|
|
2258
|
-
insert2 = next.marker(doc, 1);
|
|
2259
|
-
} else {
|
|
2260
|
-
delTo = line.from + (next ? next.to : 0);
|
|
2261
|
-
}
|
|
2262
|
-
let changes3 = [{ from: delTo, to: pos, insert: insert2 }];
|
|
2263
|
-
if (inner.node.name == "OrderedList")
|
|
2264
|
-
renumberList(inner.item, doc, changes3, -2);
|
|
2265
|
-
if (next && next.node.name == "OrderedList")
|
|
2266
|
-
renumberList(next.item, doc, changes3);
|
|
2267
|
-
return { range: EditorSelection.cursor(delTo + insert2.length), changes: changes3 };
|
|
2268
|
-
} else {
|
|
2269
|
-
let insert2 = blankLine(context, state, line);
|
|
2270
|
-
return {
|
|
2271
|
-
range: EditorSelection.cursor(pos + insert2.length + 1),
|
|
2272
|
-
changes: { from: line.from, insert: insert2 + state.lineBreak }
|
|
2273
|
-
};
|
|
2274
|
-
}
|
|
2275
|
-
}
|
|
2276
|
-
if (inner.node.name == "Blockquote" && emptyLine && line.from) {
|
|
2277
|
-
let prevLine = doc.lineAt(line.from - 1), quoted = />\s*$/.exec(prevLine.text);
|
|
2278
|
-
if (quoted && quoted.index == inner.from) {
|
|
2279
|
-
let changes3 = state.changes([
|
|
2280
|
-
{ from: prevLine.from + quoted.index, to: prevLine.to },
|
|
2281
|
-
{ from: line.from + inner.from, to: line.to }
|
|
2282
|
-
]);
|
|
2283
|
-
return { range: range.map(changes3), changes: changes3 };
|
|
2284
|
-
}
|
|
2285
|
-
}
|
|
2286
|
-
let changes2 = [];
|
|
2287
|
-
if (inner.node.name == "OrderedList")
|
|
2288
|
-
renumberList(inner.item, doc, changes2);
|
|
2289
|
-
let continued = inner.item && inner.item.from < line.from;
|
|
2290
|
-
let insert = "";
|
|
2291
|
-
if (!continued || /^[\s\d.)\-+*>]*/.exec(line.text)[0].length >= inner.to) {
|
|
2292
|
-
for (let i = 0, e = context.length - 1; i <= e; i++) {
|
|
2293
|
-
insert += i == e && !continued ? context[i].marker(doc, 1) : context[i].blank(i < e ? countColumn(line.text, 4, context[i + 1].from) - insert.length : null);
|
|
2294
|
-
}
|
|
2295
|
-
}
|
|
2296
|
-
let from = pos;
|
|
2297
|
-
while (from > line.from && /\s/.test(line.text.charAt(from - line.from - 1)))
|
|
2298
|
-
from--;
|
|
2299
|
-
insert = normalizeIndent(insert, state);
|
|
2300
|
-
if (nonTightList(inner.node, state.doc))
|
|
2301
|
-
insert = blankLine(context, state, line) + state.lineBreak + insert;
|
|
2302
|
-
changes2.push({ from, to: pos, insert: state.lineBreak + insert });
|
|
2303
|
-
return { range: EditorSelection.cursor(from + insert.length + 1), changes: changes2 };
|
|
2304
|
-
});
|
|
2305
|
-
if (dont)
|
|
2306
|
-
return false;
|
|
2307
|
-
dispatch(state.update(changes, { scrollIntoView: true, userEvent: "input" }));
|
|
2308
|
-
return true;
|
|
2309
|
-
};
|
|
2310
|
-
const insertNewlineContinueMarkup = /* @__PURE__ */ insertNewlineContinueMarkupCommand();
|
|
2311
|
-
function isMark(node) {
|
|
2312
|
-
return node.name == "QuoteMark" || node.name == "ListMark";
|
|
2313
|
-
}
|
|
2314
|
-
function nonTightList(node, doc) {
|
|
2315
|
-
if (node.name != "OrderedList" && node.name != "BulletList")
|
|
2316
|
-
return false;
|
|
2317
|
-
let first = node.firstChild, second = node.getChild("ListItem", "ListItem");
|
|
2318
|
-
if (!second)
|
|
2319
|
-
return false;
|
|
2320
|
-
let line1 = doc.lineAt(first.to), line2 = doc.lineAt(second.from);
|
|
2321
|
-
let empty = /^[\s>]*$/.test(line1.text);
|
|
2322
|
-
return line1.number + (empty ? 0 : 1) < line2.number;
|
|
2323
|
-
}
|
|
2324
|
-
function blankLine(context, state, line) {
|
|
2325
|
-
let insert = "";
|
|
2326
|
-
for (let i = 0, e = context.length - 2; i <= e; i++) {
|
|
2327
|
-
insert += context[i].blank(i < e ? countColumn(line.text, 4, context[i + 1].from) - insert.length : null, i < e);
|
|
2328
|
-
}
|
|
2329
|
-
return normalizeIndent(insert, state);
|
|
2330
|
-
}
|
|
2331
|
-
function contextNodeForDelete(tree, pos) {
|
|
2332
|
-
let node = tree.resolveInner(pos, -1), scan = pos;
|
|
2333
|
-
if (isMark(node)) {
|
|
2334
|
-
scan = node.from;
|
|
2335
|
-
node = node.parent;
|
|
2336
|
-
}
|
|
2337
|
-
for (let prev; prev = node.childBefore(scan); ) {
|
|
2338
|
-
if (isMark(prev)) {
|
|
2339
|
-
scan = prev.from;
|
|
2340
|
-
} else if (prev.name == "OrderedList" || prev.name == "BulletList") {
|
|
2341
|
-
node = prev.lastChild;
|
|
2342
|
-
scan = node.to;
|
|
2343
|
-
} else {
|
|
2344
|
-
break;
|
|
2345
|
-
}
|
|
2346
|
-
}
|
|
2347
|
-
return node;
|
|
2348
|
-
}
|
|
2349
|
-
const deleteMarkupBackward = ({ state, dispatch }) => {
|
|
2350
|
-
let tree = syntaxTree(state);
|
|
2351
|
-
let dont = null, changes = state.changeByRange((range) => {
|
|
2352
|
-
let pos = range.from, { doc } = state;
|
|
2353
|
-
if (range.empty && markdownLanguage.isActiveAt(state, range.from)) {
|
|
2354
|
-
let line = doc.lineAt(pos);
|
|
2355
|
-
let context = getContext(contextNodeForDelete(tree, pos), doc);
|
|
2356
|
-
if (context.length) {
|
|
2357
|
-
let inner = context[context.length - 1];
|
|
2358
|
-
let spaceEnd = inner.to - inner.spaceAfter.length + (inner.spaceAfter ? 1 : 0);
|
|
2359
|
-
if (pos - line.from > spaceEnd && !/\S/.test(line.text.slice(spaceEnd, pos - line.from)))
|
|
2360
|
-
return {
|
|
2361
|
-
range: EditorSelection.cursor(line.from + spaceEnd),
|
|
2362
|
-
changes: { from: line.from + spaceEnd, to: pos }
|
|
2363
|
-
};
|
|
2364
|
-
if (pos - line.from == spaceEnd && // Only apply this if we're on the line that has the
|
|
2365
|
-
// construct's syntax, or there's only indentation in the
|
|
2366
|
-
// target range
|
|
2367
|
-
(!inner.item || line.from <= inner.item.from || !/\S/.test(line.text.slice(0, inner.to)))) {
|
|
2368
|
-
let start = line.from + inner.from;
|
|
2369
|
-
if (inner.item && inner.node.from < inner.item.from && /\S/.test(line.text.slice(inner.from, inner.to))) {
|
|
2370
|
-
let insert = inner.blank(countColumn(line.text, 4, inner.to) - countColumn(line.text, 4, inner.from));
|
|
2371
|
-
if (start == line.from)
|
|
2372
|
-
insert = normalizeIndent(insert, state);
|
|
2373
|
-
return {
|
|
2374
|
-
range: EditorSelection.cursor(start + insert.length),
|
|
2375
|
-
changes: { from: start, to: line.from + inner.to, insert }
|
|
2376
|
-
};
|
|
2377
|
-
}
|
|
2378
|
-
if (start < pos)
|
|
2379
|
-
return { range: EditorSelection.cursor(start), changes: { from: start, to: pos } };
|
|
2380
|
-
}
|
|
2381
|
-
}
|
|
2382
|
-
}
|
|
2383
|
-
return dont = { range };
|
|
2384
|
-
});
|
|
2385
|
-
if (dont)
|
|
2386
|
-
return false;
|
|
2387
|
-
dispatch(state.update(changes, { scrollIntoView: true, userEvent: "delete" }));
|
|
2388
|
-
return true;
|
|
2389
|
-
};
|
|
2390
|
-
const markdownKeymap = [
|
|
2391
|
-
{ key: "Enter", run: insertNewlineContinueMarkup },
|
|
2392
|
-
{ key: "Backspace", run: deleteMarkupBackward }
|
|
2393
|
-
];
|
|
2394
|
-
const htmlNoMatch = /* @__PURE__ */ html({ matchClosingTags: false });
|
|
2395
|
-
function markdown(config = {}) {
|
|
2396
|
-
let { codeLanguages, defaultCodeLanguage, addKeymap = true, base: { parser: parser2 } = commonmarkLanguage, completeHTMLTags = true, pasteURLAsLink: pasteURL = true, htmlTagLanguage = htmlNoMatch } = config;
|
|
2397
|
-
if (!(parser2 instanceof MarkdownParser))
|
|
2398
|
-
throw new RangeError("Base parser provided to `markdown` should be a Markdown parser");
|
|
2399
|
-
let extensions = config.extensions ? [config.extensions] : [];
|
|
2400
|
-
let support = [htmlTagLanguage.support, headerIndent], defaultCode;
|
|
2401
|
-
if (pasteURL)
|
|
2402
|
-
support.push(pasteURLAsLink);
|
|
2403
|
-
if (defaultCodeLanguage instanceof LanguageSupport) {
|
|
2404
|
-
support.push(defaultCodeLanguage.support);
|
|
2405
|
-
defaultCode = defaultCodeLanguage.language;
|
|
2406
|
-
} else if (defaultCodeLanguage) {
|
|
2407
|
-
defaultCode = defaultCodeLanguage;
|
|
2408
|
-
}
|
|
2409
|
-
let codeParser = codeLanguages || defaultCode ? getCodeParser(codeLanguages, defaultCode) : void 0;
|
|
2410
|
-
extensions.push(parseCode({ codeParser, htmlParser: htmlTagLanguage.language.parser }));
|
|
2411
|
-
if (addKeymap)
|
|
2412
|
-
support.push(Prec.high(keymap.of(markdownKeymap)));
|
|
2413
|
-
let lang = mkLang(parser2.configure(extensions));
|
|
2414
|
-
if (completeHTMLTags)
|
|
2415
|
-
support.push(lang.data.of({ autocomplete: htmlTagCompletion }));
|
|
2416
|
-
return new LanguageSupport(lang, support);
|
|
2417
|
-
}
|
|
2418
|
-
function htmlTagCompletion(context) {
|
|
2419
|
-
let { state, pos } = context, m = /<[:\-\.\w\u00b7-\uffff]*$/.exec(state.sliceDoc(pos - 25, pos));
|
|
2420
|
-
if (!m)
|
|
2421
|
-
return null;
|
|
2422
|
-
let tree = syntaxTree(state).resolveInner(pos, -1);
|
|
2423
|
-
while (tree && !tree.type.isTop) {
|
|
2424
|
-
if (tree.name == "CodeBlock" || tree.name == "FencedCode" || tree.name == "ProcessingInstructionBlock" || tree.name == "CommentBlock" || tree.name == "Link" || tree.name == "Image")
|
|
2425
|
-
return null;
|
|
2426
|
-
tree = tree.parent;
|
|
2427
|
-
}
|
|
2428
|
-
return {
|
|
2429
|
-
from: pos - m[0].length,
|
|
2430
|
-
to: pos,
|
|
2431
|
-
options: htmlTagCompletions(),
|
|
2432
|
-
validFor: /^<[:\-\.\w\u00b7-\uffff]*$/
|
|
2433
|
-
};
|
|
2434
|
-
}
|
|
2435
|
-
let _tagCompletions = null;
|
|
2436
|
-
function htmlTagCompletions() {
|
|
2437
|
-
if (_tagCompletions)
|
|
2438
|
-
return _tagCompletions;
|
|
2439
|
-
let result = htmlCompletionSource(new CompletionContext(EditorState.create({ extensions: htmlNoMatch }), 0, true));
|
|
2440
|
-
return _tagCompletions = result ? result.options : [];
|
|
2441
|
-
}
|
|
2442
|
-
const nonPlainText = /code|horizontalrule|html|link|comment|processing|escape|entity|image|mark|url/i;
|
|
2443
|
-
const pasteURLAsLink = /* @__PURE__ */ EditorView.domEventHandlers({
|
|
2444
|
-
paste: (event, view) => {
|
|
2445
|
-
var _a;
|
|
2446
|
-
let { main } = view.state.selection;
|
|
2447
|
-
if (main.empty)
|
|
2448
|
-
return false;
|
|
2449
|
-
let link = (_a = event.clipboardData) === null || _a === void 0 ? void 0 : _a.getData("text/plain");
|
|
2450
|
-
if (!link || !/^(https?:\/\/|mailto:|xmpp:|www\.)/.test(link))
|
|
2451
|
-
return false;
|
|
2452
|
-
if (/^www\./.test(link))
|
|
2453
|
-
link = "https://" + link;
|
|
2454
|
-
if (!markdownLanguage.isActiveAt(view.state, main.from, 1))
|
|
2455
|
-
return false;
|
|
2456
|
-
let tree = syntaxTree(view.state), crossesNode = false;
|
|
2457
|
-
tree.iterate({
|
|
2458
|
-
from: main.from,
|
|
2459
|
-
to: main.to,
|
|
2460
|
-
enter: (node) => {
|
|
2461
|
-
if (node.from > main.from || nonPlainText.test(node.name))
|
|
2462
|
-
crossesNode = true;
|
|
2463
|
-
},
|
|
2464
|
-
leave: (node) => {
|
|
2465
|
-
if (node.to < main.to)
|
|
2466
|
-
crossesNode = true;
|
|
2467
|
-
}
|
|
2468
|
-
});
|
|
2469
|
-
if (crossesNode)
|
|
2470
|
-
return false;
|
|
2471
|
-
view.dispatch({
|
|
2472
|
-
changes: [{ from: main.from, insert: "[" }, { from: main.to, insert: `](${link})` }],
|
|
2473
|
-
userEvent: "input.paste",
|
|
2474
|
-
scrollIntoView: true
|
|
2475
|
-
});
|
|
2476
|
-
return true;
|
|
2477
|
-
}
|
|
2478
|
-
});
|
|
2479
|
-
export {
|
|
2480
|
-
commonmarkLanguage,
|
|
2481
|
-
deleteMarkupBackward,
|
|
2482
|
-
insertNewlineContinueMarkup,
|
|
2483
|
-
insertNewlineContinueMarkupCommand,
|
|
2484
|
-
markdown,
|
|
2485
|
-
markdownKeymap,
|
|
2486
|
-
markdownLanguage,
|
|
2487
|
-
pasteURLAsLink
|
|
2488
|
-
};
|