diff --git a/core/modules/parsers/wikiparser/rules/block/rule.js b/core/modules/parsers/wikiparser/rules/block/rule.js new file mode 100644 index 000000000..00fe3254e --- /dev/null +++ b/core/modules/parsers/wikiparser/rules/block/rule.js @@ -0,0 +1,33 @@ +/*\ +title: $:/core/modules/parsers/wikiparser/rules/block/rule.js +type: application/javascript +module-type: wikiblockrule + +Wiki text block rule for rules. For example: + +{{{ +--- +}}} + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +exports.name = "rule"; + +exports.init = function(parser) { + this.parser = parser; + // Regexp to match + this.matchRegExp = /-{3,}\r?\n/mg; +}; + +exports.parse = function(match,isBlock) { + // Move past the match + this.parser.pos = this.matchRegExp.lastIndex; + return [{type: "element", tag: "hr"}]; +}; + +})(); diff --git a/core/modules/parsers/wikiparser/rules/block/transcludeblock.js b/core/modules/parsers/wikiparser/rules/block/transcludeblock.js new file mode 100644 index 000000000..db1ecc9c7 --- /dev/null +++ b/core/modules/parsers/wikiparser/rules/block/transcludeblock.js @@ -0,0 +1,58 @@ +/*\ +title: $:/core/modules/parsers/wikiparser/rules/block/transcludeblock.js +type: application/javascript +module-type: wikiblockrule + +Wiki text rule for block-level transclusion. For example: + +{{{ +{{MyTiddler}} +{{MyTiddler|tooltip}} +{{MyTiddler}width:40;height:50;}.class.class +}}} + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +exports.name = "transclude"; + +exports.init = function(parser) { + this.parser = parser; + // Regexp to match + this.matchRegExp = /\{\{([^\{\}\|]+)(?:\|([^\{\}]+))?\}([^\}]*)\}/mg; +}; + +exports.parse = function(match,isBlock) { + // Move past the match + this.parser.pos = this.matchRegExp.lastIndex; + // Get the match details + var targetTitle = this.match[1], + tooltip = this.match[2], + style = this.match[3]; + // Parse any class definitions + var classes = this.parser.parseClasses(); + // Return the transclude widget + var node = { + type: "widget", + tag: "transclude", + attributes: { + target: {type: "string", value: targetTitle} + } + }; + if(tooltip) { + node.attributes.tooltip = {type: "string", value: tooltip}; + } + if(style) { + node.attributes.style = {type: "string", value: style}; + } + if(classes.length > 0) { + node.attributes["class"] = {type: "string", value: classes.join(" ")}; + } + return [node]; +}; + +})(); diff --git a/core/modules/parsers/wikiparser/rules/run/extlink.js b/core/modules/parsers/wikiparser/rules/run/extlink.js new file mode 100644 index 000000000..dea22f79f --- /dev/null +++ b/core/modules/parsers/wikiparser/rules/run/extlink.js @@ -0,0 +1,51 @@ +/*\ +title: $:/core/modules/parsers/wikiparser/rules/run/extlink.js +type: application/javascript +module-type: wikirunrule + +Wiki text run rule for external links. For example: + +{{{ +An external link: http://www.tiddlywiki.com/ + +A suppressed external link: ~http://www.tiddlyspace.com/ +}}} + +External links can be suppressed by preceding them with `~`. + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +exports.name = "extlink"; + +exports.init = function(parser) { + this.parser = parser; + // Regexp to match + this.matchRegExp = /~?(?:file|http|https|mailto|ftp|irc|news|data):[^\s'"]+(?:\/|\b)/mg; +}; + +exports.parse = function() { + // Move past the match + this.parser.pos = this.matchRegExp.lastIndex; + // Create the link unless it is suppressed + if(this.match[0].substr(0,1) === "~") { + return [{type: "text", text: this.match[0].substr(1)}]; + } else { + return [{ + type: "widget", + tag: "link", + attributes: { + to: {type: "string", value: this.match[0]} + }, + children: [{ + type: "text", text: this.match[0] + }] + }]; + } +}; + +})(); diff --git a/core/modules/parsers/wikiparser/rules/run/prettylink.js b/core/modules/parsers/wikiparser/rules/run/prettylink.js new file mode 100644 index 000000000..0fae9a5d3 --- /dev/null +++ b/core/modules/parsers/wikiparser/rules/run/prettylink.js @@ -0,0 +1,47 @@ +/*\ +title: $:/core/modules/parsers/wikiparser/rules/run/prettylink.js +type: application/javascript +module-type: wikirunrule + +Wiki text run rule for pretty links. For example: + +{{{ +[[Introduction]] + +[[Link description|TiddlerTitle]] +}}} + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +exports.name = "prettylink"; + +exports.init = function(parser) { + this.parser = parser; + // Regexp to match + this.matchRegExp = /\[\[(.*?)(?:\|(.*?))?\]\]/mg; +}; + +exports.parse = function() { + // Move past the match + this.parser.pos = this.matchRegExp.lastIndex; + // Process the link + var text = this.match[1], + link = this.match[2] || text; + return [{ + type: "widget", + tag: "link", + attributes: { + to: {type: "string", value: link} + }, + children: [{ + type: "text", text: text + }] + }]; +}; + +})();