1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-18 11:29:55 +00:00

checkin of updates to latest version of widget tree format, includes tiddler, slider and tabs macros

This commit is contained in:
buggyj 2014-06-17 18:56:31 +02:00
parent 9147cadd3c
commit d13de81c7a
7 changed files with 550 additions and 100 deletions

View File

@ -0,0 +1,184 @@
/*\
title: $:/core/modules/widgets/classictransclude.js
type: application/javascript
module-type: widget
Transclude widget
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
var sliceSeparator = "::";
var sectionSeparator = "##";
function getsectionname(title) {
if(!title)
return "";
var pos = title.indexOf(sectionSeparator);
if(pos != -1) {
return title.substr(pos + sectionSeparator.length);
}
return "";
}
function getslicename(title) {
if(!title)
return "";
var pos = title.indexOf(sliceSeparator);
if(pos != -1) {
return title.substr(pos + sliceSeparator.length);
}
return "";
};
function gettiddlername(title) {
if(!title)
return "";
var pos = title.indexOf(sectionSeparator);
if(pos != -1) {
return title.substr(0,pos);
}
pos = title.indexOf(sliceSeparator);
if(pos != -1) {
return title.substr(0,pos);
}
return title;
}
var Widget = require("$:/core/modules/widgets/widget.js").widget;
var TranscludeWidget = function(parseTreeNode,options) {
this.initialise(parseTreeNode,options);
};
/*
Inherit from the base widget class
*/
TranscludeWidget.prototype = new Widget();
/*
Render this widget into the DOM
*/
TranscludeWidget.prototype.render = function(parent,nextSibling) {
this.parentDomNode = parent;
this.computeAttributes();
this.execute();
this.renderChildren(parent,nextSibling);
};
/*
Compute the internal state of the widget
*/
TranscludeWidget.prototype.execute = function() {
// Get our parameters
this.rawTitle = this.getAttribute("tiddler",this.getVariable("currentTiddler"));
this.transcludeTitle = gettiddlername(this.rawTitle);
this.section = getsectionname(this.rawTitle);
this.slice = getslicename(this.rawTitle);
// Check for recursion
var recursionMarker = this.makeRecursionMarker();
if(this.parentWidget && this.parentWidget.hasVariable("transclusion",recursionMarker)) {
this.makeChildWidgets([{type: "text", text: "Recursive transclusion error in transclude widget"}]);
return;
}
// Set context variables for recursion detection
this.setVariable("transclusion",recursionMarker);
// Parse
var text = this.wiki.getTiddlerText(this.transcludeTitle);
if (!!this.section||!!this.slice) {
text =this.refineTiddlerText(text, this.section, this.slice);
}
this.options ={};
this.options.parseAsInline = false;
var parser = this.wiki.parseText("text/x-tiddlywiki",text,{});
var parseTreeNodes = parser ? parser.tree : this.parseTreeNode.children;
// Construct the child widgets
this.makeChildWidgets(parseTreeNodes);
};
/*
Compose a string comprising the title, field and/or index to identify this transclusion for recursion detection
*/
TranscludeWidget.prototype.makeRecursionMarker = function() {
var output = [];
output.push("{");
output.push(this.getVariable("currentTiddler",{defaultValue: ""}));
output.push("|");
output.push(this.transcludeTitle || "");
output.push("|");
output.push(this.transcludeField || "");
output.push("|");
output.push(this.transcludeIndex || "");
output.push("|");
output.push(this.section || "");
output.push("|");
output.push(this.slice || "");
output.push("}");
return output.join("");
};
TranscludeWidget.prototype.slicesRE = /(?:^([\'\/]{0,2})~?([\.\w]+)\:\1[\t\x20]*([^\n]*)[\t\x20]*$)|(?:^\|([\'\/]{0,2})~?([\.\w]+)\:?\4\|[\t\x20]*([^\|\n]*)[\t\x20]*\|$)/gm;
TranscludeWidget.prototype.calcAllSlices = function(text)
{
var slices = {};
this.slicesRE.lastIndex = 0;
var m = this.slicesRE.exec(text);
while(m) {
if(m[2])
slices[m[2]] = m[3];
else
slices[m[5]] = m[6];
m = this.slicesRE.exec(text);
}
return slices;
};
// Returns the slice of text of the given name
TranscludeWidget.prototype.getTextSlice = function(text,sliceName)
{
return (this.calcAllSlices(text))[sliceName];
};
TranscludeWidget.prototype.refineTiddlerText = function(text,section,slice)
{
var textsection = null;
if (slice) {
var textslice = this.getTextSlice(text,slice);
if(textslice)
return textslice;
}
if(!section)
return text;
var re = new RegExp("(^!{1,6}[ \t]*" + $tw.utils.escapeRegExp(section) + "[ \t]*\n)","mg");
re.lastIndex = 0;
var match = re.exec(text);
if(match) {
var t = text.substr(match.index+match[1].length);
var re2 = /^!/mg;
re2.lastIndex = 0;
match = re2.exec(t); //# search for the next heading
if(match)
t = t.substr(0,match.index-1);//# don't include final \n
return t;
}
return "";
}
/*
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
*/
TranscludeWidget.prototype.refresh = function(changedTiddlers) {
var changedAttributes = this.computeAttributes();
if(changedAttributes.tiddler ||changedTiddlers[this.transcludeTitle]) {
this.refreshSelf();
return true;
} else {
return this.refreshChildren(changedTiddlers);
}
};
exports.classictransclude = TranscludeWidget;
})();

View File

@ -0,0 +1,30 @@
/*\
title: $:/macros/tiddlywiki/entry.js
type: application/javascript
module-type: macro
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Information about this macro
returns value of key in a data json tiddler
note that macros are not connected with the refresh mechanism -use with caution.
*/
exports.name = "entryof";
exports.params = [
{ name: "key" }, { name: "map" }
];
/*
Run the macro
*/
exports.run = function(key,map) {
try{
return JSON.parse(map)[key];
} catch(e) {
return "";
}
}
})();

