// Inline parser state 'use strict'; var Token = require('../token'); function StateInline(src, md, env, outTokens) { this.src = src; this.env = env; this.md = md; this.tokens = outTokens; this.pos = 0; this.posMax = this.src.length; this.level = 0; this.pending = ''; this.pendingLevel = 0; this.cache = {}; // Stores { start: end } pairs. Useful for backtrack // optimization of pairs parse (emphasis, strikes). } // Flush pending text // StateInline.prototype.pushPending = function () { var token = new Token('text', '', 0); token.content = this.pending; token.level = this.pendingLevel; this.tokens.push(token); this.pending = ''; return token; }; // Push new token to "stream". // If pending text exists - flush it as text token // StateInline.prototype.push = function (type, tag, nesting) { if (this.pending) { this.pushPending(); } var token = new Token(type, tag, nesting); if (nesting < 0) { this.level--; } token.level = this.level; if (nesting > 0) { this.level++; } this.pendingLevel = this.level; this.tokens.push(token); return token; }; // re-export Token class to use in block rules StateInline.prototype.Token = Token; module.exports = StateInline;