2011-12-13 12:30:09 +00:00
|
|
|
/*\
|
|
|
|
title: js/WikiTextProcessor.js
|
|
|
|
|
|
|
|
\*/
|
2011-12-12 10:52:04 +00:00
|
|
|
(function(){
|
|
|
|
|
2011-12-11 18:28:09 +00:00
|
|
|
/*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
|
2011-12-13 12:30:09 +00:00
|
|
|
options are a hashmap of mandatory members as follows:
|
|
|
|
|
2011-12-28 17:45:58 +00:00
|
|
|
store: The store object to use to parse any cascaded content (eg transclusion)
|
2011-12-13 12:30:09 +00:00
|
|
|
|
|
|
|
Planned:
|
2011-12-11 18:28:09 +00:00
|
|
|
|
|
|
|
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) {
|
2011-12-28 17:45:58 +00:00
|
|
|
options = options || {};
|
|
|
|
this.store = options.store;
|
2011-12-11 18:28:09 +00:00
|
|
|
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);
|
2011-12-12 10:52:04 +00:00
|
|
|
};
|
2011-12-11 18:28:09 +00:00
|
|
|
|
|
|
|
exports.WikiTextProcessor = WikiTextProcessor;
|
2011-12-12 10:52:04 +00:00
|
|
|
|
|
|
|
})();
|