View File

@ -0,0 +1,34 @@
title: $:/plugins/tiddlywiki/tw2parser/macrodefs
\define tiddler(tiddler)
<$classictransclude tiddler = "$tiddler$"/>
\end
\define slider(chkUniqueCookieName tiddler label tooltip)
<span title=$tooltip$><$button popup="$chkUniqueCookieName$" class="btn-invisible tw-slider">$label$</$button>
<$reveal type="nomatch" text="" default="" state="$chkUniqueCookieName$" animate="yes">
<$classictransclude tiddler = "$tiddler$"/>
</$reveal></span>
\end
\define __system_tabinstance(state, currentTab, prompts, labels)
<span title=<<entryof "$currentTab$" '$prompts$'>> ><$button set=<<qualify "$state$">> setTo="$currentTab$" selectedClass="tw-tab-selected">
<<entryof "$currentTab$" '$labels$' >>
</$button></span>
\end
\define __system_tabs(tabsList,prompts,labels,state:"$:/state/tab")
<div class="tw-tab-buttons">
<$list filter="$tabsList$" variable="currentTab">
<$macrocall $name="__system_tabinstance" state="$state$" prompts='$prompts$' labels='$labels$'currentTab=<<currentTab>>/>
</$list>
</div>
<div class="tw-tab-divider"/>
<div class="tw-tab-content">
<$list filter="$tabsList$" variable="currentTab">
<$reveal type="match" state=<<qualify "$state$">> text=<<currentTab>> default="$default$">
<$classictransclude tiddler=<<currentTab>> />
</$reveal>
</$list>
</div>
\end

View File

