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
1.4 KiB
56 lines
1.4 KiB
// Inline parser state
|
|
|
|
'use strict';
|
|
|
|
|
|
function StateInline(src, parser, options, env) {
|
|
this.src = src;
|
|
this.env = env;
|
|
this.options = options;
|
|
this.parser = parser;
|
|
this.tokens = [];
|
|
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).
|
|
|
|
// Link parser state vars
|
|
|
|
this.isInLabel = false; // Set true when seek link label - we should disable
|
|
// "paired" rules (emphasis, strikes) to not skip
|
|
// tailing `]`
|
|
|
|
this.linkLevel = 0; // Increment for each nesting link. Used to prevent
|
|
// nesting in definitions
|
|
|
|
this.linkContent = ''; // Temporary storage for link url
|
|
|
|
this.labelUnmatchedScopes = 0; // Track unpaired `[` for link labels
|
|
// (backtrack optimization)
|
|
}
|
|
|
|
|
|
StateInline.prototype.pushPending = function () {
|
|
this.tokens.push({
|
|
type: 'text',
|
|
content: this.pending,
|
|
level: this.pendingLevel
|
|
});
|
|
this.pending = '';
|
|
};
|
|
|
|
StateInline.prototype.push = function (token) {
|
|
if (this.pending) {
|
|
this.pushPending();
|
|
}
|
|
|
|
this.tokens.push(token);
|
|
this.pendingLevel = this.level;
|
|
};
|
|
|
|
|
|
module.exports = StateInline;
|
|
|