From 5738d146e01695bd6a06dcee3402157318a257ee Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Sun, 27 May 2012 00:22:58 +0100 Subject: [PATCH] Amended macro mechanism so that the same wikitext rule can act as both a run rule and a block rule --- .../newwikitextparser/blockrules/class.js | 4 +- .../newwikitextparser/blockrules/heading.js | 4 +- .../newwikitextparser/blockrules/html.js | 5 +- .../newwikitextparser/blockrules/list.js | 4 +- .../newwikitextparser/blockrules/rule.js | 4 +- .../newwikitextparser/newwikitextparser.js | 60 +++++++++---------- .../newwikitextparser/runrules/macro.js | 5 +- .../newwikitextparser/runrules/prettylink.js | 4 +- .../newwikitextparser/runrules/wikilink.js | 4 +- tw5.com/tiddlers/TestingNewWikiText.tid | 4 +- 10 files changed, 59 insertions(+), 39 deletions(-) diff --git a/core/modules/parsers/newwikitextparser/blockrules/class.js b/core/modules/parsers/newwikitextparser/blockrules/class.js index ff95bf6aa..283253fc3 100644 --- a/core/modules/parsers/newwikitextparser/blockrules/class.js +++ b/core/modules/parsers/newwikitextparser/blockrules/class.js @@ -1,7 +1,7 @@ /*\ title: $:/core/modules/parsers/newwikitextparser/blockrules/class.js type: application/javascript -module-type: wikitextblockrule +module-type: wikirule Wiki text block rule for assigning classes to paragraphs and other blocks @@ -14,6 +14,8 @@ Wiki text block rule for assigning classes to paragraphs and other blocks exports.name = "class"; +exports.blockParser = true; + exports.regExpString = "\\{\\{(?:[^\\{\\r\\n]*)\\{$"; exports.parse = function(match) { diff --git a/core/modules/parsers/newwikitextparser/blockrules/heading.js b/core/modules/parsers/newwikitextparser/blockrules/heading.js index ea381e499..1c324e7ca 100644 --- a/core/modules/parsers/newwikitextparser/blockrules/heading.js +++ b/core/modules/parsers/newwikitextparser/blockrules/heading.js @@ -1,7 +1,7 @@ /*\ title: $:/core/modules/parsers/newwikitextparser/blockrules/heading.js type: application/javascript -module-type: wikitextblockrule +module-type: wikirule Wiki text block rule for headings @@ -14,6 +14,8 @@ Wiki text block rule for headings exports.name = "heading"; +exports.blockParser = true; + exports.regExpString = "!{1,6}"; exports.parse = function(match) { diff --git a/core/modules/parsers/newwikitextparser/blockrules/html.js b/core/modules/parsers/newwikitextparser/blockrules/html.js index 49fdb7091..649deb1a3 100644 --- a/core/modules/parsers/newwikitextparser/blockrules/html.js +++ b/core/modules/parsers/newwikitextparser/blockrules/html.js @@ -1,7 +1,7 @@ /*\ title: $:/core/modules/parsers/newwikitextparser/blockrules/html.js type: application/javascript -module-type: wikitextblockrule +module-type: wikirule Wiki text block rule for block level HTML elements @@ -14,6 +14,9 @@ Wiki text block rule for block level HTML elements exports.name = "html"; +exports.blockParser = true; +exports.runParser = true; + exports.regExpString = "<[A-Za-z]+\\s*[^>]*>"; exports.parse = function(match) { diff --git a/core/modules/parsers/newwikitextparser/blockrules/list.js b/core/modules/parsers/newwikitextparser/blockrules/list.js index d5f250ca0..8028a97df 100644 --- a/core/modules/parsers/newwikitextparser/blockrules/list.js +++ b/core/modules/parsers/newwikitextparser/blockrules/list.js @@ -1,7 +1,7 @@ /*\ title: $:/core/modules/parsers/newwikitextparser/blockrules/list.js type: application/javascript -module-type: wikitextblockrule +module-type: wikirule Wiki text block rule for lists. @@ -16,6 +16,8 @@ Wiki text block rule for lists. exports.name = "list"; +exports.blockParser = true; + exports.regExpString = "[\\*#;:]+"; var listTypes = { diff --git a/core/modules/parsers/newwikitextparser/blockrules/rule.js b/core/modules/parsers/newwikitextparser/blockrules/rule.js index c7a1775c3..b7b5fc081 100644 --- a/core/modules/parsers/newwikitextparser/blockrules/rule.js +++ b/core/modules/parsers/newwikitextparser/blockrules/rule.js @@ -1,7 +1,7 @@ /*\ title: $:/core/modules/parsers/newwikitextparser/blockrules/rule.js type: application/javascript -module-type: wikitextblockrule +module-type: wikirule Wiki text block rule for rules @@ -14,6 +14,8 @@ Wiki text block rule for rules exports.name = "rule"; +exports.blockParser = true; + exports.regExpString = "-{3,}\r?\n"; exports.parse = function(match) { diff --git a/core/modules/parsers/newwikitextparser/newwikitextparser.js b/core/modules/parsers/newwikitextparser/newwikitextparser.js index eac2c5575..ffb1bf8b3 100644 --- a/core/modules/parsers/newwikitextparser/newwikitextparser.js +++ b/core/modules/parsers/newwikitextparser/newwikitextparser.js @@ -45,13 +45,13 @@ WikiTextRenderer.prototype.parseBlock = function() { return []; } // Look for a block rule - this.parser.blockRules.regExp.lastIndex = this.pos; - var match = this.parser.blockRules.regExp.exec(this.source); - if(this.parser.blockRules.rules.length && match && match.index === this.pos) { + this.parser.blockRegExp.lastIndex = this.pos; + var match = this.parser.blockRegExp.exec(this.source); + if(this.parser.blockRules.length && match && match.index === this.pos) { var rule; - for(var t=0; t> and that was it. + Here is a macro <> ! This is a new heading @@ -75,4 +77,4 @@ This is my nice and simple block of text. HelloThere And another: -
This time the text is all squashed up, without line breaks
+
This time the text is all squashed up, without line breaks