@ -0,0 +1,97 @@
/*\
title: $:/macros/classic/macroadapter.js
type: application/javascript
module-type: module
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Information about this module:
rename macros and
re-jig macro params from tw2 to tw5 style
new macros created as a result of adapting tw2 should be
prepended "__system" to distinguish them from the actual used name
*/
var sliceSeparator = "::";
var sectionSeparator = "##";
function getsectionname(title) {
if(!title)
return "";
var pos = title.indexOf(sectionSeparator);
if(pos != -1) {
return title.substr(pos + sectionSeparator.length);
}
return "";
}
function getslicename(title) {
if(!title)
return "";
var pos = title.indexOf(sliceSeparator);
if(pos != -1) {
return title.substr(pos + sliceSeparator.length);
}
return "";
};
function gettiddlername(title) {
if(!title)
return "";
var pos = title.indexOf(sectionSeparator);
if(pos != -1) {
return title.substr(0,pos);
}
pos = title.indexOf(sliceSeparator);
if(pos != -1) {
return title.substr(0,pos);
}
return title;
}
var parserparams = function(paramString) {
var params = [],
reParam = /\s*(?:([A-Za-z0-9\-_]+)\s*:)?(?:\s*(?:"([^"]*)"|'([^']*)'|\[\[([^\]]*)\]\]|([^"'\s]+)))/mg,
paramMatch = reParam.exec(paramString);
while(paramMatch) {
// Process this parameter
var paramInfo = {
value: paramMatch[2] || paramMatch[3] || paramMatch[4] || paramMatch[5]
};
if(paramMatch[1]) {
paramInfo.name = paramMatch[1];
}
params.push(paramInfo);
// Find the next match
paramMatch = reParam.exec(paramString);
}
return params;
}
var tabshandler = function(paramstring) {
var params = parserparams(paramstring);
var cookie = params[0].value;
var numTabs = (params.length-1)/3;
var t;
var tabslist = "";
var labelarray = {};
var promptarray = {};
for(t=0; t<numTabs; t++) {
var contentName = params[t*3+3].value;
tabslist = tabslist+" " + contentName;
labelarray[contentName] = params[t*3+1].value;
promptarray[contentName] = params[t*3+2].value;
}
//Create a list of names (tiddlers, tiddler/sections, tiddler/slices), and create maps from name -> label and name -> prompt
//Use json to implement maps
return "'"+tabslist +"' '"+JSON.stringify(promptarray)+"' '"+JSON.stringify(labelarray)+"' '"+cookie+"'";
};
var namedapter = {tabs:'__system_tabs'};
var paramadapter = {
tabs: tabshandler
}
exports.name = 'macroadapter';
exports.namedapter = namedapter;
exports.paramadapter = paramadapter;
})();

View File

@ -0,0 +1,8 @@
{
"title": "$:/plugins/bj/tw2parser",
"description": "legacy parser",
"author": "JeremyRuston, JeffreyWilkinson",
"version": "0.0.2-alpha-tw2parser",
"core-version": ">=5.0.0",
"plugin-type": "plugin"
}

View File

