mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-12-09 02:08:05 +00:00
Further improvements to parser rule implementation
This commit is contained in:
@@ -14,7 +14,8 @@ Wiki text block rule for headings
|
||||
|
||||
exports.name = "heading";
|
||||
|
||||
exports.init = function() {
|
||||
exports.init = function(parser) {
|
||||
this.parser = parser;
|
||||
// Regexp to match
|
||||
this.matchRegExp = /(!{1,6})/mg;
|
||||
};
|
||||
|
||||
@@ -48,7 +48,8 @@ A CSS class can be applied to a list item as follows:
|
||||
|
||||
exports.name = "list";
|
||||
|
||||
exports.init = function() {
|
||||
exports.init = function(parser) {
|
||||
this.parser = parser;
|
||||
// Regexp to match
|
||||
this.matchRegExp = /([\\*#;:]+)/mg;
|
||||
};
|
||||
|
||||
@@ -23,7 +23,8 @@ exports.name = "macrodef";
|
||||
/*
|
||||
Instantiate parse rule
|
||||
*/
|
||||
exports.init = function() {
|
||||
exports.init = function(parser) {
|
||||
this.parser = parser;
|
||||
// Regexp to match
|
||||
this.matchRegExp = /^\\define\s*([^(\s]+)\(\s*([^)]*)\)(\r?\n)?/mg;
|
||||
};
|
||||
|
||||
@@ -18,7 +18,8 @@ Wiki text run rule for HTML entities. For example:
|
||||
|
||||
exports.name = "entity";
|
||||
|
||||
exports.init = function() {
|
||||
exports.init = function(parser) {
|
||||
this.parser = parser;
|
||||
// Regexp to match
|
||||
this.matchRegExp = /(&#?[a-zA-Z0-9]{2,8};)/mg;
|
||||
};
|
||||
|
||||
@@ -27,7 +27,8 @@ exports.name = "html";
|
||||
|
||||
var voidElements = "area,base,br,col,command,embed,hr,img,input,keygen,link,meta,param,source,track,wbr".split(",");
|
||||
|
||||
exports.init = function() {
|
||||
exports.init = function(parser) {
|
||||
this.parser = parser;
|
||||
// Regexp to match
|
||||
this.matchRegExp = /<(_)?([A-Za-z]+)(\s*[^>]*?)(\/)?>/mg;
|
||||
};
|
||||
|
||||
@@ -18,7 +18,8 @@ Wiki rule for macro calls
|
||||
|
||||
exports.name = "macrocall";
|
||||
|
||||
exports.init = function() {
|
||||
exports.init = function(parser) {
|
||||
this.parser = parser;
|
||||
// Regexp to match
|
||||
this.matchRegExp = /<<([^\s>]+)\s*([\s\S]*?)>>/mg;
|
||||
};
|
||||
|
||||
@@ -35,7 +35,8 @@ textPrimitives.wikiLink = textPrimitives.upperLetter + "+" +
|
||||
textPrimitives.upperLetter +
|
||||
textPrimitives.anyLetter + "*";
|
||||
|
||||
exports.init = function() {
|
||||
exports.init = function(parser) {
|
||||
this.parser = parser;
|
||||
// Regexp to match
|
||||
this.matchRegExp = new RegExp(textPrimitives.unWikiLink + "?" + textPrimitives.wikiLink,"mg");
|
||||
};
|
||||
|
||||
@@ -12,24 +12,28 @@ Base class for wiki parser rules
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
var WikiRuleDefaultProperties = {};
|
||||
/*
|
||||
This constructor is always overridden with a blank constructor, and so shouldn't be used
|
||||
*/
|
||||
var WikiRule = function() {
|
||||
};
|
||||
|
||||
/*
|
||||
To be overridden by individual rules
|
||||
*/
|
||||
WikiRuleDefaultProperties.init = function() {
|
||||
|
||||
WikiRule.prototype.init = function(parser) {
|
||||
this.parser = parser;
|
||||
};
|
||||
|
||||
/*
|
||||
Default implementation of findNextMatch looks uses RegExp matching
|
||||
Default implementation of findNextMatch uses RegExp matching
|
||||
*/
|
||||
WikiRuleDefaultProperties.findNextMatch = function(startPos) {
|
||||
WikiRule.prototype.findNextMatch = function(startPos) {
|
||||
this.matchRegExp.lastIndex = startPos;
|
||||
this.match = this.matchRegExp.exec(this.parser.source);
|
||||
return this.match ? this.match.index : undefined;
|
||||
};
|
||||
|
||||
exports.WikiRuleDefaultProperties = WikiRuleDefaultProperties;
|
||||
exports.WikiRule = WikiRule;
|
||||
|
||||
})();
|
||||
|
||||
@@ -38,12 +38,12 @@ var WikiParser = function(vocabulary,type,text,options) {
|
||||
// Initialise the things that pragma rules can change
|
||||
this.macroDefinitions = {}; // Hash map of macro definitions
|
||||
// Instantiate the pragma parse rules
|
||||
this.pragmaRules = this.instantiateRules(this.vocabulary.pragmaRules,0);
|
||||
this.pragmaRules = this.instantiateRules(this.vocabulary.pragmaRuleClasses,0);
|
||||
// Parse any pragmas
|
||||
this.parsePragmas();
|
||||
// Instantiate the parser block and run rules
|
||||
this.blockRules = this.instantiateRules(this.vocabulary.blockRules,this.pos);
|
||||
this.runRules = this.instantiateRules(this.vocabulary.runRules,this.pos);
|
||||
this.blockRules = this.instantiateRules(this.vocabulary.blockRuleClasses,this.pos);
|
||||
this.runRules = this.instantiateRules(this.vocabulary.runRuleClasses,this.pos);
|
||||
// Parse the text into runs or blocks
|
||||
if(this.type === "text/vnd.tiddlywiki-run") {
|
||||
this.tree = this.parseRun();
|
||||
@@ -61,7 +61,7 @@ WikiParser.prototype.instantiateRules = function(classes,startPos) {
|
||||
$tw.utils.each(classes,function(RuleClass) {
|
||||
// Instantiate the rule
|
||||
var rule = new RuleClass(self);
|
||||
rule.init();
|
||||
rule.init(self);
|
||||
var matchIndex = rule.findNextMatch(startPos);
|
||||
if(matchIndex !== undefined) {
|
||||
rulesInfo.push({
|
||||
|
||||
Reference in New Issue
Block a user