1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-12-25 01:20:30 +00:00
TiddlyWiki5/js/WikiTextProcessor.js
2011-12-28 17:45:58 +00:00

44 lines
1.2 KiB
JavaScript

/*\
title: js/WikiTextProcessor.js
\*/
(function(){
/*jslint node: true */
"use strict";
var WikiTextRules = require("./WikiTextRules.js"),
WikiTextParser = require("./WikiTextParser.js").WikiTextParser;
/*
Creates a new instance of the wiki text processor with the specified options. The
options are a hashmap of mandatory members as follows:
store: The store object to use to parse any cascaded content (eg transclusion)
Planned:
enableRules: An array of names of wiki text rules to enable. If not specified, all rules are available
extraRules: An array of additional rule handlers to add
enableMacros: An array of names of macros to enable. If not specified, all macros are available
extraMacros: An array of additional macro handlers to add
*/
var WikiTextProcessor = function(options) {
options = options || {};
this.store = options.store;
this.rules = WikiTextRules.rules;
var pattern = [];
for(var n=0; n<this.rules.length; n++) {
pattern.push("(" + this.rules[n].match + ")");
}
this.rulesRegExp = new RegExp(pattern.join("|"),"mg");
};
WikiTextProcessor.prototype.parse = function(text) {
return new WikiTextParser(text,this);
};
exports.WikiTextProcessor = WikiTextProcessor;
})();