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