jc-marked
Version:
Markdown AST (Abstract syntax tree) parser based on finite-state machine (FSM).
1 lines • 819 B
JavaScript
"use strict";var State;Object.defineProperty(exports,"__esModule",{value:!0}),function(t){t.PLAIN="PLAIN",t.ESCAPE="ESCAPE"}(State=State||{});class Escape{constructor(t,e){this._currentState=State.PLAIN,this._nextState=State.PLAIN,this._index=0,this._escapKeys=[],this._nodes=[],this._text=t,this._escapKeys=e,this._handelItem()}_handelItem(){this._countStateAndAction(),this._enterState()}_countStateAndAction(){const e=this._text.substring(this._index);e[0],this._escapKeys.forEach(t=>{new RegExp("^\\"+t).test(e)?("plainCharacter"!==t?this._nodes.push({type:t}):this._nodes.push({type:t,body:"\\"+t}),this._index=this._index+t.length+1):(this._nodes.push({type:"plainCharacter",body:this._text[this._index]}),this._index++)})}_enterState(){this._currentState!==this._nextState&&(this._currentState=this._nextState)}}