summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-markdown/lib/annotate.js
diff options
context:
space:
mode:
Diffstat (limited to 'packages/gitbook-markdown/lib/annotate.js')
-rw-r--r--packages/gitbook-markdown/lib/annotate.js42
1 files changed, 3 insertions, 39 deletions
diff --git a/packages/gitbook-markdown/lib/annotate.js b/packages/gitbook-markdown/lib/annotate.js
index dab3d0e..34e5d90 100644
--- a/packages/gitbook-markdown/lib/annotate.js
+++ b/packages/gitbook-markdown/lib/annotate.js
@@ -1,3 +1,5 @@
+var engine = require('./annotate_engine');
+
// Pulled from "kramed.Lexer.rules.tables"
var rules = { newline: /^\n+/,
code: /^( {4}[^\n]+\n*)+/,
@@ -36,45 +38,7 @@ var ruleMap = {
}
function annotate(src) {
- var tokens = [];
-
- while(src) {
- // Pick rule
- var rule = ruleTypes.filter(function(ruleName, idx) {
- var regex = rules[ruleName];
- return regex.exec(src);
- })[0];
-
- // No matching rules
- if(!rule) {
- throw new Error('No rule found for: ' + src);
- }
-
- // Use rule to extract block
- var ruleRegex = rules[rule];
- var block = ruleRegex.exec(src);
-
- // Get rule type
- var type = ruleMap[rule] || rule;
-
- // Get raw text
- var raw = block[0];
-
- // Break out here to avoid infinite loops
- if(raw.length === 0) {
- break;
- }
-
- tokens.push({
- type: ruleMap[rule] || rule,
- raw: raw,
- });
-
- // Update source
- src = src.substring(raw.length);
- }
-
- return tokens
+ return engine(src, rules, ruleTypes, ruleMap);
}
module.exports = annotate;