2012-05-26 22:37:44 +00:00
|
|
|
/*\
|
2012-06-02 08:54:00 +00:00
|
|
|
title: $:/core/modules/parsers/newwikitextparser/rules/macro.js
|
2012-05-26 22:37:44 +00:00
|
|
|
type: application/javascript
|
2012-05-27 08:19:37 +00:00
|
|
|
module-type: wikitextrule
|
2012-05-26 22:37:44 +00:00
|
|
|
|
2012-06-05 21:54:36 +00:00
|
|
|
Wiki text run rule for pretty links. For example:
|
|
|
|
|
|
|
|
{{{
|
|
|
|
<<version>>
|
|
|
|
|
|
|
|
<<link to:HelloThere><
|
|
|
|
A macro with a bunch of content inside it. The content can include //formatting//.
|
|
|
|
>>
|
|
|
|
}}}
|
2012-05-26 22:37:44 +00:00
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
exports.name = "macro";
|
|
|
|
|
2012-05-26 23:22:58 +00:00
|
|
|
exports.runParser = true;
|
|
|
|
exports.blockParser = true;
|
|
|
|
|
2012-06-05 16:01:17 +00:00
|
|
|
exports.regExpString = "<<(?:(?:[!@£\\$%\\^\\&\\*\\(\\)`\\~'\"\\|\\\\\\/;\\:\\.\\,\\+\\=\\-\\_\\{\\}])|(?:[^>\\s]+))(?:\\s*)(?:(?:[^>]|(?:>(?!>|<)))*)>(?:>|<)";
|
2012-05-26 22:37:44 +00:00
|
|
|
|
2012-05-28 14:51:52 +00:00
|
|
|
exports.parse = function(match,isBlock) {
|
2012-06-05 16:01:17 +00:00
|
|
|
var regExp = /<<(?:([!@£\$%\^\&\*\(\)`\~'"\|\\\/;\:\.\,\+\=\-\_\{\}])|([^>\s]+))(?:\s*)((?:[^>]|(?:>(?!>|<)))*)>(?:(>)|(<))/mg,
|
2012-07-16 12:58:00 +00:00
|
|
|
reLineBreak = /(\r?\n)/mg,
|
2012-06-05 16:01:17 +00:00
|
|
|
content = [];
|
2012-05-26 22:37:44 +00:00
|
|
|
regExp.lastIndex = this.pos;
|
|
|
|
match = regExp.exec(this.source);
|
|
|
|
if(match && match.index === this.pos) {
|
|
|
|
this.pos = match.index + match[0].length;
|
2012-06-05 16:01:17 +00:00
|
|
|
if(match[5]) {
|
2012-07-16 12:58:00 +00:00
|
|
|
// Look for a line break immediately after the `><` to trigger block mode
|
|
|
|
reLineBreak.lastIndex = this.pos;
|
|
|
|
var lineBreakMatch = reLineBreak.exec(this.source);
|
|
|
|
if(lineBreakMatch && lineBreakMatch.index === this.pos) {
|
|
|
|
this.pos = lineBreakMatch.index + lineBreakMatch[0].length;
|
|
|
|
isBlock = true;
|
|
|
|
} else {
|
|
|
|
isBlock = false;
|
|
|
|
}
|
2012-06-07 12:09:48 +00:00
|
|
|
// If the macro has content then parse it as a block or run
|
|
|
|
if(isBlock) {
|
2012-06-10 16:26:54 +00:00
|
|
|
content = this.parseBlocks(">>");
|
2012-06-07 12:09:48 +00:00
|
|
|
} else {
|
|
|
|
content = this.parseRun(/(>>)/mg);
|
|
|
|
}
|
2012-06-05 16:01:17 +00:00
|
|
|
}
|
2012-05-28 14:51:52 +00:00
|
|
|
var macroNode = $tw.Tree.Macro(match[1] || match[2],{
|
|
|
|
srcParams: match[3],
|
2012-06-05 16:01:17 +00:00
|
|
|
content: content,
|
2012-05-28 14:51:52 +00:00
|
|
|
isBlock: isBlock,
|
|
|
|
wiki: this.wiki
|
|
|
|
});
|
2012-05-26 22:37:44 +00:00
|
|
|
this.dependencies.mergeDependencies(macroNode.dependencies);
|
|
|
|
return [macroNode];
|
|
|
|
}
|
|
|
|
return [];
|
|
|
|
};
|
|
|
|
|
|
|
|
})();
|