mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-27 03:57:21 +00:00
checkin of updates to latest version of widget tree format, includes tiddler, slider and tabs macros
This commit is contained in:
parent
9147cadd3c
commit
d13de81c7a
184
plugins/tiddlywiki/tw2parser/classictransclude.js
Normal file
184
plugins/tiddlywiki/tw2parser/classictransclude.js
Normal 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;
|
||||||
|
|
||||||
|
})();
|
30
plugins/tiddlywiki/tw2parser/entry.js
Normal file
30
plugins/tiddlywiki/tw2parser/entry.js
Normal 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 "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})();
|
34
plugins/tiddlywiki/tw2parser/macrodefs.tid
Normal file
34
plugins/tiddlywiki/tw2parser/macrodefs.tid
Normal 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
|
97
plugins/tiddlywiki/tw2parser/parameteradapter.js
Normal file
97
plugins/tiddlywiki/tw2parser/parameteradapter.js
Normal 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;
|
||||||
|
})();
|
8
plugins/tiddlywiki/tw2parser/plugin.info
Normal file
8
plugins/tiddlywiki/tw2parser/plugin.info
Normal 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"
|
||||||
|
}
|
@ -48,11 +48,29 @@ Planned:
|
|||||||
extraMacros: An array of additional macro handlers to add
|
extraMacros: An array of additional macro handlers to add
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var WikiTextParser = function(options) {
|
var WikiTextParser = function(type,text,options) {
|
||||||
this.wiki = options.wiki;
|
this.wiki = options.wiki;
|
||||||
this.autoLinkWikiWords = true;
|
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() {
|
WikiTextParser.prototype.installRules = function() {
|
||||||
var rules = require("./wikitextrules.js").rules,
|
var rules = require("./wikitextrules.js").rules,
|
||||||
pattern = [];
|
pattern = [];
|
||||||
@ -63,23 +81,10 @@ WikiTextParser.prototype.installRules = function() {
|
|||||||
this.rulesRegExp = new RegExp(pattern.join("|"),"mg");
|
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) {
|
WikiTextParser.prototype.outputText = function(place,startPos,endPos) {
|
||||||
if(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)});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ Rule modules for the wikitext parser
|
|||||||
/*jslint node: true, browser: true */
|
/*jslint node: true, browser: true */
|
||||||
/*global $tw: false */
|
/*global $tw: false */
|
||||||
"use strict";
|
"use strict";
|
||||||
|
var macroadapter = require("$:/macros/classic/macroadapter.js");
|
||||||
var textPrimitives = {
|
var textPrimitives = {
|
||||||
upperLetter: "[A-Z\u00c0-\u00de\u0150\u0170]",
|
upperLetter: "[A-Z\u00c0-\u00de\u0150\u0170]",
|
||||||
lowerLetter: "[a-z0-9_\\-\u00df-\u00ff\u0151\u0171]",
|
lowerLetter: "[a-z0-9_\\-\u00df-\u00ff\u0151\u0171]",
|
||||||
@ -51,7 +51,7 @@ var setAttr = function(node,attr,value) {
|
|||||||
if(!node.attributes) {
|
if(!node.attributes) {
|
||||||
node.attributes = {};
|
node.attributes = {};
|
||||||
}
|
}
|
||||||
node.attributes[attr] = value;
|
node.attributes[attr] ={type: "string", value:value} ;
|
||||||
};
|
};
|
||||||
|
|
||||||
var inlineCssHelper = function(w) {
|
var inlineCssHelper = function(w) {
|
||||||
@ -80,17 +80,14 @@ var inlineCssHelper = function(w) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var applyCssHelper = function(e,styles) {
|
var applyCssHelper = function(e,styles) {
|
||||||
|
|
||||||
if(styles.length > 0) {
|
if(styles.length > 0) {
|
||||||
if(!e.attributes) {
|
|
||||||
e.attributes = {};
|
|
||||||
}
|
|
||||||
if(!e.attributes.style) {
|
|
||||||
e.attributes.style = {};
|
|
||||||
}
|
|
||||||
for(var t=0; t< styles.length; t++) {
|
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) {
|
var enclosedTextHelper = function(w) {
|
||||||
@ -98,23 +95,41 @@ var enclosedTextHelper = function(w) {
|
|||||||
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
|
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
|
||||||
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
|
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
|
||||||
var text = lookaheadMatch[1];
|
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;
|
w.nextMatch = lookaheadMatch.index + lookaheadMatch[0].length;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var insertMacroCall = function(w,output,name,params,content) {
|
var insertMacroCall = function(w,output,macroName,paramString) {
|
||||||
if(name in w.wiki.macros) {
|
var params = [],
|
||||||
var macroNode = $tw.Tree.Macro(name,{
|
reParam = /\s*(?:([A-Za-z0-9\-_]+)\s*:)?(?:\s*(?:"([^"]*)"|'([^']*)'|\[\[([^\]]*)\]\]|([^"'\s]+)))/mg,
|
||||||
srcParams: params,
|
paramMatch = reParam.exec(paramString);
|
||||||
content: content,
|
while(paramMatch) {
|
||||||
wiki: w.wiki
|
// Process this parameter
|
||||||
});
|
var paramInfo = {
|
||||||
w.dependencies.mergeDependencies(macroNode.dependencies);
|
value: paramMatch[2] || paramMatch[3] || paramMatch[4] || paramMatch[5]
|
||||||
output.push(macroNode);
|
};
|
||||||
|
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 = [
|
var rules = [
|
||||||
{
|
{
|
||||||
name: "table",
|
name: "table",
|
||||||
@ -126,7 +141,9 @@ var rules = [
|
|||||||
rowTypes: {"c":"caption", "h":"thead", "":"tbody", "f":"tfoot"},
|
rowTypes: {"c":"caption", "h":"thead", "":"tbody", "f":"tfoot"},
|
||||||
handler: function(w)
|
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);
|
w.output.push(table);
|
||||||
var prevColumns = [];
|
var prevColumns = [];
|
||||||
var currRowType = null;
|
var currRowType = null;
|
||||||
@ -142,7 +159,7 @@ var rules = [
|
|||||||
w.nextMatch += lookaheadMatch[0].length+1;
|
w.nextMatch += lookaheadMatch[0].length+1;
|
||||||
} else {
|
} else {
|
||||||
if(nextRowType != currRowType) {
|
if(nextRowType != currRowType) {
|
||||||
rowContainer = $tw.Tree.Element(this.rowTypes[nextRowType],{},[]);
|
rowContainer = {type:"element",tag:this.rowTypes[nextRowType],children: []};
|
||||||
table.children.push(rowContainer);
|
table.children.push(rowContainer);
|
||||||
currRowType = nextRowType;
|
currRowType = nextRowType;
|
||||||
}
|
}
|
||||||
@ -154,11 +171,14 @@ var rules = [
|
|||||||
table.children.pop(); // Take rowContainer out of the children array
|
table.children.pop(); // Take rowContainer out of the children array
|
||||||
table.children.splice(0,0,rowContainer); // Insert it at the bottom
|
table.children.splice(0,0,rowContainer); // Insert it at the bottom
|
||||||
}
|
}
|
||||||
|
rowContainer.attributes={};
|
||||||
rowContainer.attributes.align = rowCount === 0 ? "top" : "bottom";
|
rowContainer.attributes.align = rowCount === 0 ? "top" : "bottom";
|
||||||
w.subWikifyTerm(rowContainer.children,this.rowTermRegExp);
|
w.subWikifyTerm(rowContainer.children,this.rowTermRegExp);
|
||||||
} else {
|
} else {
|
||||||
var theRow = $tw.Tree.Element("tr",{},[]);
|
var theRow = {type:"element",tag:"tr",
|
||||||
theRow.attributes["class"] = rowCount%2 ? "oddRow" : "evenRow";
|
attributes: {"class": {type: "string", value:rowCount%2 ? "oddRow" : "evenRow"}},
|
||||||
|
children: []};
|
||||||
|
|
||||||
rowContainer.children.push(theRow);
|
rowContainer.children.push(theRow);
|
||||||
this.rowHandler(w,theRow.children,prevColumns);
|
this.rowHandler(w,theRow.children,prevColumns);
|
||||||
rowCount++;
|
rowCount++;
|
||||||
@ -179,15 +199,16 @@ var rules = [
|
|||||||
if(cellMatch[1] == "~") {
|
if(cellMatch[1] == "~") {
|
||||||
// Rowspan
|
// Rowspan
|
||||||
var last = prevColumns[col];
|
var last = prevColumns[col];
|
||||||
if(last) {
|
if(last) {
|
||||||
last.rowSpanCount++;
|
last.rowSpanCount++;
|
||||||
last.element.attributes.rowspan = last.rowSpanCount;
|
$tw.utils.addAttributeToParseTreeNode(last.element,"rowspan",last.rowSpanCount);
|
||||||
last.element.attributes.valign = "center";
|
var vAlign = $tw.utils.getAttributeValueFromParseTreeNode(last.element,"valign","center");
|
||||||
if(colSpanCount > 1) {
|
$tw.utils.addAttributeToParseTreeNode(last.element,"valign",vAlign);
|
||||||
last.element.attributes.colspan = colSpanCount;
|
if(colSpanCount > 1) {
|
||||||
colSpanCount = 1;
|
$tw.utils.addAttributeToParseTreeNode(last.element,"colspan",colSpanCount);
|
||||||
}
|
colSpanCount = 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
w.nextMatch = this.cellRegExp.lastIndex-1;
|
w.nextMatch = this.cellRegExp.lastIndex-1;
|
||||||
} else if(cellMatch[1] == ">") {
|
} else if(cellMatch[1] == ">") {
|
||||||
// Colspan
|
// Colspan
|
||||||
@ -213,25 +234,26 @@ var rules = [
|
|||||||
}
|
}
|
||||||
var cell;
|
var cell;
|
||||||
if(chr == "!") {
|
if(chr == "!") {
|
||||||
cell = $tw.Tree.Element("th",{},[]);
|
cell = {type:"element",tag:"th",children: []};
|
||||||
e.push(cell);
|
e.push(cell);
|
||||||
w.nextMatch++;
|
w.nextMatch++;
|
||||||
} else {
|
} else {
|
||||||
cell = $tw.Tree.Element("td",{},[]);
|
cell = {type:"element",tag:"td",children: []};
|
||||||
e.push(cell);
|
e.push(cell);
|
||||||
}
|
}
|
||||||
prevCell = cell;
|
prevCell = cell;
|
||||||
prevColumns[col] = {rowSpanCount:1,element:cell};
|
prevColumns[col] = {rowSpanCount:1,element:cell};
|
||||||
if(colSpanCount > 1) {
|
if(colSpanCount > 1) {
|
||||||
cell.attributes.colspan = colSpanCount;
|
$tw.utils.addAttributeToParseTreeNode(cell,"colspan",colSpanCount);
|
||||||
colSpanCount = 1;
|
colSpanCount = 1;
|
||||||
}
|
}
|
||||||
applyCssHelper(cell,styles);
|
applyCssHelper(cell,styles);
|
||||||
w.subWikifyTerm(cell.children,this.cellTermRegExp);
|
w.subWikifyTerm(cell.children,this.cellTermRegExp);
|
||||||
|
if (!cell.attributes) cell.attributes ={};
|
||||||
if(w.matchText.substr(w.matchText.length-2,1) == " ") // spaceRight
|
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)
|
else if(spaceLeft)
|
||||||
cell.attributes.align = "right";
|
$tw.utils.addAttributeToParseTreeNode(cell,"align","right");
|
||||||
w.nextMatch--;
|
w.nextMatch--;
|
||||||
}
|
}
|
||||||
col++;
|
col++;
|
||||||
@ -247,7 +269,7 @@ var rules = [
|
|||||||
termRegExp: /(\n)/mg,
|
termRegExp: /(\n)/mg,
|
||||||
handler: function(w)
|
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.output.push(e);
|
||||||
w.subWikifyTerm(e.children,this.termRegExp);
|
w.subWikifyTerm(e.children,this.termRegExp);
|
||||||
}
|
}
|
||||||
@ -291,7 +313,7 @@ var rules = [
|
|||||||
if(currLevel !== 0 && target.children) {
|
if(currLevel !== 0 && target.children) {
|
||||||
target = target.children[target.children.length-1];
|
target = target.children[target.children.length-1];
|
||||||
}
|
}
|
||||||
e = $tw.Tree.Element(listType,{},[]);
|
e = {type:"element",tag:listType,children: []};
|
||||||
target.push(e);
|
target.push(e);
|
||||||
stack.push(e.children);
|
stack.push(e.children);
|
||||||
}
|
}
|
||||||
@ -303,13 +325,13 @@ var rules = [
|
|||||||
stack.pop();
|
stack.pop();
|
||||||
} else if(listLevel == currLevel && listType != currType) {
|
} else if(listLevel == currLevel && listType != currType) {
|
||||||
stack.pop();
|
stack.pop();
|
||||||
e = $tw.Tree.Element(listType,{},[]);
|
e = {type:"element",tag:listType,children: []};
|
||||||
stack[stack.length-1].push(e);
|
stack[stack.length-1].push(e);
|
||||||
stack.push(e.children);
|
stack.push(e.children);
|
||||||
}
|
}
|
||||||
currLevel = listLevel;
|
currLevel = listLevel;
|
||||||
currType = listType;
|
currType = listType;
|
||||||
e = $tw.Tree.Element(itemType,{},[]);
|
e = {type:"element",tag:itemType,children: []};
|
||||||
stack[stack.length-1].push(e);
|
stack[stack.length-1].push(e);
|
||||||
w.subWikifyTerm(e.children,this.termRegExp);
|
w.subWikifyTerm(e.children,this.termRegExp);
|
||||||
this.lookaheadRegExp.lastIndex = w.nextMatch;
|
this.lookaheadRegExp.lastIndex = w.nextMatch;
|
||||||
@ -324,7 +346,7 @@ var rules = [
|
|||||||
termRegExp: /(^<<<(\n|$))/mg,
|
termRegExp: /(^<<<(\n|$))/mg,
|
||||||
element: "blockquote",
|
element: "blockquote",
|
||||||
handler: function(w) {
|
handler: function(w) {
|
||||||
var e = $tw.Tree.Element(this.element,{},[]);
|
var e = {type:"element",tag:this.element,children: []};
|
||||||
w.output.push(e);
|
w.output.push(e);
|
||||||
w.subWikifyTerm(e.children,this.termRegExp);
|
w.subWikifyTerm(e.children,this.termRegExp);
|
||||||
}
|
}
|
||||||
@ -338,23 +360,32 @@ var rules = [
|
|||||||
element: "blockquote",
|
element: "blockquote",
|
||||||
handler: function(w)
|
handler: function(w)
|
||||||
{
|
{
|
||||||
var stack = [w.output];
|
var stack = [];
|
||||||
var currLevel = 0;
|
var currLevel = 0;
|
||||||
var newLevel = w.matchLength;
|
var newLevel = w.matchLength;
|
||||||
var t,matched,e;
|
var t,matched,e;
|
||||||
do {
|
do {
|
||||||
if(newLevel > currLevel) {
|
if(newLevel > currLevel) {
|
||||||
for(t=currLevel; t<newLevel; t++) {
|
for(t=currLevel; t<newLevel; t++) {
|
||||||
e = $tw.Tree.Element(this.element,{},[]);
|
var f = stack[stack.length-1];
|
||||||
stack[stack.length-1].push(e);
|
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) {
|
} else if(newLevel < currLevel) {
|
||||||
for(t=currLevel; t>newLevel; t--)
|
for(t=currLevel; t>newLevel; t--)
|
||||||
stack.pop();
|
stack.pop();
|
||||||
}
|
}
|
||||||
currLevel = newLevel;
|
currLevel = newLevel;
|
||||||
w.subWikifyTerm(stack[stack.length-1],this.termRegExp);
|
w.subWikifyTerm(stack[stack.length-1].children,this.termRegExp);
|
||||||
stack[stack.length-1].push($tw.Tree.Element("br"));
|
stack[stack.length-1].children.push({type:"element",tag:"br"});
|
||||||
|
//e.push({type:"element",tag:"br"});
|
||||||
|
|
||||||
this.lookaheadRegExp.lastIndex = w.nextMatch;
|
this.lookaheadRegExp.lastIndex = w.nextMatch;
|
||||||
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
|
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
|
||||||
matched = lookaheadMatch && lookaheadMatch.index == w.nextMatch;
|
matched = lookaheadMatch && lookaheadMatch.index == w.nextMatch;
|
||||||
@ -371,7 +402,7 @@ var rules = [
|
|||||||
match: "^----+$\\n?|<hr ?/?>\\n?",
|
match: "^----+$\\n?|<hr ?/?>\\n?",
|
||||||
handler: function(w)
|
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",
|
name: "typedBlock",
|
||||||
match: "^\\$\\$\\$(?:.*)\\n",
|
match: "^\\$\\$\\$(?:[^ >\\r\\n]*)\\r?\\n",
|
||||||
lookaheadRegExp: /^\$\$\$(.*)\n((?:^[^\n]*\n)+?)(^\f*\$\$\$$\n?)/mg,
|
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)
|
handler: function(w)
|
||||||
{
|
{
|
||||||
this.lookaheadRegExp.lastIndex = w.matchStart;
|
this.lookaheadRegExp.lastIndex = w.matchStart;
|
||||||
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
|
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
|
||||||
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
|
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
|
||||||
// The wikitext parsing infrastructure is horribly unre-entrant
|
// The wikitext parsing infrastructure is horribly unre-entrant
|
||||||
var mimeType = lookaheadMatch[1],
|
var parseType = lookaheadMatch[1],
|
||||||
content = lookaheadMatch[2],
|
renderType ,//= this.match[2],
|
||||||
|
text = lookaheadMatch[2],
|
||||||
oldOutput = w.output,
|
oldOutput = w.output,
|
||||||
oldSource = w.source,
|
oldSource = w.source,
|
||||||
oldNextMatch = w.nextMatch,
|
oldNextMatch = w.nextMatch,
|
||||||
oldChildren = w.children,
|
oldChildren = w.children;
|
||||||
oldDependencies = w.dependencies,
|
// Parse the block according to the specified type
|
||||||
parseTree = w.wiki.parseText(mimeType,content,{defaultType: "text/plain"}).tree;
|
var parser = $tw.wiki.parseText(parseType,text.toString(),{defaultType: "text/plain"});
|
||||||
|
|
||||||
w.output = oldOutput;
|
w.output = oldOutput;
|
||||||
w.source = oldSource;
|
w.source = oldSource;
|
||||||
w.nextMatch = oldNextMatch;
|
w.nextMatch = oldNextMatch;
|
||||||
w.children = oldChildren;
|
w.children = oldChildren;
|
||||||
w.dependencies = oldDependencies;
|
for (var i=0; i<parser.tree.length; i++) {
|
||||||
w.output.push.apply(w.output,parseTree);
|
w.output.push(parser.tree[i]);
|
||||||
|
}
|
||||||
w.nextMatch = this.lookaheadRegExp.lastIndex;
|
w.nextMatch = this.lookaheadRegExp.lastIndex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -448,14 +484,25 @@ var rules = [
|
|||||||
{
|
{
|
||||||
this.lookaheadRegExp.lastIndex = w.matchStart;
|
this.lookaheadRegExp.lastIndex = w.matchStart;
|
||||||
var lookaheadMatch = this.lookaheadRegExp.exec(w.source),
|
var lookaheadMatch = this.lookaheadRegExp.exec(w.source),
|
||||||
|
name;
|
||||||
|
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
|
||||||
name = lookaheadMatch[1] || lookaheadMatch[2];
|
name = lookaheadMatch[1] || lookaheadMatch[2];
|
||||||
if(lookaheadMatch && lookaheadMatch.index == w.matchStart && name) {
|
var params = lookaheadMatch[3], nameold =name;
|
||||||
w.nextMatch = this.lookaheadRegExp.lastIndex;
|
if (name) {
|
||||||
insertMacroCall(w,w.output,name,lookaheadMatch[3]);
|
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",
|
name: "prettyLink",
|
||||||
match: "\\[\\[",
|
match: "\\[\\[",
|
||||||
@ -471,12 +518,35 @@ var rules = [
|
|||||||
// Pretty bracketted link
|
// Pretty bracketted link
|
||||||
link = lookaheadMatch[3];
|
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;
|
w.nextMatch = this.lookaheadRegExp.lastIndex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
name: "wikiLink",
|
name: "wikiLink",
|
||||||
match: textPrimitives.unWikiLink+"?"+textPrimitives.wikiLink,
|
match: textPrimitives.unWikiLink+"?"+textPrimitives.wikiLink,
|
||||||
@ -496,8 +566,17 @@ var rules = [
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(w.autoLinkWikiWords) {
|
if(w.autoLinkWikiWords) {
|
||||||
insertMacroCall(w,w.output,"link",{to: w.matchText},[$tw.Tree.Text(w.source.substring(w.matchStart,w.nextMatch))]);
|
w.output.push({
|
||||||
} else {
|
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);
|
w.outputText(w.output,w.matchStart,w.nextMatch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -508,10 +587,22 @@ var rules = [
|
|||||||
match: textPrimitives.urlPattern,
|
match: textPrimitives.urlPattern,
|
||||||
handler: function(w)
|
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",
|
name: "image",
|
||||||
match: "\\[[<>]?[Ii][Mm][Gg]\\[",
|
match: "\\[[<>]?[Ii][Mm][Gg]\\[",
|
||||||
@ -545,7 +636,7 @@ var rules = [
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
*/
|
||||||
{
|
{
|
||||||
name: "html",
|
name: "html",
|
||||||
match: "<[Hh][Tt][Mm][Ll]>",
|
match: "<[Hh][Tt][Mm][Ll]>",
|
||||||
@ -555,7 +646,7 @@ var rules = [
|
|||||||
this.lookaheadRegExp.lastIndex = w.matchStart;
|
this.lookaheadRegExp.lastIndex = w.matchStart;
|
||||||
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
|
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
|
||||||
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
|
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;
|
w.nextMatch = this.lookaheadRegExp.lastIndex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -582,32 +673,32 @@ var rules = [
|
|||||||
var e,lookaheadRegExp,lookaheadMatch;
|
var e,lookaheadRegExp,lookaheadMatch;
|
||||||
switch(w.matchText) {
|
switch(w.matchText) {
|
||||||
case "''":
|
case "''":
|
||||||
e = $tw.Tree.Element("strong",null,[]);
|
e = {type:"element",tag:"strong",children: []};
|
||||||
w.output.push(e);
|
w.output.push(e);
|
||||||
w.subWikifyTerm(e.children,/('')/mg);
|
w.subWikifyTerm(e.children,/('')/mg);
|
||||||
break;
|
break;
|
||||||
case "//":
|
case "//":
|
||||||
e = $tw.Tree.Element("em",null,[]);
|
e = {type:"element",tag:"em",children: []};
|
||||||
w.output.push(e);
|
w.output.push(e);
|
||||||
w.subWikifyTerm(e.children,/(\/\/)/mg);
|
w.subWikifyTerm(e.children,/(\/\/)/mg);
|
||||||
break;
|
break;
|
||||||
case "__":
|
case "__":
|
||||||
e = $tw.Tree.Element("u",null,[]);
|
e = {type:"element",tag:"u",children: []};
|
||||||
w.output.push(e);
|
w.output.push(e);
|
||||||
w.subWikifyTerm(e.children,/(__)/mg);
|
w.subWikifyTerm(e.children,/(__)/mg);
|
||||||
break;
|
break;
|
||||||
case "^^":
|
case "^^":
|
||||||
e = $tw.Tree.Element("sup",null,[]);
|
e = {type:"element",tag:"sup",children: []};
|
||||||
w.output.push(e);
|
w.output.push(e);
|
||||||
w.subWikifyTerm(e.children,/(\^\^)/mg);
|
w.subWikifyTerm(e.children,/(\^\^)/mg);
|
||||||
break;
|
break;
|
||||||
case "~~":
|
case "~~":
|
||||||
e = $tw.Tree.Element("sub",null,[]);
|
e = {type:"element",tag:"sub",children: []};
|
||||||
w.output.push(e);
|
w.output.push(e);
|
||||||
w.subWikifyTerm(e.children,/(~~)/mg);
|
w.subWikifyTerm(e.children,/(~~)/mg);
|
||||||
break;
|
break;
|
||||||
case "--":
|
case "--":
|
||||||
e = $tw.Tree.Element("strike",null,[]);
|
e = {type:"element",tag:"strike",children: []};
|
||||||
w.output.push(e);
|
w.output.push(e);
|
||||||
w.subWikifyTerm(e.children,/(--)/mg);
|
w.subWikifyTerm(e.children,/(--)/mg);
|
||||||
break;
|
break;
|
||||||
@ -616,8 +707,8 @@ var rules = [
|
|||||||
lookaheadRegExp.lastIndex = w.matchStart;
|
lookaheadRegExp.lastIndex = w.matchStart;
|
||||||
lookaheadMatch = lookaheadRegExp.exec(w.source);
|
lookaheadMatch = lookaheadRegExp.exec(w.source);
|
||||||
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
|
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",
|
||||||
w.nextMatch = lookaheadRegExp.lastIndex;
|
children:[{type: "text",text: lookaheadMatch[1]}]});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "{{{":
|
case "{{{":
|
||||||
@ -625,7 +716,8 @@ var rules = [
|
|||||||
lookaheadRegExp.lastIndex = w.matchStart;
|
lookaheadRegExp.lastIndex = w.matchStart;
|
||||||
lookaheadMatch = lookaheadRegExp.exec(w.source);
|
lookaheadMatch = lookaheadRegExp.exec(w.source);
|
||||||
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
|
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;
|
w.nextMatch = lookaheadRegExp.lastIndex;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -640,7 +732,7 @@ var rules = [
|
|||||||
{
|
{
|
||||||
switch(w.matchText) {
|
switch(w.matchText) {
|
||||||
case "@@":
|
case "@@":
|
||||||
var e = $tw.Tree.Element("span",null,[]);
|
var e = {type:"element",tag:"span",children: []};
|
||||||
w.output.push(e);
|
w.output.push(e);
|
||||||
var styles = inlineCssHelper(w);
|
var styles = inlineCssHelper(w);
|
||||||
if(styles.length === 0)
|
if(styles.length === 0)
|
||||||
@ -655,9 +747,8 @@ var rules = [
|
|||||||
var lookaheadMatch = lookaheadRegExp.exec(w.source);
|
var lookaheadMatch = lookaheadRegExp.exec(w.source);
|
||||||
if(lookaheadMatch) {
|
if(lookaheadMatch) {
|
||||||
w.nextMatch = lookaheadRegExp.lastIndex;
|
w.nextMatch = lookaheadRegExp.lastIndex;
|
||||||
e = $tw.Tree.Element(lookaheadMatch[2] == "\n" ? "div" : "span",{
|
e = {type:"element",tag:lookaheadMatch[2] == "\n" ? "div" : "span",
|
||||||
"class": lookaheadMatch[1]
|
attributes: {"class": {type: "string", value:lookaheadMatch[1]}},children: []};
|
||||||
},[]);
|
|
||||||
w.output.push(e);
|
w.output.push(e);
|
||||||
w.subWikifyTerm(e.children,/(\}\}\})/mg);
|
w.subWikifyTerm(e.children,/(\}\}\})/mg);
|
||||||
}
|
}
|
||||||
@ -671,7 +762,7 @@ var rules = [
|
|||||||
match: "--",
|
match: "--",
|
||||||
handler: function(w)
|
handler: function(w)
|
||||||
{
|
{
|
||||||
w.output.push($tw.Tree.Entity("—"));
|
w.output.push({type: "entity", entity: "—"});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -680,7 +771,7 @@ var rules = [
|
|||||||
match: "\\n|<br ?/?>",
|
match: "\\n|<br ?/?>",
|
||||||
handler: function(w)
|
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;
|
this.lookaheadRegExp.lastIndex = w.matchStart;
|
||||||
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
|
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
|
||||||
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
|
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;
|
w.nextMatch = this.lookaheadRegExp.lastIndex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -704,7 +796,7 @@ var rules = [
|
|||||||
match: "&#?[a-zA-Z0-9]{2,8};",
|
match: "&#?[a-zA-Z0-9]{2,8};",
|
||||||
handler: function(w)
|
handler: function(w)
|
||||||
{
|
{
|
||||||
w.output.push($tw.Tree.Entity(w.matchText));
|
w.output.push({type: "entity", entity: w.matchText});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user