Markdown parser, done right. 100% CommonMark support, extensions, syntax plugins & high speed https://markdown-it.github.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

56 lines
965 B

// Main perser class
'use strict';
var assign = require('object-assign');
var State = require('./state');
var Renderer = require('./renderer');
var LexerBlock = require('./lexer_block');
var LexerInline = require('./lexer_inline');
// Main class
//
function Parser(options) {
this.options = {};
this.state = null;
this.lexerInline = new LexerInline();
this.lexerBlock = new LexerBlock();
this.renderer = new Renderer();
if (options) { this.set(options); }
}
Parser.prototype.set = function (options) {
assign(this.options, options);
};
Parser.prototype.render = function (src) {
var state;
if (!src) { return ''; }
state = new State(
src,
this.lexerBlock,
this.lexerInline,
this.renderer,
[],
this.options
);
while (state.line < state.lineMax) {
state.lexerBlock.tokenize(state, state.line, state.lineMax);
}
return this.renderer.render(state);
};
module.exports = Parser;