@milkdown/crepe 7.5.1 → 7.5.3
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/lib/cjs/{index-udZSknd8.js → index-TGmNEvsj.js} +7 -7
- package/lib/cjs/index-TGmNEvsj.js.map +1 -0
- package/lib/cjs/index-fhKBUFkq.js +46 -0
- package/lib/cjs/index-fhKBUFkq.js.map +1 -0
- package/lib/cjs/{index-tqAbVyds.js → index-rLAgJeYn.js} +4 -4
- package/lib/cjs/index-rLAgJeYn.js.map +1 -0
- package/lib/cjs/index.js +3 -3
- package/lib/cjs/index.js.map +1 -1
- package/lib/esm/{index-v3rvbocl.js → index-amuALmzU.js} +2 -2
- package/lib/esm/{index-v3rvbocl.js.map → index-amuALmzU.js.map} +1 -1
- package/lib/esm/index-jU_6odT9.js +44 -0
- package/lib/esm/index-jU_6odT9.js.map +1 -0
- package/lib/esm/{index-lm00PM0y.js → index-w69wbtEZ.js} +2 -2
- package/lib/esm/{index-lm00PM0y.js.map → index-w69wbtEZ.js.map} +1 -1
- package/lib/esm/index.js +3 -3
- package/lib/esm/index.js.map +1 -1
- package/package.json +3 -5
- package/lib/cjs/apl-99bWvYTf.js +0 -145
- package/lib/cjs/apl-99bWvYTf.js.map +0 -1
- package/lib/cjs/asciiarmor-cf0JLIr_.js +0 -59
- package/lib/cjs/asciiarmor-cf0JLIr_.js.map +0 -1
- package/lib/cjs/asn1-H4XzAvBS.js +0 -195
- package/lib/cjs/asn1-H4XzAvBS.js.map +0 -1
- package/lib/cjs/asterisk-0FgJEfZB.js +0 -190
- package/lib/cjs/asterisk-0FgJEfZB.js.map +0 -1
- package/lib/cjs/brainfuck-JX7vRZy7.js +0 -73
- package/lib/cjs/brainfuck-JX7vRZy7.js.map +0 -1
- package/lib/cjs/clike-ueXlMQy5.js +0 -1034
- package/lib/cjs/clike-ueXlMQy5.js.map +0 -1
- package/lib/cjs/clojure-6iDAG5oi.js +0 -277
- package/lib/cjs/clojure-6iDAG5oi.js.map +0 -1
- package/lib/cjs/clsx-dASsG01A.js +0 -6
- package/lib/cjs/clsx-dASsG01A.js.map +0 -1
- package/lib/cjs/cmake-L0RIBnfc.js +0 -84
- package/lib/cjs/cmake-L0RIBnfc.js.map +0 -1
- package/lib/cjs/cobol-oxkMh1GJ.js +0 -238
- package/lib/cjs/cobol-oxkMh1GJ.js.map +0 -1
- package/lib/cjs/coffeescript--eauIeRQ.js +0 -332
- package/lib/cjs/coffeescript--eauIeRQ.js.map +0 -1
- package/lib/cjs/commonlisp-pgSu-q6f.js +0 -111
- package/lib/cjs/commonlisp-pgSu-q6f.js.map +0 -1
- package/lib/cjs/crystal-2y3I5ibZ.js +0 -422
- package/lib/cjs/crystal-2y3I5ibZ.js.map +0 -1
- package/lib/cjs/css-WH69cXzo.js +0 -855
- package/lib/cjs/css-WH69cXzo.js.map +0 -1
- package/lib/cjs/cypher-da-dqVyQ.js +0 -125
- package/lib/cjs/cypher-da-dqVyQ.js.map +0 -1
- package/lib/cjs/d-58J7EOkP.js +0 -208
- package/lib/cjs/d-58J7EOkP.js.map +0 -1
- package/lib/cjs/diff-437Hfzqm.js +0 -33
- package/lib/cjs/diff-437Hfzqm.js.map +0 -1
- package/lib/cjs/dockerfile-7i0OoaQe.js +0 -202
- package/lib/cjs/dockerfile-7i0OoaQe.js.map +0 -1
- package/lib/cjs/dtd-AKekCPPB.js +0 -124
- package/lib/cjs/dtd-AKekCPPB.js.map +0 -1
- package/lib/cjs/dylan-DLEmvz1I.js +0 -340
- package/lib/cjs/dylan-DLEmvz1I.js.map +0 -1
- package/lib/cjs/ebnf-36cJWqxB.js +0 -154
- package/lib/cjs/ebnf-36cJWqxB.js.map +0 -1
- package/lib/cjs/ecl-UWr5vJKJ.js +0 -193
- package/lib/cjs/ecl-UWr5vJKJ.js.map +0 -1
- package/lib/cjs/eiffel-Su-C9LAY.js +0 -149
- package/lib/cjs/eiffel-Su-C9LAY.js.map +0 -1
- package/lib/cjs/elm-vNNfVJj7.js +0 -233
- package/lib/cjs/elm-vNNfVJj7.js.map +0 -1
- package/lib/cjs/erlang-NM9dgYaS.js +0 -584
- package/lib/cjs/erlang-NM9dgYaS.js.map +0 -1
- package/lib/cjs/factor-RWs-4aWg.js +0 -68
- package/lib/cjs/factor-RWs-4aWg.js.map +0 -1
- package/lib/cjs/fcl-acUhGCfs.js +0 -157
- package/lib/cjs/fcl-acUhGCfs.js.map +0 -1
- package/lib/cjs/forth-sDkE6z3A.js +0 -167
- package/lib/cjs/forth-sDkE6z3A.js.map +0 -1
- package/lib/cjs/fortran-gkb4yvdk.js +0 -175
- package/lib/cjs/fortran-gkb4yvdk.js.map +0 -1
- package/lib/cjs/gas-mNA0qvkv.js +0 -347
- package/lib/cjs/gas-mNA0qvkv.js.map +0 -1
- package/lib/cjs/gherkin-5uyKpXXh.js +0 -150
- package/lib/cjs/gherkin-5uyKpXXh.js.map +0 -1
- package/lib/cjs/go-5XitXoIZ.js +0 -167
- package/lib/cjs/go-5XitXoIZ.js.map +0 -1
- package/lib/cjs/groovy-mz3pWMKN.js +0 -233
- package/lib/cjs/groovy-mz3pWMKN.js.map +0 -1
- package/lib/cjs/haskell-9KaSS7kb.js +0 -242
- package/lib/cjs/haskell-9KaSS7kb.js.map +0 -1
- package/lib/cjs/haxe-L8h6Pvni.js +0 -494
- package/lib/cjs/haxe-L8h6Pvni.js.map +0 -1
- package/lib/cjs/http-BFQQnRR-.js +0 -92
- package/lib/cjs/http-BFQQnRR-.js.map +0 -1
- package/lib/cjs/idl-29T-AzAy.js +0 -277
- package/lib/cjs/idl-29T-AzAy.js.map +0 -1
- package/lib/cjs/index--2zEz40J.js +0 -93
- package/lib/cjs/index--2zEz40J.js.map +0 -1
- package/lib/cjs/index-5n9R-QCl.js +0 -390
- package/lib/cjs/index-5n9R-QCl.js.map +0 -1
- package/lib/cjs/index-HEdBw63r.js +0 -428
- package/lib/cjs/index-HEdBw63r.js.map +0 -1
- package/lib/cjs/index-Hlt9dRH5.js +0 -113
- package/lib/cjs/index-Hlt9dRH5.js.map +0 -1
- package/lib/cjs/index-KCW2CzRk.js +0 -2504
- package/lib/cjs/index-KCW2CzRk.js.map +0 -1
- package/lib/cjs/index-KSZhahYb.js +0 -146
- package/lib/cjs/index-KSZhahYb.js.map +0 -1
- package/lib/cjs/index-NNo_VSEA.js +0 -684
- package/lib/cjs/index-NNo_VSEA.js.map +0 -1
- package/lib/cjs/index-O1bDbloo.js +0 -383
- package/lib/cjs/index-O1bDbloo.js.map +0 -1
- package/lib/cjs/index-OPh9naof.js +0 -141
- package/lib/cjs/index-OPh9naof.js.map +0 -1
- package/lib/cjs/index-PAhfZtcH.js +0 -517
- package/lib/cjs/index-PAhfZtcH.js.map +0 -1
- package/lib/cjs/index-PeRHVz4A.js +0 -759
- package/lib/cjs/index-PeRHVz4A.js.map +0 -1
- package/lib/cjs/index-U7GWrg-w.js +0 -25251
- package/lib/cjs/index-U7GWrg-w.js.map +0 -1
- package/lib/cjs/index-UTb0Az5e.js +0 -1877
- package/lib/cjs/index-UTb0Az5e.js.map +0 -1
- package/lib/cjs/index-UnEAyH8X.js +0 -194
- package/lib/cjs/index-UnEAyH8X.js.map +0 -1
- package/lib/cjs/index-VCkq0ru1.js +0 -188
- package/lib/cjs/index-VCkq0ru1.js.map +0 -1
- package/lib/cjs/index-WQl7Du53.js +0 -248
- package/lib/cjs/index-WQl7Du53.js.map +0 -1
- package/lib/cjs/index-ahL5MvrQ.js +0 -1014
- package/lib/cjs/index-ahL5MvrQ.js.map +0 -1
- package/lib/cjs/index-bpgWLeRY.js +0 -104
- package/lib/cjs/index-bpgWLeRY.js.map +0 -1
- package/lib/cjs/index-fZupvR_f.js +0 -341
- package/lib/cjs/index-fZupvR_f.js.map +0 -1
- package/lib/cjs/index-gSM-jgti.js +0 -449
- package/lib/cjs/index-gSM-jgti.js.map +0 -1
- package/lib/cjs/index-jlPr_A_N.js +0 -66
- package/lib/cjs/index-jlPr_A_N.js.map +0 -1
- package/lib/cjs/index-tqAbVyds.js.map +0 -1
- package/lib/cjs/index-udZSknd8.js.map +0 -1
- package/lib/cjs/index-urB-WDqA.js +0 -1030
- package/lib/cjs/index-urB-WDqA.js.map +0 -1
- package/lib/cjs/index-xWgWtxUR.js +0 -347
- package/lib/cjs/index-xWgWtxUR.js.map +0 -1
- package/lib/cjs/javascript-5-BTydbD.js +0 -928
- package/lib/cjs/javascript-5-BTydbD.js.map +0 -1
- package/lib/cjs/jinja2-BWMz4gPk.js +0 -174
- package/lib/cjs/jinja2-BWMz4gPk.js.map +0 -1
- package/lib/cjs/julia-dtR9J3KZ.js +0 -372
- package/lib/cjs/julia-dtR9J3KZ.js.map +0 -1
- package/lib/cjs/livescript-YxT0INe3.js +0 -262
- package/lib/cjs/livescript-YxT0INe3.js.map +0 -1
- package/lib/cjs/lua-h7_AXjy9.js +0 -140
- package/lib/cjs/lua-h7_AXjy9.js.map +0 -1
- package/lib/cjs/mathematica-Zc57fOr3.js +0 -156
- package/lib/cjs/mathematica-Zc57fOr3.js.map +0 -1
- package/lib/cjs/mbox-ltKsKgJd.js +0 -117
- package/lib/cjs/mbox-ltKsKgJd.js.map +0 -1
- package/lib/cjs/mirc-xTLeWqmy.js +0 -179
- package/lib/cjs/mirc-xTLeWqmy.js.map +0 -1
- package/lib/cjs/mllike-xukl-Kjp.js +0 -351
- package/lib/cjs/mllike-xukl-Kjp.js.map +0 -1
- package/lib/cjs/modelica-LsXtAawk.js +0 -195
- package/lib/cjs/modelica-LsXtAawk.js.map +0 -1
- package/lib/cjs/mscgen-9HooYIVW.js +0 -154
- package/lib/cjs/mscgen-9HooYIVW.js.map +0 -1
- package/lib/cjs/mumps-VXqGp84f.js +0 -132
- package/lib/cjs/mumps-VXqGp84f.js.map +0 -1
- package/lib/cjs/nginx-UrubUbn1.js +0 -166
- package/lib/cjs/nginx-UrubUbn1.js.map +0 -1
- package/lib/cjs/nsis-c2AYwqyy.js +0 -83
- package/lib/cjs/nsis-c2AYwqyy.js.map +0 -1
- package/lib/cjs/ntriples-N1nwiheD.js +0 -144
- package/lib/cjs/ntriples-N1nwiheD.js.map +0 -1
- package/lib/cjs/octave-ElonStfZ.js +0 -115
- package/lib/cjs/octave-ElonStfZ.js.map +0 -1
- package/lib/cjs/oz-7VQTnCfu.js +0 -238
- package/lib/cjs/oz-7VQTnCfu.js.map +0 -1
- package/lib/cjs/pascal-yq2Cb88Q.js +0 -127
- package/lib/cjs/pascal-yq2Cb88Q.js.map +0 -1
- package/lib/cjs/perl-hJq4byS9.js +0 -822
- package/lib/cjs/perl-hJq4byS9.js.map +0 -1
- package/lib/cjs/pig-2syuOlAa.js +0 -152
- package/lib/cjs/pig-2syuOlAa.js.map +0 -1
- package/lib/cjs/powershell-NDwxuSDg.js +0 -384
- package/lib/cjs/powershell-NDwxuSDg.js.map +0 -1
- package/lib/cjs/properties-wacODxDJ.js +0 -65
- package/lib/cjs/properties-wacODxDJ.js.map +0 -1
- package/lib/cjs/protobuf-zVHZwskk.js +0 -57
- package/lib/cjs/protobuf-zVHZwskk.js.map +0 -1
- package/lib/cjs/puppet-koQikqO-.js +0 -208
- package/lib/cjs/puppet-koQikqO-.js.map +0 -1
- package/lib/cjs/python-P3UsKHbj.js +0 -394
- package/lib/cjs/python-P3UsKHbj.js.map +0 -1
- package/lib/cjs/q-Z_d2uXoA.js +0 -126
- package/lib/cjs/q-Z_d2uXoA.js.map +0 -1
- package/lib/cjs/r-J6Jl9z1i.js +0 -177
- package/lib/cjs/r-J6Jl9z1i.js.map +0 -1
- package/lib/cjs/rpm-6C0Omumu.js +0 -93
- package/lib/cjs/rpm-6C0Omumu.js.map +0 -1
- package/lib/cjs/ruby-POVyUmsb.js +0 -290
- package/lib/cjs/ruby-POVyUmsb.js.map +0 -1
- package/lib/cjs/sas-vDtpSmFr.js +0 -271
- package/lib/cjs/sas-vDtpSmFr.js.map +0 -1
- package/lib/cjs/scheme-5AA5BH7S.js +0 -266
- package/lib/cjs/scheme-5AA5BH7S.js.map +0 -1
- package/lib/cjs/shell-_ztDMiW6.js +0 -148
- package/lib/cjs/shell-_ztDMiW6.js.map +0 -1
- package/lib/cjs/sieve-R_vzlbvH.js +0 -181
- package/lib/cjs/sieve-R_vzlbvH.js.map +0 -1
- package/lib/cjs/simple-mode-ZwmNbV0h.js +0 -138
- package/lib/cjs/simple-mode-ZwmNbV0h.js.map +0 -1
- package/lib/cjs/smalltalk-dWLp5zN8.js +0 -156
- package/lib/cjs/smalltalk-dWLp5zN8.js.map +0 -1
- package/lib/cjs/solr-wSmvjKI8.js +0 -83
- package/lib/cjs/solr-wSmvjKI8.js.map +0 -1
- package/lib/cjs/sparql-GNU_0xKB.js +0 -173
- package/lib/cjs/sparql-GNU_0xKB.js.map +0 -1
- package/lib/cjs/spreadsheet-BiqYLk6M.js +0 -101
- package/lib/cjs/spreadsheet-BiqYLk6M.js.map +0 -1
- package/lib/cjs/sql-9GpHBPsC.js +0 -497
- package/lib/cjs/sql-9GpHBPsC.js.map +0 -1
- package/lib/cjs/stex-1V41CNLk.js +0 -250
- package/lib/cjs/stex-1V41CNLk.js.map +0 -1
- package/lib/cjs/stylus-H6hn9z_G.js +0 -753
- package/lib/cjs/stylus-H6hn9z_G.js.map +0 -1
- package/lib/cjs/swift-Xv5f8zgN.js +0 -205
- package/lib/cjs/swift-Xv5f8zgN.js.map +0 -1
- package/lib/cjs/tcl-LI-LOw_t.js +0 -128
- package/lib/cjs/tcl-LI-LOw_t.js.map +0 -1
- package/lib/cjs/textile-3NvRPUgg.js +0 -444
- package/lib/cjs/textile-3NvRPUgg.js.map +0 -1
- package/lib/cjs/tiddlywiki-PkMzy8_R.js +0 -281
- package/lib/cjs/tiddlywiki-PkMzy8_R.js.map +0 -1
- package/lib/cjs/tiki-Zk_GnEC8.js +0 -292
- package/lib/cjs/tiki-Zk_GnEC8.js.map +0 -1
- package/lib/cjs/toml-36gJ0YCq.js +0 -78
- package/lib/cjs/toml-36gJ0YCq.js.map +0 -1
- package/lib/cjs/troff-RLZ_o61o.js +0 -67
- package/lib/cjs/troff-RLZ_o61o.js.map +0 -1
- package/lib/cjs/ttcn-cfg-twaoJYvf.js +0 -204
- package/lib/cjs/ttcn-cfg-twaoJYvf.js.map +0 -1
- package/lib/cjs/ttcn-kGwvGb2v.js +0 -260
- package/lib/cjs/ttcn-kGwvGb2v.js.map +0 -1
- package/lib/cjs/turtle-nnevat7b.js +0 -144
- package/lib/cjs/turtle-nnevat7b.js.map +0 -1
- package/lib/cjs/vb-fO_I9s3s.js +0 -252
- package/lib/cjs/vb-fO_I9s3s.js.map +0 -1
- package/lib/cjs/vbscript-HXnn40y4.js +0 -324
- package/lib/cjs/vbscript-HXnn40y4.js.map +0 -1
- package/lib/cjs/velocity-Wn-ZfFzr.js +0 -189
- package/lib/cjs/velocity-Wn-ZfFzr.js.map +0 -1
- package/lib/cjs/verilog-y1ev34z6.js +0 -569
- package/lib/cjs/verilog-y1ev34z6.js.map +0 -1
- package/lib/cjs/vhdl-LF0oeXxc.js +0 -177
- package/lib/cjs/vhdl-LF0oeXxc.js.map +0 -1
- package/lib/cjs/webidl-6kI5KbeC.js +0 -182
- package/lib/cjs/webidl-6kI5KbeC.js.map +0 -1
- package/lib/cjs/xquery-BavrmwsO.js +0 -428
- package/lib/cjs/xquery-BavrmwsO.js.map +0 -1
- package/lib/cjs/yacas-1g_AbTrl.js +0 -185
- package/lib/cjs/yacas-1g_AbTrl.js.map +0 -1
- package/lib/cjs/z80-QYzKAAp7.js +0 -106
- package/lib/cjs/z80-QYzKAAp7.js.map +0 -1
- package/lib/esm/apl-eHQxyJFn.js +0 -143
- package/lib/esm/apl-eHQxyJFn.js.map +0 -1
- package/lib/esm/asciiarmor-Z-IGYCI4.js +0 -57
- package/lib/esm/asciiarmor-Z-IGYCI4.js.map +0 -1
- package/lib/esm/asn1-gF7x-q1y.js +0 -193
- package/lib/esm/asn1-gF7x-q1y.js.map +0 -1
- package/lib/esm/asterisk-swk20ftp.js +0 -188
- package/lib/esm/asterisk-swk20ftp.js.map +0 -1
- package/lib/esm/brainfuck-IFQdiQoR.js +0 -71
- package/lib/esm/brainfuck-IFQdiQoR.js.map +0 -1
- package/lib/esm/clike-q3hUF2Cx.js +0 -1019
- package/lib/esm/clike-q3hUF2Cx.js.map +0 -1
- package/lib/esm/clojure-I2Krbr2M.js +0 -275
- package/lib/esm/clojure-I2Krbr2M.js.map +0 -1
- package/lib/esm/clsx-RxCLxYpD.js +0 -4
- package/lib/esm/clsx-RxCLxYpD.js.map +0 -1
- package/lib/esm/cmake-ewwXLeuZ.js +0 -82
- package/lib/esm/cmake-ewwXLeuZ.js.map +0 -1
- package/lib/esm/cobol-fpN1nAnR.js +0 -236
- package/lib/esm/cobol-fpN1nAnR.js.map +0 -1
- package/lib/esm/coffeescript--eTFR-bH.js +0 -330
- package/lib/esm/coffeescript--eTFR-bH.js.map +0 -1
- package/lib/esm/commonlisp-XLSwVdLc.js +0 -109
- package/lib/esm/commonlisp-XLSwVdLc.js.map +0 -1
- package/lib/esm/crystal-_r3Aa1_a.js +0 -420
- package/lib/esm/crystal-_r3Aa1_a.js.map +0 -1
- package/lib/esm/css-hgwYGMKZ.js +0 -848
- package/lib/esm/css-hgwYGMKZ.js.map +0 -1
- package/lib/esm/cypher-bbJyAa-4.js +0 -123
- package/lib/esm/cypher-bbJyAa-4.js.map +0 -1
- package/lib/esm/d-5MyulviS.js +0 -206
- package/lib/esm/d-5MyulviS.js.map +0 -1
- package/lib/esm/diff-neOaT_vk.js +0 -31
- package/lib/esm/diff-neOaT_vk.js.map +0 -1
- package/lib/esm/dockerfile-lzx42-zz.js +0 -200
- package/lib/esm/dockerfile-lzx42-zz.js.map +0 -1
- package/lib/esm/dtd-FmzPLZcQ.js +0 -122
- package/lib/esm/dtd-FmzPLZcQ.js.map +0 -1
- package/lib/esm/dylan-1HtRK4GO.js +0 -338
- package/lib/esm/dylan-1HtRK4GO.js.map +0 -1
- package/lib/esm/ebnf-Nz-pnLHy.js +0 -152
- package/lib/esm/ebnf-Nz-pnLHy.js.map +0 -1
- package/lib/esm/ecl-lQsZhQz0.js +0 -191
- package/lib/esm/ecl-lQsZhQz0.js.map +0 -1
- package/lib/esm/eiffel-R_HiEkhx.js +0 -147
- package/lib/esm/eiffel-R_HiEkhx.js.map +0 -1
- package/lib/esm/elm-KYv4VTDg.js +0 -231
- package/lib/esm/elm-KYv4VTDg.js.map +0 -1
- package/lib/esm/erlang-7YaHCBIe.js +0 -582
- package/lib/esm/erlang-7YaHCBIe.js.map +0 -1
- package/lib/esm/factor-opBU9aTK.js +0 -66
- package/lib/esm/factor-opBU9aTK.js.map +0 -1
- package/lib/esm/fcl-jm31FmFz.js +0 -155
- package/lib/esm/fcl-jm31FmFz.js.map +0 -1
- package/lib/esm/forth-5NKbjnWh.js +0 -165
- package/lib/esm/forth-5NKbjnWh.js.map +0 -1
- package/lib/esm/fortran-dXm_-cb9.js +0 -173
- package/lib/esm/fortran-dXm_-cb9.js.map +0 -1
- package/lib/esm/gas-nsYVnsy-.js +0 -344
- package/lib/esm/gas-nsYVnsy-.js.map +0 -1
- package/lib/esm/gherkin-fzKpjm3M.js +0 -148
- package/lib/esm/gherkin-fzKpjm3M.js.map +0 -1
- package/lib/esm/go-Pn1qh7yl.js +0 -165
- package/lib/esm/go-Pn1qh7yl.js.map +0 -1
- package/lib/esm/groovy-DZY-8keZ.js +0 -231
- package/lib/esm/groovy-DZY-8keZ.js.map +0 -1
- package/lib/esm/haskell-JGh2upDd.js +0 -240
- package/lib/esm/haskell-JGh2upDd.js.map +0 -1
- package/lib/esm/haxe-1hvVK-Fy.js +0 -491
- package/lib/esm/haxe-1hvVK-Fy.js.map +0 -1
- package/lib/esm/http-mY1M77wn.js +0 -90
- package/lib/esm/http-mY1M77wn.js.map +0 -1
- package/lib/esm/idl-dy_653wH.js +0 -275
- package/lib/esm/idl-dy_653wH.js.map +0 -1
- package/lib/esm/index-1NetiFdJ.js +0 -90
- package/lib/esm/index-1NetiFdJ.js.map +0 -1
- package/lib/esm/index-2I_xbjAZ.js +0 -1012
- package/lib/esm/index-2I_xbjAZ.js.map +0 -1
- package/lib/esm/index-2huXYfuJ.js +0 -138
- package/lib/esm/index-2huXYfuJ.js.map +0 -1
- package/lib/esm/index-4x6_TVZv.js +0 -100
- package/lib/esm/index-4x6_TVZv.js.map +0 -1
- package/lib/esm/index-A-dNwMMf.js +0 -1872
- package/lib/esm/index-A-dNwMMf.js.map +0 -1
- package/lib/esm/index-AV99ipmP.js +0 -446
- package/lib/esm/index-AV99ipmP.js.map +0 -1
- package/lib/esm/index-PC2bahtq.js +0 -110
- package/lib/esm/index-PC2bahtq.js.map +0 -1
- package/lib/esm/index-QBYz82jZ.js +0 -378
- package/lib/esm/index-QBYz82jZ.js.map +0 -1
- package/lib/esm/index-W1pAMr_8.js +0 -142
- package/lib/esm/index-W1pAMr_8.js.map +0 -1
- package/lib/esm/index-Xzdc2jbA.js +0 -25207
- package/lib/esm/index-Xzdc2jbA.js.map +0 -1
- package/lib/esm/index-ZAtZWqJQ.js +0 -191
- package/lib/esm/index-ZAtZWqJQ.js.map +0 -1
- package/lib/esm/index-bnSKBrbD.js +0 -386
- package/lib/esm/index-bnSKBrbD.js.map +0 -1
- package/lib/esm/index-ftnOhuRS.js +0 -244
- package/lib/esm/index-ftnOhuRS.js.map +0 -1
- package/lib/esm/index-iQPB0Rdl.js +0 -343
- package/lib/esm/index-iQPB0Rdl.js.map +0 -1
- package/lib/esm/index-kPj3-TKp.js +0 -63
- package/lib/esm/index-kPj3-TKp.js.map +0 -1
- package/lib/esm/index-kgOR7SZ6.js +0 -336
- package/lib/esm/index-kgOR7SZ6.js.map +0 -1
- package/lib/esm/index-m49Bj3q7.js +0 -185
- package/lib/esm/index-m49Bj3q7.js.map +0 -1
- package/lib/esm/index-sWVjGw-3.js +0 -2497
- package/lib/esm/index-sWVjGw-3.js.map +0 -1
- package/lib/esm/index-twh8lL5o.js +0 -671
- package/lib/esm/index-twh8lL5o.js.map +0 -1
- package/lib/esm/index-v02MCz4_.js +0 -744
- package/lib/esm/index-v02MCz4_.js.map +0 -1
- package/lib/esm/index-wEXT8mbN.js +0 -512
- package/lib/esm/index-wEXT8mbN.js.map +0 -1
- package/lib/esm/index-wFIac5Kw.js +0 -1023
- package/lib/esm/index-wFIac5Kw.js.map +0 -1
- package/lib/esm/index-wg94ewRo.js +0 -425
- package/lib/esm/index-wg94ewRo.js.map +0 -1
- package/lib/esm/javascript-TMTz-YQH.js +0 -923
- package/lib/esm/javascript-TMTz-YQH.js.map +0 -1
- package/lib/esm/jinja2-sRIdliZK.js +0 -172
- package/lib/esm/jinja2-sRIdliZK.js.map +0 -1
- package/lib/esm/julia-fK0wmpGL.js +0 -370
- package/lib/esm/julia-fK0wmpGL.js.map +0 -1
- package/lib/esm/livescript-FRbAot3D.js +0 -260
- package/lib/esm/livescript-FRbAot3D.js.map +0 -1
- package/lib/esm/lua-t4FHEjvK.js +0 -138
- package/lib/esm/lua-t4FHEjvK.js.map +0 -1
- package/lib/esm/mathematica-sn_KGlYj.js +0 -154
- package/lib/esm/mathematica-sn_KGlYj.js.map +0 -1
- package/lib/esm/mbox-KvVC319E.js +0 -115
- package/lib/esm/mbox-KvVC319E.js.map +0 -1
- package/lib/esm/mirc-PzJ0zKSk.js +0 -177
- package/lib/esm/mirc-PzJ0zKSk.js.map +0 -1
- package/lib/esm/mllike-ZK411xkN.js +0 -347
- package/lib/esm/mllike-ZK411xkN.js.map +0 -1
- package/lib/esm/modelica-ZaHlRCbp.js +0 -193
- package/lib/esm/modelica-ZaHlRCbp.js.map +0 -1
- package/lib/esm/mscgen-Kkq4o4Zm.js +0 -150
- package/lib/esm/mscgen-Kkq4o4Zm.js.map +0 -1
- package/lib/esm/mumps-M8a87-rl.js +0 -130
- package/lib/esm/mumps-M8a87-rl.js.map +0 -1
- package/lib/esm/nginx-2LJIX23E.js +0 -164
- package/lib/esm/nginx-2LJIX23E.js.map +0 -1
- package/lib/esm/nsis-zvfFgMLi.js +0 -81
- package/lib/esm/nsis-zvfFgMLi.js.map +0 -1
- package/lib/esm/ntriples-tVkHy5bk.js +0 -142
- package/lib/esm/ntriples-tVkHy5bk.js.map +0 -1
- package/lib/esm/octave-mE4T5MF5.js +0 -113
- package/lib/esm/octave-mE4T5MF5.js.map +0 -1
- package/lib/esm/oz-q-LCsuVg.js +0 -236
- package/lib/esm/oz-q-LCsuVg.js.map +0 -1
- package/lib/esm/pascal-0IgUAn4C.js +0 -125
- package/lib/esm/pascal-0IgUAn4C.js.map +0 -1
- package/lib/esm/perl-AqxdYGac.js +0 -820
- package/lib/esm/perl-AqxdYGac.js.map +0 -1
- package/lib/esm/pig-ESM-IjQj.js +0 -150
- package/lib/esm/pig-ESM-IjQj.js.map +0 -1
- package/lib/esm/powershell-CLFP0L55.js +0 -382
- package/lib/esm/powershell-CLFP0L55.js.map +0 -1
- package/lib/esm/properties-oWHNzvb9.js +0 -63
- package/lib/esm/properties-oWHNzvb9.js.map +0 -1
- package/lib/esm/protobuf-c7eMmdcc.js +0 -55
- package/lib/esm/protobuf-c7eMmdcc.js.map +0 -1
- package/lib/esm/puppet-FjzvdRJr.js +0 -206
- package/lib/esm/puppet-FjzvdRJr.js.map +0 -1
- package/lib/esm/python-3Pv0tnvt.js +0 -390
- package/lib/esm/python-3Pv0tnvt.js.map +0 -1
- package/lib/esm/q-IImW8da6.js +0 -124
- package/lib/esm/q-IImW8da6.js.map +0 -1
- package/lib/esm/r-CnEkTvR0.js +0 -175
- package/lib/esm/r-CnEkTvR0.js.map +0 -1
- package/lib/esm/rpm-Q55-fEHj.js +0 -90
- package/lib/esm/rpm-Q55-fEHj.js.map +0 -1
- package/lib/esm/ruby-zhaGB3Kh.js +0 -288
- package/lib/esm/ruby-zhaGB3Kh.js.map +0 -1
- package/lib/esm/sas-Ur9jZIOV.js +0 -269
- package/lib/esm/sas-Ur9jZIOV.js.map +0 -1
- package/lib/esm/scheme-daT5-Rya.js +0 -264
- package/lib/esm/scheme-daT5-Rya.js.map +0 -1
- package/lib/esm/shell-cwFL0AYP.js +0 -146
- package/lib/esm/shell-cwFL0AYP.js.map +0 -1
- package/lib/esm/sieve-MlNXFFUq.js +0 -179
- package/lib/esm/sieve-MlNXFFUq.js.map +0 -1
- package/lib/esm/simple-mode-m1rsX7Gw.js +0 -136
- package/lib/esm/simple-mode-m1rsX7Gw.js.map +0 -1
- package/lib/esm/smalltalk-xrQICp9e.js +0 -154
- package/lib/esm/smalltalk-xrQICp9e.js.map +0 -1
- package/lib/esm/solr-PU3oPgQz.js +0 -81
- package/lib/esm/solr-PU3oPgQz.js.map +0 -1
- package/lib/esm/sparql--u8NRBii.js +0 -171
- package/lib/esm/sparql--u8NRBii.js.map +0 -1
- package/lib/esm/spreadsheet-QCp0LifX.js +0 -99
- package/lib/esm/spreadsheet-QCp0LifX.js.map +0 -1
- package/lib/esm/sql-dsGfl64h.js +0 -482
- package/lib/esm/sql-dsGfl64h.js.map +0 -1
- package/lib/esm/stex-WcLBzvkD.js +0 -247
- package/lib/esm/stex-WcLBzvkD.js.map +0 -1
- package/lib/esm/stylus--A5XAqOX.js +0 -751
- package/lib/esm/stylus--A5XAqOX.js.map +0 -1
- package/lib/esm/swift-qAm73i7G.js +0 -203
- package/lib/esm/swift-qAm73i7G.js.map +0 -1
- package/lib/esm/tcl-Kdc7qxc-.js +0 -126
- package/lib/esm/tcl-Kdc7qxc-.js.map +0 -1
- package/lib/esm/textile--sz8UrIz.js +0 -442
- package/lib/esm/textile--sz8UrIz.js.map +0 -1
- package/lib/esm/tiddlywiki-xNXTeBlQ.js +0 -279
- package/lib/esm/tiddlywiki-xNXTeBlQ.js.map +0 -1
- package/lib/esm/tiki-LCXjrNH3.js +0 -290
- package/lib/esm/tiki-LCXjrNH3.js.map +0 -1
- package/lib/esm/toml-Ac4tlBMn.js +0 -76
- package/lib/esm/toml-Ac4tlBMn.js.map +0 -1
- package/lib/esm/troff-LLW1x1Yz.js +0 -65
- package/lib/esm/troff-LLW1x1Yz.js.map +0 -1
- package/lib/esm/ttcn-ZYZ9FS3u.js +0 -258
- package/lib/esm/ttcn-ZYZ9FS3u.js.map +0 -1
- package/lib/esm/ttcn-cfg-qsvf3MfB.js +0 -202
- package/lib/esm/ttcn-cfg-qsvf3MfB.js.map +0 -1
- package/lib/esm/turtle-wq3TqOth.js +0 -142
- package/lib/esm/turtle-wq3TqOth.js.map +0 -1
- package/lib/esm/vb-86M_JuNP.js +0 -250
- package/lib/esm/vb-86M_JuNP.js.map +0 -1
- package/lib/esm/vbscript-GueAeVug.js +0 -321
- package/lib/esm/vbscript-GueAeVug.js.map +0 -1
- package/lib/esm/velocity-7PW9GXO2.js +0 -187
- package/lib/esm/velocity-7PW9GXO2.js.map +0 -1
- package/lib/esm/verilog-PXtXH14C.js +0 -566
- package/lib/esm/verilog-PXtXH14C.js.map +0 -1
- package/lib/esm/vhdl-I8eyK83X.js +0 -175
- package/lib/esm/vhdl-I8eyK83X.js.map +0 -1
- package/lib/esm/webidl-1f8ATJ66.js +0 -180
- package/lib/esm/webidl-1f8ATJ66.js.map +0 -1
- package/lib/esm/xquery-IYp28Wx6.js +0 -426
- package/lib/esm/xquery-IYp28Wx6.js.map +0 -1
- package/lib/esm/yacas-wkENB05f.js +0 -183
- package/lib/esm/yacas-wkENB05f.js.map +0 -1
- package/lib/esm/z80-GaXiLdiV.js +0 -103
- package/lib/esm/z80-GaXiLdiV.js.map +0 -1
|
@@ -1,2497 +0,0 @@
|
|
|
1
|
-
import { N as NodeType, n as NodeProp, b as styleTags, t as tags, o as NodeSet, P as Parser, T as Tag, q as Tree, p as parseMixed, h as syntaxTree, m as EditorSelection, r as countColumn, a as LanguageSupport, u as Prec, v as keymap, C as CompletionContext, w as EditorState, x as Language, y as indentUnit, z as defineLanguageFacet, f as foldNodeProp, i as indentNodeProp, A as languageDataProp, B as foldService, L as LanguageDescription, D as ParseContext } from './index-Xzdc2jbA.js';
|
|
2
|
-
import { htmlCompletionSource, html } from './index-wFIac5Kw.js';
|
|
3
|
-
import '@milkdown/kit/component/code-block';
|
|
4
|
-
import './todoList-9QsDDcmB.js';
|
|
5
|
-
import 'atomico';
|
|
6
|
-
import './index-A-dNwMMf.js';
|
|
7
|
-
import './index-QBYz82jZ.js';
|
|
8
|
-
import './index-twh8lL5o.js';
|
|
9
|
-
|
|
10
|
-
class CompositeBlock {
|
|
11
|
-
static create(type, value, from, parentHash, end) {
|
|
12
|
-
let hash = (parentHash + (parentHash << 8) + type + (value << 4)) | 0;
|
|
13
|
-
return new CompositeBlock(type, value, from, hash, end, [], []);
|
|
14
|
-
}
|
|
15
|
-
constructor(type,
|
|
16
|
-
// Used for indentation in list items, markup character in lists
|
|
17
|
-
value, from, hash, end, children, positions) {
|
|
18
|
-
this.type = type;
|
|
19
|
-
this.value = value;
|
|
20
|
-
this.from = from;
|
|
21
|
-
this.hash = hash;
|
|
22
|
-
this.end = end;
|
|
23
|
-
this.children = children;
|
|
24
|
-
this.positions = positions;
|
|
25
|
-
this.hashProp = [[NodeProp.contextHash, hash]];
|
|
26
|
-
}
|
|
27
|
-
addChild(child, pos) {
|
|
28
|
-
if (child.prop(NodeProp.contextHash) != this.hash)
|
|
29
|
-
child = new Tree(child.type, child.children, child.positions, child.length, this.hashProp);
|
|
30
|
-
this.children.push(child);
|
|
31
|
-
this.positions.push(pos);
|
|
32
|
-
}
|
|
33
|
-
toTree(nodeSet, end = this.end) {
|
|
34
|
-
let last = this.children.length - 1;
|
|
35
|
-
if (last >= 0)
|
|
36
|
-
end = Math.max(end, this.positions[last] + this.children[last].length + this.from);
|
|
37
|
-
return new Tree(nodeSet.types[this.type], this.children, this.positions, end - this.from).balance({
|
|
38
|
-
makeTree: (children, positions, length) => new Tree(NodeType.none, children, positions, length, this.hashProp)
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
var Type;
|
|
43
|
-
(function (Type) {
|
|
44
|
-
Type[Type["Document"] = 1] = "Document";
|
|
45
|
-
Type[Type["CodeBlock"] = 2] = "CodeBlock";
|
|
46
|
-
Type[Type["FencedCode"] = 3] = "FencedCode";
|
|
47
|
-
Type[Type["Blockquote"] = 4] = "Blockquote";
|
|
48
|
-
Type[Type["HorizontalRule"] = 5] = "HorizontalRule";
|
|
49
|
-
Type[Type["BulletList"] = 6] = "BulletList";
|
|
50
|
-
Type[Type["OrderedList"] = 7] = "OrderedList";
|
|
51
|
-
Type[Type["ListItem"] = 8] = "ListItem";
|
|
52
|
-
Type[Type["ATXHeading1"] = 9] = "ATXHeading1";
|
|
53
|
-
Type[Type["ATXHeading2"] = 10] = "ATXHeading2";
|
|
54
|
-
Type[Type["ATXHeading3"] = 11] = "ATXHeading3";
|
|
55
|
-
Type[Type["ATXHeading4"] = 12] = "ATXHeading4";
|
|
56
|
-
Type[Type["ATXHeading5"] = 13] = "ATXHeading5";
|
|
57
|
-
Type[Type["ATXHeading6"] = 14] = "ATXHeading6";
|
|
58
|
-
Type[Type["SetextHeading1"] = 15] = "SetextHeading1";
|
|
59
|
-
Type[Type["SetextHeading2"] = 16] = "SetextHeading2";
|
|
60
|
-
Type[Type["HTMLBlock"] = 17] = "HTMLBlock";
|
|
61
|
-
Type[Type["LinkReference"] = 18] = "LinkReference";
|
|
62
|
-
Type[Type["Paragraph"] = 19] = "Paragraph";
|
|
63
|
-
Type[Type["CommentBlock"] = 20] = "CommentBlock";
|
|
64
|
-
Type[Type["ProcessingInstructionBlock"] = 21] = "ProcessingInstructionBlock";
|
|
65
|
-
// Inline
|
|
66
|
-
Type[Type["Escape"] = 22] = "Escape";
|
|
67
|
-
Type[Type["Entity"] = 23] = "Entity";
|
|
68
|
-
Type[Type["HardBreak"] = 24] = "HardBreak";
|
|
69
|
-
Type[Type["Emphasis"] = 25] = "Emphasis";
|
|
70
|
-
Type[Type["StrongEmphasis"] = 26] = "StrongEmphasis";
|
|
71
|
-
Type[Type["Link"] = 27] = "Link";
|
|
72
|
-
Type[Type["Image"] = 28] = "Image";
|
|
73
|
-
Type[Type["InlineCode"] = 29] = "InlineCode";
|
|
74
|
-
Type[Type["HTMLTag"] = 30] = "HTMLTag";
|
|
75
|
-
Type[Type["Comment"] = 31] = "Comment";
|
|
76
|
-
Type[Type["ProcessingInstruction"] = 32] = "ProcessingInstruction";
|
|
77
|
-
Type[Type["URL"] = 33] = "URL";
|
|
78
|
-
// Smaller tokens
|
|
79
|
-
Type[Type["HeaderMark"] = 34] = "HeaderMark";
|
|
80
|
-
Type[Type["QuoteMark"] = 35] = "QuoteMark";
|
|
81
|
-
Type[Type["ListMark"] = 36] = "ListMark";
|
|
82
|
-
Type[Type["LinkMark"] = 37] = "LinkMark";
|
|
83
|
-
Type[Type["EmphasisMark"] = 38] = "EmphasisMark";
|
|
84
|
-
Type[Type["CodeMark"] = 39] = "CodeMark";
|
|
85
|
-
Type[Type["CodeText"] = 40] = "CodeText";
|
|
86
|
-
Type[Type["CodeInfo"] = 41] = "CodeInfo";
|
|
87
|
-
Type[Type["LinkTitle"] = 42] = "LinkTitle";
|
|
88
|
-
Type[Type["LinkLabel"] = 43] = "LinkLabel";
|
|
89
|
-
})(Type || (Type = {}));
|
|
90
|
-
/// Data structure used to accumulate a block's content during [leaf
|
|
91
|
-
/// block parsing](#BlockParser.leaf).
|
|
92
|
-
class LeafBlock {
|
|
93
|
-
/// @internal
|
|
94
|
-
constructor(
|
|
95
|
-
/// The start position of the block.
|
|
96
|
-
start,
|
|
97
|
-
/// The block's text content.
|
|
98
|
-
content) {
|
|
99
|
-
this.start = start;
|
|
100
|
-
this.content = content;
|
|
101
|
-
/// @internal
|
|
102
|
-
this.marks = [];
|
|
103
|
-
/// The block parsers active for this block.
|
|
104
|
-
this.parsers = [];
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
/// Data structure used during block-level per-line parsing.
|
|
108
|
-
class Line {
|
|
109
|
-
constructor() {
|
|
110
|
-
/// The line's full text.
|
|
111
|
-
this.text = "";
|
|
112
|
-
/// The base indent provided by the composite contexts (that have
|
|
113
|
-
/// been handled so far).
|
|
114
|
-
this.baseIndent = 0;
|
|
115
|
-
/// The string position corresponding to the base indent.
|
|
116
|
-
this.basePos = 0;
|
|
117
|
-
/// The number of contexts handled @internal
|
|
118
|
-
this.depth = 0;
|
|
119
|
-
/// Any markers (i.e. block quote markers) parsed for the contexts. @internal
|
|
120
|
-
this.markers = [];
|
|
121
|
-
/// The position of the next non-whitespace character beyond any
|
|
122
|
-
/// list, blockquote, or other composite block markers.
|
|
123
|
-
this.pos = 0;
|
|
124
|
-
/// The column of the next non-whitespace character.
|
|
125
|
-
this.indent = 0;
|
|
126
|
-
/// The character code of the character after `pos`.
|
|
127
|
-
this.next = -1;
|
|
128
|
-
}
|
|
129
|
-
/// @internal
|
|
130
|
-
forward() {
|
|
131
|
-
if (this.basePos > this.pos)
|
|
132
|
-
this.forwardInner();
|
|
133
|
-
}
|
|
134
|
-
/// @internal
|
|
135
|
-
forwardInner() {
|
|
136
|
-
let newPos = this.skipSpace(this.basePos);
|
|
137
|
-
this.indent = this.countIndent(newPos, this.pos, this.indent);
|
|
138
|
-
this.pos = newPos;
|
|
139
|
-
this.next = newPos == this.text.length ? -1 : this.text.charCodeAt(newPos);
|
|
140
|
-
}
|
|
141
|
-
/// Skip whitespace after the given position, return the position of
|
|
142
|
-
/// the next non-space character or the end of the line if there's
|
|
143
|
-
/// only space after `from`.
|
|
144
|
-
skipSpace(from) { return skipSpace(this.text, from); }
|
|
145
|
-
/// @internal
|
|
146
|
-
reset(text) {
|
|
147
|
-
this.text = text;
|
|
148
|
-
this.baseIndent = this.basePos = this.pos = this.indent = 0;
|
|
149
|
-
this.forwardInner();
|
|
150
|
-
this.depth = 1;
|
|
151
|
-
while (this.markers.length)
|
|
152
|
-
this.markers.pop();
|
|
153
|
-
}
|
|
154
|
-
/// Move the line's base position forward to the given position.
|
|
155
|
-
/// This should only be called by composite [block
|
|
156
|
-
/// parsers](#BlockParser.parse) or [markup skipping
|
|
157
|
-
/// functions](#NodeSpec.composite).
|
|
158
|
-
moveBase(to) {
|
|
159
|
-
this.basePos = to;
|
|
160
|
-
this.baseIndent = this.countIndent(to, this.pos, this.indent);
|
|
161
|
-
}
|
|
162
|
-
/// Move the line's base position forward to the given _column_.
|
|
163
|
-
moveBaseColumn(indent) {
|
|
164
|
-
this.baseIndent = indent;
|
|
165
|
-
this.basePos = this.findColumn(indent);
|
|
166
|
-
}
|
|
167
|
-
/// Store a composite-block-level marker. Should be called from
|
|
168
|
-
/// [markup skipping functions](#NodeSpec.composite) when they
|
|
169
|
-
/// consume any non-whitespace characters.
|
|
170
|
-
addMarker(elt) {
|
|
171
|
-
this.markers.push(elt);
|
|
172
|
-
}
|
|
173
|
-
/// Find the column position at `to`, optionally starting at a given
|
|
174
|
-
/// position and column.
|
|
175
|
-
countIndent(to, from = 0, indent = 0) {
|
|
176
|
-
for (let i = from; i < to; i++)
|
|
177
|
-
indent += this.text.charCodeAt(i) == 9 ? 4 - indent % 4 : 1;
|
|
178
|
-
return indent;
|
|
179
|
-
}
|
|
180
|
-
/// Find the position corresponding to the given column.
|
|
181
|
-
findColumn(goal) {
|
|
182
|
-
let i = 0;
|
|
183
|
-
for (let indent = 0; i < this.text.length && indent < goal; i++)
|
|
184
|
-
indent += this.text.charCodeAt(i) == 9 ? 4 - indent % 4 : 1;
|
|
185
|
-
return i;
|
|
186
|
-
}
|
|
187
|
-
/// @internal
|
|
188
|
-
scrub() {
|
|
189
|
-
if (!this.baseIndent)
|
|
190
|
-
return this.text;
|
|
191
|
-
let result = "";
|
|
192
|
-
for (let i = 0; i < this.basePos; i++)
|
|
193
|
-
result += " ";
|
|
194
|
-
return result + this.text.slice(this.basePos);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
function skipForList(bl, cx, line) {
|
|
198
|
-
if (line.pos == line.text.length ||
|
|
199
|
-
(bl != cx.block && line.indent >= cx.stack[line.depth + 1].value + line.baseIndent))
|
|
200
|
-
return true;
|
|
201
|
-
if (line.indent >= line.baseIndent + 4)
|
|
202
|
-
return false;
|
|
203
|
-
let size = (bl.type == Type.OrderedList ? isOrderedList : isBulletList)(line, cx, false);
|
|
204
|
-
return size > 0 &&
|
|
205
|
-
(bl.type != Type.BulletList || isHorizontalRule(line, cx, false) < 0) &&
|
|
206
|
-
line.text.charCodeAt(line.pos + size - 1) == bl.value;
|
|
207
|
-
}
|
|
208
|
-
const DefaultSkipMarkup = {
|
|
209
|
-
[Type.Blockquote](bl, cx, line) {
|
|
210
|
-
if (line.next != 62 /* '>' */)
|
|
211
|
-
return false;
|
|
212
|
-
line.markers.push(elt(Type.QuoteMark, cx.lineStart + line.pos, cx.lineStart + line.pos + 1));
|
|
213
|
-
line.moveBase(line.pos + (space(line.text.charCodeAt(line.pos + 1)) ? 2 : 1));
|
|
214
|
-
bl.end = cx.lineStart + line.text.length;
|
|
215
|
-
return true;
|
|
216
|
-
},
|
|
217
|
-
[Type.ListItem](bl, _cx, line) {
|
|
218
|
-
if (line.indent < line.baseIndent + bl.value && line.next > -1)
|
|
219
|
-
return false;
|
|
220
|
-
line.moveBaseColumn(line.baseIndent + bl.value);
|
|
221
|
-
return true;
|
|
222
|
-
},
|
|
223
|
-
[Type.OrderedList]: skipForList,
|
|
224
|
-
[Type.BulletList]: skipForList,
|
|
225
|
-
[Type.Document]() { return true; }
|
|
226
|
-
};
|
|
227
|
-
function space(ch) { return ch == 32 || ch == 9 || ch == 10 || ch == 13; }
|
|
228
|
-
function skipSpace(line, i = 0) {
|
|
229
|
-
while (i < line.length && space(line.charCodeAt(i)))
|
|
230
|
-
i++;
|
|
231
|
-
return i;
|
|
232
|
-
}
|
|
233
|
-
function skipSpaceBack(line, i, to) {
|
|
234
|
-
while (i > to && space(line.charCodeAt(i - 1)))
|
|
235
|
-
i--;
|
|
236
|
-
return i;
|
|
237
|
-
}
|
|
238
|
-
function isFencedCode(line) {
|
|
239
|
-
if (line.next != 96 && line.next != 126 /* '`~' */)
|
|
240
|
-
return -1;
|
|
241
|
-
let pos = line.pos + 1;
|
|
242
|
-
while (pos < line.text.length && line.text.charCodeAt(pos) == line.next)
|
|
243
|
-
pos++;
|
|
244
|
-
if (pos < line.pos + 3)
|
|
245
|
-
return -1;
|
|
246
|
-
if (line.next == 96)
|
|
247
|
-
for (let i = pos; i < line.text.length; i++)
|
|
248
|
-
if (line.text.charCodeAt(i) == 96)
|
|
249
|
-
return -1;
|
|
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 count = 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
|
-
count++;
|
|
263
|
-
else if (!space(ch))
|
|
264
|
-
return -1;
|
|
265
|
-
}
|
|
266
|
-
// Setext headers take precedence
|
|
267
|
-
if (breaking && line.next == 45 && isSetextUnderline(line) > -1 && line.depth == cx.stack.length)
|
|
268
|
-
return -1;
|
|
269
|
-
return count < 3 ? -1 : 1;
|
|
270
|
-
}
|
|
271
|
-
function inList(cx, type) {
|
|
272
|
-
for (let i = cx.stack.length - 1; i >= 0; i--)
|
|
273
|
-
if (cx.stack[i].type == type)
|
|
274
|
-
return true;
|
|
275
|
-
return false;
|
|
276
|
-
}
|
|
277
|
-
function isBulletList(line, cx, breaking) {
|
|
278
|
-
return (line.next == 45 || line.next == 43 || line.next == 42 /* '-+*' */) &&
|
|
279
|
-
(line.pos == line.text.length - 1 || space(line.text.charCodeAt(line.pos + 1))) &&
|
|
280
|
-
(!breaking || inList(cx, Type.BulletList) || line.skipSpace(line.pos + 2) < line.text.length) ? 1 : -1;
|
|
281
|
-
}
|
|
282
|
-
function isOrderedList(line, cx, breaking) {
|
|
283
|
-
let pos = line.pos, next = line.next;
|
|
284
|
-
for (;;) {
|
|
285
|
-
if (next >= 48 && next <= 57 /* '0-9' */)
|
|
286
|
-
pos++;
|
|
287
|
-
else
|
|
288
|
-
break;
|
|
289
|
-
if (pos == line.text.length)
|
|
290
|
-
return -1;
|
|
291
|
-
next = line.text.charCodeAt(pos);
|
|
292
|
-
}
|
|
293
|
-
if (pos == line.pos || pos > line.pos + 9 ||
|
|
294
|
-
(next != 46 && next != 41 /* '.)' */) ||
|
|
295
|
-
(pos < line.text.length - 1 && !space(line.text.charCodeAt(pos + 1))) ||
|
|
296
|
-
breaking && !inList(cx, Type.OrderedList) &&
|
|
297
|
-
(line.skipSpace(pos + 1) == line.text.length || pos > line.pos + 1 || line.next != 49 /* '1' */))
|
|
298
|
-
return -1;
|
|
299
|
-
return pos + 1 - line.pos;
|
|
300
|
-
}
|
|
301
|
-
function isAtxHeading(line) {
|
|
302
|
-
if (line.next != 35 /* '#' */)
|
|
303
|
-
return -1;
|
|
304
|
-
let pos = line.pos + 1;
|
|
305
|
-
while (pos < line.text.length && line.text.charCodeAt(pos) == 35)
|
|
306
|
-
pos++;
|
|
307
|
-
if (pos < line.text.length && line.text.charCodeAt(pos) != 32)
|
|
308
|
-
return -1;
|
|
309
|
-
let size = pos - line.pos;
|
|
310
|
-
return size > 6 ? -1 : size;
|
|
311
|
-
}
|
|
312
|
-
function isSetextUnderline(line) {
|
|
313
|
-
if (line.next != 45 && line.next != 61 /* '-=' */ || line.indent >= line.baseIndent + 4)
|
|
314
|
-
return -1;
|
|
315
|
-
let pos = line.pos + 1;
|
|
316
|
-
while (pos < line.text.length && line.text.charCodeAt(pos) == line.next)
|
|
317
|
-
pos++;
|
|
318
|
-
let end = pos;
|
|
319
|
-
while (pos < line.text.length && space(line.text.charCodeAt(pos)))
|
|
320
|
-
pos++;
|
|
321
|
-
return pos == line.text.length ? end : -1;
|
|
322
|
-
}
|
|
323
|
-
const EmptyLine = /^[ \t]*$/, CommentEnd = /-->/, ProcessingEnd = /\?>/;
|
|
324
|
-
const HTMLBlockStyle = [
|
|
325
|
-
[/^<(?:script|pre|style)(?:\s|>|$)/i, /<\/(?:script|pre|style)>/i],
|
|
326
|
-
[/^\s*<!--/, CommentEnd],
|
|
327
|
-
[/^\s*<\?/, ProcessingEnd],
|
|
328
|
-
[/^\s*<![A-Z]/, />/],
|
|
329
|
-
[/^\s*<!\[CDATA\[/, /\]\]>/],
|
|
330
|
-
[/^\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],
|
|
331
|
-
[/^\s*(?:<\/[a-z][\w-]*\s*>|<[a-z][\w-]*(\s+[a-z:_][\w-.]*(?:\s*=\s*(?:[^\s"'=<>`]+|'[^']*'|"[^"]*"))?)*\s*>)\s*$/i, EmptyLine]
|
|
332
|
-
];
|
|
333
|
-
function isHTMLBlock(line, _cx, breaking) {
|
|
334
|
-
if (line.next != 60 /* '<' */)
|
|
335
|
-
return -1;
|
|
336
|
-
let rest = line.text.slice(line.pos);
|
|
337
|
-
for (let i = 0, e = HTMLBlockStyle.length - (breaking ? 1 : 0); i < e; i++)
|
|
338
|
-
if (HTMLBlockStyle[i][0].test(rest))
|
|
339
|
-
return i;
|
|
340
|
-
return -1;
|
|
341
|
-
}
|
|
342
|
-
function getListIndent(line, pos) {
|
|
343
|
-
let indentAfter = line.countIndent(pos, line.pos, line.indent);
|
|
344
|
-
let indented = line.countIndent(line.skipSpace(pos), pos, indentAfter);
|
|
345
|
-
return indented >= indentAfter + 5 ? indentAfter + 1 : indented;
|
|
346
|
-
}
|
|
347
|
-
function addCodeText(marks, from, to) {
|
|
348
|
-
let last = marks.length - 1;
|
|
349
|
-
if (last >= 0 && marks[last].to == from && marks[last].type == Type.CodeText)
|
|
350
|
-
marks[last].to = to;
|
|
351
|
-
else
|
|
352
|
-
marks.push(elt(Type.CodeText, from, to));
|
|
353
|
-
}
|
|
354
|
-
// Rules for parsing blocks. A return value of false means the rule
|
|
355
|
-
// doesn't apply here, true means it does. When true is returned and
|
|
356
|
-
// `p.line` has been updated, the rule is assumed to have consumed a
|
|
357
|
-
// leaf block. Otherwise, it is assumed to have opened a context.
|
|
358
|
-
const DefaultBlockParsers = {
|
|
359
|
-
LinkReference: undefined,
|
|
360
|
-
IndentedCode(cx, line) {
|
|
361
|
-
let base = line.baseIndent + 4;
|
|
362
|
-
if (line.indent < base)
|
|
363
|
-
return false;
|
|
364
|
-
let start = line.findColumn(base);
|
|
365
|
-
let from = cx.lineStart + start, to = cx.lineStart + line.text.length;
|
|
366
|
-
let marks = [], pendingMarks = [];
|
|
367
|
-
addCodeText(marks, from, to);
|
|
368
|
-
while (cx.nextLine() && line.depth >= cx.stack.length) {
|
|
369
|
-
if (line.pos == line.text.length) { // Empty
|
|
370
|
-
addCodeText(pendingMarks, cx.lineStart - 1, cx.lineStart);
|
|
371
|
-
for (let m of line.markers)
|
|
372
|
-
pendingMarks.push(m);
|
|
373
|
-
}
|
|
374
|
-
else if (line.indent < base) {
|
|
375
|
-
break;
|
|
376
|
-
}
|
|
377
|
-
else {
|
|
378
|
-
if (pendingMarks.length) {
|
|
379
|
-
for (let m of pendingMarks) {
|
|
380
|
-
if (m.type == Type.CodeText)
|
|
381
|
-
addCodeText(marks, m.from, m.to);
|
|
382
|
-
else
|
|
383
|
-
marks.push(m);
|
|
384
|
-
}
|
|
385
|
-
pendingMarks = [];
|
|
386
|
-
}
|
|
387
|
-
addCodeText(marks, cx.lineStart - 1, cx.lineStart);
|
|
388
|
-
for (let m of line.markers)
|
|
389
|
-
marks.push(m);
|
|
390
|
-
to = cx.lineStart + line.text.length;
|
|
391
|
-
let codeStart = cx.lineStart + line.findColumn(line.baseIndent + 4);
|
|
392
|
-
if (codeStart < to)
|
|
393
|
-
addCodeText(marks, codeStart, to);
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
if (pendingMarks.length) {
|
|
397
|
-
pendingMarks = pendingMarks.filter(m => m.type != Type.CodeText);
|
|
398
|
-
if (pendingMarks.length)
|
|
399
|
-
line.markers = pendingMarks.concat(line.markers);
|
|
400
|
-
}
|
|
401
|
-
cx.addNode(cx.buffer.writeElements(marks, -from).finish(Type.CodeBlock, to - from), from);
|
|
402
|
-
return true;
|
|
403
|
-
},
|
|
404
|
-
FencedCode(cx, line) {
|
|
405
|
-
let fenceEnd = isFencedCode(line);
|
|
406
|
-
if (fenceEnd < 0)
|
|
407
|
-
return false;
|
|
408
|
-
let from = cx.lineStart + line.pos, ch = line.next, len = fenceEnd - line.pos;
|
|
409
|
-
let infoFrom = line.skipSpace(fenceEnd), infoTo = skipSpaceBack(line.text, line.text.length, infoFrom);
|
|
410
|
-
let marks = [elt(Type.CodeMark, from, from + len)];
|
|
411
|
-
if (infoFrom < infoTo)
|
|
412
|
-
marks.push(elt(Type.CodeInfo, cx.lineStart + infoFrom, cx.lineStart + infoTo));
|
|
413
|
-
for (let first = true; cx.nextLine() && line.depth >= cx.stack.length; first = false) {
|
|
414
|
-
let i = line.pos;
|
|
415
|
-
if (line.indent - line.baseIndent < 4)
|
|
416
|
-
while (i < line.text.length && line.text.charCodeAt(i) == ch)
|
|
417
|
-
i++;
|
|
418
|
-
if (i - line.pos >= len && line.skipSpace(i) == line.text.length) {
|
|
419
|
-
for (let m of line.markers)
|
|
420
|
-
marks.push(m);
|
|
421
|
-
marks.push(elt(Type.CodeMark, cx.lineStart + line.pos, cx.lineStart + i));
|
|
422
|
-
cx.nextLine();
|
|
423
|
-
break;
|
|
424
|
-
}
|
|
425
|
-
else {
|
|
426
|
-
if (!first)
|
|
427
|
-
addCodeText(marks, cx.lineStart - 1, cx.lineStart);
|
|
428
|
-
for (let m of line.markers)
|
|
429
|
-
marks.push(m);
|
|
430
|
-
let textStart = cx.lineStart + line.basePos, textEnd = cx.lineStart + line.text.length;
|
|
431
|
-
if (textStart < textEnd)
|
|
432
|
-
addCodeText(marks, textStart, textEnd);
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
cx.addNode(cx.buffer.writeElements(marks, -from)
|
|
436
|
-
.finish(Type.FencedCode, cx.prevLineEnd() - from), from);
|
|
437
|
-
return true;
|
|
438
|
-
},
|
|
439
|
-
Blockquote(cx, line) {
|
|
440
|
-
let size = isBlockquote(line);
|
|
441
|
-
if (size < 0)
|
|
442
|
-
return false;
|
|
443
|
-
cx.startContext(Type.Blockquote, line.pos);
|
|
444
|
-
cx.addNode(Type.QuoteMark, cx.lineStart + line.pos, cx.lineStart + line.pos + 1);
|
|
445
|
-
line.moveBase(line.pos + size);
|
|
446
|
-
return null;
|
|
447
|
-
},
|
|
448
|
-
HorizontalRule(cx, line) {
|
|
449
|
-
if (isHorizontalRule(line, cx, false) < 0)
|
|
450
|
-
return false;
|
|
451
|
-
let from = cx.lineStart + line.pos;
|
|
452
|
-
cx.nextLine();
|
|
453
|
-
cx.addNode(Type.HorizontalRule, from);
|
|
454
|
-
return true;
|
|
455
|
-
},
|
|
456
|
-
BulletList(cx, line) {
|
|
457
|
-
let size = isBulletList(line, cx, false);
|
|
458
|
-
if (size < 0)
|
|
459
|
-
return false;
|
|
460
|
-
if (cx.block.type != Type.BulletList)
|
|
461
|
-
cx.startContext(Type.BulletList, line.basePos, line.next);
|
|
462
|
-
let newBase = getListIndent(line, line.pos + 1);
|
|
463
|
-
cx.startContext(Type.ListItem, line.basePos, newBase - line.baseIndent);
|
|
464
|
-
cx.addNode(Type.ListMark, cx.lineStart + line.pos, cx.lineStart + line.pos + size);
|
|
465
|
-
line.moveBaseColumn(newBase);
|
|
466
|
-
return null;
|
|
467
|
-
},
|
|
468
|
-
OrderedList(cx, line) {
|
|
469
|
-
let size = isOrderedList(line, cx, false);
|
|
470
|
-
if (size < 0)
|
|
471
|
-
return false;
|
|
472
|
-
if (cx.block.type != Type.OrderedList)
|
|
473
|
-
cx.startContext(Type.OrderedList, line.basePos, line.text.charCodeAt(line.pos + size - 1));
|
|
474
|
-
let newBase = getListIndent(line, line.pos + size);
|
|
475
|
-
cx.startContext(Type.ListItem, line.basePos, newBase - line.baseIndent);
|
|
476
|
-
cx.addNode(Type.ListMark, cx.lineStart + line.pos, cx.lineStart + line.pos + size);
|
|
477
|
-
line.moveBaseColumn(newBase);
|
|
478
|
-
return null;
|
|
479
|
-
},
|
|
480
|
-
ATXHeading(cx, line) {
|
|
481
|
-
let size = isAtxHeading(line);
|
|
482
|
-
if (size < 0)
|
|
483
|
-
return false;
|
|
484
|
-
let off = line.pos, from = cx.lineStart + off;
|
|
485
|
-
let endOfSpace = skipSpaceBack(line.text, line.text.length, off), after = endOfSpace;
|
|
486
|
-
while (after > off && line.text.charCodeAt(after - 1) == line.next)
|
|
487
|
-
after--;
|
|
488
|
-
if (after == endOfSpace || after == off || !space(line.text.charCodeAt(after - 1)))
|
|
489
|
-
after = line.text.length;
|
|
490
|
-
let buf = cx.buffer
|
|
491
|
-
.write(Type.HeaderMark, 0, size)
|
|
492
|
-
.writeElements(cx.parser.parseInline(line.text.slice(off + size + 1, after), from + size + 1), -from);
|
|
493
|
-
if (after < line.text.length)
|
|
494
|
-
buf.write(Type.HeaderMark, after - off, endOfSpace - off);
|
|
495
|
-
let node = buf.finish(Type.ATXHeading1 - 1 + size, line.text.length - off);
|
|
496
|
-
cx.nextLine();
|
|
497
|
-
cx.addNode(node, from);
|
|
498
|
-
return true;
|
|
499
|
-
},
|
|
500
|
-
HTMLBlock(cx, line) {
|
|
501
|
-
let type = isHTMLBlock(line, cx, false);
|
|
502
|
-
if (type < 0)
|
|
503
|
-
return false;
|
|
504
|
-
let from = cx.lineStart + line.pos, end = HTMLBlockStyle[type][1];
|
|
505
|
-
let marks = [], trailing = end != EmptyLine;
|
|
506
|
-
while (!end.test(line.text) && cx.nextLine()) {
|
|
507
|
-
if (line.depth < cx.stack.length) {
|
|
508
|
-
trailing = false;
|
|
509
|
-
break;
|
|
510
|
-
}
|
|
511
|
-
for (let m of line.markers)
|
|
512
|
-
marks.push(m);
|
|
513
|
-
}
|
|
514
|
-
if (trailing)
|
|
515
|
-
cx.nextLine();
|
|
516
|
-
let nodeType = end == CommentEnd ? Type.CommentBlock : end == ProcessingEnd ? Type.ProcessingInstructionBlock : Type.HTMLBlock;
|
|
517
|
-
let to = cx.prevLineEnd();
|
|
518
|
-
cx.addNode(cx.buffer.writeElements(marks, -from).finish(nodeType, to - from), from);
|
|
519
|
-
return true;
|
|
520
|
-
},
|
|
521
|
-
SetextHeading: undefined // Specifies relative precedence for block-continue function
|
|
522
|
-
};
|
|
523
|
-
// This implements a state machine that incrementally parses link references. At each
|
|
524
|
-
// next line, it looks ahead to see if the line continues the reference or not. If it
|
|
525
|
-
// doesn't and a valid link is available ending before that line, it finishes that.
|
|
526
|
-
// Similarly, on `finish` (when the leaf is terminated by external circumstances), it
|
|
527
|
-
// creates a link reference if there's a valid reference up to the current point.
|
|
528
|
-
class LinkReferenceParser {
|
|
529
|
-
constructor(leaf) {
|
|
530
|
-
this.stage = 0 /* RefStage.Start */;
|
|
531
|
-
this.elts = [];
|
|
532
|
-
this.pos = 0;
|
|
533
|
-
this.start = leaf.start;
|
|
534
|
-
this.advance(leaf.content);
|
|
535
|
-
}
|
|
536
|
-
nextLine(cx, line, leaf) {
|
|
537
|
-
if (this.stage == -1 /* RefStage.Failed */)
|
|
538
|
-
return false;
|
|
539
|
-
let content = leaf.content + "\n" + line.scrub();
|
|
540
|
-
let finish = this.advance(content);
|
|
541
|
-
if (finish > -1 && finish < content.length)
|
|
542
|
-
return this.complete(cx, leaf, finish);
|
|
543
|
-
return false;
|
|
544
|
-
}
|
|
545
|
-
finish(cx, leaf) {
|
|
546
|
-
if ((this.stage == 2 /* RefStage.Link */ || this.stage == 3 /* RefStage.Title */) && skipSpace(leaf.content, this.pos) == leaf.content.length)
|
|
547
|
-
return this.complete(cx, leaf, leaf.content.length);
|
|
548
|
-
return false;
|
|
549
|
-
}
|
|
550
|
-
complete(cx, leaf, len) {
|
|
551
|
-
cx.addLeafElement(leaf, elt(Type.LinkReference, this.start, this.start + len, this.elts));
|
|
552
|
-
return true;
|
|
553
|
-
}
|
|
554
|
-
nextStage(elt) {
|
|
555
|
-
if (elt) {
|
|
556
|
-
this.pos = elt.to - this.start;
|
|
557
|
-
this.elts.push(elt);
|
|
558
|
-
this.stage++;
|
|
559
|
-
return true;
|
|
560
|
-
}
|
|
561
|
-
if (elt === false)
|
|
562
|
-
this.stage = -1 /* RefStage.Failed */;
|
|
563
|
-
return false;
|
|
564
|
-
}
|
|
565
|
-
advance(content) {
|
|
566
|
-
for (;;) {
|
|
567
|
-
if (this.stage == -1 /* RefStage.Failed */) {
|
|
568
|
-
return -1;
|
|
569
|
-
}
|
|
570
|
-
else if (this.stage == 0 /* RefStage.Start */) {
|
|
571
|
-
if (!this.nextStage(parseLinkLabel(content, this.pos, this.start, true)))
|
|
572
|
-
return -1;
|
|
573
|
-
if (content.charCodeAt(this.pos) != 58 /* ':' */)
|
|
574
|
-
return this.stage = -1 /* RefStage.Failed */;
|
|
575
|
-
this.elts.push(elt(Type.LinkMark, this.pos + this.start, this.pos + this.start + 1));
|
|
576
|
-
this.pos++;
|
|
577
|
-
}
|
|
578
|
-
else if (this.stage == 1 /* RefStage.Label */) {
|
|
579
|
-
if (!this.nextStage(parseURL(content, skipSpace(content, this.pos), this.start)))
|
|
580
|
-
return -1;
|
|
581
|
-
}
|
|
582
|
-
else if (this.stage == 2 /* RefStage.Link */) {
|
|
583
|
-
let skip = skipSpace(content, this.pos), end = 0;
|
|
584
|
-
if (skip > this.pos) {
|
|
585
|
-
let title = parseLinkTitle(content, skip, this.start);
|
|
586
|
-
if (title) {
|
|
587
|
-
let titleEnd = lineEnd(content, title.to - this.start);
|
|
588
|
-
if (titleEnd > 0) {
|
|
589
|
-
this.nextStage(title);
|
|
590
|
-
end = titleEnd;
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
if (!end)
|
|
595
|
-
end = lineEnd(content, this.pos);
|
|
596
|
-
return end > 0 && end < content.length ? end : -1;
|
|
597
|
-
}
|
|
598
|
-
else { // RefStage.Title
|
|
599
|
-
return lineEnd(content, this.pos);
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
function lineEnd(text, pos) {
|
|
605
|
-
for (; pos < text.length; pos++) {
|
|
606
|
-
let next = text.charCodeAt(pos);
|
|
607
|
-
if (next == 10)
|
|
608
|
-
break;
|
|
609
|
-
if (!space(next))
|
|
610
|
-
return -1;
|
|
611
|
-
}
|
|
612
|
-
return pos;
|
|
613
|
-
}
|
|
614
|
-
class SetextHeadingParser {
|
|
615
|
-
nextLine(cx, line, leaf) {
|
|
616
|
-
let underline = line.depth < cx.stack.length ? -1 : isSetextUnderline(line);
|
|
617
|
-
let next = line.next;
|
|
618
|
-
if (underline < 0)
|
|
619
|
-
return false;
|
|
620
|
-
let underlineMark = elt(Type.HeaderMark, cx.lineStart + line.pos, cx.lineStart + underline);
|
|
621
|
-
cx.nextLine();
|
|
622
|
-
cx.addLeafElement(leaf, elt(next == 61 ? Type.SetextHeading1 : Type.SetextHeading2, leaf.start, cx.prevLineEnd(), [
|
|
623
|
-
...cx.parser.parseInline(leaf.content, leaf.start),
|
|
624
|
-
underlineMark
|
|
625
|
-
]));
|
|
626
|
-
return true;
|
|
627
|
-
}
|
|
628
|
-
finish() {
|
|
629
|
-
return false;
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
const DefaultLeafBlocks = {
|
|
633
|
-
LinkReference(_, leaf) { return leaf.content.charCodeAt(0) == 91 /* '[' */ ? new LinkReferenceParser(leaf) : null; },
|
|
634
|
-
SetextHeading() { return new SetextHeadingParser; }
|
|
635
|
-
};
|
|
636
|
-
const DefaultEndLeaf = [
|
|
637
|
-
(_, line) => isAtxHeading(line) >= 0,
|
|
638
|
-
(_, line) => isFencedCode(line) >= 0,
|
|
639
|
-
(_, line) => isBlockquote(line) >= 0,
|
|
640
|
-
(p, line) => isBulletList(line, p, true) >= 0,
|
|
641
|
-
(p, line) => isOrderedList(line, p, true) >= 0,
|
|
642
|
-
(p, line) => isHorizontalRule(line, p, true) >= 0,
|
|
643
|
-
(p, line) => isHTMLBlock(line, p, true) >= 0
|
|
644
|
-
];
|
|
645
|
-
const scanLineResult = { text: "", end: 0 };
|
|
646
|
-
/// Block-level parsing functions get access to this context object.
|
|
647
|
-
class BlockContext {
|
|
648
|
-
/// @internal
|
|
649
|
-
constructor(
|
|
650
|
-
/// The parser configuration used.
|
|
651
|
-
parser,
|
|
652
|
-
/// @internal
|
|
653
|
-
input, fragments,
|
|
654
|
-
/// @internal
|
|
655
|
-
ranges) {
|
|
656
|
-
this.parser = parser;
|
|
657
|
-
this.input = input;
|
|
658
|
-
this.ranges = ranges;
|
|
659
|
-
this.line = new Line();
|
|
660
|
-
this.atEnd = false;
|
|
661
|
-
/// For reused nodes on gaps, we can't directly put the original
|
|
662
|
-
/// node into the tree, since that may be bitter than its parent.
|
|
663
|
-
/// When this happens, we create a dummy tree that is replaced by
|
|
664
|
-
/// the proper node in `injectGaps` @internal
|
|
665
|
-
this.reusePlaceholders = new Map;
|
|
666
|
-
this.stoppedAt = null;
|
|
667
|
-
/// The range index that absoluteLineStart points into @internal
|
|
668
|
-
this.rangeI = 0;
|
|
669
|
-
this.to = ranges[ranges.length - 1].to;
|
|
670
|
-
this.lineStart = this.absoluteLineStart = this.absoluteLineEnd = ranges[0].from;
|
|
671
|
-
this.block = CompositeBlock.create(Type.Document, 0, this.lineStart, 0, 0);
|
|
672
|
-
this.stack = [this.block];
|
|
673
|
-
this.fragments = fragments.length ? new FragmentCursor(fragments, input) : null;
|
|
674
|
-
this.readLine();
|
|
675
|
-
}
|
|
676
|
-
get parsedPos() {
|
|
677
|
-
return this.absoluteLineStart;
|
|
678
|
-
}
|
|
679
|
-
advance() {
|
|
680
|
-
if (this.stoppedAt != null && this.absoluteLineStart > this.stoppedAt)
|
|
681
|
-
return this.finish();
|
|
682
|
-
let { line } = this;
|
|
683
|
-
for (;;) {
|
|
684
|
-
for (let markI = 0;;) {
|
|
685
|
-
let next = line.depth < this.stack.length ? this.stack[this.stack.length - 1] : null;
|
|
686
|
-
while (markI < line.markers.length && (!next || line.markers[markI].from < next.end)) {
|
|
687
|
-
let mark = line.markers[markI++];
|
|
688
|
-
this.addNode(mark.type, mark.from, mark.to);
|
|
689
|
-
}
|
|
690
|
-
if (!next)
|
|
691
|
-
break;
|
|
692
|
-
this.finishContext();
|
|
693
|
-
}
|
|
694
|
-
if (line.pos < line.text.length)
|
|
695
|
-
break;
|
|
696
|
-
// Empty line
|
|
697
|
-
if (!this.nextLine())
|
|
698
|
-
return this.finish();
|
|
699
|
-
}
|
|
700
|
-
if (this.fragments && this.reuseFragment(line.basePos))
|
|
701
|
-
return null;
|
|
702
|
-
start: for (;;) {
|
|
703
|
-
for (let type of this.parser.blockParsers)
|
|
704
|
-
if (type) {
|
|
705
|
-
let result = type(this, line);
|
|
706
|
-
if (result != false) {
|
|
707
|
-
if (result == true)
|
|
708
|
-
return null;
|
|
709
|
-
line.forward();
|
|
710
|
-
continue start;
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
|
-
break;
|
|
714
|
-
}
|
|
715
|
-
let leaf = new LeafBlock(this.lineStart + line.pos, line.text.slice(line.pos));
|
|
716
|
-
for (let parse of this.parser.leafBlockParsers)
|
|
717
|
-
if (parse) {
|
|
718
|
-
let parser = parse(this, leaf);
|
|
719
|
-
if (parser)
|
|
720
|
-
leaf.parsers.push(parser);
|
|
721
|
-
}
|
|
722
|
-
lines: while (this.nextLine()) {
|
|
723
|
-
if (line.pos == line.text.length)
|
|
724
|
-
break;
|
|
725
|
-
if (line.indent < line.baseIndent + 4) {
|
|
726
|
-
for (let stop of this.parser.endLeafBlock)
|
|
727
|
-
if (stop(this, line, leaf))
|
|
728
|
-
break lines;
|
|
729
|
-
}
|
|
730
|
-
for (let parser of leaf.parsers)
|
|
731
|
-
if (parser.nextLine(this, line, leaf))
|
|
732
|
-
return null;
|
|
733
|
-
leaf.content += "\n" + line.scrub();
|
|
734
|
-
for (let m of line.markers)
|
|
735
|
-
leaf.marks.push(m);
|
|
736
|
-
}
|
|
737
|
-
this.finishLeaf(leaf);
|
|
738
|
-
return null;
|
|
739
|
-
}
|
|
740
|
-
stopAt(pos) {
|
|
741
|
-
if (this.stoppedAt != null && this.stoppedAt < pos)
|
|
742
|
-
throw new RangeError("Can't move stoppedAt forward");
|
|
743
|
-
this.stoppedAt = pos;
|
|
744
|
-
}
|
|
745
|
-
reuseFragment(start) {
|
|
746
|
-
if (!this.fragments.moveTo(this.absoluteLineStart + start, this.absoluteLineStart) ||
|
|
747
|
-
!this.fragments.matches(this.block.hash))
|
|
748
|
-
return false;
|
|
749
|
-
let taken = this.fragments.takeNodes(this);
|
|
750
|
-
if (!taken)
|
|
751
|
-
return false;
|
|
752
|
-
this.absoluteLineStart += taken;
|
|
753
|
-
this.lineStart = toRelative(this.absoluteLineStart, this.ranges);
|
|
754
|
-
this.moveRangeI();
|
|
755
|
-
if (this.absoluteLineStart < this.to) {
|
|
756
|
-
this.lineStart++;
|
|
757
|
-
this.absoluteLineStart++;
|
|
758
|
-
this.readLine();
|
|
759
|
-
}
|
|
760
|
-
else {
|
|
761
|
-
this.atEnd = true;
|
|
762
|
-
this.readLine();
|
|
763
|
-
}
|
|
764
|
-
return true;
|
|
765
|
-
}
|
|
766
|
-
/// The number of parent blocks surrounding the current block.
|
|
767
|
-
get depth() {
|
|
768
|
-
return this.stack.length;
|
|
769
|
-
}
|
|
770
|
-
/// Get the type of the parent block at the given depth. When no
|
|
771
|
-
/// depth is passed, return the type of the innermost parent.
|
|
772
|
-
parentType(depth = this.depth - 1) {
|
|
773
|
-
return this.parser.nodeSet.types[this.stack[depth].type];
|
|
774
|
-
}
|
|
775
|
-
/// Move to the next input line. This should only be called by
|
|
776
|
-
/// (non-composite) [block parsers](#BlockParser.parse) that consume
|
|
777
|
-
/// the line directly, or leaf block parser
|
|
778
|
-
/// [`nextLine`](#LeafBlockParser.nextLine) methods when they
|
|
779
|
-
/// consume the current line (and return true).
|
|
780
|
-
nextLine() {
|
|
781
|
-
this.lineStart += this.line.text.length;
|
|
782
|
-
if (this.absoluteLineEnd >= this.to) {
|
|
783
|
-
this.absoluteLineStart = this.absoluteLineEnd;
|
|
784
|
-
this.atEnd = true;
|
|
785
|
-
this.readLine();
|
|
786
|
-
return false;
|
|
787
|
-
}
|
|
788
|
-
else {
|
|
789
|
-
this.lineStart++;
|
|
790
|
-
this.absoluteLineStart = this.absoluteLineEnd + 1;
|
|
791
|
-
this.moveRangeI();
|
|
792
|
-
this.readLine();
|
|
793
|
-
return true;
|
|
794
|
-
}
|
|
795
|
-
}
|
|
796
|
-
moveRangeI() {
|
|
797
|
-
while (this.rangeI < this.ranges.length - 1 && this.absoluteLineStart >= this.ranges[this.rangeI].to) {
|
|
798
|
-
this.rangeI++;
|
|
799
|
-
this.absoluteLineStart = Math.max(this.absoluteLineStart, this.ranges[this.rangeI].from);
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
/// @internal
|
|
803
|
-
scanLine(start) {
|
|
804
|
-
let r = scanLineResult;
|
|
805
|
-
r.end = start;
|
|
806
|
-
if (start >= this.to) {
|
|
807
|
-
r.text = "";
|
|
808
|
-
}
|
|
809
|
-
else {
|
|
810
|
-
r.text = this.lineChunkAt(start);
|
|
811
|
-
r.end += r.text.length;
|
|
812
|
-
if (this.ranges.length > 1) {
|
|
813
|
-
let textOffset = this.absoluteLineStart, rangeI = this.rangeI;
|
|
814
|
-
while (this.ranges[rangeI].to < r.end) {
|
|
815
|
-
rangeI++;
|
|
816
|
-
let nextFrom = this.ranges[rangeI].from;
|
|
817
|
-
let after = this.lineChunkAt(nextFrom);
|
|
818
|
-
r.end = nextFrom + after.length;
|
|
819
|
-
r.text = r.text.slice(0, this.ranges[rangeI - 1].to - textOffset) + after;
|
|
820
|
-
textOffset = r.end - r.text.length;
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
|
-
}
|
|
824
|
-
return r;
|
|
825
|
-
}
|
|
826
|
-
/// @internal
|
|
827
|
-
readLine() {
|
|
828
|
-
let { line } = this, { text, end } = this.scanLine(this.absoluteLineStart);
|
|
829
|
-
this.absoluteLineEnd = end;
|
|
830
|
-
line.reset(text);
|
|
831
|
-
for (; line.depth < this.stack.length; line.depth++) {
|
|
832
|
-
let cx = this.stack[line.depth], handler = this.parser.skipContextMarkup[cx.type];
|
|
833
|
-
if (!handler)
|
|
834
|
-
throw new Error("Unhandled block context " + Type[cx.type]);
|
|
835
|
-
if (!handler(cx, this, line))
|
|
836
|
-
break;
|
|
837
|
-
line.forward();
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
lineChunkAt(pos) {
|
|
841
|
-
let next = this.input.chunk(pos), text;
|
|
842
|
-
if (!this.input.lineChunks) {
|
|
843
|
-
let eol = next.indexOf("\n");
|
|
844
|
-
text = eol < 0 ? next : next.slice(0, eol);
|
|
845
|
-
}
|
|
846
|
-
else {
|
|
847
|
-
text = next == "\n" ? "" : next;
|
|
848
|
-
}
|
|
849
|
-
return pos + text.length > this.to ? text.slice(0, this.to - pos) : text;
|
|
850
|
-
}
|
|
851
|
-
/// The end position of the previous line.
|
|
852
|
-
prevLineEnd() { return this.atEnd ? this.lineStart : this.lineStart - 1; }
|
|
853
|
-
/// @internal
|
|
854
|
-
startContext(type, start, value = 0) {
|
|
855
|
-
this.block = CompositeBlock.create(type, value, this.lineStart + start, this.block.hash, this.lineStart + this.line.text.length);
|
|
856
|
-
this.stack.push(this.block);
|
|
857
|
-
}
|
|
858
|
-
/// Start a composite block. Should only be called from [block
|
|
859
|
-
/// parser functions](#BlockParser.parse) that return null.
|
|
860
|
-
startComposite(type, start, value = 0) {
|
|
861
|
-
this.startContext(this.parser.getNodeType(type), start, value);
|
|
862
|
-
}
|
|
863
|
-
/// @internal
|
|
864
|
-
addNode(block, from, to) {
|
|
865
|
-
if (typeof block == "number")
|
|
866
|
-
block = new Tree(this.parser.nodeSet.types[block], none, none, (to !== null && to !== void 0 ? to : this.prevLineEnd()) - from);
|
|
867
|
-
this.block.addChild(block, from - this.block.from);
|
|
868
|
-
}
|
|
869
|
-
/// Add a block element. Can be called by [block
|
|
870
|
-
/// parsers](#BlockParser.parse).
|
|
871
|
-
addElement(elt) {
|
|
872
|
-
this.block.addChild(elt.toTree(this.parser.nodeSet), elt.from - this.block.from);
|
|
873
|
-
}
|
|
874
|
-
/// Add a block element from a [leaf parser](#LeafBlockParser). This
|
|
875
|
-
/// makes sure any extra composite block markup (such as blockquote
|
|
876
|
-
/// markers) inside the block are also added to the syntax tree.
|
|
877
|
-
addLeafElement(leaf, elt) {
|
|
878
|
-
this.addNode(this.buffer
|
|
879
|
-
.writeElements(injectMarks(elt.children, leaf.marks), -elt.from)
|
|
880
|
-
.finish(elt.type, elt.to - elt.from), elt.from);
|
|
881
|
-
}
|
|
882
|
-
/// @internal
|
|
883
|
-
finishContext() {
|
|
884
|
-
let cx = this.stack.pop();
|
|
885
|
-
let top = this.stack[this.stack.length - 1];
|
|
886
|
-
top.addChild(cx.toTree(this.parser.nodeSet), cx.from - top.from);
|
|
887
|
-
this.block = top;
|
|
888
|
-
}
|
|
889
|
-
finish() {
|
|
890
|
-
while (this.stack.length > 1)
|
|
891
|
-
this.finishContext();
|
|
892
|
-
return this.addGaps(this.block.toTree(this.parser.nodeSet, this.lineStart));
|
|
893
|
-
}
|
|
894
|
-
addGaps(tree) {
|
|
895
|
-
return this.ranges.length > 1 ?
|
|
896
|
-
injectGaps(this.ranges, 0, tree.topNode, this.ranges[0].from, this.reusePlaceholders) : tree;
|
|
897
|
-
}
|
|
898
|
-
/// @internal
|
|
899
|
-
finishLeaf(leaf) {
|
|
900
|
-
for (let parser of leaf.parsers)
|
|
901
|
-
if (parser.finish(this, leaf))
|
|
902
|
-
return;
|
|
903
|
-
let inline = injectMarks(this.parser.parseInline(leaf.content, leaf.start), leaf.marks);
|
|
904
|
-
this.addNode(this.buffer
|
|
905
|
-
.writeElements(inline, -leaf.start)
|
|
906
|
-
.finish(Type.Paragraph, leaf.content.length), leaf.start);
|
|
907
|
-
}
|
|
908
|
-
elt(type, from, to, children) {
|
|
909
|
-
if (typeof type == "string")
|
|
910
|
-
return elt(this.parser.getNodeType(type), from, to, children);
|
|
911
|
-
return new TreeElement(type, from);
|
|
912
|
-
}
|
|
913
|
-
/// @internal
|
|
914
|
-
get buffer() { return new Buffer(this.parser.nodeSet); }
|
|
915
|
-
}
|
|
916
|
-
function injectGaps(ranges, rangeI, tree, offset, dummies) {
|
|
917
|
-
let rangeEnd = ranges[rangeI].to;
|
|
918
|
-
let children = [], positions = [], start = tree.from + offset;
|
|
919
|
-
function movePastNext(upto, inclusive) {
|
|
920
|
-
while (inclusive ? upto >= rangeEnd : upto > rangeEnd) {
|
|
921
|
-
let size = ranges[rangeI + 1].from - rangeEnd;
|
|
922
|
-
offset += size;
|
|
923
|
-
upto += size;
|
|
924
|
-
rangeI++;
|
|
925
|
-
rangeEnd = ranges[rangeI].to;
|
|
926
|
-
}
|
|
927
|
-
}
|
|
928
|
-
for (let ch = tree.firstChild; ch; ch = ch.nextSibling) {
|
|
929
|
-
movePastNext(ch.from + offset, true);
|
|
930
|
-
let from = ch.from + offset, node, reuse = dummies.get(ch.tree);
|
|
931
|
-
if (reuse) {
|
|
932
|
-
node = reuse;
|
|
933
|
-
}
|
|
934
|
-
else if (ch.to + offset > rangeEnd) {
|
|
935
|
-
node = injectGaps(ranges, rangeI, ch, offset, dummies);
|
|
936
|
-
movePastNext(ch.to + offset, false);
|
|
937
|
-
}
|
|
938
|
-
else {
|
|
939
|
-
node = ch.toTree();
|
|
940
|
-
}
|
|
941
|
-
children.push(node);
|
|
942
|
-
positions.push(from - start);
|
|
943
|
-
}
|
|
944
|
-
movePastNext(tree.to + offset, false);
|
|
945
|
-
return new Tree(tree.type, children, positions, tree.to + offset - start, tree.tree ? tree.tree.propValues : undefined);
|
|
946
|
-
}
|
|
947
|
-
/// A Markdown parser configuration.
|
|
948
|
-
class MarkdownParser extends Parser {
|
|
949
|
-
/// @internal
|
|
950
|
-
constructor(
|
|
951
|
-
/// The parser's syntax [node
|
|
952
|
-
/// types](https://lezer.codemirror.net/docs/ref/#common.NodeSet).
|
|
953
|
-
nodeSet,
|
|
954
|
-
/// @internal
|
|
955
|
-
blockParsers,
|
|
956
|
-
/// @internal
|
|
957
|
-
leafBlockParsers,
|
|
958
|
-
/// @internal
|
|
959
|
-
blockNames,
|
|
960
|
-
/// @internal
|
|
961
|
-
endLeafBlock,
|
|
962
|
-
/// @internal
|
|
963
|
-
skipContextMarkup,
|
|
964
|
-
/// @internal
|
|
965
|
-
inlineParsers,
|
|
966
|
-
/// @internal
|
|
967
|
-
inlineNames,
|
|
968
|
-
/// @internal
|
|
969
|
-
wrappers) {
|
|
970
|
-
super();
|
|
971
|
-
this.nodeSet = nodeSet;
|
|
972
|
-
this.blockParsers = blockParsers;
|
|
973
|
-
this.leafBlockParsers = leafBlockParsers;
|
|
974
|
-
this.blockNames = blockNames;
|
|
975
|
-
this.endLeafBlock = endLeafBlock;
|
|
976
|
-
this.skipContextMarkup = skipContextMarkup;
|
|
977
|
-
this.inlineParsers = inlineParsers;
|
|
978
|
-
this.inlineNames = inlineNames;
|
|
979
|
-
this.wrappers = wrappers;
|
|
980
|
-
/// @internal
|
|
981
|
-
this.nodeTypes = Object.create(null);
|
|
982
|
-
for (let t of nodeSet.types)
|
|
983
|
-
this.nodeTypes[t.name] = t.id;
|
|
984
|
-
}
|
|
985
|
-
createParse(input, fragments, ranges) {
|
|
986
|
-
let parse = new BlockContext(this, input, fragments, ranges);
|
|
987
|
-
for (let w of this.wrappers)
|
|
988
|
-
parse = w(parse, input, fragments, ranges);
|
|
989
|
-
return parse;
|
|
990
|
-
}
|
|
991
|
-
/// Reconfigure the parser.
|
|
992
|
-
configure(spec) {
|
|
993
|
-
let config = resolveConfig(spec);
|
|
994
|
-
if (!config)
|
|
995
|
-
return this;
|
|
996
|
-
let { nodeSet, skipContextMarkup } = this;
|
|
997
|
-
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;
|
|
998
|
-
if (nonEmpty(config.defineNodes)) {
|
|
999
|
-
skipContextMarkup = Object.assign({}, skipContextMarkup);
|
|
1000
|
-
let nodeTypes = nodeSet.types.slice(), styles;
|
|
1001
|
-
for (let s of config.defineNodes) {
|
|
1002
|
-
let { name, block, composite, style } = typeof s == "string" ? { name: s } : s;
|
|
1003
|
-
if (nodeTypes.some(t => t.name == name))
|
|
1004
|
-
continue;
|
|
1005
|
-
if (composite)
|
|
1006
|
-
skipContextMarkup[nodeTypes.length] =
|
|
1007
|
-
(bl, cx, line) => composite(cx, line, bl.value);
|
|
1008
|
-
let id = nodeTypes.length;
|
|
1009
|
-
let group = composite ? ["Block", "BlockContext"] : !block ? undefined
|
|
1010
|
-
: id >= Type.ATXHeading1 && id <= Type.SetextHeading2 ? ["Block", "LeafBlock", "Heading"] : ["Block", "LeafBlock"];
|
|
1011
|
-
nodeTypes.push(NodeType.define({
|
|
1012
|
-
id,
|
|
1013
|
-
name,
|
|
1014
|
-
props: group && [[NodeProp.group, group]]
|
|
1015
|
-
}));
|
|
1016
|
-
if (style) {
|
|
1017
|
-
if (!styles)
|
|
1018
|
-
styles = {};
|
|
1019
|
-
if (Array.isArray(style) || style instanceof Tag)
|
|
1020
|
-
styles[name] = style;
|
|
1021
|
-
else
|
|
1022
|
-
Object.assign(styles, style);
|
|
1023
|
-
}
|
|
1024
|
-
}
|
|
1025
|
-
nodeSet = new NodeSet(nodeTypes);
|
|
1026
|
-
if (styles)
|
|
1027
|
-
nodeSet = nodeSet.extend(styleTags(styles));
|
|
1028
|
-
}
|
|
1029
|
-
if (nonEmpty(config.props))
|
|
1030
|
-
nodeSet = nodeSet.extend(...config.props);
|
|
1031
|
-
if (nonEmpty(config.remove)) {
|
|
1032
|
-
for (let rm of config.remove) {
|
|
1033
|
-
let block = this.blockNames.indexOf(rm), inline = this.inlineNames.indexOf(rm);
|
|
1034
|
-
if (block > -1)
|
|
1035
|
-
blockParsers[block] = leafBlockParsers[block] = undefined;
|
|
1036
|
-
if (inline > -1)
|
|
1037
|
-
inlineParsers[inline] = undefined;
|
|
1038
|
-
}
|
|
1039
|
-
}
|
|
1040
|
-
if (nonEmpty(config.parseBlock)) {
|
|
1041
|
-
for (let spec of config.parseBlock) {
|
|
1042
|
-
let found = blockNames.indexOf(spec.name);
|
|
1043
|
-
if (found > -1) {
|
|
1044
|
-
blockParsers[found] = spec.parse;
|
|
1045
|
-
leafBlockParsers[found] = spec.leaf;
|
|
1046
|
-
}
|
|
1047
|
-
else {
|
|
1048
|
-
let pos = spec.before ? findName(blockNames, spec.before)
|
|
1049
|
-
: spec.after ? findName(blockNames, spec.after) + 1 : blockNames.length - 1;
|
|
1050
|
-
blockParsers.splice(pos, 0, spec.parse);
|
|
1051
|
-
leafBlockParsers.splice(pos, 0, spec.leaf);
|
|
1052
|
-
blockNames.splice(pos, 0, spec.name);
|
|
1053
|
-
}
|
|
1054
|
-
if (spec.endLeaf)
|
|
1055
|
-
endLeafBlock.push(spec.endLeaf);
|
|
1056
|
-
}
|
|
1057
|
-
}
|
|
1058
|
-
if (nonEmpty(config.parseInline)) {
|
|
1059
|
-
for (let spec of config.parseInline) {
|
|
1060
|
-
let found = inlineNames.indexOf(spec.name);
|
|
1061
|
-
if (found > -1) {
|
|
1062
|
-
inlineParsers[found] = spec.parse;
|
|
1063
|
-
}
|
|
1064
|
-
else {
|
|
1065
|
-
let pos = spec.before ? findName(inlineNames, spec.before)
|
|
1066
|
-
: spec.after ? findName(inlineNames, spec.after) + 1 : inlineNames.length - 1;
|
|
1067
|
-
inlineParsers.splice(pos, 0, spec.parse);
|
|
1068
|
-
inlineNames.splice(pos, 0, spec.name);
|
|
1069
|
-
}
|
|
1070
|
-
}
|
|
1071
|
-
}
|
|
1072
|
-
if (config.wrap)
|
|
1073
|
-
wrappers = wrappers.concat(config.wrap);
|
|
1074
|
-
return new MarkdownParser(nodeSet, blockParsers, leafBlockParsers, blockNames, endLeafBlock, skipContextMarkup, inlineParsers, inlineNames, wrappers);
|
|
1075
|
-
}
|
|
1076
|
-
/// @internal
|
|
1077
|
-
getNodeType(name) {
|
|
1078
|
-
let found = this.nodeTypes[name];
|
|
1079
|
-
if (found == null)
|
|
1080
|
-
throw new RangeError(`Unknown node type '${name}'`);
|
|
1081
|
-
return found;
|
|
1082
|
-
}
|
|
1083
|
-
/// Parse the given piece of inline text at the given offset,
|
|
1084
|
-
/// returning an array of [`Element`](#Element) objects representing
|
|
1085
|
-
/// the inline content.
|
|
1086
|
-
parseInline(text, offset) {
|
|
1087
|
-
let cx = new InlineContext(this, text, offset);
|
|
1088
|
-
outer: for (let pos = offset; pos < cx.end;) {
|
|
1089
|
-
let next = cx.char(pos);
|
|
1090
|
-
for (let token of this.inlineParsers)
|
|
1091
|
-
if (token) {
|
|
1092
|
-
let result = token(cx, next, pos);
|
|
1093
|
-
if (result >= 0) {
|
|
1094
|
-
pos = result;
|
|
1095
|
-
continue outer;
|
|
1096
|
-
}
|
|
1097
|
-
}
|
|
1098
|
-
pos++;
|
|
1099
|
-
}
|
|
1100
|
-
return cx.resolveMarkers(0);
|
|
1101
|
-
}
|
|
1102
|
-
}
|
|
1103
|
-
function nonEmpty(a) {
|
|
1104
|
-
return a != null && a.length > 0;
|
|
1105
|
-
}
|
|
1106
|
-
function resolveConfig(spec) {
|
|
1107
|
-
if (!Array.isArray(spec))
|
|
1108
|
-
return spec;
|
|
1109
|
-
if (spec.length == 0)
|
|
1110
|
-
return null;
|
|
1111
|
-
let conf = resolveConfig(spec[0]);
|
|
1112
|
-
if (spec.length == 1)
|
|
1113
|
-
return conf;
|
|
1114
|
-
let rest = resolveConfig(spec.slice(1));
|
|
1115
|
-
if (!rest || !conf)
|
|
1116
|
-
return conf || rest;
|
|
1117
|
-
let conc = (a, b) => (a || none).concat(b || none);
|
|
1118
|
-
let wrapA = conf.wrap, wrapB = rest.wrap;
|
|
1119
|
-
return {
|
|
1120
|
-
props: conc(conf.props, rest.props),
|
|
1121
|
-
defineNodes: conc(conf.defineNodes, rest.defineNodes),
|
|
1122
|
-
parseBlock: conc(conf.parseBlock, rest.parseBlock),
|
|
1123
|
-
parseInline: conc(conf.parseInline, rest.parseInline),
|
|
1124
|
-
remove: conc(conf.remove, rest.remove),
|
|
1125
|
-
wrap: !wrapA ? wrapB : !wrapB ? wrapA :
|
|
1126
|
-
(inner, input, fragments, ranges) => wrapA(wrapB(inner, input, fragments, ranges), input, fragments, ranges)
|
|
1127
|
-
};
|
|
1128
|
-
}
|
|
1129
|
-
function findName(names, name) {
|
|
1130
|
-
let found = names.indexOf(name);
|
|
1131
|
-
if (found < 0)
|
|
1132
|
-
throw new RangeError(`Position specified relative to unknown parser ${name}`);
|
|
1133
|
-
return found;
|
|
1134
|
-
}
|
|
1135
|
-
let nodeTypes = [NodeType.none];
|
|
1136
|
-
for (let i = 1, name; name = Type[i]; i++) {
|
|
1137
|
-
nodeTypes[i] = NodeType.define({
|
|
1138
|
-
id: i,
|
|
1139
|
-
name,
|
|
1140
|
-
props: i >= Type.Escape ? [] : [[NodeProp.group, i in DefaultSkipMarkup ? ["Block", "BlockContext"] : ["Block", "LeafBlock"]]],
|
|
1141
|
-
top: name == "Document"
|
|
1142
|
-
});
|
|
1143
|
-
}
|
|
1144
|
-
const none = [];
|
|
1145
|
-
class Buffer {
|
|
1146
|
-
constructor(nodeSet) {
|
|
1147
|
-
this.nodeSet = nodeSet;
|
|
1148
|
-
this.content = [];
|
|
1149
|
-
this.nodes = [];
|
|
1150
|
-
}
|
|
1151
|
-
write(type, from, to, children = 0) {
|
|
1152
|
-
this.content.push(type, from, to, 4 + children * 4);
|
|
1153
|
-
return this;
|
|
1154
|
-
}
|
|
1155
|
-
writeElements(elts, offset = 0) {
|
|
1156
|
-
for (let e of elts)
|
|
1157
|
-
e.writeTo(this, offset);
|
|
1158
|
-
return this;
|
|
1159
|
-
}
|
|
1160
|
-
finish(type, length) {
|
|
1161
|
-
return Tree.build({
|
|
1162
|
-
buffer: this.content,
|
|
1163
|
-
nodeSet: this.nodeSet,
|
|
1164
|
-
reused: this.nodes,
|
|
1165
|
-
topID: type,
|
|
1166
|
-
length
|
|
1167
|
-
});
|
|
1168
|
-
}
|
|
1169
|
-
}
|
|
1170
|
-
/// Elements are used to compose syntax nodes during parsing.
|
|
1171
|
-
class Element {
|
|
1172
|
-
/// @internal
|
|
1173
|
-
constructor(
|
|
1174
|
-
/// The node's
|
|
1175
|
-
/// [id](https://lezer.codemirror.net/docs/ref/#common.NodeType.id).
|
|
1176
|
-
type,
|
|
1177
|
-
/// The start of the node, as an offset from the start of the document.
|
|
1178
|
-
from,
|
|
1179
|
-
/// The end of the node.
|
|
1180
|
-
to,
|
|
1181
|
-
/// The node's child nodes @internal
|
|
1182
|
-
children = none) {
|
|
1183
|
-
this.type = type;
|
|
1184
|
-
this.from = from;
|
|
1185
|
-
this.to = to;
|
|
1186
|
-
this.children = children;
|
|
1187
|
-
}
|
|
1188
|
-
/// @internal
|
|
1189
|
-
writeTo(buf, offset) {
|
|
1190
|
-
let startOff = buf.content.length;
|
|
1191
|
-
buf.writeElements(this.children, offset);
|
|
1192
|
-
buf.content.push(this.type, this.from + offset, this.to + offset, buf.content.length + 4 - startOff);
|
|
1193
|
-
}
|
|
1194
|
-
/// @internal
|
|
1195
|
-
toTree(nodeSet) {
|
|
1196
|
-
return new Buffer(nodeSet).writeElements(this.children, -this.from).finish(this.type, this.to - this.from);
|
|
1197
|
-
}
|
|
1198
|
-
}
|
|
1199
|
-
class TreeElement {
|
|
1200
|
-
constructor(tree, from) {
|
|
1201
|
-
this.tree = tree;
|
|
1202
|
-
this.from = from;
|
|
1203
|
-
}
|
|
1204
|
-
get to() { return this.from + this.tree.length; }
|
|
1205
|
-
get type() { return this.tree.type.id; }
|
|
1206
|
-
get children() { return none; }
|
|
1207
|
-
writeTo(buf, offset) {
|
|
1208
|
-
buf.nodes.push(this.tree);
|
|
1209
|
-
buf.content.push(buf.nodes.length - 1, this.from + offset, this.to + offset, -1);
|
|
1210
|
-
}
|
|
1211
|
-
toTree() { return this.tree; }
|
|
1212
|
-
}
|
|
1213
|
-
function elt(type, from, to, children) {
|
|
1214
|
-
return new Element(type, from, to, children);
|
|
1215
|
-
}
|
|
1216
|
-
const EmphasisUnderscore = { resolve: "Emphasis", mark: "EmphasisMark" };
|
|
1217
|
-
const EmphasisAsterisk = { resolve: "Emphasis", mark: "EmphasisMark" };
|
|
1218
|
-
const LinkStart = {}, ImageStart = {};
|
|
1219
|
-
class InlineDelimiter {
|
|
1220
|
-
constructor(type, from, to, side) {
|
|
1221
|
-
this.type = type;
|
|
1222
|
-
this.from = from;
|
|
1223
|
-
this.to = to;
|
|
1224
|
-
this.side = side;
|
|
1225
|
-
}
|
|
1226
|
-
}
|
|
1227
|
-
const Escapable = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";
|
|
1228
|
-
let Punctuation = /[!"#$%&'()*+,\-.\/:;<=>?@\[\\\]^_`{|}~\xA1\u2010-\u2027]/;
|
|
1229
|
-
try {
|
|
1230
|
-
Punctuation = new RegExp("[\\p{Pc}|\\p{Pd}|\\p{Pe}|\\p{Pf}|\\p{Pi}|\\p{Po}|\\p{Ps}]", "u");
|
|
1231
|
-
}
|
|
1232
|
-
catch (_) { }
|
|
1233
|
-
const DefaultInline = {
|
|
1234
|
-
Escape(cx, next, start) {
|
|
1235
|
-
if (next != 92 /* '\\' */ || start == cx.end - 1)
|
|
1236
|
-
return -1;
|
|
1237
|
-
let escaped = cx.char(start + 1);
|
|
1238
|
-
for (let i = 0; i < Escapable.length; i++)
|
|
1239
|
-
if (Escapable.charCodeAt(i) == escaped)
|
|
1240
|
-
return cx.append(elt(Type.Escape, start, start + 2));
|
|
1241
|
-
return -1;
|
|
1242
|
-
},
|
|
1243
|
-
Entity(cx, next, start) {
|
|
1244
|
-
if (next != 38 /* '&' */)
|
|
1245
|
-
return -1;
|
|
1246
|
-
let m = /^(?:#\d+|#x[a-f\d]+|\w+);/i.exec(cx.slice(start + 1, start + 31));
|
|
1247
|
-
return m ? cx.append(elt(Type.Entity, start, start + 1 + m[0].length)) : -1;
|
|
1248
|
-
},
|
|
1249
|
-
InlineCode(cx, next, start) {
|
|
1250
|
-
if (next != 96 /* '`' */ || start && cx.char(start - 1) == 96)
|
|
1251
|
-
return -1;
|
|
1252
|
-
let pos = start + 1;
|
|
1253
|
-
while (pos < cx.end && cx.char(pos) == 96)
|
|
1254
|
-
pos++;
|
|
1255
|
-
let size = pos - start, curSize = 0;
|
|
1256
|
-
for (; pos < cx.end; pos++) {
|
|
1257
|
-
if (cx.char(pos) == 96) {
|
|
1258
|
-
curSize++;
|
|
1259
|
-
if (curSize == size && cx.char(pos + 1) != 96)
|
|
1260
|
-
return cx.append(elt(Type.InlineCode, start, pos + 1, [
|
|
1261
|
-
elt(Type.CodeMark, start, start + size),
|
|
1262
|
-
elt(Type.CodeMark, pos + 1 - size, pos + 1)
|
|
1263
|
-
]));
|
|
1264
|
-
}
|
|
1265
|
-
else {
|
|
1266
|
-
curSize = 0;
|
|
1267
|
-
}
|
|
1268
|
-
}
|
|
1269
|
-
return -1;
|
|
1270
|
-
},
|
|
1271
|
-
HTMLTag(cx, next, start) {
|
|
1272
|
-
if (next != 60 /* '<' */ || start == cx.end - 1)
|
|
1273
|
-
return -1;
|
|
1274
|
-
let after = cx.slice(start + 1, cx.end);
|
|
1275
|
-
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);
|
|
1276
|
-
if (url)
|
|
1277
|
-
return cx.append(elt(Type.URL, start, start + 1 + url[0].length));
|
|
1278
|
-
let comment = /^!--[^>](?:-[^-]|[^-])*?-->/i.exec(after);
|
|
1279
|
-
if (comment)
|
|
1280
|
-
return cx.append(elt(Type.Comment, start, start + 1 + comment[0].length));
|
|
1281
|
-
let procInst = /^\?[^]*?\?>/.exec(after);
|
|
1282
|
-
if (procInst)
|
|
1283
|
-
return cx.append(elt(Type.ProcessingInstruction, start, start + 1 + procInst[0].length));
|
|
1284
|
-
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);
|
|
1285
|
-
if (!m)
|
|
1286
|
-
return -1;
|
|
1287
|
-
return cx.append(elt(Type.HTMLTag, start, start + 1 + m[0].length));
|
|
1288
|
-
},
|
|
1289
|
-
Emphasis(cx, next, start) {
|
|
1290
|
-
if (next != 95 && next != 42)
|
|
1291
|
-
return -1;
|
|
1292
|
-
let pos = start + 1;
|
|
1293
|
-
while (cx.char(pos) == next)
|
|
1294
|
-
pos++;
|
|
1295
|
-
let before = cx.slice(start - 1, start), after = cx.slice(pos, pos + 1);
|
|
1296
|
-
let pBefore = Punctuation.test(before), pAfter = Punctuation.test(after);
|
|
1297
|
-
let sBefore = /\s|^$/.test(before), sAfter = /\s|^$/.test(after);
|
|
1298
|
-
let leftFlanking = !sAfter && (!pAfter || sBefore || pBefore);
|
|
1299
|
-
let rightFlanking = !sBefore && (!pBefore || sAfter || pAfter);
|
|
1300
|
-
let canOpen = leftFlanking && (next == 42 || !rightFlanking || pBefore);
|
|
1301
|
-
let canClose = rightFlanking && (next == 42 || !leftFlanking || pAfter);
|
|
1302
|
-
return cx.append(new InlineDelimiter(next == 95 ? EmphasisUnderscore : EmphasisAsterisk, start, pos, (canOpen ? 1 /* Mark.Open */ : 0 /* Mark.None */) | (canClose ? 2 /* Mark.Close */ : 0 /* Mark.None */)));
|
|
1303
|
-
},
|
|
1304
|
-
HardBreak(cx, next, start) {
|
|
1305
|
-
if (next == 92 /* '\\' */ && cx.char(start + 1) == 10 /* '\n' */)
|
|
1306
|
-
return cx.append(elt(Type.HardBreak, start, start + 2));
|
|
1307
|
-
if (next == 32) {
|
|
1308
|
-
let pos = start + 1;
|
|
1309
|
-
while (cx.char(pos) == 32)
|
|
1310
|
-
pos++;
|
|
1311
|
-
if (cx.char(pos) == 10 && pos >= start + 2)
|
|
1312
|
-
return cx.append(elt(Type.HardBreak, start, pos + 1));
|
|
1313
|
-
}
|
|
1314
|
-
return -1;
|
|
1315
|
-
},
|
|
1316
|
-
Link(cx, next, start) {
|
|
1317
|
-
return next == 91 /* '[' */ ? cx.append(new InlineDelimiter(LinkStart, start, start + 1, 1 /* Mark.Open */)) : -1;
|
|
1318
|
-
},
|
|
1319
|
-
Image(cx, next, start) {
|
|
1320
|
-
return next == 33 /* '!' */ && cx.char(start + 1) == 91 /* '[' */
|
|
1321
|
-
? cx.append(new InlineDelimiter(ImageStart, start, start + 2, 1 /* Mark.Open */)) : -1;
|
|
1322
|
-
},
|
|
1323
|
-
LinkEnd(cx, next, start) {
|
|
1324
|
-
if (next != 93 /* ']' */)
|
|
1325
|
-
return -1;
|
|
1326
|
-
// Scanning back to the next link/image start marker
|
|
1327
|
-
for (let i = cx.parts.length - 1; i >= 0; i--) {
|
|
1328
|
-
let part = cx.parts[i];
|
|
1329
|
-
if (part instanceof InlineDelimiter && (part.type == LinkStart || part.type == ImageStart)) {
|
|
1330
|
-
// If this one has been set invalid (because it would produce
|
|
1331
|
-
// a nested link) or there's no valid link here ignore both.
|
|
1332
|
-
if (!part.side || cx.skipSpace(part.to) == start && !/[(\[]/.test(cx.slice(start + 1, start + 2))) {
|
|
1333
|
-
cx.parts[i] = null;
|
|
1334
|
-
return -1;
|
|
1335
|
-
}
|
|
1336
|
-
// Finish the content and replace the entire range in
|
|
1337
|
-
// this.parts with the link/image node.
|
|
1338
|
-
let content = cx.takeContent(i);
|
|
1339
|
-
let link = cx.parts[i] = finishLink(cx, content, part.type == LinkStart ? Type.Link : Type.Image, part.from, start + 1);
|
|
1340
|
-
// Set any open-link markers before this link to invalid.
|
|
1341
|
-
if (part.type == LinkStart)
|
|
1342
|
-
for (let j = 0; j < i; j++) {
|
|
1343
|
-
let p = cx.parts[j];
|
|
1344
|
-
if (p instanceof InlineDelimiter && p.type == LinkStart)
|
|
1345
|
-
p.side = 0 /* Mark.None */;
|
|
1346
|
-
}
|
|
1347
|
-
return link.to;
|
|
1348
|
-
}
|
|
1349
|
-
}
|
|
1350
|
-
return -1;
|
|
1351
|
-
}
|
|
1352
|
-
};
|
|
1353
|
-
function finishLink(cx, content, type, start, startPos) {
|
|
1354
|
-
let { text } = cx, next = cx.char(startPos), endPos = startPos;
|
|
1355
|
-
content.unshift(elt(Type.LinkMark, start, start + (type == Type.Image ? 2 : 1)));
|
|
1356
|
-
content.push(elt(Type.LinkMark, startPos - 1, startPos));
|
|
1357
|
-
if (next == 40 /* '(' */) {
|
|
1358
|
-
let pos = cx.skipSpace(startPos + 1);
|
|
1359
|
-
let dest = parseURL(text, pos - cx.offset, cx.offset), title;
|
|
1360
|
-
if (dest) {
|
|
1361
|
-
pos = cx.skipSpace(dest.to);
|
|
1362
|
-
title = parseLinkTitle(text, pos - cx.offset, cx.offset);
|
|
1363
|
-
if (title)
|
|
1364
|
-
pos = cx.skipSpace(title.to);
|
|
1365
|
-
}
|
|
1366
|
-
if (cx.char(pos) == 41 /* ')' */) {
|
|
1367
|
-
content.push(elt(Type.LinkMark, startPos, startPos + 1));
|
|
1368
|
-
endPos = pos + 1;
|
|
1369
|
-
if (dest)
|
|
1370
|
-
content.push(dest);
|
|
1371
|
-
if (title)
|
|
1372
|
-
content.push(title);
|
|
1373
|
-
content.push(elt(Type.LinkMark, pos, endPos));
|
|
1374
|
-
}
|
|
1375
|
-
}
|
|
1376
|
-
else if (next == 91 /* '[' */) {
|
|
1377
|
-
let label = parseLinkLabel(text, startPos - cx.offset, cx.offset, false);
|
|
1378
|
-
if (label) {
|
|
1379
|
-
content.push(label);
|
|
1380
|
-
endPos = label.to;
|
|
1381
|
-
}
|
|
1382
|
-
}
|
|
1383
|
-
return elt(type, start, endPos, content);
|
|
1384
|
-
}
|
|
1385
|
-
// These return `null` when falling off the end of the input, `false`
|
|
1386
|
-
// when parsing fails otherwise (for use in the incremental link
|
|
1387
|
-
// reference parser).
|
|
1388
|
-
function parseURL(text, start, offset) {
|
|
1389
|
-
let next = text.charCodeAt(start);
|
|
1390
|
-
if (next == 60 /* '<' */) {
|
|
1391
|
-
for (let pos = start + 1; pos < text.length; pos++) {
|
|
1392
|
-
let ch = text.charCodeAt(pos);
|
|
1393
|
-
if (ch == 62 /* '>' */)
|
|
1394
|
-
return elt(Type.URL, start + offset, pos + 1 + offset);
|
|
1395
|
-
if (ch == 60 || ch == 10 /* '<\n' */)
|
|
1396
|
-
return false;
|
|
1397
|
-
}
|
|
1398
|
-
return null;
|
|
1399
|
-
}
|
|
1400
|
-
else {
|
|
1401
|
-
let depth = 0, pos = start;
|
|
1402
|
-
for (let escaped = false; pos < text.length; pos++) {
|
|
1403
|
-
let ch = text.charCodeAt(pos);
|
|
1404
|
-
if (space(ch)) {
|
|
1405
|
-
break;
|
|
1406
|
-
}
|
|
1407
|
-
else if (escaped) {
|
|
1408
|
-
escaped = false;
|
|
1409
|
-
}
|
|
1410
|
-
else if (ch == 40 /* '(' */) {
|
|
1411
|
-
depth++;
|
|
1412
|
-
}
|
|
1413
|
-
else if (ch == 41 /* ')' */) {
|
|
1414
|
-
if (!depth)
|
|
1415
|
-
break;
|
|
1416
|
-
depth--;
|
|
1417
|
-
}
|
|
1418
|
-
else if (ch == 92 /* '\\' */) {
|
|
1419
|
-
escaped = true;
|
|
1420
|
-
}
|
|
1421
|
-
}
|
|
1422
|
-
return pos > start ? elt(Type.URL, start + offset, pos + offset) : pos == text.length ? null : false;
|
|
1423
|
-
}
|
|
1424
|
-
}
|
|
1425
|
-
function parseLinkTitle(text, start, offset) {
|
|
1426
|
-
let next = text.charCodeAt(start);
|
|
1427
|
-
if (next != 39 && next != 34 && next != 40 /* '"\'(' */)
|
|
1428
|
-
return false;
|
|
1429
|
-
let end = next == 40 ? 41 : next;
|
|
1430
|
-
for (let pos = start + 1, escaped = false; pos < text.length; pos++) {
|
|
1431
|
-
let ch = text.charCodeAt(pos);
|
|
1432
|
-
if (escaped)
|
|
1433
|
-
escaped = false;
|
|
1434
|
-
else if (ch == end)
|
|
1435
|
-
return elt(Type.LinkTitle, start + offset, pos + 1 + offset);
|
|
1436
|
-
else if (ch == 92 /* '\\' */)
|
|
1437
|
-
escaped = true;
|
|
1438
|
-
}
|
|
1439
|
-
return null;
|
|
1440
|
-
}
|
|
1441
|
-
function parseLinkLabel(text, start, offset, requireNonWS) {
|
|
1442
|
-
for (let escaped = false, pos = start + 1, end = Math.min(text.length, pos + 999); pos < end; pos++) {
|
|
1443
|
-
let ch = text.charCodeAt(pos);
|
|
1444
|
-
if (escaped)
|
|
1445
|
-
escaped = false;
|
|
1446
|
-
else if (ch == 93 /* ']' */)
|
|
1447
|
-
return requireNonWS ? false : elt(Type.LinkLabel, start + offset, pos + 1 + offset);
|
|
1448
|
-
else {
|
|
1449
|
-
if (requireNonWS && !space(ch))
|
|
1450
|
-
requireNonWS = false;
|
|
1451
|
-
if (ch == 91 /* '[' */)
|
|
1452
|
-
return false;
|
|
1453
|
-
else if (ch == 92 /* '\\' */)
|
|
1454
|
-
escaped = true;
|
|
1455
|
-
}
|
|
1456
|
-
}
|
|
1457
|
-
return null;
|
|
1458
|
-
}
|
|
1459
|
-
/// Inline parsing functions get access to this context, and use it to
|
|
1460
|
-
/// read the content and emit syntax nodes.
|
|
1461
|
-
class InlineContext {
|
|
1462
|
-
/// @internal
|
|
1463
|
-
constructor(
|
|
1464
|
-
/// The parser that is being used.
|
|
1465
|
-
parser,
|
|
1466
|
-
/// The text of this inline section.
|
|
1467
|
-
text,
|
|
1468
|
-
/// The starting offset of the section in the document.
|
|
1469
|
-
offset) {
|
|
1470
|
-
this.parser = parser;
|
|
1471
|
-
this.text = text;
|
|
1472
|
-
this.offset = offset;
|
|
1473
|
-
/// @internal
|
|
1474
|
-
this.parts = [];
|
|
1475
|
-
}
|
|
1476
|
-
/// Get the character code at the given (document-relative)
|
|
1477
|
-
/// position.
|
|
1478
|
-
char(pos) { return pos >= this.end ? -1 : this.text.charCodeAt(pos - this.offset); }
|
|
1479
|
-
/// The position of the end of this inline section.
|
|
1480
|
-
get end() { return this.offset + this.text.length; }
|
|
1481
|
-
/// Get a substring of this inline section. Again uses
|
|
1482
|
-
/// document-relative positions.
|
|
1483
|
-
slice(from, to) { return this.text.slice(from - this.offset, to - this.offset); }
|
|
1484
|
-
/// @internal
|
|
1485
|
-
append(elt) {
|
|
1486
|
-
this.parts.push(elt);
|
|
1487
|
-
return elt.to;
|
|
1488
|
-
}
|
|
1489
|
-
/// Add a [delimiter](#DelimiterType) at this given position. `open`
|
|
1490
|
-
/// and `close` indicate whether this delimiter is opening, closing,
|
|
1491
|
-
/// or both. Returns the end of the delimiter, for convenient
|
|
1492
|
-
/// returning from [parse functions](#InlineParser.parse).
|
|
1493
|
-
addDelimiter(type, from, to, open, close) {
|
|
1494
|
-
return this.append(new InlineDelimiter(type, from, to, (open ? 1 /* Mark.Open */ : 0 /* Mark.None */) | (close ? 2 /* Mark.Close */ : 0 /* Mark.None */)));
|
|
1495
|
-
}
|
|
1496
|
-
/// Add an inline element. Returns the end of the element.
|
|
1497
|
-
addElement(elt) {
|
|
1498
|
-
return this.append(elt);
|
|
1499
|
-
}
|
|
1500
|
-
/// Resolve markers between this.parts.length and from, wrapping matched markers in the
|
|
1501
|
-
/// appropriate node and updating the content of this.parts. @internal
|
|
1502
|
-
resolveMarkers(from) {
|
|
1503
|
-
// Scan forward, looking for closing tokens
|
|
1504
|
-
for (let i = from; i < this.parts.length; i++) {
|
|
1505
|
-
let close = this.parts[i];
|
|
1506
|
-
if (!(close instanceof InlineDelimiter && close.type.resolve && (close.side & 2 /* Mark.Close */)))
|
|
1507
|
-
continue;
|
|
1508
|
-
let emp = close.type == EmphasisUnderscore || close.type == EmphasisAsterisk;
|
|
1509
|
-
let closeSize = close.to - close.from;
|
|
1510
|
-
let open, j = i - 1;
|
|
1511
|
-
// Continue scanning for a matching opening token
|
|
1512
|
-
for (; j >= from; j--) {
|
|
1513
|
-
let part = this.parts[j];
|
|
1514
|
-
if (part instanceof InlineDelimiter && (part.side & 1 /* Mark.Open */) && part.type == close.type &&
|
|
1515
|
-
// Ignore emphasis delimiters where the character count doesn't match
|
|
1516
|
-
!(emp && ((close.side & 1 /* Mark.Open */) || (part.side & 2 /* Mark.Close */)) &&
|
|
1517
|
-
(part.to - part.from + closeSize) % 3 == 0 && ((part.to - part.from) % 3 || closeSize % 3))) {
|
|
1518
|
-
open = part;
|
|
1519
|
-
break;
|
|
1520
|
-
}
|
|
1521
|
-
}
|
|
1522
|
-
if (!open)
|
|
1523
|
-
continue;
|
|
1524
|
-
let type = close.type.resolve, content = [];
|
|
1525
|
-
let start = open.from, end = close.to;
|
|
1526
|
-
// Emphasis marker effect depends on the character count. Size consumed is minimum of the two
|
|
1527
|
-
// markers.
|
|
1528
|
-
if (emp) {
|
|
1529
|
-
let size = Math.min(2, open.to - open.from, closeSize);
|
|
1530
|
-
start = open.to - size;
|
|
1531
|
-
end = close.from + size;
|
|
1532
|
-
type = size == 1 ? "Emphasis" : "StrongEmphasis";
|
|
1533
|
-
}
|
|
1534
|
-
// Move the covered region into content, optionally adding marker nodes
|
|
1535
|
-
if (open.type.mark)
|
|
1536
|
-
content.push(this.elt(open.type.mark, start, open.to));
|
|
1537
|
-
for (let k = j + 1; k < i; k++) {
|
|
1538
|
-
if (this.parts[k] instanceof Element)
|
|
1539
|
-
content.push(this.parts[k]);
|
|
1540
|
-
this.parts[k] = null;
|
|
1541
|
-
}
|
|
1542
|
-
if (close.type.mark)
|
|
1543
|
-
content.push(this.elt(close.type.mark, close.from, end));
|
|
1544
|
-
let element = this.elt(type, start, end, content);
|
|
1545
|
-
// If there are leftover emphasis marker characters, shrink the close/open markers. Otherwise, clear them.
|
|
1546
|
-
this.parts[j] = emp && open.from != start ? new InlineDelimiter(open.type, open.from, start, open.side) : null;
|
|
1547
|
-
let keep = this.parts[i] = emp && close.to != end ? new InlineDelimiter(close.type, end, close.to, close.side) : null;
|
|
1548
|
-
// Insert the new element in this.parts
|
|
1549
|
-
if (keep)
|
|
1550
|
-
this.parts.splice(i, 0, element);
|
|
1551
|
-
else
|
|
1552
|
-
this.parts[i] = element;
|
|
1553
|
-
}
|
|
1554
|
-
// Collect the elements remaining in this.parts into an array.
|
|
1555
|
-
let result = [];
|
|
1556
|
-
for (let i = from; i < this.parts.length; i++) {
|
|
1557
|
-
let part = this.parts[i];
|
|
1558
|
-
if (part instanceof Element)
|
|
1559
|
-
result.push(part);
|
|
1560
|
-
}
|
|
1561
|
-
return result;
|
|
1562
|
-
}
|
|
1563
|
-
/// Find an opening delimiter of the given type. Returns `null` if
|
|
1564
|
-
/// no delimiter is found, or an index that can be passed to
|
|
1565
|
-
/// [`takeContent`](#InlineContext.takeContent) otherwise.
|
|
1566
|
-
findOpeningDelimiter(type) {
|
|
1567
|
-
for (let i = this.parts.length - 1; i >= 0; i--) {
|
|
1568
|
-
let part = this.parts[i];
|
|
1569
|
-
if (part instanceof InlineDelimiter && part.type == type)
|
|
1570
|
-
return i;
|
|
1571
|
-
}
|
|
1572
|
-
return null;
|
|
1573
|
-
}
|
|
1574
|
-
/// Remove all inline elements and delimiters starting from the
|
|
1575
|
-
/// given index (which you should get from
|
|
1576
|
-
/// [`findOpeningDelimiter`](#InlineContext.findOpeningDelimiter),
|
|
1577
|
-
/// resolve delimiters inside of them, and return them as an array
|
|
1578
|
-
/// of elements.
|
|
1579
|
-
takeContent(startIndex) {
|
|
1580
|
-
let content = this.resolveMarkers(startIndex);
|
|
1581
|
-
this.parts.length = startIndex;
|
|
1582
|
-
return content;
|
|
1583
|
-
}
|
|
1584
|
-
/// Skip space after the given (document) position, returning either
|
|
1585
|
-
/// the position of the next non-space character or the end of the
|
|
1586
|
-
/// section.
|
|
1587
|
-
skipSpace(from) { return skipSpace(this.text, from - this.offset) + this.offset; }
|
|
1588
|
-
elt(type, from, to, children) {
|
|
1589
|
-
if (typeof type == "string")
|
|
1590
|
-
return elt(this.parser.getNodeType(type), from, to, children);
|
|
1591
|
-
return new TreeElement(type, from);
|
|
1592
|
-
}
|
|
1593
|
-
}
|
|
1594
|
-
function injectMarks(elements, marks) {
|
|
1595
|
-
if (!marks.length)
|
|
1596
|
-
return elements;
|
|
1597
|
-
if (!elements.length)
|
|
1598
|
-
return marks;
|
|
1599
|
-
let elts = elements.slice(), eI = 0;
|
|
1600
|
-
for (let mark of marks) {
|
|
1601
|
-
while (eI < elts.length && elts[eI].to < mark.to)
|
|
1602
|
-
eI++;
|
|
1603
|
-
if (eI < elts.length && elts[eI].from < mark.from) {
|
|
1604
|
-
let e = elts[eI];
|
|
1605
|
-
if (e instanceof Element)
|
|
1606
|
-
elts[eI] = new Element(e.type, e.from, e.to, injectMarks(e.children, [mark]));
|
|
1607
|
-
}
|
|
1608
|
-
else {
|
|
1609
|
-
elts.splice(eI++, 0, mark);
|
|
1610
|
-
}
|
|
1611
|
-
}
|
|
1612
|
-
return elts;
|
|
1613
|
-
}
|
|
1614
|
-
// These are blocks that can span blank lines, and should thus only be
|
|
1615
|
-
// reused if their next sibling is also being reused.
|
|
1616
|
-
const NotLast = [Type.CodeBlock, Type.ListItem, Type.OrderedList, Type.BulletList];
|
|
1617
|
-
class FragmentCursor {
|
|
1618
|
-
constructor(fragments, input) {
|
|
1619
|
-
this.fragments = fragments;
|
|
1620
|
-
this.input = input;
|
|
1621
|
-
// Index into fragment array
|
|
1622
|
-
this.i = 0;
|
|
1623
|
-
// Active fragment
|
|
1624
|
-
this.fragment = null;
|
|
1625
|
-
this.fragmentEnd = -1;
|
|
1626
|
-
// Cursor into the current fragment, if any. When `moveTo` returns
|
|
1627
|
-
// true, this points at the first block after `pos`.
|
|
1628
|
-
this.cursor = null;
|
|
1629
|
-
if (fragments.length)
|
|
1630
|
-
this.fragment = fragments[this.i++];
|
|
1631
|
-
}
|
|
1632
|
-
nextFragment() {
|
|
1633
|
-
this.fragment = this.i < this.fragments.length ? this.fragments[this.i++] : null;
|
|
1634
|
-
this.cursor = null;
|
|
1635
|
-
this.fragmentEnd = -1;
|
|
1636
|
-
}
|
|
1637
|
-
moveTo(pos, lineStart) {
|
|
1638
|
-
while (this.fragment && this.fragment.to <= pos)
|
|
1639
|
-
this.nextFragment();
|
|
1640
|
-
if (!this.fragment || this.fragment.from > (pos ? pos - 1 : 0))
|
|
1641
|
-
return false;
|
|
1642
|
-
if (this.fragmentEnd < 0) {
|
|
1643
|
-
let end = this.fragment.to;
|
|
1644
|
-
while (end > 0 && this.input.read(end - 1, end) != "\n")
|
|
1645
|
-
end--;
|
|
1646
|
-
this.fragmentEnd = end ? end - 1 : 0;
|
|
1647
|
-
}
|
|
1648
|
-
let c = this.cursor;
|
|
1649
|
-
if (!c) {
|
|
1650
|
-
c = this.cursor = this.fragment.tree.cursor();
|
|
1651
|
-
c.firstChild();
|
|
1652
|
-
}
|
|
1653
|
-
let rPos = pos + this.fragment.offset;
|
|
1654
|
-
while (c.to <= rPos)
|
|
1655
|
-
if (!c.parent())
|
|
1656
|
-
return false;
|
|
1657
|
-
for (;;) {
|
|
1658
|
-
if (c.from >= rPos)
|
|
1659
|
-
return this.fragment.from <= lineStart;
|
|
1660
|
-
if (!c.childAfter(rPos))
|
|
1661
|
-
return false;
|
|
1662
|
-
}
|
|
1663
|
-
}
|
|
1664
|
-
matches(hash) {
|
|
1665
|
-
let tree = this.cursor.tree;
|
|
1666
|
-
return tree && tree.prop(NodeProp.contextHash) == hash;
|
|
1667
|
-
}
|
|
1668
|
-
takeNodes(cx) {
|
|
1669
|
-
let cur = this.cursor, off = this.fragment.offset, fragEnd = this.fragmentEnd - (this.fragment.openEnd ? 1 : 0);
|
|
1670
|
-
let start = cx.absoluteLineStart, end = start, blockI = cx.block.children.length;
|
|
1671
|
-
let prevEnd = end, prevI = blockI;
|
|
1672
|
-
for (;;) {
|
|
1673
|
-
if (cur.to - off > fragEnd) {
|
|
1674
|
-
if (cur.type.isAnonymous && cur.firstChild())
|
|
1675
|
-
continue;
|
|
1676
|
-
break;
|
|
1677
|
-
}
|
|
1678
|
-
let pos = toRelative(cur.from - off, cx.ranges);
|
|
1679
|
-
if (cur.to - off <= cx.ranges[cx.rangeI].to) { // Fits in current range
|
|
1680
|
-
cx.addNode(cur.tree, pos);
|
|
1681
|
-
}
|
|
1682
|
-
else {
|
|
1683
|
-
let dummy = new Tree(cx.parser.nodeSet.types[Type.Paragraph], [], [], 0, cx.block.hashProp);
|
|
1684
|
-
cx.reusePlaceholders.set(dummy, cur.tree);
|
|
1685
|
-
cx.addNode(dummy, pos);
|
|
1686
|
-
}
|
|
1687
|
-
// Taken content must always end in a block, because incremental
|
|
1688
|
-
// parsing happens on block boundaries. Never stop directly
|
|
1689
|
-
// after an indented code block, since those can continue after
|
|
1690
|
-
// any number of blank lines.
|
|
1691
|
-
if (cur.type.is("Block")) {
|
|
1692
|
-
if (NotLast.indexOf(cur.type.id) < 0) {
|
|
1693
|
-
end = cur.to - off;
|
|
1694
|
-
blockI = cx.block.children.length;
|
|
1695
|
-
}
|
|
1696
|
-
else {
|
|
1697
|
-
end = prevEnd;
|
|
1698
|
-
blockI = prevI;
|
|
1699
|
-
prevEnd = cur.to - off;
|
|
1700
|
-
prevI = cx.block.children.length;
|
|
1701
|
-
}
|
|
1702
|
-
}
|
|
1703
|
-
if (!cur.nextSibling())
|
|
1704
|
-
break;
|
|
1705
|
-
}
|
|
1706
|
-
while (cx.block.children.length > blockI) {
|
|
1707
|
-
cx.block.children.pop();
|
|
1708
|
-
cx.block.positions.pop();
|
|
1709
|
-
}
|
|
1710
|
-
return end - start;
|
|
1711
|
-
}
|
|
1712
|
-
}
|
|
1713
|
-
// Convert an input-stream-relative position to a
|
|
1714
|
-
// Markdown-doc-relative position by subtracting the size of all input
|
|
1715
|
-
// gaps before `abs`.
|
|
1716
|
-
function toRelative(abs, ranges) {
|
|
1717
|
-
let pos = abs;
|
|
1718
|
-
for (let i = 1; i < ranges.length; i++) {
|
|
1719
|
-
let gapFrom = ranges[i - 1].to, gapTo = ranges[i].from;
|
|
1720
|
-
if (gapFrom < abs)
|
|
1721
|
-
pos -= gapTo - gapFrom;
|
|
1722
|
-
}
|
|
1723
|
-
return pos;
|
|
1724
|
-
}
|
|
1725
|
-
const markdownHighlighting = styleTags({
|
|
1726
|
-
"Blockquote/...": tags.quote,
|
|
1727
|
-
HorizontalRule: tags.contentSeparator,
|
|
1728
|
-
"ATXHeading1/... SetextHeading1/...": tags.heading1,
|
|
1729
|
-
"ATXHeading2/... SetextHeading2/...": tags.heading2,
|
|
1730
|
-
"ATXHeading3/...": tags.heading3,
|
|
1731
|
-
"ATXHeading4/...": tags.heading4,
|
|
1732
|
-
"ATXHeading5/...": tags.heading5,
|
|
1733
|
-
"ATXHeading6/...": tags.heading6,
|
|
1734
|
-
"Comment CommentBlock": tags.comment,
|
|
1735
|
-
Escape: tags.escape,
|
|
1736
|
-
Entity: tags.character,
|
|
1737
|
-
"Emphasis/...": tags.emphasis,
|
|
1738
|
-
"StrongEmphasis/...": tags.strong,
|
|
1739
|
-
"Link/... Image/...": tags.link,
|
|
1740
|
-
"OrderedList/... BulletList/...": tags.list,
|
|
1741
|
-
"BlockQuote/...": tags.quote,
|
|
1742
|
-
"InlineCode CodeText": tags.monospace,
|
|
1743
|
-
URL: tags.url,
|
|
1744
|
-
"HeaderMark HardBreak QuoteMark ListMark LinkMark EmphasisMark CodeMark": tags.processingInstruction,
|
|
1745
|
-
"CodeInfo LinkLabel": tags.labelName,
|
|
1746
|
-
LinkTitle: tags.string,
|
|
1747
|
-
Paragraph: tags.content
|
|
1748
|
-
});
|
|
1749
|
-
/// The default CommonMark parser.
|
|
1750
|
-
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), []);
|
|
1751
|
-
|
|
1752
|
-
function leftOverSpace(node, from, to) {
|
|
1753
|
-
let ranges = [];
|
|
1754
|
-
for (let n = node.firstChild, pos = from;; n = n.nextSibling) {
|
|
1755
|
-
let nextPos = n ? n.from : to;
|
|
1756
|
-
if (nextPos > pos)
|
|
1757
|
-
ranges.push({ from: pos, to: nextPos });
|
|
1758
|
-
if (!n)
|
|
1759
|
-
break;
|
|
1760
|
-
pos = n.to;
|
|
1761
|
-
}
|
|
1762
|
-
return ranges;
|
|
1763
|
-
}
|
|
1764
|
-
/// Create a Markdown extension to enable nested parsing on code
|
|
1765
|
-
/// blocks and/or embedded HTML.
|
|
1766
|
-
function parseCode(config) {
|
|
1767
|
-
let { codeParser, htmlParser } = config;
|
|
1768
|
-
let wrap = parseMixed((node, input) => {
|
|
1769
|
-
let id = node.type.id;
|
|
1770
|
-
if (codeParser && (id == Type.CodeBlock || id == Type.FencedCode)) {
|
|
1771
|
-
let info = "";
|
|
1772
|
-
if (id == Type.FencedCode) {
|
|
1773
|
-
let infoNode = node.node.getChild(Type.CodeInfo);
|
|
1774
|
-
if (infoNode)
|
|
1775
|
-
info = input.read(infoNode.from, infoNode.to);
|
|
1776
|
-
}
|
|
1777
|
-
let parser = codeParser(info);
|
|
1778
|
-
if (parser)
|
|
1779
|
-
return { parser, overlay: node => node.type.id == Type.CodeText };
|
|
1780
|
-
}
|
|
1781
|
-
else if (htmlParser && (id == Type.HTMLBlock || id == Type.HTMLTag)) {
|
|
1782
|
-
return { parser: htmlParser, overlay: leftOverSpace(node.node, node.from, node.to) };
|
|
1783
|
-
}
|
|
1784
|
-
return null;
|
|
1785
|
-
});
|
|
1786
|
-
return { wrap };
|
|
1787
|
-
}
|
|
1788
|
-
|
|
1789
|
-
const StrikethroughDelim = { resolve: "Strikethrough", mark: "StrikethroughMark" };
|
|
1790
|
-
/// An extension that implements
|
|
1791
|
-
/// [GFM-style](https://github.github.com/gfm/#strikethrough-extension-)
|
|
1792
|
-
/// Strikethrough syntax using `~~` delimiters.
|
|
1793
|
-
const Strikethrough = {
|
|
1794
|
-
defineNodes: [{
|
|
1795
|
-
name: "Strikethrough",
|
|
1796
|
-
style: { "Strikethrough/...": tags.strikethrough }
|
|
1797
|
-
}, {
|
|
1798
|
-
name: "StrikethroughMark",
|
|
1799
|
-
style: tags.processingInstruction
|
|
1800
|
-
}],
|
|
1801
|
-
parseInline: [{
|
|
1802
|
-
name: "Strikethrough",
|
|
1803
|
-
parse(cx, next, pos) {
|
|
1804
|
-
if (next != 126 /* '~' */ || cx.char(pos + 1) != 126 || cx.char(pos + 2) == 126)
|
|
1805
|
-
return -1;
|
|
1806
|
-
let before = cx.slice(pos - 1, pos), after = cx.slice(pos + 2, pos + 3);
|
|
1807
|
-
let sBefore = /\s|^$/.test(before), sAfter = /\s|^$/.test(after);
|
|
1808
|
-
let pBefore = Punctuation.test(before), pAfter = Punctuation.test(after);
|
|
1809
|
-
return cx.addDelimiter(StrikethroughDelim, pos, pos + 2, !sAfter && (!pAfter || sBefore || pBefore), !sBefore && (!pBefore || sAfter || pAfter));
|
|
1810
|
-
},
|
|
1811
|
-
after: "Emphasis"
|
|
1812
|
-
}]
|
|
1813
|
-
};
|
|
1814
|
-
function parseRow(cx, line, startI = 0, elts, offset = 0) {
|
|
1815
|
-
let count = 0, first = true, cellStart = -1, cellEnd = -1, esc = false;
|
|
1816
|
-
let parseCell = () => {
|
|
1817
|
-
elts.push(cx.elt("TableCell", offset + cellStart, offset + cellEnd, cx.parser.parseInline(line.slice(cellStart, cellEnd), offset + cellStart)));
|
|
1818
|
-
};
|
|
1819
|
-
for (let i = startI; i < line.length; i++) {
|
|
1820
|
-
let next = line.charCodeAt(i);
|
|
1821
|
-
if (next == 124 /* '|' */ && !esc) {
|
|
1822
|
-
if (!first || cellStart > -1)
|
|
1823
|
-
count++;
|
|
1824
|
-
first = false;
|
|
1825
|
-
if (elts) {
|
|
1826
|
-
if (cellStart > -1)
|
|
1827
|
-
parseCell();
|
|
1828
|
-
elts.push(cx.elt("TableDelimiter", i + offset, i + offset + 1));
|
|
1829
|
-
}
|
|
1830
|
-
cellStart = cellEnd = -1;
|
|
1831
|
-
}
|
|
1832
|
-
else if (esc || next != 32 && next != 9) {
|
|
1833
|
-
if (cellStart < 0)
|
|
1834
|
-
cellStart = i;
|
|
1835
|
-
cellEnd = i + 1;
|
|
1836
|
-
}
|
|
1837
|
-
esc = !esc && next == 92;
|
|
1838
|
-
}
|
|
1839
|
-
if (cellStart > -1) {
|
|
1840
|
-
count++;
|
|
1841
|
-
if (elts)
|
|
1842
|
-
parseCell();
|
|
1843
|
-
}
|
|
1844
|
-
return count;
|
|
1845
|
-
}
|
|
1846
|
-
function hasPipe(str, start) {
|
|
1847
|
-
for (let i = start; i < str.length; i++) {
|
|
1848
|
-
let next = str.charCodeAt(i);
|
|
1849
|
-
if (next == 124 /* '|' */)
|
|
1850
|
-
return true;
|
|
1851
|
-
if (next == 92 /* '\\' */)
|
|
1852
|
-
i++;
|
|
1853
|
-
}
|
|
1854
|
-
return false;
|
|
1855
|
-
}
|
|
1856
|
-
const delimiterLine = /^\|?(\s*:?-+:?\s*\|)+(\s*:?-+:?\s*)?$/;
|
|
1857
|
-
class TableParser {
|
|
1858
|
-
constructor() {
|
|
1859
|
-
// Null means we haven't seen the second line yet, false means this
|
|
1860
|
-
// isn't a table, and an array means this is a table and we've
|
|
1861
|
-
// parsed the given rows so far.
|
|
1862
|
-
this.rows = null;
|
|
1863
|
-
}
|
|
1864
|
-
nextLine(cx, line, leaf) {
|
|
1865
|
-
if (this.rows == null) { // Second line
|
|
1866
|
-
this.rows = false;
|
|
1867
|
-
let lineText;
|
|
1868
|
-
if ((line.next == 45 || line.next == 58 || line.next == 124 /* '-:|' */) &&
|
|
1869
|
-
delimiterLine.test(lineText = line.text.slice(line.pos))) {
|
|
1870
|
-
let firstRow = [], firstCount = parseRow(cx, leaf.content, 0, firstRow, leaf.start);
|
|
1871
|
-
if (firstCount == parseRow(cx, lineText, line.pos))
|
|
1872
|
-
this.rows = [cx.elt("TableHeader", leaf.start, leaf.start + leaf.content.length, firstRow),
|
|
1873
|
-
cx.elt("TableDelimiter", cx.lineStart + line.pos, cx.lineStart + line.text.length)];
|
|
1874
|
-
}
|
|
1875
|
-
}
|
|
1876
|
-
else if (this.rows) { // Line after the second
|
|
1877
|
-
let content = [];
|
|
1878
|
-
parseRow(cx, line.text, line.pos, content, cx.lineStart);
|
|
1879
|
-
this.rows.push(cx.elt("TableRow", cx.lineStart + line.pos, cx.lineStart + line.text.length, content));
|
|
1880
|
-
}
|
|
1881
|
-
return false;
|
|
1882
|
-
}
|
|
1883
|
-
finish(cx, leaf) {
|
|
1884
|
-
if (!this.rows)
|
|
1885
|
-
return false;
|
|
1886
|
-
cx.addLeafElement(leaf, cx.elt("Table", leaf.start, leaf.start + leaf.content.length, this.rows));
|
|
1887
|
-
return true;
|
|
1888
|
-
}
|
|
1889
|
-
}
|
|
1890
|
-
/// This extension provides
|
|
1891
|
-
/// [GFM-style](https://github.github.com/gfm/#tables-extension-)
|
|
1892
|
-
/// tables, using syntax like this:
|
|
1893
|
-
///
|
|
1894
|
-
/// ```
|
|
1895
|
-
/// | head 1 | head 2 |
|
|
1896
|
-
/// | --- | --- |
|
|
1897
|
-
/// | cell 1 | cell 2 |
|
|
1898
|
-
/// ```
|
|
1899
|
-
const Table = {
|
|
1900
|
-
defineNodes: [
|
|
1901
|
-
{ name: "Table", block: true },
|
|
1902
|
-
{ name: "TableHeader", style: { "TableHeader/...": tags.heading } },
|
|
1903
|
-
"TableRow",
|
|
1904
|
-
{ name: "TableCell", style: tags.content },
|
|
1905
|
-
{ name: "TableDelimiter", style: tags.processingInstruction },
|
|
1906
|
-
],
|
|
1907
|
-
parseBlock: [{
|
|
1908
|
-
name: "Table",
|
|
1909
|
-
leaf(_, leaf) { return hasPipe(leaf.content, 0) ? new TableParser : null; },
|
|
1910
|
-
endLeaf(cx, line, leaf) {
|
|
1911
|
-
if (leaf.parsers.some(p => p instanceof TableParser) || !hasPipe(line.text, line.basePos))
|
|
1912
|
-
return false;
|
|
1913
|
-
let next = cx.scanLine(cx.absoluteLineEnd + 1).text;
|
|
1914
|
-
return delimiterLine.test(next) && parseRow(cx, line.text, line.basePos) == parseRow(cx, next, line.basePos);
|
|
1915
|
-
},
|
|
1916
|
-
before: "SetextHeading"
|
|
1917
|
-
}]
|
|
1918
|
-
};
|
|
1919
|
-
class TaskParser {
|
|
1920
|
-
nextLine() { return false; }
|
|
1921
|
-
finish(cx, leaf) {
|
|
1922
|
-
cx.addLeafElement(leaf, cx.elt("Task", leaf.start, leaf.start + leaf.content.length, [
|
|
1923
|
-
cx.elt("TaskMarker", leaf.start, leaf.start + 3),
|
|
1924
|
-
...cx.parser.parseInline(leaf.content.slice(3), leaf.start + 3)
|
|
1925
|
-
]));
|
|
1926
|
-
return true;
|
|
1927
|
-
}
|
|
1928
|
-
}
|
|
1929
|
-
/// Extension providing
|
|
1930
|
-
/// [GFM-style](https://github.github.com/gfm/#task-list-items-extension-)
|
|
1931
|
-
/// task list items, where list items can be prefixed with `[ ]` or
|
|
1932
|
-
/// `[x]` to add a checkbox.
|
|
1933
|
-
const TaskList = {
|
|
1934
|
-
defineNodes: [
|
|
1935
|
-
{ name: "Task", block: true, style: tags.list },
|
|
1936
|
-
{ name: "TaskMarker", style: tags.atom }
|
|
1937
|
-
],
|
|
1938
|
-
parseBlock: [{
|
|
1939
|
-
name: "TaskList",
|
|
1940
|
-
leaf(cx, leaf) {
|
|
1941
|
-
return /^\[[ xX]\][ \t]/.test(leaf.content) && cx.parentType().name == "ListItem" ? new TaskParser : null;
|
|
1942
|
-
},
|
|
1943
|
-
after: "SetextHeading"
|
|
1944
|
-
}]
|
|
1945
|
-
};
|
|
1946
|
-
const autolinkRE = /(www\.)|(https?:\/\/)|([\w.+-]+@)|(mailto:|xmpp:)/gy;
|
|
1947
|
-
const urlRE = /[\w-]+(\.[\w-]+)+(\/[^\s<]*)?/gy;
|
|
1948
|
-
const lastTwoDomainWords = /[\w-]+\.[\w-]+($|\/)/;
|
|
1949
|
-
const emailRE = /[\w.+-]+@[\w-]+(\.[\w.-]+)+/gy;
|
|
1950
|
-
const xmppResourceRE = /\/[a-zA-Z\d@.]+/gy;
|
|
1951
|
-
function count(str, from, to, ch) {
|
|
1952
|
-
let result = 0;
|
|
1953
|
-
for (let i = from; i < to; i++)
|
|
1954
|
-
if (str[i] == ch)
|
|
1955
|
-
result++;
|
|
1956
|
-
return result;
|
|
1957
|
-
}
|
|
1958
|
-
function autolinkURLEnd(text, from) {
|
|
1959
|
-
urlRE.lastIndex = from;
|
|
1960
|
-
let m = urlRE.exec(text);
|
|
1961
|
-
if (!m || lastTwoDomainWords.exec(m[0])[0].indexOf("_") > -1)
|
|
1962
|
-
return -1;
|
|
1963
|
-
let end = from + m[0].length;
|
|
1964
|
-
for (;;) {
|
|
1965
|
-
let last = text[end - 1], m;
|
|
1966
|
-
if (/[?!.,:*_~]/.test(last) ||
|
|
1967
|
-
last == ")" && count(text, from, end, ")") > count(text, from, end, "("))
|
|
1968
|
-
end--;
|
|
1969
|
-
else if (last == ";" && (m = /&(?:#\d+|#x[a-f\d]+|\w+);$/.exec(text.slice(from, end))))
|
|
1970
|
-
end = from + m.index;
|
|
1971
|
-
else
|
|
1972
|
-
break;
|
|
1973
|
-
}
|
|
1974
|
-
return end;
|
|
1975
|
-
}
|
|
1976
|
-
function autolinkEmailEnd(text, from) {
|
|
1977
|
-
emailRE.lastIndex = from;
|
|
1978
|
-
let m = emailRE.exec(text);
|
|
1979
|
-
if (!m)
|
|
1980
|
-
return -1;
|
|
1981
|
-
let last = m[0][m[0].length - 1];
|
|
1982
|
-
return last == "_" || last == "-" ? -1 : from + m[0].length - (last == "." ? 1 : 0);
|
|
1983
|
-
}
|
|
1984
|
-
/// Extension that implements autolinking for
|
|
1985
|
-
/// `www.`/`http://`/`https://`/`mailto:`/`xmpp:` URLs and email
|
|
1986
|
-
/// addresses.
|
|
1987
|
-
const Autolink = {
|
|
1988
|
-
parseInline: [{
|
|
1989
|
-
name: "Autolink",
|
|
1990
|
-
parse(cx, next, absPos) {
|
|
1991
|
-
let pos = absPos - cx.offset;
|
|
1992
|
-
autolinkRE.lastIndex = pos;
|
|
1993
|
-
let m = autolinkRE.exec(cx.text), end = -1;
|
|
1994
|
-
if (!m)
|
|
1995
|
-
return -1;
|
|
1996
|
-
if (m[1] || m[2]) { // www., http://
|
|
1997
|
-
end = autolinkURLEnd(cx.text, pos + m[0].length);
|
|
1998
|
-
}
|
|
1999
|
-
else if (m[3]) { // email address
|
|
2000
|
-
end = autolinkEmailEnd(cx.text, pos);
|
|
2001
|
-
}
|
|
2002
|
-
else { // mailto:/xmpp:
|
|
2003
|
-
end = autolinkEmailEnd(cx.text, pos + m[0].length);
|
|
2004
|
-
if (end > -1 && m[0] == "xmpp:") {
|
|
2005
|
-
xmppResourceRE.lastIndex = end;
|
|
2006
|
-
m = xmppResourceRE.exec(cx.text);
|
|
2007
|
-
if (m)
|
|
2008
|
-
end = m.index + m[0].length;
|
|
2009
|
-
}
|
|
2010
|
-
}
|
|
2011
|
-
if (end < 0)
|
|
2012
|
-
return -1;
|
|
2013
|
-
cx.addElement(cx.elt("URL", absPos, end + cx.offset));
|
|
2014
|
-
return end + cx.offset;
|
|
2015
|
-
}
|
|
2016
|
-
}]
|
|
2017
|
-
};
|
|
2018
|
-
/// Extension bundle containing [`Table`](#Table),
|
|
2019
|
-
/// [`TaskList`](#TaskList), [`Strikethrough`](#Strikethrough), and
|
|
2020
|
-
/// [`Autolink`](#Autolink).
|
|
2021
|
-
const GFM = [Table, TaskList, Strikethrough, Autolink];
|
|
2022
|
-
function parseSubSuper(ch, node, mark) {
|
|
2023
|
-
return (cx, next, pos) => {
|
|
2024
|
-
if (next != ch || cx.char(pos + 1) == ch)
|
|
2025
|
-
return -1;
|
|
2026
|
-
let elts = [cx.elt(mark, pos, pos + 1)];
|
|
2027
|
-
for (let i = pos + 1; i < cx.end; i++) {
|
|
2028
|
-
let next = cx.char(i);
|
|
2029
|
-
if (next == ch)
|
|
2030
|
-
return cx.addElement(cx.elt(node, pos, i + 1, elts.concat(cx.elt(mark, i, i + 1))));
|
|
2031
|
-
if (next == 92 /* '\\' */)
|
|
2032
|
-
elts.push(cx.elt("Escape", i, i++ + 2));
|
|
2033
|
-
if (space(next))
|
|
2034
|
-
break;
|
|
2035
|
-
}
|
|
2036
|
-
return -1;
|
|
2037
|
-
};
|
|
2038
|
-
}
|
|
2039
|
-
/// Extension providing
|
|
2040
|
-
/// [Pandoc-style](https://pandoc.org/MANUAL.html#superscripts-and-subscripts)
|
|
2041
|
-
/// superscript using `^` markers.
|
|
2042
|
-
const Superscript = {
|
|
2043
|
-
defineNodes: [
|
|
2044
|
-
{ name: "Superscript", style: tags.special(tags.content) },
|
|
2045
|
-
{ name: "SuperscriptMark", style: tags.processingInstruction }
|
|
2046
|
-
],
|
|
2047
|
-
parseInline: [{
|
|
2048
|
-
name: "Superscript",
|
|
2049
|
-
parse: parseSubSuper(94 /* '^' */, "Superscript", "SuperscriptMark")
|
|
2050
|
-
}]
|
|
2051
|
-
};
|
|
2052
|
-
/// Extension providing
|
|
2053
|
-
/// [Pandoc-style](https://pandoc.org/MANUAL.html#superscripts-and-subscripts)
|
|
2054
|
-
/// subscript using `~` markers.
|
|
2055
|
-
const Subscript = {
|
|
2056
|
-
defineNodes: [
|
|
2057
|
-
{ name: "Subscript", style: tags.special(tags.content) },
|
|
2058
|
-
{ name: "SubscriptMark", style: tags.processingInstruction }
|
|
2059
|
-
],
|
|
2060
|
-
parseInline: [{
|
|
2061
|
-
name: "Subscript",
|
|
2062
|
-
parse: parseSubSuper(126 /* '~' */, "Subscript", "SubscriptMark")
|
|
2063
|
-
}]
|
|
2064
|
-
};
|
|
2065
|
-
/// Extension that parses two colons with only letters, underscores,
|
|
2066
|
-
/// and numbers between them as `Emoji` nodes.
|
|
2067
|
-
const Emoji = {
|
|
2068
|
-
defineNodes: [{ name: "Emoji", style: tags.character }],
|
|
2069
|
-
parseInline: [{
|
|
2070
|
-
name: "Emoji",
|
|
2071
|
-
parse(cx, next, pos) {
|
|
2072
|
-
let match;
|
|
2073
|
-
if (next != 58 /* ':' */ || !(match = /^[a-zA-Z_0-9]+:/.exec(cx.slice(pos + 1, cx.end))))
|
|
2074
|
-
return -1;
|
|
2075
|
-
return cx.addElement(cx.elt("Emoji", pos, pos + 1 + match[0].length));
|
|
2076
|
-
}
|
|
2077
|
-
}]
|
|
2078
|
-
};
|
|
2079
|
-
|
|
2080
|
-
const data = /*@__PURE__*/defineLanguageFacet({ commentTokens: { block: { open: "<!--", close: "-->" } } });
|
|
2081
|
-
const headingProp = /*@__PURE__*/new NodeProp();
|
|
2082
|
-
const commonmark = /*@__PURE__*/parser.configure({
|
|
2083
|
-
props: [
|
|
2084
|
-
/*@__PURE__*/foldNodeProp.add(type => {
|
|
2085
|
-
return !type.is("Block") || type.is("Document") || isHeading(type) != null ? undefined
|
|
2086
|
-
: (tree, state) => ({ from: state.doc.lineAt(tree.from).to, to: tree.to });
|
|
2087
|
-
}),
|
|
2088
|
-
/*@__PURE__*/headingProp.add(isHeading),
|
|
2089
|
-
/*@__PURE__*/indentNodeProp.add({
|
|
2090
|
-
Document: () => null
|
|
2091
|
-
}),
|
|
2092
|
-
/*@__PURE__*/languageDataProp.add({
|
|
2093
|
-
Document: data
|
|
2094
|
-
})
|
|
2095
|
-
]
|
|
2096
|
-
});
|
|
2097
|
-
function isHeading(type) {
|
|
2098
|
-
let match = /^(?:ATX|Setext)Heading(\d)$/.exec(type.name);
|
|
2099
|
-
return match ? +match[1] : undefined;
|
|
2100
|
-
}
|
|
2101
|
-
function findSectionEnd(headerNode, level) {
|
|
2102
|
-
let last = headerNode;
|
|
2103
|
-
for (;;) {
|
|
2104
|
-
let next = last.nextSibling, heading;
|
|
2105
|
-
if (!next || (heading = isHeading(next.type)) != null && heading <= level)
|
|
2106
|
-
break;
|
|
2107
|
-
last = next;
|
|
2108
|
-
}
|
|
2109
|
-
return last.to;
|
|
2110
|
-
}
|
|
2111
|
-
const headerIndent = /*@__PURE__*/foldService.of((state, start, end) => {
|
|
2112
|
-
for (let node = syntaxTree(state).resolveInner(end, -1); node; node = node.parent) {
|
|
2113
|
-
if (node.from < start)
|
|
2114
|
-
break;
|
|
2115
|
-
let heading = node.type.prop(headingProp);
|
|
2116
|
-
if (heading == null)
|
|
2117
|
-
continue;
|
|
2118
|
-
let upto = findSectionEnd(node, heading);
|
|
2119
|
-
if (upto > end)
|
|
2120
|
-
return { from: end, to: upto };
|
|
2121
|
-
}
|
|
2122
|
-
return null;
|
|
2123
|
-
});
|
|
2124
|
-
function mkLang(parser) {
|
|
2125
|
-
return new Language(data, parser, [headerIndent], "markdown");
|
|
2126
|
-
}
|
|
2127
|
-
/**
|
|
2128
|
-
Language support for strict CommonMark.
|
|
2129
|
-
*/
|
|
2130
|
-
const commonmarkLanguage = /*@__PURE__*/mkLang(commonmark);
|
|
2131
|
-
const extended = /*@__PURE__*/commonmark.configure([GFM, Subscript, Superscript, Emoji, {
|
|
2132
|
-
props: [
|
|
2133
|
-
/*@__PURE__*/foldNodeProp.add({
|
|
2134
|
-
Table: (tree, state) => ({ from: state.doc.lineAt(tree.from).to, to: tree.to })
|
|
2135
|
-
})
|
|
2136
|
-
]
|
|
2137
|
-
}]);
|
|
2138
|
-
/**
|
|
2139
|
-
Language support for [GFM](https://github.github.com/gfm/) plus
|
|
2140
|
-
subscript, superscript, and emoji syntax.
|
|
2141
|
-
*/
|
|
2142
|
-
const markdownLanguage = /*@__PURE__*/mkLang(extended);
|
|
2143
|
-
function getCodeParser(languages, defaultLanguage) {
|
|
2144
|
-
return (info) => {
|
|
2145
|
-
if (info && languages) {
|
|
2146
|
-
let found = null;
|
|
2147
|
-
// Strip anything after whitespace
|
|
2148
|
-
info = /\S*/.exec(info)[0];
|
|
2149
|
-
if (typeof languages == "function")
|
|
2150
|
-
found = languages(info);
|
|
2151
|
-
else
|
|
2152
|
-
found = LanguageDescription.matchLanguageName(languages, info, true);
|
|
2153
|
-
if (found instanceof LanguageDescription)
|
|
2154
|
-
return found.support ? found.support.language.parser : ParseContext.getSkippingParser(found.load());
|
|
2155
|
-
else if (found)
|
|
2156
|
-
return found.parser;
|
|
2157
|
-
}
|
|
2158
|
-
return defaultLanguage ? defaultLanguage.parser : null;
|
|
2159
|
-
};
|
|
2160
|
-
}
|
|
2161
|
-
|
|
2162
|
-
class Context {
|
|
2163
|
-
constructor(node, from, to, spaceBefore, spaceAfter, type, item) {
|
|
2164
|
-
this.node = node;
|
|
2165
|
-
this.from = from;
|
|
2166
|
-
this.to = to;
|
|
2167
|
-
this.spaceBefore = spaceBefore;
|
|
2168
|
-
this.spaceAfter = spaceAfter;
|
|
2169
|
-
this.type = type;
|
|
2170
|
-
this.item = item;
|
|
2171
|
-
}
|
|
2172
|
-
blank(maxWidth, trailing = true) {
|
|
2173
|
-
let result = this.spaceBefore + (this.node.name == "Blockquote" ? ">" : "");
|
|
2174
|
-
if (maxWidth != null) {
|
|
2175
|
-
while (result.length < maxWidth)
|
|
2176
|
-
result += " ";
|
|
2177
|
-
return result;
|
|
2178
|
-
}
|
|
2179
|
-
else {
|
|
2180
|
-
for (let i = this.to - this.from - result.length - this.spaceAfter.length; i > 0; i--)
|
|
2181
|
-
result += " ";
|
|
2182
|
-
return result + (trailing ? this.spaceAfter : "");
|
|
2183
|
-
}
|
|
2184
|
-
}
|
|
2185
|
-
marker(doc, add) {
|
|
2186
|
-
let number = this.node.name == "OrderedList" ? String((+itemNumber(this.item, doc)[2] + add)) : "";
|
|
2187
|
-
return this.spaceBefore + number + this.type + this.spaceAfter;
|
|
2188
|
-
}
|
|
2189
|
-
}
|
|
2190
|
-
function getContext(node, doc) {
|
|
2191
|
-
let nodes = [];
|
|
2192
|
-
for (let cur = node; cur && cur.name != "Document"; cur = cur.parent) {
|
|
2193
|
-
if (cur.name == "ListItem" || cur.name == "Blockquote" || cur.name == "FencedCode")
|
|
2194
|
-
nodes.push(cur);
|
|
2195
|
-
}
|
|
2196
|
-
let context = [];
|
|
2197
|
-
for (let i = nodes.length - 1; i >= 0; i--) {
|
|
2198
|
-
let node = nodes[i], match;
|
|
2199
|
-
let line = doc.lineAt(node.from), startPos = node.from - line.from;
|
|
2200
|
-
if (node.name == "FencedCode") {
|
|
2201
|
-
context.push(new Context(node, startPos, startPos, "", "", "", null));
|
|
2202
|
-
}
|
|
2203
|
-
else if (node.name == "Blockquote" && (match = /^ *>( ?)/.exec(line.text.slice(startPos)))) {
|
|
2204
|
-
context.push(new Context(node, startPos, startPos + match[0].length, "", match[1], ">", null));
|
|
2205
|
-
}
|
|
2206
|
-
else if (node.name == "ListItem" && node.parent.name == "OrderedList" &&
|
|
2207
|
-
(match = /^( *)\d+([.)])( *)/.exec(line.text.slice(startPos)))) {
|
|
2208
|
-
let after = match[3], len = match[0].length;
|
|
2209
|
-
if (after.length >= 4) {
|
|
2210
|
-
after = after.slice(0, after.length - 4);
|
|
2211
|
-
len -= 4;
|
|
2212
|
-
}
|
|
2213
|
-
context.push(new Context(node.parent, startPos, startPos + len, match[1], after, match[2], node));
|
|
2214
|
-
}
|
|
2215
|
-
else if (node.name == "ListItem" && node.parent.name == "BulletList" &&
|
|
2216
|
-
(match = /^( *)([-+*])( {1,4}\[[ xX]\])?( +)/.exec(line.text.slice(startPos)))) {
|
|
2217
|
-
let after = match[4], len = match[0].length;
|
|
2218
|
-
if (after.length > 4) {
|
|
2219
|
-
after = after.slice(0, after.length - 4);
|
|
2220
|
-
len -= 4;
|
|
2221
|
-
}
|
|
2222
|
-
let type = match[2];
|
|
2223
|
-
if (match[3])
|
|
2224
|
-
type += match[3].replace(/[xX]/, ' ');
|
|
2225
|
-
context.push(new Context(node.parent, startPos, startPos + len, match[1], after, type, node));
|
|
2226
|
-
}
|
|
2227
|
-
}
|
|
2228
|
-
return context;
|
|
2229
|
-
}
|
|
2230
|
-
function itemNumber(item, doc) {
|
|
2231
|
-
return /^(\s*)(\d+)(?=[.)])/.exec(doc.sliceString(item.from, item.from + 10));
|
|
2232
|
-
}
|
|
2233
|
-
function renumberList(after, doc, changes, offset = 0) {
|
|
2234
|
-
for (let prev = -1, node = after;;) {
|
|
2235
|
-
if (node.name == "ListItem") {
|
|
2236
|
-
let m = itemNumber(node, doc);
|
|
2237
|
-
let number = +m[2];
|
|
2238
|
-
if (prev >= 0) {
|
|
2239
|
-
if (number != prev + 1)
|
|
2240
|
-
return;
|
|
2241
|
-
changes.push({ from: node.from + m[1].length, to: node.from + m[0].length, insert: String(prev + 2 + offset) });
|
|
2242
|
-
}
|
|
2243
|
-
prev = number;
|
|
2244
|
-
}
|
|
2245
|
-
let next = node.nextSibling;
|
|
2246
|
-
if (!next)
|
|
2247
|
-
break;
|
|
2248
|
-
node = next;
|
|
2249
|
-
}
|
|
2250
|
-
}
|
|
2251
|
-
function normalizeIndent(content, state) {
|
|
2252
|
-
let blank = /^[ \t]*/.exec(content)[0].length;
|
|
2253
|
-
if (!blank || state.facet(indentUnit) != "\t")
|
|
2254
|
-
return content;
|
|
2255
|
-
let col = countColumn(content, 4, blank);
|
|
2256
|
-
let space = "";
|
|
2257
|
-
for (let i = col; i > 0;) {
|
|
2258
|
-
if (i >= 4) {
|
|
2259
|
-
space += "\t";
|
|
2260
|
-
i -= 4;
|
|
2261
|
-
}
|
|
2262
|
-
else {
|
|
2263
|
-
space += " ";
|
|
2264
|
-
i--;
|
|
2265
|
-
}
|
|
2266
|
-
}
|
|
2267
|
-
return space + content.slice(blank);
|
|
2268
|
-
}
|
|
2269
|
-
/**
|
|
2270
|
-
This command, when invoked in Markdown context with cursor
|
|
2271
|
-
selection(s), will create a new line with the markup for
|
|
2272
|
-
blockquotes and lists that were active on the old line. If the
|
|
2273
|
-
cursor was directly after the end of the markup for the old line,
|
|
2274
|
-
trailing whitespace and list markers are removed from that line.
|
|
2275
|
-
|
|
2276
|
-
The command does nothing in non-Markdown context, so it should
|
|
2277
|
-
not be used as the only binding for Enter (even in a Markdown
|
|
2278
|
-
document, HTML and code regions might use a different language).
|
|
2279
|
-
*/
|
|
2280
|
-
const insertNewlineContinueMarkup = ({ state, dispatch }) => {
|
|
2281
|
-
let tree = syntaxTree(state), { doc } = state;
|
|
2282
|
-
let dont = null, changes = state.changeByRange(range => {
|
|
2283
|
-
if (!range.empty || !markdownLanguage.isActiveAt(state, range.from))
|
|
2284
|
-
return dont = { range };
|
|
2285
|
-
let pos = range.from, line = doc.lineAt(pos);
|
|
2286
|
-
let context = getContext(tree.resolveInner(pos, -1), doc);
|
|
2287
|
-
while (context.length && context[context.length - 1].from > pos - line.from)
|
|
2288
|
-
context.pop();
|
|
2289
|
-
if (!context.length)
|
|
2290
|
-
return dont = { range };
|
|
2291
|
-
let inner = context[context.length - 1];
|
|
2292
|
-
if (inner.to - inner.spaceAfter.length > pos - line.from)
|
|
2293
|
-
return dont = { range };
|
|
2294
|
-
let emptyLine = pos >= (inner.to - inner.spaceAfter.length) && !/\S/.test(line.text.slice(inner.to));
|
|
2295
|
-
// Empty line in list
|
|
2296
|
-
if (inner.item && emptyLine) {
|
|
2297
|
-
// First list item or blank line before: delete a level of markup
|
|
2298
|
-
if (inner.node.firstChild.to >= pos ||
|
|
2299
|
-
line.from > 0 && !/[^\s>]/.test(doc.lineAt(line.from - 1).text)) {
|
|
2300
|
-
let next = context.length > 1 ? context[context.length - 2] : null;
|
|
2301
|
-
let delTo, insert = "";
|
|
2302
|
-
if (next && next.item) { // Re-add marker for the list at the next level
|
|
2303
|
-
delTo = line.from + next.from;
|
|
2304
|
-
insert = next.marker(doc, 1);
|
|
2305
|
-
}
|
|
2306
|
-
else {
|
|
2307
|
-
delTo = line.from + (next ? next.to : 0);
|
|
2308
|
-
}
|
|
2309
|
-
let changes = [{ from: delTo, to: pos, insert }];
|
|
2310
|
-
if (inner.node.name == "OrderedList")
|
|
2311
|
-
renumberList(inner.item, doc, changes, -2);
|
|
2312
|
-
if (next && next.node.name == "OrderedList")
|
|
2313
|
-
renumberList(next.item, doc, changes);
|
|
2314
|
-
return { range: EditorSelection.cursor(delTo + insert.length), changes };
|
|
2315
|
-
}
|
|
2316
|
-
else { // Move this line down
|
|
2317
|
-
let insert = "";
|
|
2318
|
-
for (let i = 0, e = context.length - 2; i <= e; i++) {
|
|
2319
|
-
insert += context[i].blank(i < e ? countColumn(line.text, 4, context[i + 1].from) - insert.length : null, i < e);
|
|
2320
|
-
}
|
|
2321
|
-
insert = normalizeIndent(insert, state);
|
|
2322
|
-
return { range: EditorSelection.cursor(pos + insert.length + 1),
|
|
2323
|
-
changes: { from: line.from, insert: insert + state.lineBreak } };
|
|
2324
|
-
}
|
|
2325
|
-
}
|
|
2326
|
-
if (inner.node.name == "Blockquote" && emptyLine && line.from) {
|
|
2327
|
-
let prevLine = doc.lineAt(line.from - 1), quoted = />\s*$/.exec(prevLine.text);
|
|
2328
|
-
// Two aligned empty quoted lines in a row
|
|
2329
|
-
if (quoted && quoted.index == inner.from) {
|
|
2330
|
-
let changes = state.changes([{ from: prevLine.from + quoted.index, to: prevLine.to },
|
|
2331
|
-
{ from: line.from + inner.from, to: line.to }]);
|
|
2332
|
-
return { range: range.map(changes), changes };
|
|
2333
|
-
}
|
|
2334
|
-
}
|
|
2335
|
-
let changes = [];
|
|
2336
|
-
if (inner.node.name == "OrderedList")
|
|
2337
|
-
renumberList(inner.item, doc, changes);
|
|
2338
|
-
let continued = inner.item && inner.item.from < line.from;
|
|
2339
|
-
let insert = "";
|
|
2340
|
-
// If not dedented
|
|
2341
|
-
if (!continued || /^[\s\d.)\-+*>]*/.exec(line.text)[0].length >= inner.to) {
|
|
2342
|
-
for (let i = 0, e = context.length - 1; i <= e; i++) {
|
|
2343
|
-
insert += i == e && !continued ? context[i].marker(doc, 1)
|
|
2344
|
-
: context[i].blank(i < e ? countColumn(line.text, 4, context[i + 1].from) - insert.length : null);
|
|
2345
|
-
}
|
|
2346
|
-
}
|
|
2347
|
-
let from = pos;
|
|
2348
|
-
while (from > line.from && /\s/.test(line.text.charAt(from - line.from - 1)))
|
|
2349
|
-
from--;
|
|
2350
|
-
insert = normalizeIndent(insert, state);
|
|
2351
|
-
changes.push({ from, to: pos, insert: state.lineBreak + insert });
|
|
2352
|
-
return { range: EditorSelection.cursor(from + insert.length + 1), changes };
|
|
2353
|
-
});
|
|
2354
|
-
if (dont)
|
|
2355
|
-
return false;
|
|
2356
|
-
dispatch(state.update(changes, { scrollIntoView: true, userEvent: "input" }));
|
|
2357
|
-
return true;
|
|
2358
|
-
};
|
|
2359
|
-
function isMark(node) {
|
|
2360
|
-
return node.name == "QuoteMark" || node.name == "ListMark";
|
|
2361
|
-
}
|
|
2362
|
-
function contextNodeForDelete(tree, pos) {
|
|
2363
|
-
let node = tree.resolveInner(pos, -1), scan = pos;
|
|
2364
|
-
if (isMark(node)) {
|
|
2365
|
-
scan = node.from;
|
|
2366
|
-
node = node.parent;
|
|
2367
|
-
}
|
|
2368
|
-
for (let prev; prev = node.childBefore(scan);) {
|
|
2369
|
-
if (isMark(prev)) {
|
|
2370
|
-
scan = prev.from;
|
|
2371
|
-
}
|
|
2372
|
-
else if (prev.name == "OrderedList" || prev.name == "BulletList") {
|
|
2373
|
-
node = prev.lastChild;
|
|
2374
|
-
scan = node.to;
|
|
2375
|
-
}
|
|
2376
|
-
else {
|
|
2377
|
-
break;
|
|
2378
|
-
}
|
|
2379
|
-
}
|
|
2380
|
-
return node;
|
|
2381
|
-
}
|
|
2382
|
-
/**
|
|
2383
|
-
This command will, when invoked in a Markdown context with the
|
|
2384
|
-
cursor directly after list or blockquote markup, delete one level
|
|
2385
|
-
of markup. When the markup is for a list, it will be replaced by
|
|
2386
|
-
spaces on the first invocation (a further invocation will delete
|
|
2387
|
-
the spaces), to make it easy to continue a list.
|
|
2388
|
-
|
|
2389
|
-
When not after Markdown block markup, this command will return
|
|
2390
|
-
false, so it is intended to be bound alongside other deletion
|
|
2391
|
-
commands, with a higher precedence than the more generic commands.
|
|
2392
|
-
*/
|
|
2393
|
-
const deleteMarkupBackward = ({ state, dispatch }) => {
|
|
2394
|
-
let tree = syntaxTree(state);
|
|
2395
|
-
let dont = null, changes = state.changeByRange(range => {
|
|
2396
|
-
let pos = range.from, { doc } = state;
|
|
2397
|
-
if (range.empty && markdownLanguage.isActiveAt(state, range.from)) {
|
|
2398
|
-
let line = doc.lineAt(pos);
|
|
2399
|
-
let context = getContext(contextNodeForDelete(tree, pos), doc);
|
|
2400
|
-
if (context.length) {
|
|
2401
|
-
let inner = context[context.length - 1];
|
|
2402
|
-
let spaceEnd = inner.to - inner.spaceAfter.length + (inner.spaceAfter ? 1 : 0);
|
|
2403
|
-
// Delete extra trailing space after markup
|
|
2404
|
-
if (pos - line.from > spaceEnd && !/\S/.test(line.text.slice(spaceEnd, pos - line.from)))
|
|
2405
|
-
return { range: EditorSelection.cursor(line.from + spaceEnd),
|
|
2406
|
-
changes: { from: line.from + spaceEnd, to: pos } };
|
|
2407
|
-
if (pos - line.from == spaceEnd &&
|
|
2408
|
-
// Only apply this if we're on the line that has the
|
|
2409
|
-
// construct's syntax, or there's only indentation in the
|
|
2410
|
-
// target range
|
|
2411
|
-
(!inner.item || line.from <= inner.item.from || !/\S/.test(line.text.slice(0, inner.to)))) {
|
|
2412
|
-
let start = line.from + inner.from;
|
|
2413
|
-
// Replace a list item marker with blank space
|
|
2414
|
-
if (inner.item && inner.node.from < inner.item.from && /\S/.test(line.text.slice(inner.from, inner.to))) {
|
|
2415
|
-
let insert = inner.blank(countColumn(line.text, 4, inner.to) - countColumn(line.text, 4, inner.from));
|
|
2416
|
-
if (start == line.from)
|
|
2417
|
-
insert = normalizeIndent(insert, state);
|
|
2418
|
-
return { range: EditorSelection.cursor(start + insert.length),
|
|
2419
|
-
changes: { from: start, to: line.from + inner.to, insert } };
|
|
2420
|
-
}
|
|
2421
|
-
// Delete one level of indentation
|
|
2422
|
-
if (start < pos)
|
|
2423
|
-
return { range: EditorSelection.cursor(start), changes: { from: start, to: pos } };
|
|
2424
|
-
}
|
|
2425
|
-
}
|
|
2426
|
-
}
|
|
2427
|
-
return dont = { range };
|
|
2428
|
-
});
|
|
2429
|
-
if (dont)
|
|
2430
|
-
return false;
|
|
2431
|
-
dispatch(state.update(changes, { scrollIntoView: true, userEvent: "delete" }));
|
|
2432
|
-
return true;
|
|
2433
|
-
};
|
|
2434
|
-
|
|
2435
|
-
/**
|
|
2436
|
-
A small keymap with Markdown-specific bindings. Binds Enter to
|
|
2437
|
-
[`insertNewlineContinueMarkup`](https://codemirror.net/6/docs/ref/#lang-markdown.insertNewlineContinueMarkup)
|
|
2438
|
-
and Backspace to
|
|
2439
|
-
[`deleteMarkupBackward`](https://codemirror.net/6/docs/ref/#lang-markdown.deleteMarkupBackward).
|
|
2440
|
-
*/
|
|
2441
|
-
const markdownKeymap = [
|
|
2442
|
-
{ key: "Enter", run: insertNewlineContinueMarkup },
|
|
2443
|
-
{ key: "Backspace", run: deleteMarkupBackward }
|
|
2444
|
-
];
|
|
2445
|
-
const htmlNoMatch = /*@__PURE__*/html({ matchClosingTags: false });
|
|
2446
|
-
/**
|
|
2447
|
-
Markdown language support.
|
|
2448
|
-
*/
|
|
2449
|
-
function markdown(config = {}) {
|
|
2450
|
-
let { codeLanguages, defaultCodeLanguage, addKeymap = true, base: { parser } = commonmarkLanguage, completeHTMLTags = true } = config;
|
|
2451
|
-
if (!(parser instanceof MarkdownParser))
|
|
2452
|
-
throw new RangeError("Base parser provided to `markdown` should be a Markdown parser");
|
|
2453
|
-
let extensions = config.extensions ? [config.extensions] : [];
|
|
2454
|
-
let support = [htmlNoMatch.support], defaultCode;
|
|
2455
|
-
if (defaultCodeLanguage instanceof LanguageSupport) {
|
|
2456
|
-
support.push(defaultCodeLanguage.support);
|
|
2457
|
-
defaultCode = defaultCodeLanguage.language;
|
|
2458
|
-
}
|
|
2459
|
-
else if (defaultCodeLanguage) {
|
|
2460
|
-
defaultCode = defaultCodeLanguage;
|
|
2461
|
-
}
|
|
2462
|
-
let codeParser = codeLanguages || defaultCode ? getCodeParser(codeLanguages, defaultCode) : undefined;
|
|
2463
|
-
extensions.push(parseCode({ codeParser, htmlParser: htmlNoMatch.language.parser }));
|
|
2464
|
-
if (addKeymap)
|
|
2465
|
-
support.push(Prec.high(keymap.of(markdownKeymap)));
|
|
2466
|
-
let lang = mkLang(parser.configure(extensions));
|
|
2467
|
-
if (completeHTMLTags)
|
|
2468
|
-
support.push(lang.data.of({ autocomplete: htmlTagCompletion }));
|
|
2469
|
-
return new LanguageSupport(lang, support);
|
|
2470
|
-
}
|
|
2471
|
-
function htmlTagCompletion(context) {
|
|
2472
|
-
let { state, pos } = context, m = /<[:\-\.\w\u00b7-\uffff]*$/.exec(state.sliceDoc(pos - 25, pos));
|
|
2473
|
-
if (!m)
|
|
2474
|
-
return null;
|
|
2475
|
-
let tree = syntaxTree(state).resolveInner(pos, -1);
|
|
2476
|
-
while (tree && !tree.type.isTop) {
|
|
2477
|
-
if (tree.name == "CodeBlock" || tree.name == "FencedCode" || tree.name == "ProcessingInstructionBlock" ||
|
|
2478
|
-
tree.name == "CommentBlock" || tree.name == "Link" || tree.name == "Image")
|
|
2479
|
-
return null;
|
|
2480
|
-
tree = tree.parent;
|
|
2481
|
-
}
|
|
2482
|
-
return {
|
|
2483
|
-
from: pos - m[0].length, to: pos,
|
|
2484
|
-
options: htmlTagCompletions(),
|
|
2485
|
-
validFor: /^<[:\-\.\w\u00b7-\uffff]*$/
|
|
2486
|
-
};
|
|
2487
|
-
}
|
|
2488
|
-
let _tagCompletions = null;
|
|
2489
|
-
function htmlTagCompletions() {
|
|
2490
|
-
if (_tagCompletions)
|
|
2491
|
-
return _tagCompletions;
|
|
2492
|
-
let result = htmlCompletionSource(new CompletionContext(EditorState.create({ extensions: htmlNoMatch }), 0, true));
|
|
2493
|
-
return _tagCompletions = result ? result.options : [];
|
|
2494
|
-
}
|
|
2495
|
-
|
|
2496
|
-
export { commonmarkLanguage, deleteMarkupBackward, insertNewlineContinueMarkup, markdown, markdownKeymap, markdownLanguage };
|
|
2497
|
-
//# sourceMappingURL=index-sWVjGw-3.js.map
|