@ -48,11 +48,29 @@ Planned:
extraMacros: An array of additional macro handlers to add
*/
var WikiTextParser = function(options) {
var WikiTextParser = function(type,text,options) {
this.wiki = options.wiki;
this.autoLinkWikiWords = true;
this.installRules();
text = text || "no text";
this.source = text;
this.nextMatch = 0;
this.children = [];
//this.children.push({type: "text",text:"hello to the queen"});
this.tree =[];
this.output = null;
this.subWikify(this.children);
var parser = $tw.wiki.old_parseTiddler("$:/plugins/tiddlywiki/tw2parser/macrodefs",{parseAsInline:false});
this.tree = [{
type: "element",
tag: "div",
children:this.children
}];
Array.prototype.push.apply(parser.tree,this.tree);
this.tree = parser.tree;
};
WikiTextParser.prototype.installRules = function() {
var rules = require("./wikitextrules.js").rules,
pattern = [];
@ -63,23 +81,10 @@ WikiTextParser.prototype.installRules = function() {
this.rulesRegExp = new RegExp(pattern.join("|"),"mg");
};
WikiTextParser.prototype.parse = function(type,text) {
text = text || "";
this.source = text;
this.nextMatch = 0;
this.children = [];
this.dependencies = new $tw.Dependencies();
this.output = null;
this.subWikify(this.children);
var tree = new $tw.Renderer(this.children,this.dependencies);
this.source = null;
this.children = null;
return tree;
};
WikiTextParser.prototype.outputText = function(place,startPos,endPos) {
if(startPos < endPos) {
place.push($tw.Tree.Text(this.source.substring(startPos,endPos)));
place.push({type: "text",text:this.source.substring(startPos,endPos)});
}
};

View File

@ -11,7 +11,7 @@ Rule modules for the wikitext parser
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
var macroadapter = require("$:/macros/classic/macroadapter.js");
var textPrimitives = {
upperLetter: "[A-Z\u00c0-\u00de\u0150\u0170]",
lowerLetter: "[a-z0-9_\\-\u00df-\u00ff\u0151\u0171]",
@ -51,7 +51,7 @@ var setAttr = function(node,attr,value) {
if(!node.attributes) {
node.attributes = {};
}
node.attributes[attr] = value;
node.attributes[attr] ={type: "string", value:value} ;
};
var inlineCssHelper = function(w) {
@ -80,17 +80,14 @@ var inlineCssHelper = function(w) {
};
var applyCssHelper = function(e,styles) {
if(styles.length > 0) {
if(!e.attributes) {
e.attributes = {};
}
if(!e.attributes.style) {
e.attributes.style = {};
}
for(var t=0; t< styles.length; t++) {
e.attributes.style[styles[t].style] = styles[t].value;
$tw.utils.addStyleToParseTreeNode(e,$tw.utils.roundTripPropertyName(styles[t].style),styles[t].value);
}
}
};
var enclosedTextHelper = function(w) {
@ -98,23 +95,41 @@ var enclosedTextHelper = function(w) {
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var text = lookaheadMatch[1];
w.output.push($tw.Tree.Element(this.element,null,[$tw.Tree.Text(text)]));
w.output.push({type:"element",tag:this.element,
children:[{type: "text",text: lookaheadMatch[1]}]});
w.nextMatch = lookaheadMatch.index + lookaheadMatch[0].length;
}
};
var insertMacroCall = function(w,output,name,params,content) {
if(name in w.wiki.macros) {
var macroNode = $tw.Tree.Macro(name,{
srcParams: params,
content: content,
wiki: w.wiki
});
w.dependencies.mergeDependencies(macroNode.dependencies);
output.push(macroNode);
var insertMacroCall = function(w,output,macroName,paramString) {
var params = [],
reParam = /\s*(?:([A-Za-z0-9\-_]+)\s*:)?(?:\s*(?:"([^"]*)"|'([^']*)'|\[\[([^\]]*)\]\]|([^"'\s]+)))/mg,
paramMatch = reParam.exec(paramString);
while(paramMatch) {
// Process this parameter
var paramInfo = {
value: paramMatch[2] || paramMatch[3] || paramMatch[4] || paramMatch[5]
};
if(paramMatch[1]) {
paramInfo.name = paramMatch[1];
}
params.push(paramInfo);
// Find the next match
paramMatch = reParam.exec(paramString);
}
};
output.push({
type: "macrocall",
name: macroName,
params: params,
isBlock: true
});
}
var isLinkExternal = function(to) {
var externalRegExp = /(?:file|http|https|mailto|ftp|irc|news|data|skype):[^\s'"]+(?:\/|\b)/i;
return externalRegExp.test(to);
};
var rules = [
{
name: "table",
@ -126,7 +141,9 @@ var rules = [
rowTypes: {"c":"caption", "h":"thead", "":"tbody", "f":"tfoot"},
handler: function(w)
{
var table = $tw.Tree.Element("table",{"class": "table"},[]);
var table = {type:"element",tag:"table",attributes: {"class": {type: "string", value:"table"}},
children: []};
w.output.push(table);
var prevColumns = [];
var currRowType = null;
@ -142,7 +159,7 @@ var rules = [
w.nextMatch += lookaheadMatch[0].length+1;
} else {
if(nextRowType != currRowType) {
rowContainer = $tw.Tree.Element(this.rowTypes[nextRowType],{},[]);
rowContainer = {type:"element",tag:this.rowTypes[nextRowType],children: []};
table.children.push(rowContainer);
currRowType = nextRowType;
}
@ -154,11 +171,14 @@ var rules = [
table.children.pop(); // Take rowContainer out of the children array
table.children.splice(0,0,rowContainer); // Insert it at the bottom
}
rowContainer.attributes={};
rowContainer.attributes.align = rowCount === 0 ? "top" : "bottom";
w.subWikifyTerm(rowContainer.children,this.rowTermRegExp);
} else {
var theRow = $tw.Tree.Element("tr",{},[]);
theRow.attributes["class"] = rowCount%2 ? "oddRow" : "evenRow";
var theRow = {type:"element",tag:"tr",
attributes: {"class": {type: "string", value:rowCount%2 ? "oddRow" : "evenRow"}},
children: []};
rowContainer.children.push(theRow);
this.rowHandler(w,theRow.children,prevColumns);
rowCount++;
@ -179,15 +199,16 @@ var rules = [
if(cellMatch[1] == "~") {
// Rowspan
var last = prevColumns[col];
if(last) {
last.rowSpanCount++;
last.element.attributes.rowspan = last.rowSpanCount;
last.element.attributes.valign = "center";
if(colSpanCount > 1) {
last.element.attributes.colspan = colSpanCount;
colSpanCount = 1;
}
if(last) {
last.rowSpanCount++;
$tw.utils.addAttributeToParseTreeNode(last.element,"rowspan",last.rowSpanCount);
var vAlign = $tw.utils.getAttributeValueFromParseTreeNode(last.element,"valign","center");
$tw.utils.addAttributeToParseTreeNode(last.element,"valign",vAlign);
if(colSpanCount > 1) {
$tw.utils.addAttributeToParseTreeNode(last.element,"colspan",colSpanCount);
colSpanCount = 1;
}
}
w.nextMatch = this.cellRegExp.lastIndex-1;
} else if(cellMatch[1] == ">") {
// Colspan
@ -213,25 +234,26 @@ var rules = [
}
var cell;
if(chr == "!") {
cell = $tw.Tree.Element("th",{},[]);
cell = {type:"element",tag:"th",children: []};
e.push(cell);
w.nextMatch++;
} else {
cell = $tw.Tree.Element("td",{},[]);
cell = {type:"element",tag:"td",children: []};
e.push(cell);
}
prevCell = cell;
prevColumns[col] = {rowSpanCount:1,element:cell};
if(colSpanCount > 1) {
cell.attributes.colspan = colSpanCount;
$tw.utils.addAttributeToParseTreeNode(cell,"colspan",colSpanCount);
colSpanCount = 1;
}
applyCssHelper(cell,styles);
w.subWikifyTerm(cell.children,this.cellTermRegExp);
if (!cell.attributes) cell.attributes ={};
if(w.matchText.substr(w.matchText.length-2,1) == " ") // spaceRight
cell.attributes.align = spaceLeft ? "center" : "left";
$tw.utils.addAttributeToParseTreeNode(cell,"align",spaceLeft ? "center" : "left");
else if(spaceLeft)
cell.attributes.align = "right";
$tw.utils.addAttributeToParseTreeNode(cell,"align","right");
w.nextMatch--;
}
col++;
@ -247,7 +269,7 @@ var rules = [
termRegExp: /(\n)/mg,
handler: function(w)
{
var e = $tw.Tree.Element("h" + w.matchLength,{},[]);
var e = {type:"element",tag:"h" + w.matchLength,children: []};
w.output.push(e);
w.subWikifyTerm(e.children,this.termRegExp);
}
@ -291,7 +313,7 @@ var rules = [
if(currLevel !== 0 && target.children) {
target = target.children[target.children.length-1];
}
e = $tw.Tree.Element(listType,{},[]);
e = {type:"element",tag:listType,children: []};
target.push(e);
stack.push(e.children);
}
@ -303,13 +325,13 @@ var rules = [
stack.pop();
} else if(listLevel == currLevel && listType != currType) {
stack.pop();
e = $tw.Tree.Element(listType,{},[]);
e = {type:"element",tag:listType,children: []};
stack[stack.length-1].push(e);
stack.push(e.children);
}
currLevel = listLevel;
currType = listType;
e = $tw.Tree.Element(itemType,{},[]);
e = {type:"element",tag:itemType,children: []};
stack[stack.length-1].push(e);
w.subWikifyTerm(e.children,this.termRegExp);
this.lookaheadRegExp.lastIndex = w.nextMatch;
@ -324,7 +346,7 @@ var rules = [
termRegExp: /(^<<<(\n|$))/mg,
element: "blockquote",
handler: function(w) {
var e = $tw.Tree.Element(this.element,{},[]);
var e = {type:"element",tag:this.element,children: []};
w.output.push(e);
w.subWikifyTerm(e.children,this.termRegExp);
}
@ -338,23 +360,32 @@ var rules = [
element: "blockquote",
handler: function(w)
{
var stack = [w.output];
var stack = [];
var currLevel = 0;
var newLevel = w.matchLength;
var t,matched,e;
do {
if(newLevel > currLevel) {
for(t=currLevel; t<newLevel; t++) {
e = $tw.Tree.Element(this.element,{},[]);
stack[stack.length-1].push(e);
var f = stack[stack.length-1];
e = {type:"element",tag:this.element,children: []};
stack.push(e);
if (t ===0){
w.output.push(e);
}else {
f.children.push(e);
}
}
} else if(newLevel < currLevel) {
for(t=currLevel; t>newLevel; t--)
stack.pop();
}
currLevel = newLevel;
w.subWikifyTerm(stack[stack.length-1],this.termRegExp);
stack[stack.length-1].push($tw.Tree.Element("br"));
w.subWikifyTerm(stack[stack.length-1].children,this.termRegExp);
stack[stack.length-1].children.push({type:"element",tag:"br"});
//e.push({type:"element",tag:"br"});
this.lookaheadRegExp.lastIndex = w.nextMatch;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
matched = lookaheadMatch && lookaheadMatch.index == w.nextMatch;
@ -371,7 +402,7 @@ var rules = [
match: "^----+$\\n?|<hr ?/?>\\n?",
handler: function(w)
{
w.output.push($tw.Tree.Element("hr"));
w.output.push({type:"element",tag:"hr"});
}
},
@ -403,28 +434,33 @@ var rules = [
{
name: "typedBlock",
match: "^\\$\\$\\$(?:.*)\\n",
lookaheadRegExp: /^\$\$\$(.*)\n((?:^[^\n]*\n)+?)(^\f*\$\$\$$\n?)/mg,
match: "^\\$\\$\\$(?:[^ >\\r\\n]*)\\r?\\n",
lookaheadRegExp: /^\$\$\$([^ >\r\n]*)\n((?:^[^\n]*\r?\n)+?)(^\f*\$\$\$\r?\n?)/mg,
//match: "^\\$\\$\\$(?:[^ >\\r\\n]*)(?: *> *([^ \\r\\n]+))?\\r?\\n",
//lookaheadRegExp: /^\$\$\$([^ >\r\n]*)(?: *> *([^ \r\n]+))\n((?:^[^\n]*\n)+?)(^\f*\$\$\$$\n?)/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
// The wikitext parsing infrastructure is horribly unre-entrant
var mimeType = lookaheadMatch[1],
content = lookaheadMatch[2],
var parseType = lookaheadMatch[1],
renderType ,//= this.match[2],
text = lookaheadMatch[2],
oldOutput = w.output,
oldSource = w.source,
oldNextMatch = w.nextMatch,
oldChildren = w.children,
oldDependencies = w.dependencies,
parseTree = w.wiki.parseText(mimeType,content,{defaultType: "text/plain"}).tree;
oldChildren = w.children;
// Parse the block according to the specified type
var parser = $tw.wiki.parseText(parseType,text.toString(),{defaultType: "text/plain"});
w.output = oldOutput;
w.source = oldSource;
w.nextMatch = oldNextMatch;
w.children = oldChildren;
w.dependencies = oldDependencies;
w.output.push.apply(w.output,parseTree);
for (var i=0; i<parser.tree.length; i++) {
w.output.push(parser.tree[i]);
}
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
@ -448,14 +484,25 @@ var rules = [
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source),
name;
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
name = lookaheadMatch[1] || lookaheadMatch[2];
if(lookaheadMatch && lookaheadMatch.index == w.matchStart && name) {
w.nextMatch = this.lookaheadRegExp.lastIndex;
insertMacroCall(w,w.output,name,lookaheadMatch[3]);
var params = lookaheadMatch[3], nameold =name;
if (name) {
if (!!macroadapter.paramadapter[name]) {
params=macroadapter.paramadapter[name](params);
}
if (!!macroadapter.namedapter[name]) {
name=macroadapter.namedapter[name];
}
w.nextMatch = this.lookaheadRegExp.lastIndex;
insertMacroCall(w,w.output,name,params);
}
}
}
},
{
name: "prettyLink",
match: "\\[\\[",
@ -471,12 +518,35 @@ var rules = [
// Pretty bracketted link
link = lookaheadMatch[3];
}
insertMacroCall(w,w.output,"link",{to: link},[$tw.Tree.Text(text)]);
if(isLinkExternal(link)) {
w.output.push({
type: "element",
tag: "a",
attributes: {
href: {type: "string", value: link},
"class": {type: "string", value: "tw-tiddlylink-external"},
target: {type: "string", value: "_blank"}
},
children: [{
type: "text", text: text
}]
});
} else {
w.output.push({
type: "link",
attributes: {
to: {type: "string", value: link}
},
children: [{
type: "text", text: text
}]
});
}
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
},
{
name: "wikiLink",
match: textPrimitives.unWikiLink+"?"+textPrimitives.wikiLink,
@ -496,8 +566,17 @@ var rules = [
}
}
if(w.autoLinkWikiWords) {
insertMacroCall(w,w.output,"link",{to: w.matchText},[$tw.Tree.Text(w.source.substring(w.matchStart,w.nextMatch))]);
} else {
w.output.push({
type: "link",
attributes: {
to: {type: "string", value: w.matchText}
},
children: [{
type: "text",
text: w.source.substring(w.matchStart,w.nextMatch)
}]
});
} else {
w.outputText(w.output,w.matchStart,w.nextMatch);
}
}
@ -508,10 +587,22 @@ var rules = [
match: textPrimitives.urlPattern,
handler: function(w)
{
insertMacroCall(w,w.output,"link",{to: w.matchText},[$tw.Tree.Text(w.source.substring(w.matchStart,w.nextMatch))]);
w.output.push({
type: "element",
tag: "a",
attributes: {
href: {type: "string", value: w.matchText},
"class": {type: "string", value: "tw-tiddlylink-external"},
target: {type: "string", value: "_blank"}
},
children: [{
type: "text", text: w.source.substring(w.matchStart,w.nextMatch)
}]
});
}
},
/*
{
name: "image",
match: "\\[[<>]?[Ii][Mm][Gg]\\[",
@ -545,7 +636,7 @@ var rules = [
}
}
},
*/
{
name: "html",
match: "<[Hh][Tt][Mm][Ll]>",
@ -555,7 +646,7 @@ var rules = [
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
w.output.push($tw.Tree.Element("html",{},[$tw.Tree.Raw(lookaheadMatch[1])]));
w.output.push({ type:"raw", html:lookaheadMatch[1]});
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
@ -582,32 +673,32 @@ var rules = [
var e,lookaheadRegExp,lookaheadMatch;
switch(w.matchText) {
case "''":
e = $tw.Tree.Element("strong",null,[]);
e = {type:"element",tag:"strong",children: []};
w.output.push(e);
w.subWikifyTerm(e.children,/('')/mg);
break;
case "//":
e = $tw.Tree.Element("em",null,[]);
e = {type:"element",tag:"em",children: []};
w.output.push(e);
w.subWikifyTerm(e.children,/(\/\/)/mg);
break;
case "__":
e = $tw.Tree.Element("u",null,[]);
e = {type:"element",tag:"u",children: []};
w.output.push(e);
w.subWikifyTerm(e.children,/(__)/mg);
break;
case "^^":
e = $tw.Tree.Element("sup",null,[]);
e = {type:"element",tag:"sup",children: []};
w.output.push(e);
w.subWikifyTerm(e.children,/(\^\^)/mg);
break;
case "~~":
e = $tw.Tree.Element("sub",null,[]);
e = {type:"element",tag:"sub",children: []};
w.output.push(e);
w.subWikifyTerm(e.children,/(~~)/mg);
break;
case "--":
e = $tw.Tree.Element("strike",null,[]);
e = {type:"element",tag:"strike",children: []};
w.output.push(e);
w.subWikifyTerm(e.children,/(--)/mg);
break;
@ -616,8 +707,8 @@ var rules = [
lookaheadRegExp.lastIndex = w.matchStart;
lookaheadMatch = lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
w.output.push($tw.Tree.Element("code",null,[$tw.Tree.Text(lookaheadMatch[1])]));
w.nextMatch = lookaheadRegExp.lastIndex;
w.output.push({type:"element",tag:"code",
children:[{type: "text",text: lookaheadMatch[1]}]});
}
break;
case "{{{":
@ -625,7 +716,8 @@ var rules = [
lookaheadRegExp.lastIndex = w.matchStart;
lookaheadMatch = lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
w.output.push($tw.Tree.Element("code",null,[$tw.Tree.Text(lookaheadMatch[1])]));
w.output.push({type:"element",tag:"code",
children:[{type: "text",text: lookaheadMatch[1]}]});
w.nextMatch = lookaheadRegExp.lastIndex;
}
break;
@ -640,7 +732,7 @@ var rules = [
{
switch(w.matchText) {
case "@@":
var e = $tw.Tree.Element("span",null,[]);
var e = {type:"element",tag:"span",children: []};
w.output.push(e);
var styles = inlineCssHelper(w);
if(styles.length === 0)
@ -655,9 +747,8 @@ var rules = [
var lookaheadMatch = lookaheadRegExp.exec(w.source);
if(lookaheadMatch) {
w.nextMatch = lookaheadRegExp.lastIndex;
e = $tw.Tree.Element(lookaheadMatch[2] == "\n" ? "div" : "span",{
"class": lookaheadMatch[1]
},[]);
e = {type:"element",tag:lookaheadMatch[2] == "\n" ? "div" : "span",
attributes: {"class": {type: "string", value:lookaheadMatch[1]}},children: []};
w.output.push(e);
w.subWikifyTerm(e.children,/(\}\}\})/mg);
}
@ -671,7 +762,7 @@ var rules = [
match: "--",
handler: function(w)
{
w.output.push($tw.Tree.Entity("&mdash;"));
w.output.push({type: "entity", entity: "&mdash;"});
}
},
@ -680,7 +771,7 @@ var rules = [
match: "\\n|<br ?/?>",
handler: function(w)
{
w.output.push($tw.Tree.Element("br"));
w.output.push({type:"element",tag:"br"});
}
},
@ -693,7 +784,8 @@ var rules = [
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
w.output.push($tw.Tree.Text(lookaheadMatch[1]));
w.output.push({type: "text",text: lookaheadMatch[1]
});
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
@ -704,7 +796,7 @@ var rules = [
match: "&#?[a-zA-Z0-9]{2,8};",
handler: function(w)
{
w.output.push($tw.Tree.Entity(w.matchText));
w.output.push({type: "entity", entity: w.matchText});
}
}