@actualwave/react-native-codeditor 1.0.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 +20 -0
- package/README.md +790 -0
- package/app.plugin.js +133 -0
- package/lib/module/BlockingView.js +25 -0
- package/lib/module/CodeEditor.js +239 -0
- package/lib/module/EditorAPI.js +2 -0
- package/lib/module/WebViewAPI.js +133 -0
- package/lib/module/index.js +6 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/app.plugin.d.ts +3 -0
- package/lib/typescript/babel.config.d.ts +10 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/react-native.config.d.ts +2 -0
- package/lib/typescript/scripts/copy-assets.d.ts +2 -0
- package/lib/typescript/src/BlockingView.d.ts +3 -0
- package/lib/typescript/src/CodeEditor.d.ts +33 -0
- package/lib/typescript/src/EditorAPI.d.ts +66 -0
- package/lib/typescript/src/WebViewAPI.d.ts +46 -0
- package/lib/typescript/src/index.d.ts +7 -0
- package/package.json +106 -0
- package/react-native.config.js +3 -0
- package/src/assets/codemirror/@actualwave_codemirror-lang-sksl.js +15 -0
- package/src/assets/codemirror/@babel_runtime_helpers_interopRequireDefault.js +1 -0
- package/src/assets/codemirror/@babel_runtime_helpers_objectSpread2.js +1 -0
- package/src/assets/codemirror/@babel_runtime_helpers_toConsumableArray.js +1 -0
- package/src/assets/codemirror/@codemirror_autocomplete.js +206 -0
- package/src/assets/codemirror/@codemirror_collab.js +31 -0
- package/src/assets/codemirror/@codemirror_commands.js +411 -0
- package/src/assets/codemirror/@codemirror_lang-angular.js +7 -0
- package/src/assets/codemirror/@codemirror_lang-cpp.js +7 -0
- package/src/assets/codemirror/@codemirror_lang-css.js +14 -0
- package/src/assets/codemirror/@codemirror_lang-go.js +13 -0
- package/src/assets/codemirror/@codemirror_lang-html.js +20 -0
- package/src/assets/codemirror/@codemirror_lang-java.js +7 -0
- package/src/assets/codemirror/@codemirror_lang-javascript.js +54 -0
- package/src/assets/codemirror/@codemirror_lang-jinja.js +15 -0
- package/src/assets/codemirror/@codemirror_lang-json.js +10 -0
- package/src/assets/codemirror/@codemirror_lang-less.js +10 -0
- package/src/assets/codemirror/@codemirror_lang-lezer.js +7 -0
- package/src/assets/codemirror/@codemirror_lang-liquid.js +15 -0
- package/src/assets/codemirror/@codemirror_lang-markdown.js +55 -0
- package/src/assets/codemirror/@codemirror_lang-php.js +7 -0
- package/src/assets/codemirror/@codemirror_lang-python.js +19 -0
- package/src/assets/codemirror/@codemirror_lang-rust.js +7 -0
- package/src/assets/codemirror/@codemirror_lang-sass.js +10 -0
- package/src/assets/codemirror/@codemirror_lang-sql.js +52 -0
- package/src/assets/codemirror/@codemirror_lang-vue.js +6 -0
- package/src/assets/codemirror/@codemirror_lang-wast.js +2 -0
- package/src/assets/codemirror/@codemirror_lang-xml.js +13 -0
- package/src/assets/codemirror/@codemirror_lang-yaml.js +13 -0
- package/src/assets/codemirror/@codemirror_language-data.js +5 -0
- package/src/assets/codemirror/@codemirror_language.js +524 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_apl.js +1 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_asciiarmor.js +1 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_asn1.js +3 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_asterisk.js +9 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_brainfuck.js +13 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_clike.js +31 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_clojure.js +5 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_cmake.js +6 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_cobol.js +7 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_coffeescript.js +14 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_commonlisp.js +1 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_crystal.js +18 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_css.js +5 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_cypher.js +1 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_d.js +2 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_diff.js +1 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_dockerfile.js +9 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_dtd.js +3 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_dylan.js +35 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_ebnf.js +9 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_ecl.js +3 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_eiffel.js +1 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_elm.js +3 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_erlang.js +52 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_factor.js +14 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_fcl.js +2 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_forth.js +5 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_fortran.js +2 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_gas.js +13 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_gherkin.js +5 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_go.js +2 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_groovy.js +3 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_haskell.js +5 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_haxe.js +12 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_http.js +1 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_idl.js +7 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_javascript.js +23 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_jinja2.js +8 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_julia.js +17 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_livescript.js +1 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_lua.js +2 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_mathematica.js +26 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_mbox.js +11 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_mirc.js +1 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_mllike.js +8 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_modelica.js +12 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_mscgen.js +3 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_mumps.js +16 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_nginx.js +1 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_nsis.js +20 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_ntriples.js +1 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_octave.js +8 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_oz.js +17 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_pascal.js +2 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_pegjs.js +25 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_perl.js +247 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_pig.js +6 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_powershell.js +7 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_properties.js +5 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_protobuf.js +7 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_pug.js +24 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_puppet.js +42 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_python.js +15 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_q.js +2 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_r.js +1 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_rpm.js +9 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_ruby.js +4 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_rust.js +5 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_sas.js +23 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_sass.js +26 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_scheme.js +14 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_shell.js +1 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_sieve.js +7 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_simple-mode.js +1 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_smalltalk.js +1 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_solr.js +1 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_sparql.js +1 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_spreadsheet.js +6 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_sql.js +84 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_stex.js +11 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_stylus.js +45 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_swift.js +2 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_tcl.js +1 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_textile.js +2 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_tiddlywiki.js +33 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_tiki.js +20 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_toml.js +4 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_troff.js +1 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_ttcn-cfg.js +3 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_ttcn.js +3 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_turtle.js +1 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_vb.js +11 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_vbscript.js +26 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_velocity.js +15 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_verilog.js +67 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_vhdl.js +2 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_wast.js +7 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_webidl.js +25 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_xml.js +6 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_xquery.js +51 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_yacas.js +16 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_yaml.js +1 -0
- package/src/assets/codemirror/@codemirror_legacy-modes_mode_z80.js +1 -0
- package/src/assets/codemirror/@codemirror_lint.js +46 -0
- package/src/assets/codemirror/@codemirror_merge.js +167 -0
- package/src/assets/codemirror/@codemirror_search.js +121 -0
- package/src/assets/codemirror/@codemirror_state.js +793 -0
- package/src/assets/codemirror/@codemirror_theme-one-dark.js +12 -0
- package/src/assets/codemirror/@codemirror_view.js +1210 -0
- package/src/assets/codemirror/@lezer_common.js +407 -0
- package/src/assets/codemirror/@lezer_cpp.js +4 -0
- package/src/assets/codemirror/@lezer_css.js +4 -0
- package/src/assets/codemirror/@lezer_go.js +3 -0
- package/src/assets/codemirror/@lezer_highlight.js +380 -0
- package/src/assets/codemirror/@lezer_html.js +20 -0
- package/src/assets/codemirror/@lezer_java.js +2 -0
- package/src/assets/codemirror/@lezer_javascript.js +7 -0
- package/src/assets/codemirror/@lezer_json.js +2 -0
- package/src/assets/codemirror/@lezer_lezer.js +2 -0
- package/src/assets/codemirror/@lezer_lr.js +325 -0
- package/src/assets/codemirror/@lezer_markdown.js +286 -0
- package/src/assets/codemirror/@lezer_php.js +3 -0
- package/src/assets/codemirror/@lezer_python.js +5 -0
- package/src/assets/codemirror/@lezer_rust.js +3 -0
- package/src/assets/codemirror/@lezer_sass.js +5 -0
- package/src/assets/codemirror/@lezer_xml.js +3 -0
- package/src/assets/codemirror/@lezer_yaml.js +12 -0
- package/src/assets/codemirror/@marijn_find-cluster-break.js +10 -0
- package/src/assets/codemirror/@uiw_codemirror-theme-androidstudio.js +3 -0
- package/src/assets/codemirror/@uiw_codemirror-theme-andromeda.js +1 -0
- package/src/assets/codemirror/@uiw_codemirror-theme-atomone.js +6 -0
- package/src/assets/codemirror/@uiw_codemirror-theme-aura.js +1 -0
- package/src/assets/codemirror/@uiw_codemirror-theme-basic.js +1 -0
- package/src/assets/codemirror/@uiw_codemirror-theme-bbedit.js +1 -0
- package/src/assets/codemirror/@uiw_codemirror-theme-copilot.js +1 -0
- package/src/assets/codemirror/@uiw_codemirror-theme-darcula.js +6 -0
- package/src/assets/codemirror/@uiw_codemirror-theme-dracula.js +6 -0
- package/src/assets/codemirror/@uiw_codemirror-theme-duotone.js +5 -0
- package/src/assets/codemirror/@uiw_codemirror-theme-eclipse.js +1 -0
- package/src/assets/codemirror/@uiw_codemirror-theme-github.js +3 -0
- package/src/assets/codemirror/@uiw_codemirror-theme-material.js +1 -0
- package/src/assets/codemirror/@uiw_codemirror-theme-monokai.js +1 -0
- package/src/assets/codemirror/@uiw_codemirror-theme-nord.js +2 -0
- package/src/assets/codemirror/@uiw_codemirror-theme-okaidia.js +2 -0
- package/src/assets/codemirror/@uiw_codemirror-theme-solarized.js +1 -0
- package/src/assets/codemirror/@uiw_codemirror-theme-sublime.js +2 -0
- package/src/assets/codemirror/@uiw_codemirror-theme-tokyo-night.js +1 -0
- package/src/assets/codemirror/@uiw_codemirror-theme-vscode.js +5 -0
- package/src/assets/codemirror/@uiw_codemirror-theme-xcode.js +3 -0
- package/src/assets/codemirror/@uiw_codemirror-themes.js +1 -0
- package/src/assets/codemirror/_core.js +4494 -0
- package/src/assets/codemirror/codemirror.js +46 -0
- package/src/assets/codemirror/crelt.js +1 -0
- package/src/assets/codemirror/style-mod.js +36 -0
- package/src/assets/codemirror/w3c-keyname.js +8 -0
- package/src/assets/codemirror-editor.umd.js +415 -0
- package/src/assets/editor.html +377 -0
- package/src/assets/webview-interface.umd.js +2 -0
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
async function moduleInitFunction(requireAsyncModule,exports={}){function requireDist(){function skipForList(bl,cx,line){if(line.pos==line.text.length||bl!=cx.block&&line.indent>=cx.stack[line.depth+1].value+line.baseIndent)return!0;if(line.indent>=line.baseIndent+4)return!1;let size=(bl.type==Type.OrderedList?isOrderedList:isBulletList)(line,cx,!1);return 0<size&&(bl.type!=Type.BulletList||0>isHorizontalRule(line,cx,!1))&&line.text.charCodeAt(line.pos+size-1)==bl.value}function space(ch){return 32==ch||9==ch||10==ch||13==ch}function skipSpace(line,i=0){for(;i<line.length&&space(line.charCodeAt(i));)i++;return i}function skipSpaceBack(line,i,to){for(;i>to&&space(line.charCodeAt(i-1));)i--;return i}function isFencedCode(line){if(96!=line.next&&126!=line.next/* '`~' */)return-1;let pos=line.pos+1;for(;pos<line.text.length&&line.text.charCodeAt(pos)==line.next;)pos++;if(pos<line.pos+3)return-1;if(96==line.next)for(let i=pos;i<line.text.length;i++)if(96==line.text.charCodeAt(i))return-1;return pos}function isBlockquote(line){return 62==line.next/* '>' */?32==line.text.charCodeAt(line.pos+1)?2:1:-1}function isHorizontalRule(line,cx,breaking){if(42!=line.next&&45!=line.next&&95!=line.next/* '_-*' */)return-1;let count=1;for(let ch,pos=line.pos+1;pos<line.text.length;pos++)if(ch=line.text.charCodeAt(pos),ch==line.next)count++;else if(!space(ch))return-1;// Setext headers take precedence
|
|
2
|
+
return breaking&&45==line.next&&-1<isSetextUnderline(line)&&line.depth==cx.stack.length&&-1<cx.parser.leafBlockParsers.indexOf(DefaultLeafBlocks.SetextHeading)?-1:3>count?-1:1}function inList(cx,type){for(let i=cx.stack.length-1;0<=i;i--)if(cx.stack[i].type==type)return!0;return!1}function isBulletList(line,cx,breaking){return(45==line.next||43==line.next||42==line.next/* '-+*' */)&&(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}function isOrderedList(line,cx,breaking){let pos=line.pos,next=line.next;for(;;){if(48<=next&&57>=next/* '0-9' */)pos++;else break;if(pos==line.text.length)return-1;next=line.text.charCodeAt(pos)}return pos==line.pos||pos>line.pos+9||46!=next&&41!=next/* '.)' */||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||49!=line.next/* '1' */)?-1:pos+1-line.pos}function isAtxHeading(line){if(35!=line.next/* '#' */)return-1;let pos=line.pos+1;for(;pos<line.text.length&&35==line.text.charCodeAt(pos);)pos++;if(pos<line.text.length&&32!=line.text.charCodeAt(pos))return-1;let size=pos-line.pos;return 6<size?-1:size}function isSetextUnderline(line){if(45!=line.next&&61!=line.next/* '-=' */||line.indent>=line.baseIndent+4)return-1;let pos=line.pos+1;for(;pos<line.text.length&&line.text.charCodeAt(pos)==line.next;)pos++;let end=pos;for(;pos<line.text.length&&space(line.text.charCodeAt(pos));)pos++;return pos==line.text.length?end:-1}function isHTMLBlock(line,_cx,breaking){if(60!=line.next/* '<' */)return-1;let rest=line.text.slice(line.pos);for(let i=0,e=HTMLBlockStyle.length-(breaking?1:0);i<e;i++)if(HTMLBlockStyle[i][0].test(rest))return i;return-1}function getListIndent(line,pos){let indentAfter=line.countIndent(pos,line.pos,line.indent),indented=line.countIndent(line.skipSpace(pos),pos,indentAfter);return indented>=indentAfter+5?indentAfter+1:indented}function addCodeText(marks,from,to){let last=marks.length-1;0<=last&&marks[last].to==from&&marks[last].type==Type.CodeText?marks[last].to=to:marks.push(elt(Type.CodeText,from,to))}// Rules for parsing blocks. A return value of false means the rule
|
|
3
|
+
// doesn't apply here, true means it does. When true is returned and
|
|
4
|
+
// `p.line` has been updated, the rule is assumed to have consumed a
|
|
5
|
+
// leaf block. Otherwise, it is assumed to have opened a context.
|
|
6
|
+
function lineEnd(text,pos){for(;pos<text.length;pos++){let next=text.charCodeAt(pos);if(10==next)break;if(!space(next))return-1}return pos}function injectGaps(ranges,rangeI,tree,offset,dummies){function movePastNext(upto,inclusive){for(;inclusive?upto>=rangeEnd:upto>rangeEnd;){let size=ranges[rangeI+1].from-rangeEnd;offset+=size,upto+=size,rangeI++,rangeEnd=ranges[rangeI].to}}let rangeEnd=ranges[rangeI].to,children=[],positions=[],start=tree.from+offset;for(let ch=tree.firstChild;ch;ch=ch.nextSibling){movePastNext(ch.from+offset,!0);let node,from=ch.from+offset,reuse=dummies.get(ch.tree);reuse?node=reuse:ch.to+offset>rangeEnd?(node=injectGaps(ranges,rangeI,ch,offset,dummies),movePastNext(ch.to+offset,!1)):node=ch.toTree(),children.push(node),positions.push(from-start)}return movePastNext(tree.to+offset,!1),new common.Tree(tree.type,children,positions,tree.to+offset-start,tree.tree?tree.tree.propValues:void 0)}/**
|
|
7
|
+
A Markdown parser configuration.
|
|
8
|
+
*/function nonEmpty(a){return null!=a&&0<a.length}function resolveConfig(spec){if(!Array.isArray(spec))return spec;if(0==spec.length)return null;let conf=resolveConfig(spec[0]);if(1==spec.length)return conf;let rest=resolveConfig(spec.slice(1));if(!rest||!conf)return conf||rest;let conc=(a,b)=>(a||none).concat(b||none),wrapA=conf.wrap,wrapB=rest.wrap;return{props:conc(conf.props,rest.props),defineNodes:conc(conf.defineNodes,rest.defineNodes),parseBlock:conc(conf.parseBlock,rest.parseBlock),parseInline:conc(conf.parseInline,rest.parseInline),remove:conc(conf.remove,rest.remove),wrap:wrapA?wrapB?(inner,input,fragments,ranges)=>wrapA(wrapB(inner,input,fragments,ranges),input,fragments,ranges):wrapA:wrapB}}function findName(names,name){let found=names.indexOf(name);if(0>found)throw new RangeError(`Position specified relative to unknown parser ${name}`);return found}function elt(type,from,to,children){return new Element(type,from,to,children)}function finishLink(cx,content,type,start,startPos){let{text}=cx,next=cx.char(startPos),endPos=startPos;if(content.unshift(elt(Type.LinkMark,start,start+(type==Type.Image?2:1))),content.push(elt(Type.LinkMark,startPos-1,startPos)),40==next/* '(' */){let title,pos=cx.skipSpace(startPos+1),dest=parseURL(text,pos-cx.offset,cx.offset);dest&&(pos=cx.skipSpace(dest.to),pos!=dest.to&&(title=parseLinkTitle(text,pos-cx.offset,cx.offset),title&&(pos=cx.skipSpace(title.to)))),41==cx.char(pos)/* ')' */&&(content.push(elt(Type.LinkMark,startPos,startPos+1)),endPos=pos+1,dest&&content.push(dest),title&&content.push(title),content.push(elt(Type.LinkMark,pos,endPos)))}else if(91==next/* '[' */){let label=parseLinkLabel(text,startPos-cx.offset,cx.offset,!1);label&&(content.push(label),endPos=label.to)}return elt(type,start,endPos,content)}// These return `null` when falling off the end of the input, `false`
|
|
9
|
+
// when parsing fails otherwise (for use in the incremental link
|
|
10
|
+
// reference parser).
|
|
11
|
+
function parseURL(text,start,offset){let next=text.charCodeAt(start);if(60==next/* '<' */){for(let ch,pos=start+1;pos<text.length;pos++){if(ch=text.charCodeAt(pos),62==ch/* '>' */)return elt(Type.URL,start+offset,pos+1+offset);if(60==ch||10==ch/* '<\n' */)return!1}return null}else{let depth=0,pos=start;for(let ch,escaped=!1;pos<text.length&&(ch=text.charCodeAt(pos),!space(ch));pos++)if(escaped)escaped=!1;else if(40==ch/* '(' */)depth++;else if(41==ch/* ')' */){if(!depth)break;depth--}else 92==ch/* '\\' */&&(escaped=!0);return pos>start?elt(Type.URL,start+offset,pos+offset):pos==text.length&&null}}function parseLinkTitle(text,start,offset){let next=text.charCodeAt(start);if(39!=next&&34!=next&&40!=next/* '"\'(' */)return!1;let end=40==next?41:next;for(let ch,pos=start+1,escaped=!1;pos<text.length;pos++)if(ch=text.charCodeAt(pos),escaped)escaped=!1;else{if(ch==end)return elt(Type.LinkTitle,start+offset,pos+1+offset);92==ch/* '\\' */&&(escaped=!0)}return null}function parseLinkLabel(text,start,offset,requireNonWS){for(let ch,escaped=!1,pos=start+1,end=Math.min(text.length,pos+999);pos<end;pos++)if(ch=text.charCodeAt(pos),escaped)escaped=!1;else{if(93==ch/* ']' */)return!requireNonWS&&elt(Type.LinkLabel,start+offset,pos+1+offset);if(requireNonWS&&!space(ch)&&(requireNonWS=!1),91==ch/* '[' */)return!1;92==ch/* '\\' */&&(escaped=!0)}return null}/**
|
|
12
|
+
Inline parsing functions get access to this context, and use it to
|
|
13
|
+
read the content and emit syntax nodes.
|
|
14
|
+
*/function injectMarks(elements,marks){if(!marks.length)return elements;if(!elements.length)return marks;let elts=elements.slice(),eI=0;for(let mark of marks){for(;eI<elts.length&&elts[eI].to<mark.to;)eI++;if(eI<elts.length&&elts[eI].from<mark.from){let e=elts[eI];e instanceof Element&&(elts[eI]=new Element(e.type,e.from,e.to,injectMarks(e.children,[mark])))}else elts.splice(eI++,0,mark)}return elts}// These are blocks that can span blank lines, and should thus only be
|
|
15
|
+
// reused if their next sibling is also being reused.
|
|
16
|
+
// Convert an input-stream-relative position to a
|
|
17
|
+
// Markdown-doc-relative position by subtracting the size of all input
|
|
18
|
+
// gaps before `abs`.
|
|
19
|
+
function toRelative(abs,ranges){let pos=abs;for(let i=1;i<ranges.length;i++){let gapFrom=ranges[i-1].to,gapTo=ranges[i].from;gapFrom<abs&&(pos-=gapTo-gapFrom)}return pos}function leftOverSpace(node,from,to){let ranges=[];for(let nextPos,n=node.firstChild,pos=from;;n=n.nextSibling){if(nextPos=n?n.from:to,nextPos>pos&&ranges.push({from:pos,to:nextPos}),!n)break;pos=n.to}return ranges}/**
|
|
20
|
+
Create a Markdown extension to enable nested parsing on code
|
|
21
|
+
blocks and/or embedded HTML.
|
|
22
|
+
*/function parseCode(config){let{codeParser,htmlParser}=config,wrap=common.parseMixed((node,input)=>{let id=node.type.id;if(codeParser&&(id==Type.CodeBlock||id==Type.FencedCode)){let info="";if(id==Type.FencedCode){let infoNode=node.node.getChild(Type.CodeInfo);infoNode&&(info=input.read(infoNode.from,infoNode.to))}let parser=codeParser(info);if(parser)return{parser,overlay:node=>node.type.id==Type.CodeText,bracketed:id==Type.FencedCode}}else if(htmlParser&&(id==Type.HTMLBlock||id==Type.HTMLTag||id==Type.CommentBlock))return{parser:htmlParser,overlay:leftOverSpace(node.node,node.from,node.to)};return null});return{wrap}}// Parse a line as a table row and return the row count. When `elts`
|
|
23
|
+
// is given, push syntax elements for the content onto it.
|
|
24
|
+
function parseRow(cx,line,startI=0,elts,offset=0){let count=0,first=!0,cellStart=-1,cellEnd=-1,esc=!1,parseCell=()=>{elts.push(cx.elt("TableCell",offset+cellStart,offset+cellEnd,cx.parser.parseInline(line.slice(cellStart,cellEnd),offset+cellStart)))};for(let next,i=startI;i<line.length;i++)next=line.charCodeAt(i),124!=next/* '|' */||esc?(esc||32!=next&&9!=next)&&(0>cellStart&&(cellStart=i),cellEnd=i+1):((!first||-1<cellStart)&&count++,first=!1,elts&&(-1<cellStart&&parseCell(),elts.push(cx.elt("TableDelimiter",i+offset,i+offset+1))),cellStart=cellEnd=-1),esc=!esc&&92==next;return-1<cellStart&&(count++,elts&&parseCell()),count}function hasPipe(str,start){for(let next,i=start;i<str.length;i++){if(next=str.charCodeAt(i),124==next/* '|' */)return!0;92==next/* '\\' */&&i++}return!1}function count(str,from,to,ch){let result=0;for(let i=from;i<to;i++)str[i]==ch&&result++;return result}function autolinkURLEnd(text,from){urlRE.lastIndex=from;let m=urlRE.exec(text);if(!m||-1<lastTwoDomainWords.exec(m[0])[0].indexOf("_"))return-1;let end=from+m[0].length;for(;;){let m,last=text[end-1];if(/[?!.,:*_~]/.test(last)||")"==last&&count(text,from,end,")")>count(text,from,end,"("))end--;else if(";"==last&&(m=/&(?:#\d+|#x[a-f\d]+|\w+);$/.exec(text.slice(from,end))))end=from+m.index;else break}return end}function autolinkEmailEnd(text,from){emailRE.lastIndex=from;let m=emailRE.exec(text);if(!m)return-1;let last=m[0][m[0].length-1];return"_"==last||"-"==last?-1:from+m[0].length-("."==last?1:0)}/**
|
|
25
|
+
Extension that implements autolinking for
|
|
26
|
+
`www.`/`http://`/`https://`/`mailto:`/`xmpp:` URLs and email
|
|
27
|
+
addresses.
|
|
28
|
+
*/function parseSubSuper(ch,node,mark){return(cx,next,pos)=>{if(next!=ch||cx.char(pos+1)==ch)return-1;let elts=[cx.elt(mark,pos,pos+1)];for(let next,i=pos+1;i<cx.end;i++){if(next=cx.char(i),next==ch)return cx.addElement(cx.elt(node,pos,i+1,elts.concat(cx.elt(mark,i,i+1))));if(92==next/* '\\' */&&elts.push(cx.elt("Escape",i,i++ +2)),space(next))break}return-1}}/**
|
|
29
|
+
Extension providing
|
|
30
|
+
[Pandoc-style](https://pandoc.org/MANUAL.html#superscripts-and-subscripts)
|
|
31
|
+
superscript using `^` markers.
|
|
32
|
+
*/if(hasRequiredDist)return dist;hasRequiredDist=1;var common=require$$0,highlight=require$$1;class CompositeBlock{static create(type,value,from,parentHash,end){let hash=0|parentHash+(parentHash<<8)+type+(value<<4);return new CompositeBlock(type,value,from,hash,end,[],[])}constructor(type,// Used for indentation in list items, markup character in lists
|
|
33
|
+
value,from,hash,end,children,positions){this.type=type,this.value=value,this.from=from,this.hash=hash,this.end=end,this.children=children,this.positions=positions,this.hashProp=[[common.NodeProp.contextHash,hash]]}addChild(child,pos){child.prop(common.NodeProp.contextHash)!=this.hash&&(child=new common.Tree(child.type,child.children,child.positions,child.length,this.hashProp)),this.children.push(child),this.positions.push(pos)}toTree(nodeSet,end=this.end){let last=this.children.length-1;return 0<=last&&(end=Math.max(end,this.positions[last]+this.children[last].length+this.from)),new common.Tree(nodeSet.types[this.type],this.children,this.positions,end-this.from).balance({makeTree:(children,positions,length)=>new common.Tree(common.NodeType.none,children,positions,length,this.hashProp)})}}var Type;(function(Type){Type[Type.Document=1]="Document",Type[Type.CodeBlock=2]="CodeBlock",Type[Type.FencedCode=3]="FencedCode",Type[Type.Blockquote=4]="Blockquote",Type[Type.HorizontalRule=5]="HorizontalRule",Type[Type.BulletList=6]="BulletList",Type[Type.OrderedList=7]="OrderedList",Type[Type.ListItem=8]="ListItem",Type[Type.ATXHeading1=9]="ATXHeading1",Type[Type.ATXHeading2=10]="ATXHeading2",Type[Type.ATXHeading3=11]="ATXHeading3",Type[Type.ATXHeading4=12]="ATXHeading4",Type[Type.ATXHeading5=13]="ATXHeading5",Type[Type.ATXHeading6=14]="ATXHeading6",Type[Type.SetextHeading1=15]="SetextHeading1",Type[Type.SetextHeading2=16]="SetextHeading2",Type[Type.HTMLBlock=17]="HTMLBlock",Type[Type.LinkReference=18]="LinkReference",Type[Type.Paragraph=19]="Paragraph",Type[Type.CommentBlock=20]="CommentBlock",Type[Type.ProcessingInstructionBlock=21]="ProcessingInstructionBlock",Type[Type.Escape=22]="Escape",Type[Type.Entity=23]="Entity",Type[Type.HardBreak=24]="HardBreak",Type[Type.Emphasis=25]="Emphasis",Type[Type.StrongEmphasis=26]="StrongEmphasis",Type[Type.Link=27]="Link",Type[Type.Image=28]="Image",Type[Type.InlineCode=29]="InlineCode",Type[Type.HTMLTag=30]="HTMLTag",Type[Type.Comment=31]="Comment",Type[Type.ProcessingInstruction=32]="ProcessingInstruction",Type[Type.Autolink=33]="Autolink",Type[Type.HeaderMark=34]="HeaderMark",Type[Type.QuoteMark=35]="QuoteMark",Type[Type.ListMark=36]="ListMark",Type[Type.LinkMark=37]="LinkMark",Type[Type.EmphasisMark=38]="EmphasisMark",Type[Type.CodeMark=39]="CodeMark",Type[Type.CodeText=40]="CodeText",Type[Type.CodeInfo=41]="CodeInfo",Type[Type.LinkTitle=42]="LinkTitle",Type[Type.LinkLabel=43]="LinkLabel",Type[Type.URL=44]="URL"})(Type||(Type={}));/**
|
|
34
|
+
Data structure used to accumulate a block's content during [leaf
|
|
35
|
+
block parsing](#BlockParser.leaf).
|
|
36
|
+
*/class LeafBlock{/**
|
|
37
|
+
@internal
|
|
38
|
+
*/constructor(/**
|
|
39
|
+
The start position of the block.
|
|
40
|
+
*/start,/**
|
|
41
|
+
The block's text content.
|
|
42
|
+
*/content){this.start=start,this.content=content,this.marks=[],this.parsers=[]}}/**
|
|
43
|
+
Data structure used during block-level per-line parsing.
|
|
44
|
+
*/class Line{constructor(){this.text="",this.baseIndent=0,this.basePos=0,this.depth=0,this.markers=[],this.pos=0,this.indent=0,this.next=-1}/**
|
|
45
|
+
@internal
|
|
46
|
+
*/forward(){this.basePos>this.pos&&this.forwardInner()}/**
|
|
47
|
+
@internal
|
|
48
|
+
*/forwardInner(){let newPos=this.skipSpace(this.basePos);this.indent=this.countIndent(newPos,this.pos,this.indent),this.pos=newPos,this.next=newPos==this.text.length?-1:this.text.charCodeAt(newPos)}/**
|
|
49
|
+
Skip whitespace after the given position, return the position of
|
|
50
|
+
the next non-space character or the end of the line if there's
|
|
51
|
+
only space after `from`.
|
|
52
|
+
*/skipSpace(from){return skipSpace(this.text,from)}/**
|
|
53
|
+
@internal
|
|
54
|
+
*/reset(text){for(this.text=text,this.baseIndent=this.basePos=this.pos=this.indent=0,this.forwardInner(),this.depth=1;this.markers.length;)this.markers.pop()}/**
|
|
55
|
+
Move the line's base position forward to the given position.
|
|
56
|
+
This should only be called by composite [block
|
|
57
|
+
parsers](#BlockParser.parse) or [markup skipping
|
|
58
|
+
functions](#NodeSpec.composite).
|
|
59
|
+
*/moveBase(to){this.basePos=to,this.baseIndent=this.countIndent(to,this.pos,this.indent)}/**
|
|
60
|
+
Move the line's base position forward to the given _column_.
|
|
61
|
+
*/moveBaseColumn(indent){this.baseIndent=indent,this.basePos=this.findColumn(indent)}/**
|
|
62
|
+
Store a composite-block-level marker. Should be called from
|
|
63
|
+
[markup skipping functions](#NodeSpec.composite) when they
|
|
64
|
+
consume any non-whitespace characters.
|
|
65
|
+
*/addMarker(elt){this.markers.push(elt)}/**
|
|
66
|
+
Find the column position at `to`, optionally starting at a given
|
|
67
|
+
position and column.
|
|
68
|
+
*/countIndent(to,from=0,indent=0){for(let i=from;i<to;i++)indent+=9==this.text.charCodeAt(i)?4-indent%4:1;return indent}/**
|
|
69
|
+
Find the position corresponding to the given column.
|
|
70
|
+
*/findColumn(goal){let i=0;for(let indent=0;i<this.text.length&&indent<goal;i++)indent+=9==this.text.charCodeAt(i)?4-indent%4:1;return i}/**
|
|
71
|
+
@internal
|
|
72
|
+
*/scrub(){if(!this.baseIndent)return this.text;let result="";for(let i=0;i<this.basePos;i++)result+=" ";return result+this.text.slice(this.basePos)}}const DefaultSkipMarkup={[Type.Blockquote](bl,cx,line){return 62==line.next/* '>' */&&(line.markers.push(elt(Type.QuoteMark,cx.lineStart+line.pos,cx.lineStart+line.pos+1)),line.moveBase(line.pos+(space(line.text.charCodeAt(line.pos+1))?2:1)),bl.end=cx.lineStart+line.text.length,!0)},[Type.ListItem](bl,_cx,line){return!(line.indent<line.baseIndent+bl.value&&-1<line.next)&&(line.moveBaseColumn(line.baseIndent+bl.value),!0)},[Type.OrderedList]:skipForList,[Type.BulletList]:skipForList,[Type.Document](){return!0}},EmptyLine=/^[ \t]*$/,CommentEnd=/-->/,ProcessingEnd=/\?>/,HTMLBlockStyle=[[/^<(?:script|pre|style)(?:\s|>|$)/i,/<\/(?:script|pre|style)>/i],[/^\s*<!--/,CommentEnd],[/^\s*<\?/,ProcessingEnd],[/^\s*<![A-Z]/,/>/],[/^\s*<!\[CDATA\[/,/\]\]>/],[/^\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],[/^\s*(?:<\/[a-z][\w-]*\s*>|<[a-z][\w-]*(\s+[a-z:_][\w-.]*(?:\s*=\s*(?:[^\s"'=<>`]+|'[^']*'|"[^"]*"))?)*\s*>)\s*$/i,EmptyLine]],DefaultBlockParsers={LinkReference:void 0,IndentedCode(cx,line){let base=line.baseIndent+4;if(line.indent<base)return!1;let start=line.findColumn(base),from=cx.lineStart+start,to=cx.lineStart+line.text.length,marks=[],pendingMarks=[];for(addCodeText(marks,from,to);cx.nextLine()&&line.depth>=cx.stack.length;)if(line.pos==line.text.length){addCodeText(pendingMarks,cx.lineStart-1,cx.lineStart);for(let m of line.markers)pendingMarks.push(m)}else if(line.indent<base)break;else{if(pendingMarks.length){for(let m of pendingMarks)m.type==Type.CodeText?addCodeText(marks,m.from,m.to):marks.push(m);pendingMarks=[]}addCodeText(marks,cx.lineStart-1,cx.lineStart);for(let m of line.markers)marks.push(m);to=cx.lineStart+line.text.length;let codeStart=cx.lineStart+line.findColumn(line.baseIndent+4);codeStart<to&&addCodeText(marks,codeStart,to)}return pendingMarks.length&&(pendingMarks=pendingMarks.filter(m=>m.type!=Type.CodeText),pendingMarks.length&&(line.markers=pendingMarks.concat(line.markers))),cx.addNode(cx.buffer.writeElements(marks,-from).finish(Type.CodeBlock,to-from),from),!0},FencedCode(cx,line){let fenceEnd=isFencedCode(line);if(0>fenceEnd)return!1;let from=cx.lineStart+line.pos,ch=line.next,len=fenceEnd-line.pos,infoFrom=line.skipSpace(fenceEnd),infoTo=skipSpaceBack(line.text,line.text.length,infoFrom),marks=[elt(Type.CodeMark,from,from+len)];infoFrom<infoTo&&marks.push(elt(Type.CodeInfo,cx.lineStart+infoFrom,cx.lineStart+infoTo));for(let i,first=!0,empty=!0,hasLine=!1;cx.nextLine()&&line.depth>=cx.stack.length;first=!1){if(i=line.pos,4>line.indent-line.baseIndent)for(;i<line.text.length&&line.text.charCodeAt(i)==ch;)i++;if(i-line.pos>=len&&line.skipSpace(i)==line.text.length){for(let m of line.markers)marks.push(m);empty&&hasLine&&addCodeText(marks,cx.lineStart-1,cx.lineStart),marks.push(elt(Type.CodeMark,cx.lineStart+line.pos,cx.lineStart+i)),cx.nextLine();break}else{hasLine=!0,first||(addCodeText(marks,cx.lineStart-1,cx.lineStart),empty=!1);for(let m of line.markers)marks.push(m);let textStart=cx.lineStart+line.basePos,textEnd=cx.lineStart+line.text.length;textStart<textEnd&&(addCodeText(marks,textStart,textEnd),empty=!1)}}return cx.addNode(cx.buffer.writeElements(marks,-from).finish(Type.FencedCode,cx.prevLineEnd()-from),from),!0},Blockquote(cx,line){let size=isBlockquote(line);return!(0>size)&&(cx.startContext(Type.Blockquote,line.pos),cx.addNode(Type.QuoteMark,cx.lineStart+line.pos,cx.lineStart+line.pos+1),line.moveBase(line.pos+size),null)},HorizontalRule(cx,line){if(0>isHorizontalRule(line,cx,!1))return!1;let from=cx.lineStart+line.pos;return cx.nextLine(),cx.addNode(Type.HorizontalRule,from),!0},BulletList(cx,line){let size=isBulletList(line,cx,!1);if(0>size)return!1;cx.block.type!=Type.BulletList&&cx.startContext(Type.BulletList,line.basePos,line.next);let newBase=getListIndent(line,line.pos+1);return cx.startContext(Type.ListItem,line.basePos,newBase-line.baseIndent),cx.addNode(Type.ListMark,cx.lineStart+line.pos,cx.lineStart+line.pos+size),line.moveBaseColumn(newBase),null},OrderedList(cx,line){let size=isOrderedList(line,cx,!1);if(0>size)return!1;cx.block.type!=Type.OrderedList&&cx.startContext(Type.OrderedList,line.basePos,line.text.charCodeAt(line.pos+size-1));let newBase=getListIndent(line,line.pos+size);return cx.startContext(Type.ListItem,line.basePos,newBase-line.baseIndent),cx.addNode(Type.ListMark,cx.lineStart+line.pos,cx.lineStart+line.pos+size),line.moveBaseColumn(newBase),null},ATXHeading(cx,line){let size=isAtxHeading(line);if(0>size)return!1;let off=line.pos,from=cx.lineStart+off,endOfSpace=skipSpaceBack(line.text,line.text.length,off),after=endOfSpace;for(;after>off&&line.text.charCodeAt(after-1)==line.next;)after--;after!=endOfSpace&&after!=off&&space(line.text.charCodeAt(after-1))||(after=line.text.length);let buf=cx.buffer.write(Type.HeaderMark,0,size).writeElements(cx.parser.parseInline(line.text.slice(off+size+1,after),from+size+1),-from);after<line.text.length&&buf.write(Type.HeaderMark,after-off,endOfSpace-off);let node=buf.finish(Type.ATXHeading1-1+size,line.text.length-off);return cx.nextLine(),cx.addNode(node,from),!0},HTMLBlock(cx,line){let type=isHTMLBlock(line,cx,!1);if(0>type)return!1;let from=cx.lineStart+line.pos,end=HTMLBlockStyle[type][1],marks=[],trailing=end!=EmptyLine;for(;!end.test(line.text)&&cx.nextLine();){if(line.depth<cx.stack.length){trailing=!1;break}for(let m of line.markers)marks.push(m)}trailing&&cx.nextLine();let nodeType=end==CommentEnd?Type.CommentBlock:end==ProcessingEnd?Type.ProcessingInstructionBlock:Type.HTMLBlock,to=cx.prevLineEnd();return cx.addNode(cx.buffer.writeElements(marks,-from).finish(nodeType,to-from),from),!0},SetextHeading:void 0// Specifies relative precedence for block-continue function
|
|
73
|
+
};// This implements a state machine that incrementally parses link references. At each
|
|
74
|
+
// next line, it looks ahead to see if the line continues the reference or not. If it
|
|
75
|
+
// doesn't and a valid link is available ending before that line, it finishes that.
|
|
76
|
+
// Similarly, on `finish` (when the leaf is terminated by external circumstances), it
|
|
77
|
+
// creates a link reference if there's a valid reference up to the current point.
|
|
78
|
+
class LinkReferenceParser{constructor(leaf){this.stage=0/* RefStage.Start */,this.elts=[],this.pos=0,this.start=leaf.start,this.advance(leaf.content)}nextLine(cx,line,leaf){if(-1==this.stage/* RefStage.Failed */)return!1;let content=leaf.content+"\n"+line.scrub(),finish=this.advance(content);return!!(-1<finish&&finish<content.length)&&this.complete(cx,leaf,finish)}finish(cx,leaf){return(2==this.stage/* RefStage.Link */||3==this.stage/* RefStage.Title */)&&skipSpace(leaf.content,this.pos)==leaf.content.length&&this.complete(cx,leaf,leaf.content.length)}complete(cx,leaf,len){return cx.addLeafElement(leaf,elt(Type.LinkReference,this.start,this.start+len,this.elts)),!0}nextStage(elt){return elt?(this.pos=elt.to-this.start,this.elts.push(elt),this.stage++,!0):(!1===elt&&(this.stage=-1/* RefStage.Failed */),!1)}advance(content){for(;;){if(-1==this.stage/* RefStage.Failed */)return-1;if(0==this.stage/* RefStage.Start */){if(!this.nextStage(parseLinkLabel(content,this.pos,this.start,!0)))return-1;if(58!=content.charCodeAt(this.pos)/* ':' */)return this.stage=-1/* RefStage.Failed */;this.elts.push(elt(Type.LinkMark,this.pos+this.start,this.pos+this.start+1)),this.pos++}else{if(1!=this.stage/* RefStage.Label */){if(2==this.stage/* RefStage.Link */){let skip=skipSpace(content,this.pos),end=0;if(skip>this.pos){let title=parseLinkTitle(content,skip,this.start);if(title){let titleEnd=lineEnd(content,title.to-this.start);0<titleEnd&&(this.nextStage(title),end=titleEnd)}}return end||(end=lineEnd(content,this.pos)),0<end&&end<content.length?end:-1}// RefStage.Title
|
|
79
|
+
return lineEnd(content,this.pos)}if(!this.nextStage(parseURL(content,skipSpace(content,this.pos),this.start)))return-1}}}}class SetextHeadingParser{nextLine(cx,line,leaf){let underline=line.depth<cx.stack.length?-1:isSetextUnderline(line),next=line.next;if(0>underline)return!1;let underlineMark=elt(Type.HeaderMark,cx.lineStart+line.pos,cx.lineStart+underline);return cx.nextLine(),cx.addLeafElement(leaf,elt(61==next?Type.SetextHeading1:Type.SetextHeading2,leaf.start,cx.prevLineEnd(),[...cx.parser.parseInline(leaf.content,leaf.start),underlineMark])),!0}finish(){return!1}}const DefaultLeafBlocks={LinkReference(_,leaf){return 91==leaf.content.charCodeAt(0)/* '[' */?new LinkReferenceParser(leaf):null},SetextHeading(){return new SetextHeadingParser}},DefaultEndLeaf=[(_,line)=>0<=isAtxHeading(line),(_,line)=>0<=isFencedCode(line),(_,line)=>0<=isBlockquote(line),(p,line)=>0<=isBulletList(line,p,!0),(p,line)=>0<=isOrderedList(line,p,!0),(p,line)=>0<=isHorizontalRule(line,p,!0),(p,line)=>0<=isHTMLBlock(line,p,!0)],scanLineResult={text:"",end:0};/**
|
|
80
|
+
Block-level parsing functions get access to this context object.
|
|
81
|
+
*/class BlockContext{/**
|
|
82
|
+
@internal
|
|
83
|
+
*/constructor(/**
|
|
84
|
+
The parser configuration used.
|
|
85
|
+
*/parser,/**
|
|
86
|
+
@internal
|
|
87
|
+
*/input,fragments,/**
|
|
88
|
+
@internal
|
|
89
|
+
*/ranges){this.parser=parser,this.input=input,this.ranges=ranges,this.line=new Line,this.atEnd=!1,this.reusePlaceholders=new Map,this.stoppedAt=null,this.rangeI=0,this.to=ranges[ranges.length-1].to,this.lineStart=this.absoluteLineStart=this.absoluteLineEnd=ranges[0].from,this.block=CompositeBlock.create(Type.Document,0,this.lineStart,0,0),this.stack=[this.block],this.fragments=fragments.length?new FragmentCursor(fragments,input):null,this.readLine()}get parsedPos(){return this.absoluteLineStart}advance(){if(null!=this.stoppedAt&&this.absoluteLineStart>this.stoppedAt)return this.finish();let{line}=this;for(;;){for(let next,markI=0;;){for(next=line.depth<this.stack.length?this.stack[this.stack.length-1]:null;markI<line.markers.length&&(!next||line.markers[markI].from<next.end);){let mark=line.markers[markI++];this.addNode(mark.type,mark.from,mark.to)}if(!next)break;this.finishContext()}if(line.pos<line.text.length)break;// Empty line
|
|
90
|
+
if(!this.nextLine())return this.finish()}if(this.fragments&&this.reuseFragment(line.basePos))return null;start:for(;;){for(let type of this.parser.blockParsers)if(type){let result=type(this,line);if(!1!=result){if(!0==result)return null;line.forward();continue start}}break}let leaf=new LeafBlock(this.lineStart+line.pos,line.text.slice(line.pos));for(let parse of this.parser.leafBlockParsers)if(parse){let parser=parse(this,leaf);parser&&leaf.parsers.push(parser)}lines:for(;this.nextLine()&&line.pos!=line.text.length;){if(line.indent<line.baseIndent+4)for(let stop of this.parser.endLeafBlock)if(stop(this,line,leaf))break lines;for(let parser of leaf.parsers)if(parser.nextLine(this,line,leaf))return null;leaf.content+="\n"+line.scrub();for(let m of line.markers)leaf.marks.push(m)}return this.finishLeaf(leaf),null}stopAt(pos){if(null!=this.stoppedAt&&this.stoppedAt<pos)throw new RangeError("Can't move stoppedAt forward");this.stoppedAt=pos}reuseFragment(start){if(!this.fragments.moveTo(this.absoluteLineStart+start,this.absoluteLineStart)||!this.fragments.matches(this.block.hash))return!1;let taken=this.fragments.takeNodes(this);return!!taken&&(this.absoluteLineStart+=taken,this.lineStart=toRelative(this.absoluteLineStart,this.ranges),this.moveRangeI(),this.absoluteLineStart<this.to?(this.lineStart++,this.absoluteLineStart++,this.readLine()):(this.atEnd=!0,this.readLine()),!0)}/**
|
|
91
|
+
The number of parent blocks surrounding the current block.
|
|
92
|
+
*/get depth(){return this.stack.length}/**
|
|
93
|
+
Get the type of the parent block at the given depth. When no
|
|
94
|
+
depth is passed, return the type of the innermost parent.
|
|
95
|
+
*/parentType(depth=this.depth-1){return this.parser.nodeSet.types[this.stack[depth].type]}/**
|
|
96
|
+
Move to the next input line. This should only be called by
|
|
97
|
+
(non-composite) [block parsers](#BlockParser.parse) that consume
|
|
98
|
+
the line directly, or leaf block parser
|
|
99
|
+
[`nextLine`](#LeafBlockParser.nextLine) methods when they
|
|
100
|
+
consume the current line (and return true).
|
|
101
|
+
*/nextLine(){return this.lineStart+=this.line.text.length,this.absoluteLineEnd>=this.to?(this.absoluteLineStart=this.absoluteLineEnd,this.atEnd=!0,this.readLine(),!1):(this.lineStart++,this.absoluteLineStart=this.absoluteLineEnd+1,this.moveRangeI(),this.readLine(),!0)}/**
|
|
102
|
+
Retrieve the text of the line after the current one, without
|
|
103
|
+
actually moving the context's current line forward.
|
|
104
|
+
*/peekLine(){return this.scanLine(this.absoluteLineEnd+1).text}moveRangeI(){for(;this.rangeI<this.ranges.length-1&&this.absoluteLineStart>=this.ranges[this.rangeI].to;)this.rangeI++,this.absoluteLineStart=Math.max(this.absoluteLineStart,this.ranges[this.rangeI].from)}/**
|
|
105
|
+
@internal
|
|
106
|
+
Collect the text for the next line.
|
|
107
|
+
*/scanLine(start){let r=scanLineResult;if(r.end=start,start>=this.to)r.text="";else if(r.text=this.lineChunkAt(start),r.end+=r.text.length,1<this.ranges.length)for(let textOffset=this.absoluteLineStart,rangeI=this.rangeI;this.ranges[rangeI].to<r.end;){rangeI++;let nextFrom=this.ranges[rangeI].from,after=this.lineChunkAt(nextFrom);r.end=nextFrom+after.length,r.text=r.text.slice(0,this.ranges[rangeI-1].to-textOffset)+after,textOffset=r.end-r.text.length}return r}/**
|
|
108
|
+
@internal
|
|
109
|
+
Populate this.line with the content of the next line. Skip
|
|
110
|
+
leading characters covered by composite blocks.
|
|
111
|
+
*/readLine(){let{line}=this,{text,end}=this.scanLine(this.absoluteLineStart);for(this.absoluteLineEnd=end,line.reset(text);line.depth<this.stack.length;line.depth++){let cx=this.stack[line.depth],handler=this.parser.skipContextMarkup[cx.type];if(!handler)throw new Error("Unhandled block context "+Type[cx.type]);let marks=this.line.markers.length;if(!handler(cx,this,line)){this.line.markers.length>marks&&(cx.end=this.line.markers[this.line.markers.length-1].to),line.forward();break}line.forward()}}lineChunkAt(pos){let text,next=this.input.chunk(pos);if(!this.input.lineChunks){let eol=next.indexOf("\n");text=0>eol?next:next.slice(0,eol)}else text="\n"==next?"":next;return pos+text.length>this.to?text.slice(0,this.to-pos):text}/**
|
|
112
|
+
The end position of the previous line.
|
|
113
|
+
*/prevLineEnd(){return this.atEnd?this.lineStart:this.lineStart-1}/**
|
|
114
|
+
@internal
|
|
115
|
+
*/startContext(type,start,value=0){this.block=CompositeBlock.create(type,value,this.lineStart+start,this.block.hash,this.lineStart+this.line.text.length),this.stack.push(this.block)}/**
|
|
116
|
+
Start a composite block. Should only be called from [block
|
|
117
|
+
parser functions](#BlockParser.parse) that return null.
|
|
118
|
+
*/startComposite(type,start,value=0){this.startContext(this.parser.getNodeType(type),start,value)}/**
|
|
119
|
+
@internal
|
|
120
|
+
*/addNode(block,from,to){"number"==typeof block&&(block=new common.Tree(this.parser.nodeSet.types[block],none,none,(null!==to&&void 0!==to?to:this.prevLineEnd())-from)),this.block.addChild(block,from-this.block.from)}/**
|
|
121
|
+
Add a block element. Can be called by [block
|
|
122
|
+
parsers](#BlockParser.parse).
|
|
123
|
+
*/addElement(elt){this.block.addChild(elt.toTree(this.parser.nodeSet),elt.from-this.block.from)}/**
|
|
124
|
+
Add a block element from a [leaf parser](#LeafBlockParser). This
|
|
125
|
+
makes sure any extra composite block markup (such as blockquote
|
|
126
|
+
markers) inside the block are also added to the syntax tree.
|
|
127
|
+
*/addLeafElement(leaf,elt){this.addNode(this.buffer.writeElements(injectMarks(elt.children,leaf.marks),-elt.from).finish(elt.type,elt.to-elt.from),elt.from)}/**
|
|
128
|
+
@internal
|
|
129
|
+
*/finishContext(){let cx=this.stack.pop(),top=this.stack[this.stack.length-1];top.addChild(cx.toTree(this.parser.nodeSet),cx.from-top.from),this.block=top}finish(){for(;1<this.stack.length;)this.finishContext();return this.addGaps(this.block.toTree(this.parser.nodeSet,this.lineStart))}addGaps(tree){return 1<this.ranges.length?injectGaps(this.ranges,0,tree.topNode,this.ranges[0].from,this.reusePlaceholders):tree}/**
|
|
130
|
+
@internal
|
|
131
|
+
*/finishLeaf(leaf){for(let parser of leaf.parsers)if(parser.finish(this,leaf))return;let inline=injectMarks(this.parser.parseInline(leaf.content,leaf.start),leaf.marks);this.addNode(this.buffer.writeElements(inline,-leaf.start).finish(Type.Paragraph,leaf.content.length),leaf.start)}elt(type,from,to,children){return"string"==typeof type?elt(this.parser.getNodeType(type),from,to,children):new TreeElement(type,from)}/**
|
|
132
|
+
@internal
|
|
133
|
+
*/get buffer(){return new Buffer(this.parser.nodeSet)}}class MarkdownParser extends common.Parser{/**
|
|
134
|
+
@internal
|
|
135
|
+
*/constructor(/**
|
|
136
|
+
The parser's syntax [node
|
|
137
|
+
types](https://lezer.codemirror.net/docs/ref/#common.NodeSet).
|
|
138
|
+
*/nodeSet,/**
|
|
139
|
+
@internal
|
|
140
|
+
*/blockParsers,/**
|
|
141
|
+
@internal
|
|
142
|
+
*/leafBlockParsers,/**
|
|
143
|
+
@internal
|
|
144
|
+
*/blockNames,/**
|
|
145
|
+
@internal
|
|
146
|
+
*/endLeafBlock,/**
|
|
147
|
+
@internal
|
|
148
|
+
*/skipContextMarkup,/**
|
|
149
|
+
@internal
|
|
150
|
+
*/inlineParsers,/**
|
|
151
|
+
@internal
|
|
152
|
+
*/inlineNames,/**
|
|
153
|
+
@internal
|
|
154
|
+
*/wrappers){super(),this.nodeSet=nodeSet,this.blockParsers=blockParsers,this.leafBlockParsers=leafBlockParsers,this.blockNames=blockNames,this.endLeafBlock=endLeafBlock,this.skipContextMarkup=skipContextMarkup,this.inlineParsers=inlineParsers,this.inlineNames=inlineNames,this.wrappers=wrappers,this.nodeTypes=Object.create(null);for(let t of nodeSet.types)this.nodeTypes[t.name]=t.id}createParse(input,fragments,ranges){let parse=new BlockContext(this,input,fragments,ranges);for(let w of this.wrappers)parse=w(parse,input,fragments,ranges);return parse}/**
|
|
155
|
+
Reconfigure the parser.
|
|
156
|
+
*/configure(spec){let config=resolveConfig(spec);if(!config)return this;let{nodeSet,skipContextMarkup}=this,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;if(nonEmpty(config.defineNodes)){skipContextMarkup=Object.assign({},skipContextMarkup);let styles,nodeTypes=nodeSet.types.slice();for(let s of config.defineNodes){let{name,block,composite,style}="string"==typeof s?{name:s}:s;if(nodeTypes.some(t=>t.name==name))continue;composite&&(skipContextMarkup[nodeTypes.length]=(bl,cx,line)=>composite(cx,line,bl.value));let id=nodeTypes.length,group=composite?["Block","BlockContext"]:block?id>=Type.ATXHeading1&&id<=Type.SetextHeading2?["Block","LeafBlock","Heading"]:["Block","LeafBlock"]:void 0;nodeTypes.push(common.NodeType.define({id,name,props:group&&[[common.NodeProp.group,group]]})),style&&(!styles&&(styles={}),Array.isArray(style)||style instanceof highlight.Tag?styles[name]=style:Object.assign(styles,style))}nodeSet=new common.NodeSet(nodeTypes),styles&&(nodeSet=nodeSet.extend(highlight.styleTags(styles)))}if(nonEmpty(config.props)&&(nodeSet=nodeSet.extend(...config.props)),nonEmpty(config.remove))for(let rm of config.remove){let block=this.blockNames.indexOf(rm),inline=this.inlineNames.indexOf(rm);-1<block&&(blockParsers[block]=leafBlockParsers[block]=void 0),-1<inline&&(inlineParsers[inline]=void 0)}if(nonEmpty(config.parseBlock))for(let spec of config.parseBlock){let found=blockNames.indexOf(spec.name);if(-1<found)blockParsers[found]=spec.parse,leafBlockParsers[found]=spec.leaf;else{let pos=spec.before?findName(blockNames,spec.before):spec.after?findName(blockNames,spec.after)+1:blockNames.length-1;blockParsers.splice(pos,0,spec.parse),leafBlockParsers.splice(pos,0,spec.leaf),blockNames.splice(pos,0,spec.name)}spec.endLeaf&&endLeafBlock.push(spec.endLeaf)}if(nonEmpty(config.parseInline))for(let spec of config.parseInline){let found=inlineNames.indexOf(spec.name);if(-1<found)inlineParsers[found]=spec.parse;else{let pos=spec.before?findName(inlineNames,spec.before):spec.after?findName(inlineNames,spec.after)+1:inlineNames.length-1;inlineParsers.splice(pos,0,spec.parse),inlineNames.splice(pos,0,spec.name)}}return config.wrap&&(wrappers=wrappers.concat(config.wrap)),new MarkdownParser(nodeSet,blockParsers,leafBlockParsers,blockNames,endLeafBlock,skipContextMarkup,inlineParsers,inlineNames,wrappers)}/**
|
|
157
|
+
@internal
|
|
158
|
+
*/getNodeType(name){let found=this.nodeTypes[name];if(null==found)throw new RangeError(`Unknown node type '${name}'`);return found}/**
|
|
159
|
+
Parse the given piece of inline text at the given offset,
|
|
160
|
+
returning an array of [`Element`](#Element) objects representing
|
|
161
|
+
the inline content.
|
|
162
|
+
*/parseInline(text,offset){let cx=new InlineContext(this,text,offset);outer:for(let next,pos=offset;pos<cx.end;){next=cx.char(pos);for(let token of this.inlineParsers)if(token){let result=token(cx,next,pos);if(0<=result){pos=result;continue outer}}pos++}return cx.resolveMarkers(0)}}let nodeTypes=[common.NodeType.none];for(let name,i=1;name=Type[i];i++)nodeTypes[i]=common.NodeType.define({id:i,name,props:i>=Type.Escape?[]:[[common.NodeProp.group,i in DefaultSkipMarkup?["Block","BlockContext"]:["Block","LeafBlock"]]],top:"Document"==name});const none=[];class Buffer{constructor(nodeSet){this.nodeSet=nodeSet,this.content=[],this.nodes=[]}write(type,from,to,children=0){return this.content.push(type,from,to,4+4*children),this}writeElements(elts,offset=0){for(let e of elts)e.writeTo(this,offset);return this}finish(type,length){return common.Tree.build({buffer:this.content,nodeSet:this.nodeSet,reused:this.nodes,topID:type,length})}}/**
|
|
163
|
+
Elements are used to compose syntax nodes during parsing.
|
|
164
|
+
*/class Element{/**
|
|
165
|
+
@internal
|
|
166
|
+
*/constructor(/**
|
|
167
|
+
The node's
|
|
168
|
+
[id](https://lezer.codemirror.net/docs/ref/#common.NodeType.id).
|
|
169
|
+
*/type,/**
|
|
170
|
+
The start of the node, as an offset from the start of the document.
|
|
171
|
+
*/from,/**
|
|
172
|
+
The end of the node.
|
|
173
|
+
*/to,/**
|
|
174
|
+
The node's child nodes @internal
|
|
175
|
+
*/children=none){this.type=type,this.from=from,this.to=to,this.children=children}/**
|
|
176
|
+
@internal
|
|
177
|
+
*/writeTo(buf,offset){let startOff=buf.content.length;buf.writeElements(this.children,offset),buf.content.push(this.type,this.from+offset,this.to+offset,buf.content.length+4-startOff)}/**
|
|
178
|
+
@internal
|
|
179
|
+
*/toTree(nodeSet){return new Buffer(nodeSet).writeElements(this.children,-this.from).finish(this.type,this.to-this.from)}}class TreeElement{constructor(tree,from){this.tree=tree,this.from=from}get to(){return this.from+this.tree.length}get type(){return this.tree.type.id}get children(){return none}writeTo(buf,offset){buf.nodes.push(this.tree),buf.content.push(buf.nodes.length-1,this.from+offset,this.to+offset,-1)}toTree(){return this.tree}}const EmphasisUnderscore={resolve:"Emphasis",mark:"EmphasisMark"},EmphasisAsterisk={resolve:"Emphasis",mark:"EmphasisMark"},LinkStart={},ImageStart={};class InlineDelimiter{constructor(type,from,to,side){this.type=type,this.from=from,this.to=to,this.side=side}}const Escapable="!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";let Punctuation=/[!"#$%&'()*+,\-.\/:;<=>?@\[\\\]^_`{|}~\xA1\u2010-\u2027]/;try{Punctuation=/[\p{S}|\p{P}]/u}catch(_){}const DefaultInline={Escape(cx,next,start){if(92!=next/* '\\' */||start==cx.end-1)return-1;let escaped=cx.char(start+1);for(let i=0;i<Escapable.length;i++)if(Escapable.charCodeAt(i)==escaped)return cx.append(elt(Type.Escape,start,start+2));return-1},Entity(cx,next,start){if(38!=next/* '&' */)return-1;let m=/^(?:#\d+|#x[a-f\d]+|\w+);/i.exec(cx.slice(start+1,start+31));return m?cx.append(elt(Type.Entity,start,start+1+m[0].length)):-1},InlineCode(cx,next,start){if(96!=next/* '`' */||start&&96==cx.char(start-1))return-1;let pos=start+1;for(;pos<cx.end&&96==cx.char(pos);)pos++;for(let size=pos-start,curSize=0;pos<cx.end;pos++)if(96!=cx.char(pos))curSize=0;else if(curSize++,curSize==size&&96!=cx.char(pos+1))return cx.append(elt(Type.InlineCode,start,pos+1,[elt(Type.CodeMark,start,start+size),elt(Type.CodeMark,pos+1-size,pos+1)]));return-1},HTMLTag(cx,next,start){if(60!=next/* '<' */||start==cx.end-1)return-1;let after=cx.slice(start+1,cx.end),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);if(url)return cx.append(elt(Type.Autolink,start,start+1+url[0].length,[elt(Type.LinkMark,start,start+1),// url[0] includes the closing bracket, so exclude it from this slice
|
|
180
|
+
elt(Type.URL,start+1,start+url[0].length),elt(Type.LinkMark,start+url[0].length,start+1+url[0].length)]));let comment=/^!--[^>](?:-[^-]|[^-])*?-->/i.exec(after);if(comment)return cx.append(elt(Type.Comment,start,start+1+comment[0].length));let procInst=/^\?[^]*?\?>/.exec(after);if(procInst)return cx.append(elt(Type.ProcessingInstruction,start,start+1+procInst[0].length));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);return m?cx.append(elt(Type.HTMLTag,start,start+1+m[0].length)):-1},Emphasis(cx,next,start){if(95!=next&&42!=next)return-1;let pos=start+1;for(;cx.char(pos)==next;)pos++;let before=cx.slice(start-1,start),after=cx.slice(pos,pos+1),pBefore=Punctuation.test(before),pAfter=Punctuation.test(after),sBefore=/\s|^$/.test(before),sAfter=/\s|^$/.test(after),leftFlanking=!sAfter&&(!pAfter||sBefore||pBefore),rightFlanking=!sBefore&&(!pBefore||sAfter||pAfter),canOpen=leftFlanking&&(42==next||!rightFlanking||pBefore),canClose=rightFlanking&&(42==next||!leftFlanking||pAfter);return cx.append(new InlineDelimiter(95==next?EmphasisUnderscore:EmphasisAsterisk,start,pos,(canOpen?1/* Mark.Open */:0/* Mark.None */)|(canClose?2/* Mark.Close */:0/* Mark.None */)))},HardBreak(cx,next,start){if(92==next/* '\\' */&&10==cx.char(start+1)/* '\n' */)return cx.append(elt(Type.HardBreak,start,start+2));if(32==next){let pos=start+1;for(;32==cx.char(pos);)pos++;if(10==cx.char(pos)&&pos>=start+2)return cx.append(elt(Type.HardBreak,start,pos+1))}return-1},Link(cx,next,start){return 91==next/* '[' */?cx.append(new InlineDelimiter(LinkStart,start,start+1,1/* Mark.Open */)):-1},Image(cx,next,start){return 33==next/* '!' */&&91==cx.char(start+1)/* '[' */?cx.append(new InlineDelimiter(ImageStart,start,start+2,1/* Mark.Open */)):-1},LinkEnd(cx,next,start){if(93!=next/* ']' */)return-1;// Scanning back to the next link/image start marker
|
|
181
|
+
for(let part,i=cx.parts.length-1;0<=i;i--)if(part=cx.parts[i],part instanceof InlineDelimiter&&(part.type==LinkStart||part.type==ImageStart)){// If this one has been set invalid (because it would produce
|
|
182
|
+
// a nested link) or there's no valid link here ignore both.
|
|
183
|
+
if(!part.side||cx.skipSpace(part.to)==start&&!/[(\[]/.test(cx.slice(start+1,start+2)))return cx.parts[i]=null,-1;// Finish the content and replace the entire range in
|
|
184
|
+
// this.parts with the link/image node.
|
|
185
|
+
let content=cx.takeContent(i),link=cx.parts[i]=finishLink(cx,content,part.type==LinkStart?Type.Link:Type.Image,part.from,start+1);// Set any open-link markers before this link to invalid.
|
|
186
|
+
if(part.type==LinkStart)for(let p,j=0;j<i;j++)p=cx.parts[j],p instanceof InlineDelimiter&&p.type==LinkStart&&(p.side=0/* Mark.None */);return link.to}return-1}};class InlineContext{/**
|
|
187
|
+
@internal
|
|
188
|
+
*/constructor(/**
|
|
189
|
+
The parser that is being used.
|
|
190
|
+
*/parser,/**
|
|
191
|
+
The text of this inline section.
|
|
192
|
+
*/text,/**
|
|
193
|
+
The starting offset of the section in the document.
|
|
194
|
+
*/offset){this.parser=parser,this.text=text,this.offset=offset,this.parts=[]}/**
|
|
195
|
+
Get the character code at the given (document-relative)
|
|
196
|
+
position.
|
|
197
|
+
*/char(pos){return pos>=this.end?-1:this.text.charCodeAt(pos-this.offset)}/**
|
|
198
|
+
The position of the end of this inline section.
|
|
199
|
+
*/get end(){return this.offset+this.text.length}/**
|
|
200
|
+
Get a substring of this inline section. Again uses
|
|
201
|
+
document-relative positions.
|
|
202
|
+
*/slice(from,to){return this.text.slice(from-this.offset,to-this.offset)}/**
|
|
203
|
+
@internal
|
|
204
|
+
*/append(elt){return this.parts.push(elt),elt.to}/**
|
|
205
|
+
Add a [delimiter](#DelimiterType) at this given position. `open`
|
|
206
|
+
and `close` indicate whether this delimiter is opening, closing,
|
|
207
|
+
or both. Returns the end of the delimiter, for convenient
|
|
208
|
+
returning from [parse functions](#InlineParser.parse).
|
|
209
|
+
*/addDelimiter(type,from,to,open,close){return this.append(new InlineDelimiter(type,from,to,(open?1/* Mark.Open */:0/* Mark.None */)|(close?2/* Mark.Close */:0/* Mark.None */)))}/**
|
|
210
|
+
Returns true when there is an unmatched link or image opening
|
|
211
|
+
token before the current position.
|
|
212
|
+
*/get hasOpenLink(){for(let part,i=this.parts.length-1;0<=i;i--)if(part=this.parts[i],part instanceof InlineDelimiter&&(part.type==LinkStart||part.type==ImageStart))return!0;return!1}/**
|
|
213
|
+
Add an inline element. Returns the end of the element.
|
|
214
|
+
*/addElement(elt){return this.append(elt)}/**
|
|
215
|
+
Resolve markers between this.parts.length and from, wrapping matched markers in the
|
|
216
|
+
appropriate node and updating the content of this.parts. @internal
|
|
217
|
+
*/resolveMarkers(from){// Scan forward, looking for closing tokens
|
|
218
|
+
for(let close,i=from;i<this.parts.length;i++){if(close=this.parts[i],!(close instanceof InlineDelimiter&&close.type.resolve&&2&close.side/* Mark.Close */))continue;let open,emp=close.type==EmphasisUnderscore||close.type==EmphasisAsterisk,closeSize=close.to-close.from,j=i-1;// Continue scanning for a matching opening token
|
|
219
|
+
for(;j>=from;j--){let part=this.parts[j];if(part instanceof InlineDelimiter&&1&part.side/* Mark.Open */&&part.type==close.type&&// Ignore emphasis delimiters where the character count doesn't match
|
|
220
|
+
!(emp&&(1&close.side/* Mark.Open */||2&part.side/* Mark.Close */)&&0==(part.to-part.from+closeSize)%3&&((part.to-part.from)%3||closeSize%3))){open=part;break}}if(!open)continue;let type=close.type.resolve,content=[],start=open.from,end=close.to;// Emphasis marker effect depends on the character count. Size consumed is minimum of the two
|
|
221
|
+
// markers.
|
|
222
|
+
if(emp){let size=Math.min(2,open.to-open.from,closeSize);start=open.to-size,end=close.from+size,type=1==size?"Emphasis":"StrongEmphasis"}// Move the covered region into content, optionally adding marker nodes
|
|
223
|
+
open.type.mark&&content.push(this.elt(open.type.mark,start,open.to));for(let k=j+1;k<i;k++)this.parts[k]instanceof Element&&content.push(this.parts[k]),this.parts[k]=null;close.type.mark&&content.push(this.elt(close.type.mark,close.from,end));let element=this.elt(type,start,end,content);// If there are leftover emphasis marker characters, shrink the close/open markers. Otherwise, clear them.
|
|
224
|
+
this.parts[j]=emp&&open.from!=start?new InlineDelimiter(open.type,open.from,start,open.side):null;let keep=this.parts[i]=emp&&close.to!=end?new InlineDelimiter(close.type,end,close.to,close.side):null;// Insert the new element in this.parts
|
|
225
|
+
keep?this.parts.splice(i,0,element):this.parts[i]=element}// Collect the elements remaining in this.parts into an array.
|
|
226
|
+
let result=[];for(let part,i=from;i<this.parts.length;i++)part=this.parts[i],part instanceof Element&&result.push(part);return result}/**
|
|
227
|
+
Find an opening delimiter of the given type. Returns `null` if
|
|
228
|
+
no delimiter is found, or an index that can be passed to
|
|
229
|
+
[`takeContent`](#InlineContext.takeContent) otherwise.
|
|
230
|
+
*/findOpeningDelimiter(type){for(let part,i=this.parts.length-1;0<=i;i--)if(part=this.parts[i],part instanceof InlineDelimiter&&part.type==type&&1&part.side/* Mark.Open */)return i;return null}/**
|
|
231
|
+
Remove all inline elements and delimiters starting from the
|
|
232
|
+
given index (which you should get from
|
|
233
|
+
[`findOpeningDelimiter`](#InlineContext.findOpeningDelimiter),
|
|
234
|
+
resolve delimiters inside of them, and return them as an array
|
|
235
|
+
of elements.
|
|
236
|
+
*/takeContent(startIndex){let content=this.resolveMarkers(startIndex);return this.parts.length=startIndex,content}/**
|
|
237
|
+
Return the delimiter at the given index. Mostly useful to get
|
|
238
|
+
additional info out of a delimiter index returned by
|
|
239
|
+
[`findOpeningDelimiter`](#InlineContext.findOpeningDelimiter).
|
|
240
|
+
Returns null if there is no delimiter at this index.
|
|
241
|
+
*/getDelimiterAt(index){let part=this.parts[index];return part instanceof InlineDelimiter?part:null}/**
|
|
242
|
+
Skip space after the given (document) position, returning either
|
|
243
|
+
the position of the next non-space character or the end of the
|
|
244
|
+
section.
|
|
245
|
+
*/skipSpace(from){return skipSpace(this.text,from-this.offset)+this.offset}elt(type,from,to,children){return"string"==typeof type?elt(this.parser.getNodeType(type),from,to,children):new TreeElement(type,from)}}/**
|
|
246
|
+
The opening delimiter type used by the standard link parser.
|
|
247
|
+
*/InlineContext.linkStart=LinkStart,InlineContext.imageStart=ImageStart;const NotLast=[Type.CodeBlock,Type.ListItem,Type.OrderedList,Type.BulletList];class FragmentCursor{constructor(fragments,input){this.fragments=fragments,this.input=input,this.i=0,this.fragment=null,this.fragmentEnd=-1,this.cursor=null,fragments.length&&(this.fragment=fragments[this.i++])}nextFragment(){this.fragment=this.i<this.fragments.length?this.fragments[this.i++]:null,this.cursor=null,this.fragmentEnd=-1}moveTo(pos,lineStart){for(;this.fragment&&this.fragment.to<=pos;)this.nextFragment();if(!this.fragment||this.fragment.from>(pos?pos-1:0))return!1;if(0>this.fragmentEnd){let end=this.fragment.to;for(;0<end&&"\n"!=this.input.read(end-1,end);)end--;this.fragmentEnd=end?end-1:0}let c=this.cursor;c||(c=this.cursor=this.fragment.tree.cursor(),c.firstChild());let rPos=pos+this.fragment.offset;for(;c.to<=rPos;)if(!c.parent())return!1;for(;;){if(c.from>=rPos)return this.fragment.from<=lineStart;if(!c.childAfter(rPos))return!1}}matches(hash){let tree=this.cursor.tree;return tree&&tree.prop(common.NodeProp.contextHash)==hash}takeNodes(cx){let cur=this.cursor,off=this.fragment.offset,fragEnd=this.fragmentEnd-(this.fragment.openEnd?1:0),start=cx.absoluteLineStart,end=start,blockI=cx.block.children.length,prevEnd=end,prevI=blockI;for(;;){if(cur.to-off>fragEnd){if(cur.type.isAnonymous&&cur.firstChild())continue;break}let pos=toRelative(cur.from-off,cx.ranges);if(cur.to-off<=cx.ranges[cx.rangeI].to)cx.addNode(cur.tree,pos);else{let dummy=new common.Tree(cx.parser.nodeSet.types[Type.Paragraph],[],[],0,cx.block.hashProp);cx.reusePlaceholders.set(dummy,cur.tree),cx.addNode(dummy,pos)}// Taken content must always end in a block, because incremental
|
|
248
|
+
// parsing happens on block boundaries. Never stop directly
|
|
249
|
+
// after an indented code block, since those can continue after
|
|
250
|
+
// any number of blank lines.
|
|
251
|
+
if(cur.type.is("Block")&&(0>NotLast.indexOf(cur.type.id)?(end=cur.to-off,blockI=cx.block.children.length):(end=prevEnd,blockI=prevI),prevEnd=cur.to-off,prevI=cx.block.children.length),!cur.nextSibling())break}for(;cx.block.children.length>blockI;)cx.block.children.pop(),cx.block.positions.pop();return end-start}}const markdownHighlighting=highlight.styleTags({"Blockquote/...":highlight.tags.quote,HorizontalRule:highlight.tags.contentSeparator,"ATXHeading1/... SetextHeading1/...":highlight.tags.heading1,"ATXHeading2/... SetextHeading2/...":highlight.tags.heading2,"ATXHeading3/...":highlight.tags.heading3,"ATXHeading4/...":highlight.tags.heading4,"ATXHeading5/...":highlight.tags.heading5,"ATXHeading6/...":highlight.tags.heading6,"Comment CommentBlock":highlight.tags.comment,Escape:highlight.tags.escape,Entity:highlight.tags.character,"Emphasis/...":highlight.tags.emphasis,"StrongEmphasis/...":highlight.tags.strong,"Link/... Image/...":highlight.tags.link,"OrderedList/... BulletList/...":highlight.tags.list,"BlockQuote/...":highlight.tags.quote,"InlineCode CodeText":highlight.tags.monospace,"URL Autolink":highlight.tags.url,"HeaderMark HardBreak QuoteMark ListMark LinkMark EmphasisMark CodeMark":highlight.tags.processingInstruction,"CodeInfo LinkLabel":highlight.tags.labelName,LinkTitle:highlight.tags.string,Paragraph:highlight.tags.content}),parser=new MarkdownParser(new common.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),[]),StrikethroughDelim={resolve:"Strikethrough",mark:"StrikethroughMark"},Strikethrough={defineNodes:[{name:"Strikethrough",style:{"Strikethrough/...":highlight.tags.strikethrough}},{name:"StrikethroughMark",style:highlight.tags.processingInstruction}],parseInline:[{name:"Strikethrough",parse(cx,next,pos){if(126!=next/* '~' */||126!=cx.char(pos+1)||126==cx.char(pos+2))return-1;let before=cx.slice(pos-1,pos),after=cx.slice(pos+2,pos+3),sBefore=/\s|^$/.test(before),sAfter=/\s|^$/.test(after),pBefore=Punctuation.test(before),pAfter=Punctuation.test(after);return cx.addDelimiter(StrikethroughDelim,pos,pos+2,!sAfter&&(!pAfter||sBefore||pBefore),!sBefore&&(!pBefore||sAfter||pAfter))},after:"Emphasis"}]},delimiterLine=/^\|?(\s*:?-+:?\s*\|)+(\s*:?-+:?\s*)?$/;/**
|
|
252
|
+
The default CommonMark parser.
|
|
253
|
+
*/ /**
|
|
254
|
+
An extension that implements
|
|
255
|
+
[GFM-style](https://github.github.com/gfm/#strikethrough-extension-)
|
|
256
|
+
Strikethrough syntax using `~~` delimiters.
|
|
257
|
+
*/class TableParser{constructor(){this.rows=null}nextLine(cx,line,leaf){if(null==this.rows){this.rows=!1;let lineText;if((45==line.next||58==line.next||124==line.next/* '-:|' */)&&delimiterLine.test(lineText=line.text.slice(line.pos))){let firstRow=[],firstCount=parseRow(cx,leaf.content,0,firstRow,leaf.start);firstCount==parseRow(cx,lineText,line.pos)&&(this.rows=[cx.elt("TableHeader",leaf.start,leaf.start+leaf.content.length,firstRow),cx.elt("TableDelimiter",cx.lineStart+line.pos,cx.lineStart+line.text.length)])}}else if(this.rows){// Line after the second
|
|
258
|
+
let content=[];parseRow(cx,line.text,line.pos,content,cx.lineStart),this.rows.push(cx.elt("TableRow",cx.lineStart+line.pos,cx.lineStart+line.text.length,content))}return!1}finish(cx,leaf){return!!this.rows&&(cx.addLeafElement(leaf,cx.elt("Table",leaf.start,leaf.start+leaf.content.length,this.rows)),!0)}}/**
|
|
259
|
+
This extension provides
|
|
260
|
+
[GFM-style](https://github.github.com/gfm/#tables-extension-)
|
|
261
|
+
tables, using syntax like this:
|
|
262
|
+
|
|
263
|
+
```
|
|
264
|
+
| head 1 | head 2 |
|
|
265
|
+
| --- | --- |
|
|
266
|
+
| cell 1 | cell 2 |
|
|
267
|
+
```
|
|
268
|
+
*/const Table={defineNodes:[{name:"Table",block:!0},{name:"TableHeader",style:{"TableHeader/...":highlight.tags.heading}},"TableRow",{name:"TableCell",style:highlight.tags.content},{name:"TableDelimiter",style:highlight.tags.processingInstruction}],parseBlock:[{name:"Table",leaf(_,leaf){return hasPipe(leaf.content,0)?new TableParser:null},endLeaf(cx,line,leaf){if(leaf.parsers.some(p=>p instanceof TableParser)||!hasPipe(line.text,line.basePos))return!1;let next=cx.peekLine();return delimiterLine.test(next)&&parseRow(cx,line.text,line.basePos)==parseRow(cx,next,line.basePos)},before:"SetextHeading"}]};class TaskParser{nextLine(){return!1}finish(cx,leaf){return cx.addLeafElement(leaf,cx.elt("Task",leaf.start,leaf.start+leaf.content.length,[cx.elt("TaskMarker",leaf.start,leaf.start+3),...cx.parser.parseInline(leaf.content.slice(3),leaf.start+3)])),!0}}/**
|
|
269
|
+
Extension providing
|
|
270
|
+
[GFM-style](https://github.github.com/gfm/#task-list-items-extension-)
|
|
271
|
+
task list items, where list items can be prefixed with `[ ]` or
|
|
272
|
+
`[x]` to add a checkbox.
|
|
273
|
+
*/const TaskList={defineNodes:[{name:"Task",block:!0,style:highlight.tags.list},{name:"TaskMarker",style:highlight.tags.atom}],parseBlock:[{name:"TaskList",leaf(cx,leaf){return /^\[[ xX]\][ \t]/.test(leaf.content)&&"ListItem"==cx.parentType().name?new TaskParser:null},after:"SetextHeading"}]},autolinkRE=/(www\.)|(https?:\/\/)|([\w.+-]{1,100}@)|(mailto:|xmpp:)/gy,urlRE=/[\w-]+(\.[\w-]+)+(\/[^\s<]*)?/gy,lastTwoDomainWords=/[\w-]+\.[\w-]+($|\/)/,emailRE=/[\w.+-]+@[\w-]+(\.[\w.-]+)+/gy,xmppResourceRE=/\/[a-zA-Z\d@.]+/gy,Autolink={parseInline:[{name:"Autolink",parse(cx,next,absPos){let pos=absPos-cx.offset;if(pos&&/\w/.test(cx.text[pos-1]))return-1;autolinkRE.lastIndex=pos;let m=autolinkRE.exec(cx.text),end=-1;if(!m)return-1;if(!(m[1]||m[2]))m[3]?// email address
|
|
274
|
+
end=autolinkEmailEnd(cx.text,pos):(// mailto:/xmpp:
|
|
275
|
+
end=autolinkEmailEnd(cx.text,pos+m[0].length),-1<end&&"xmpp:"==m[0]&&(xmppResourceRE.lastIndex=end,m=xmppResourceRE.exec(cx.text),m&&(end=m.index+m[0].length)));else if(end=autolinkURLEnd(cx.text,pos+m[0].length),-1<end&&cx.hasOpenLink){let noBracket=/([^\[\]]|\[[^\]]*\])*/.exec(cx.text.slice(pos,end));end=pos+noBracket[0].length}return 0>end?-1:(cx.addElement(cx.elt("URL",absPos,end+cx.offset)),end+cx.offset)}}]},GFM=[Table,TaskList,Strikethrough,Autolink],Superscript={defineNodes:[{name:"Superscript",style:highlight.tags.special(highlight.tags.content)},{name:"SuperscriptMark",style:highlight.tags.processingInstruction}],parseInline:[{name:"Superscript",parse:parseSubSuper(94/* '^' */,"Superscript","SuperscriptMark")}]},Subscript={defineNodes:[{name:"Subscript",style:highlight.tags.special(highlight.tags.content)},{name:"SubscriptMark",style:highlight.tags.processingInstruction}],parseInline:[{name:"Subscript",parse:parseSubSuper(126/* '~' */,"Subscript","SubscriptMark")}]},Emoji={defineNodes:[{name:"Emoji",style:highlight.tags.character}],parseInline:[{name:"Emoji",parse(cx,next,pos){let match;return 58==next/* ':' */&&(match=/^[a-zA-Z_0-9]+:/.exec(cx.slice(pos+1,cx.end)))?cx.addElement(cx.elt("Emoji",pos,pos+1+match[0].length)):-1}}]};/**
|
|
276
|
+
Extension bundle containing [`Table`](#Table),
|
|
277
|
+
[`TaskList`](#TaskList), [`Strikethrough`](#Strikethrough), and
|
|
278
|
+
[`Autolink`](#Autolink).
|
|
279
|
+
*/ /**
|
|
280
|
+
Extension providing
|
|
281
|
+
[Pandoc-style](https://pandoc.org/MANUAL.html#superscripts-and-subscripts)
|
|
282
|
+
subscript using `~` markers.
|
|
283
|
+
*/ /**
|
|
284
|
+
Extension that parses two colons with only letters, underscores,
|
|
285
|
+
and numbers between them as `Emoji` nodes.
|
|
286
|
+
*/return dist.Autolink=Autolink,dist.BlockContext=BlockContext,dist.Element=Element,dist.Emoji=Emoji,dist.GFM=GFM,dist.InlineContext=InlineContext,dist.LeafBlock=LeafBlock,dist.Line=Line,dist.MarkdownParser=MarkdownParser,dist.Strikethrough=Strikethrough,dist.Subscript=Subscript,dist.Superscript=Superscript,dist.Table=Table,dist.TaskList=TaskList,dist.parseCode=parseCode,dist.parser=parser,dist}const module={exports:exports};var hasRequiredDist,require$$0=await requireAsyncModule("@lezer/common"),require$$1=await requireAsyncModule("@lezer/highlight"),dist={},distExports=requireDist(),index=/*@__PURE__*/function getDefaultExportFromCjs(x){return x}(distExports);return module.exports=index,module.exports}
|