UNPKG

jc-marked

Version:

Markdown AST (Abstract syntax tree) parser based on finite-state machine (FSM).

1 lines 3.27 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.TextLoader=void 0;const __1=require(".."),exceps_1=require("./exceps"),regBold=/^\*\*.*\*\*$/,regItalic=/^\*.\*$/,regHtmlTagBegin=/^<.*>$/,regHtmlTagEnd=/^<\\.*>$/,regPictrue=/^/,regVideo=/^/,regMark=/^/,regSub=/^/,regSup=/^/,regCode=/^/,regOverline=/^/,regUnderline=/^/,regDoubleUnderline=/^/,regLink=/^/,regFont=/^/;class TextLoader{constructor(e=""){this._currentState=__1.SText.IDLE,this._nextState=null,this._index=0,this._nodes=[],this._recognizedText=null,this._text=e}run(){}_handelText(){this._runActions(),this._countNewState(),this._enterState()}_runActions(){switch(this._currentState){case __1.SText.IDLE:(0,__1.noop)();break;case __1.SText.BOLD:this._nodes.push({type:"bold",body:this._recognizedText});break;case __1.SText.MARK:this._nodes.push({type:"mark",body:this._recognizedText});break;case __1.SText.DELETE:this._nodes.push({type:"delete",body:this._recognizedText});break;case __1.SText.ITALIC:this._nodes.push({type:"italic",body:this._recognizedText});break;case __1.SText.SUB:this._nodes.push({type:"sub",body:this._recognizedText});break;case __1.SText.SUP:this._nodes.push({type:"sup",body:this._recognizedText});break;case __1.SText.UBDERLINE:this._nodes.push({type:"underline",body:this._recognizedText});break;case __1.SText.OVERLINE:this._nodes.push({type:"overline",body:this._recognizedText});break;case __1.SText.DOUBLE_UNDERLINE:this._nodes.push({type:"doubleUnderline",body:this._recognizedText});break;case __1.SText.MATH:this._nodes.push({type:"math",body:this._recognizedText});break;case __1.SText.CODE:this._nodes.push({type:"code",body:this._recognizedText});break;case __1.SText.PLAIN:this._nodes.push({type:"plain",body:this._recognizedText});break;case __1.SText.LINK:this._nodes.push({type:"link",body:this._recognizedText,url:""});break;case __1.SText.PICTURE:this._nodes.push({type:"pictrue",body:this._recognizedText,url:""});break;case __1.SText.VIDEO:this._nodes.push({type:"video",body:this._recognizedText,url:""});break;case __1.SText.AUDIO:this._nodes.push({type:"audio",body:this._recognizedText,url:""});break;case __1.SText.FONT:this._nodes.push({type:"font",body:this._recognizedText,color:"#000",bold:"normal"});break;default:throw(0,exceps_1.StateNotExistError)(`There is no state named "${this._currentState}"`)}}_countNewState(){var e=this._text.substring(this._index);regBold.test(e)?this._nextState=__1.SText.BOLD:regItalic.test(e)?this._nextState=__1.SText.ITALIC:regPictrue.test(e)?this._nextState=__1.SText.PICTURE:regVideo.test(e)?this._nextState=__1.SText.VIDEO:regMark.test(e)?this._nextState=__1.SText.MARK:regSub.test(e)?this._nextState=__1.SText.SUB:regSup.test(e)?this._nextState=__1.SText.SUP:regCode.test(e)?this._nextState=__1.SText.CODE:regOverline.test(e)?this._nextState=__1.SText.OVERLINE:regUnderline.test(e)?this._nextState=__1.SText.UBDERLINE:regDoubleUnderline.test(e)?this._nextState=__1.SText.DOUBLE_UNDERLINE:regLink.test(e)?this._nextState=__1.SText.LINK:regFont.test(e)?this._nextState=__1.SText.FONT:this._nextState=__1.SText.PLAIN}_enterState(){null!==this._nextState&&this._nextState!==this._currentState&&(this._currentState=this._nextState)}_patternMatching(){}}exports.TextLoader=TextLoader;