mirror of https://github.com/lukechilds/node.git
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.
67 lines
1.2 KiB
67 lines
1.2 KiB
/**
|
|
* @author Titus Wormer
|
|
* @copyright 2015 Titus Wormer
|
|
* @license MIT
|
|
* @module remark:parse:tokenize:text
|
|
* @fileoverview Tokenise text.
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
module.exports = text;
|
|
|
|
/* Tokenise text. */
|
|
function text(eat, value, silent) {
|
|
var self = this;
|
|
var methods;
|
|
var tokenizers;
|
|
var index;
|
|
var length;
|
|
var subvalue;
|
|
var position;
|
|
var tokenizer;
|
|
var name;
|
|
var min;
|
|
var now;
|
|
|
|
/* istanbul ignore if - never used (yet) */
|
|
if (silent) {
|
|
return true;
|
|
}
|
|
|
|
methods = self.inlineMethods;
|
|
length = methods.length;
|
|
tokenizers = self.inlineTokenizers;
|
|
index = -1;
|
|
min = value.length;
|
|
|
|
while (++index < length) {
|
|
name = methods[index];
|
|
|
|
if (name === 'text' || !tokenizers[name]) {
|
|
continue;
|
|
}
|
|
|
|
tokenizer = tokenizers[name].locator;
|
|
|
|
if (!tokenizer) {
|
|
eat.file.fail('Missing locator: `' + name + '`');
|
|
}
|
|
|
|
position = tokenizer.call(self, value, 1);
|
|
|
|
if (position !== -1 && position < min) {
|
|
min = position;
|
|
}
|
|
}
|
|
|
|
subvalue = value.slice(0, min);
|
|
now = eat.now();
|
|
|
|
self.decode(subvalue, now, function (content, position, source) {
|
|
eat(source || content)({
|
|
type: 'text',
|
|
value: content
|
|
});
|
|
});
|
|
}
|
|
|