|
|
- import{NodeType,NodeProp,NodeSet,Tree,Parser,parseMixed}from"@lezer/common";import{styleTags,tags,Tag}from"@lezer/highlight";class CompositeBlock{constructor(type,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=[[NodeProp.contextHash,hash]]}static create(type,value,from,parentHash,end){let hash=parentHash+(parentHash<<8)+type+(value<<4)|0;return new CompositeBlock(type,value,from,hash,end,[],[])}addChild(child,pos){if(child.prop(NodeProp.contextHash)!=this.hash)child=new 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;if(last>=0)end=Math.max(end,this.positions[last]+this.children[last].length+this.from);let tree=new Tree(nodeSet.types[this.type],this.children,this.positions,end-this.from).balance({makeTree:(children,positions,length)=>new Tree(NodeType.none,children,positions,length,this.hashProp)});return tree}}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["URL"]=33]="URL";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={}));class LeafBlock{constructor(start,content){this.start=start;this.content=content;this.marks=[];this.parsers=[]}}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}forward(){if(this.basePos>this.pos)this.forwardInner()}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)}skipSpace(from){return skipSpace(this.text,from)}reset(text){this.text=text;this.baseIndent=this.basePos=this.pos=this.indent=0;this.forwardInner();this.depth=1;while(this.markers.length)this.markers.pop()}moveBase(to){this.basePos=to;this.baseIndent=this.countIndent(to,this.pos,this.indent)}moveBaseColumn(indent){this.baseIndent=indent;this.basePos=this.findColumn(indent)}addMarker(elt){this.markers.push(elt)}countIndent(to,from=0,indent=0){for(let i=from;i<to;i++)indent+=this.text.charCodeAt(i)==9?4-indent%4:1;return indent}findColumn(goal){let i=0;for(let indent=0;i<this.text.length&&indent<goal;i++)indent+=this.text.charCodeAt(i)==9?4-indent%4:1;return i}scrub(){if(!this.baseIndent)retur
|