2012-04-30 11:23:03 +00:00
|
|
|
/*\
|
2012-05-03 20:47:16 +00:00
|
|
|
title: $:/core/modules/parsers/tiddlytextparser.js
|
2012-04-30 11:23:03 +00:00
|
|
|
type: application/javascript
|
|
|
|
module-type: parser
|
|
|
|
|
|
|
|
Parses a plain text block that can also contain macros and transclusions.
|
|
|
|
|
|
|
|
The syntax for transclusions is:
|
|
|
|
|
|
|
|
[[tiddlerTitle]]
|
|
|
|
|
|
|
|
The syntax for macros is:
|
|
|
|
|
|
|
|
<<macroName params>>
|
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
2012-05-04 17:49:04 +00:00
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
2012-04-30 11:23:03 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var TiddlyTextParser = function(options) {
|
|
|
|
this.wiki = options.wiki;
|
|
|
|
};
|
|
|
|
|
|
|
|
TiddlyTextParser.prototype.parse = function(type,text) {
|
|
|
|
var output = [],
|
|
|
|
dependencies = new $tw.Dependencies(),
|
2012-05-29 21:16:02 +00:00
|
|
|
macroRegExp = /(?:\[\[([^\]]+)\]\])|(?:<<(?:([!@£\$%\^\&\*\(\)`\~'"\|\\\/;\:\.\,\+\=\-\_\{\}])|([^>\s]+))(?:\s*)((?:[^>]|(?:>(?!>)))*)>>((?:\r?\n)?))/mg,
|
2012-04-30 11:23:03 +00:00
|
|
|
lastMatchPos = 0,
|
|
|
|
match,
|
|
|
|
macroNode;
|
|
|
|
do {
|
|
|
|
match = macroRegExp.exec(text);
|
|
|
|
if(match) {
|
|
|
|
output.push($tw.Tree.Text(text.substring(lastMatchPos,match.index)));
|
2012-05-05 10:57:24 +00:00
|
|
|
var macroName = match[2] || match[3];
|
2012-04-30 11:23:03 +00:00
|
|
|
if(match[1]) { // Transclusion
|
|
|
|
macroNode = $tw.Tree.Macro("tiddler",{
|
2012-05-28 14:51:52 +00:00
|
|
|
srcParams: {target: match[1]},
|
|
|
|
wiki: this.wiki
|
|
|
|
});
|
2012-05-05 10:57:24 +00:00
|
|
|
} else if(macroName) { // Macro call
|
2012-05-28 14:51:52 +00:00
|
|
|
macroNode = $tw.Tree.Macro(macroName,{
|
|
|
|
srcParams: match[4],
|
2012-05-29 21:16:02 +00:00
|
|
|
wiki: this.wiki,
|
|
|
|
isBlock: !!match[5]
|
2012-05-28 14:51:52 +00:00
|
|
|
});
|
2012-04-30 11:23:03 +00:00
|
|
|
}
|
|
|
|
output.push(macroNode);
|
|
|
|
dependencies.mergeDependencies(macroNode.dependencies);
|
|
|
|
lastMatchPos = match.index + match[0].length;
|
|
|
|
} else {
|
|
|
|
output.push($tw.Tree.Text(text.substr(lastMatchPos)));
|
|
|
|
}
|
|
|
|
} while(match);
|
|
|
|
return new $tw.Renderer(output,dependencies);
|
|
|
|
};
|
|
|
|
|
|
|
|
exports["text/x-tiddlywiki-css"] = TiddlyTextParser;
|
2012-05-05 10:19:10 +00:00
|
|
|
exports["text/x-tiddlywiki-html"] = TiddlyTextParser;
|
2012-04-30 11:23:03 +00:00
|
|
|
|
|
|
|
})();
|