|
@ -47,7 +47,6 @@ function validateLink(url) { |
|
|
// Inline Parser class
|
|
|
// Inline Parser class
|
|
|
//
|
|
|
//
|
|
|
function ParserInline() { |
|
|
function ParserInline() { |
|
|
this._rules = []; |
|
|
|
|
|
|
|
|
|
|
|
// Rule to skip pure text
|
|
|
// Rule to skip pure text
|
|
|
// - '{}$%@+=:' reserved for extentions
|
|
|
// - '{}$%@+=:' reserved for extentions
|
|
@ -57,7 +56,7 @@ function ParserInline() { |
|
|
// If you need to restrict it - override this with your validator.
|
|
|
// If you need to restrict it - override this with your validator.
|
|
|
this.validateLink = validateLink; |
|
|
this.validateLink = validateLink; |
|
|
|
|
|
|
|
|
this.ruler = new Ruler(this.rulesUpdate.bind(this)); |
|
|
this.ruler = new Ruler(); |
|
|
|
|
|
|
|
|
for (var i = 0; i < _rules.length; i++) { |
|
|
for (var i = 0; i < _rules.length; i++) { |
|
|
this.ruler.push(_rules[i][0], _rules[i][1]); |
|
|
this.ruler.push(_rules[i][0], _rules[i][1]); |
|
@ -65,17 +64,13 @@ function ParserInline() { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ParserInline.prototype.rulesUpdate = function () { |
|
|
|
|
|
this._rules = this.ruler.getRules(); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Skip single token by running all rules in validation mode;
|
|
|
// Skip single token by running all rules in validation mode;
|
|
|
// returns `true` if any rule reported success
|
|
|
// returns `true` if any rule reported success
|
|
|
//
|
|
|
//
|
|
|
ParserInline.prototype.skipToken = function (state) { |
|
|
ParserInline.prototype.skipToken = function (state) { |
|
|
var i, cached_pos, pos = state.pos, |
|
|
var i, cached_pos, pos = state.pos, |
|
|
len = this._rules.length; |
|
|
rules = this.ruler.getRules(''), |
|
|
|
|
|
len = rules.length; |
|
|
|
|
|
|
|
|
if ((cached_pos = state.cacheGet(pos)) > 0) { |
|
|
if ((cached_pos = state.cacheGet(pos)) > 0) { |
|
|
state.pos = cached_pos; |
|
|
state.pos = cached_pos; |
|
@ -83,7 +78,7 @@ ParserInline.prototype.skipToken = function (state) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++) { |
|
|
for (i = 0; i < len; i++) { |
|
|
if (this._rules[i](state, true)) { |
|
|
if (rules[i](state, true)) { |
|
|
state.cacheSet(pos, state.pos); |
|
|
state.cacheSet(pos, state.pos); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
@ -98,7 +93,8 @@ ParserInline.prototype.skipToken = function (state) { |
|
|
//
|
|
|
//
|
|
|
ParserInline.prototype.tokenize = function (state) { |
|
|
ParserInline.prototype.tokenize = function (state) { |
|
|
var ok, i, |
|
|
var ok, i, |
|
|
len = this._rules.length, |
|
|
rules = this.ruler.getRules(''), |
|
|
|
|
|
len = rules.length, |
|
|
end = state.posMax; |
|
|
end = state.posMax; |
|
|
|
|
|
|
|
|
while (state.pos < end) { |
|
|
while (state.pos < end) { |
|
@ -111,7 +107,7 @@ ParserInline.prototype.tokenize = function (state) { |
|
|
// - return true
|
|
|
// - return true
|
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++) { |
|
|
for (i = 0; i < len; i++) { |
|
|
ok = this._rules[i](state, false); |
|
|
ok = rules[i](state, false); |
|
|
if (ok) { break; } |
|
|
if (ok) { break; } |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|