Skip to content
Snippets Groups Projects
Commit db1908a6 authored by Marijn Haverbeke's avatar Marijn Haverbeke
Browse files

[mode/simple addon] Allow token source to be a function

Issue #4787
parent 0aec8bfc
No related branches found
No related tags found
No related merge requests found
...@@ -77,6 +77,7 @@ ...@@ -77,6 +77,7 @@
function asToken(val) { function asToken(val) {
if (!val) return null; if (!val) return null;
if (val.apply) return val
if (typeof val == "string") return val.replace(/\./g, " "); if (typeof val == "string") return val.replace(/\./g, " ");
var result = []; var result = [];
for (var i = 0; i < val.length; i++) for (var i = 0; i < val.length; i++)
...@@ -133,17 +134,19 @@ ...@@ -133,17 +134,19 @@
state.indent.push(stream.indentation() + config.indentUnit); state.indent.push(stream.indentation() + config.indentUnit);
if (rule.data.dedent) if (rule.data.dedent)
state.indent.pop(); state.indent.pop();
var token = rule.token
if (token.apply) token = token(matches)
if (matches.length > 2) { if (matches.length > 2) {
state.pending = []; state.pending = [];
for (var j = 2; j < matches.length; j++) for (var j = 2; j < matches.length; j++)
if (matches[j]) if (matches[j])
state.pending.push({text: matches[j], token: rule.token[j - 1]}); state.pending.push({text: matches[j], token: rule.token[j - 1]});
stream.backUp(matches[0].length - (matches[1] ? matches[1].length : 0)); stream.backUp(matches[0].length - (matches[1] ? matches[1].length : 0));
return rule.token[0]; return token[0];
} else if (rule.token && rule.token.join) { } else if (token && token.join) {
return rule.token[0]; return token[0];
} else { } else {
return rule.token; return token;
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment