Welcome to TiddlyWiki created by Jeremy Ruston, Copyright © 2007 UnaMesa Association
/***
|''Name:''|AdaptorCommandsPlugin|
|''Description:''|Commands to access hosted TiddlyWiki data|
|''Author:''|Martin Budden (mjbudden (at) gmail (dot) com)|
|''Source:''|http://www.martinswiki.com/#AdaptorCommandsPlugin |
|''CodeRepository:''|http://svn.tiddlywiki.org/Trunk/contributors/MartinBudden/adaptors/AdaptorCommandsPlugin.js |
|''Version:''|0.5.5|
|''Date:''|Aug 23, 2007|
|''Comments:''|Please make comments at http://groups.google.co.uk/group/TiddlyWikiDev |
|''License:''|[[Creative Commons Attribution-ShareAlike 2.5 License|http://creativecommons.org/licenses/by-sa/2.5/]] |
|''~CoreVersion:''|2.2.0|
***/
//{{{
// Ensure that the plugin is only installed once.
if(!version.extensions.AdaptorCommandsPlugin) {
version.extensions.AdaptorCommandsPlugin = {installed:true};
function getServerType(fields)
{
if(!fields)
return null;
var serverType = fields['server.type'];
if(!serverType)
serverType = fields['wikiformat'];
if(!serverType)
serverType = config.defaultCustomFields['server.type'];
return serverType;
}
function invokeAdaptor(fnName,param1,param2,context,userParams,callback,fields)
{
var serverType = getServerType(fields);
if(!serverType)
return null;
var adaptor = new config.adaptors[serverType];
if(!adaptor)
return false;
if(!config.adaptors[serverType].prototype[fnName])
return false;
adaptor.openHost(fields['server.host']);
adaptor.openWorkspace(fields['server.workspace']);
if(param1)
var ret = param2 ? adaptor[fnName](param1,param2,context,userParams,callback) : adaptor[fnName](param1,context,userParams,callback);
else
ret = adaptor[fnName](context,userParams,callback);
//adaptor.close();
//delete adaptor;
return ret;
}
function isAdaptorFunctionSupported(fnName,fields)
{
var serverType = getServerType(fields);
if(!serverType || !config.adaptors[serverType])
return false;
var fn = config.adaptors[serverType].prototype[fnName];
return fn ? true : false;
}
config.commands.getTiddler = {};
merge(config.commands.getTiddler,{
text: "get",
tooltip:"Download this tiddler",
readOnlyText: "get",
readOnlyTooltip: "Download this tiddler",
done: "Tiddler downloaded"
});
config.commands.getTiddler.isEnabled = function(tiddler)
{
return isAdaptorFunctionSupported('getTiddler',tiddler.fields);
};
config.commands.getTiddler.handler = function(event,src,title)
{
var tiddler = store.fetchTiddler(title);
if(tiddler) {
var fields = tiddler.fields;
} else {
fields = String(document.getElementById(story.idPrefix + title).getAttribute("tiddlyFields"));
fields = fields ? fields.decodeHashMap() : null;
}
return invokeAdaptor('getTiddler',title,null,null,null,config.commands.getTiddler.callback,fields);
};
config.commands.getTiddler.callback = function(context,userParams)
{
if(context.status) {
var tiddler = context.tiddler;
store.saveTiddler(tiddler.title,tiddler.title,tiddler.text,tiddler.modifier,tiddler.modified,tiddler.tags,tiddler.fields);
story.refreshTiddler(tiddler.title,1,true);
displayMessage(config.commands.getTiddler.done);
} else {
displayMessage(context.statusText);
}
};
config.commands.putTiddler = {};
merge(config.commands.putTiddler,{
text: "put",
tooltip: "Upload this tiddler",
hideReadOnly: true,
done: "Tiddler uploaded"
});
config.commands.putTiddler.isEnabled = function(tiddler)
{
return tiddler && tiddler.isTouched() && isAdaptorFunctionSupported('putTiddler',tiddler.fields);
};
config.commands.putTiddler.handler = function(event,src,title)
{
var tiddler = store.fetchTiddler(title);
if(!tiddler)
return false;
return invokeAdaptor('putTiddler',tiddler,null,null,null,config.commands.putTiddler.callback,tiddler.fields);
};
config.commands.putTiddler.callback = function(context,userParams)
{
if(context.status) {
store.fetchTiddler(context.title).clearChangeCount();
displayMessage(config.commands.putTiddler.done);
} else {
displayMessage(context.statusText);
}
};
config.commands.revisions = {};
merge(config.commands.revisions,{
text: "revisions",
tooltip: "View another revision of this tiddler",
loading: "loading...",
done: "Revision downloaded",
revisionTooltip: "View this revision",
popupNone: "No revisions"});
config.commands.revisions.isEnabled = function(tiddler)
{
return isAdaptorFunctionSupported('getTiddlerRevisionList',tiddler.fields);
};
config.commands.revisions.handler = function(event,src,title)
{
var tiddler = store.fetchTiddler(title);
userParams = {};
userParams.tiddler = tiddler;
userParams.src = src;
userParams.dateFormat = 'YYYY mmm 0DD 0hh:0mm';
var revisionLimit = 10;
if(!invokeAdaptor('getTiddlerRevisionList',title,revisionLimit,null,userParams,config.commands.revisions.callback,tiddler.fields))
return false;
event.cancelBubble = true;
if(event.stopPropagation)
event.stopPropagation();
return true;
};
config.commands.revisions.callback = function(context,userParams)
// The revisions are returned as tiddlers in the context.revisions array
{
var revisions = context.revisions;
popup = Popup.create(userParams.src);
Popup.show(popup,false);
if(revisions.length==0) {
createTiddlyText(createTiddlyElement(popup,'li',null,'disabled'),config.commands.revisions.popupNone);
} else {
revisions.sort(function(a,b) {return a.modified < b.modified ? +1 : -1;});
for(var i=0; i<revisions.length; i++) {
var tiddler = revisions[i];
var modified = tiddler.modified;
var revision = tiddler.fields['server.page.revision'];
var btn = createTiddlyButton(createTiddlyElement(popup,'li'),
modified.formatString(userParams.dateFormat) + ' r:' + revision,
config.commands.revisions.revisionTooltip,
function() {
config.commands.revisions.getTiddlerRevision(this.getAttribute('tiddlerTitle'),this.getAttribute('tiddlerModified'),this.getAttribute('tiddlerRevision'),this);
return false;
},
'tiddlyLinkExisting tiddlyLink');
btn.setAttribute('tiddlerTitle',userParams.tiddler.title);
btn.setAttribute('tiddlerRevision',revision);
btn.setAttribute('tiddlerModified',modified.convertToYYYYMMDDHHMM());
if(userParams.tiddler.fields['server.page.revision'] == revision || (!userParams.tiddler.fields['server.page.revision'] && i==0))
btn.className = 'revisionCurrent';
}
}
};
config.commands.revisions.getTiddlerRevision = function(title,modified,revision)
{
var tiddler = store.fetchTiddler(title);
var context = {};
context.modified = modified;
return invokeAdaptor('getTiddlerRevision',title,revision,context,null,config.commands.revisions.getTiddlerRevisionCallback,tiddler.fields);
};
config.commands.revisions.getTiddlerRevisionCallback = function(context,userParams)
{
if(context.status) {
var tiddler = context.tiddler;
store.saveTiddler(tiddler.title,tiddler.title,tiddler.text,tiddler.modifier,tiddler.modified,tiddler.tags,tiddler.fields);
story.refreshTiddler(tiddler.title,1,true);
displayMessage(config.commands.revisions.done);
} else {
displayMessage(context.statusText);
}
};
config.commands.saveTiddlerAndPut = {};
merge(config.commands.saveTiddlerAndPut,{
text: "done",
tooltip: "Save this tiddler and upload",
hideReadOnly: true,
done: "Tiddler uploaded"
});
config.commands.saveTiddlerAndPut.handler = function(event,src,title)
{
var newTitle = story.saveTiddler(title,event.shiftKey);
if(newTitle)
story.displayTiddler(null,newTitle);
return config.commands.putTiddler.handler(event,src,newTitle);
};
config.commands.saveTiddlerHosted = {};
merge(config.commands.saveTiddlerHosted,{
text: "done",
tooltip: "Save changes to this tiddler",
hideReadOnly: true,
done: "done"
});
config.commands.saveTiddlerHosted.handler = function(event,src,title)
{
var tiddler = store.fetchTiddler(title);
if(!tiddler)
return false;
return invokeAdaptor('saveTiddlerHosted',tiddler,null,null,null,config.commands.saveTiddlerHosted.callback,tiddler.fields);
};
config.commands.saveTiddlerHosted.callback = function(context,userParams)
{
if(context.status) {
displayMessage(config.commands.saveTiddlerHosted.done);
} else {
displayMessage(context.statusText);
}
};
}//# end of 'install only once'
//}}}
/***
|''Name:''|AdaptorMacrosPlugin|
|''Description:''|Commands to access hosted TiddlyWiki data|
|''Author:''|Martin Budden (mjbudden (at) gmail (dot) com)|
|''Source:''|http://www.martinswiki.com/#AdaptorMacrosPlugin |
|''CodeRepository:''|http://svn.tiddlywiki.org/Trunk/contributors/MartinBudden/adaptors/AdaptorMacrosPlugin.js |
|''Version:''|0.3.8|
|''Date:''|Aug 23, 2007|
|''Comments:''|Please make comments at http://groups.google.co.uk/group/TiddlyWikiDev |
|''License:''|[[Creative Commons Attribution-ShareAlike 2.5 License|http://creativecommons.org/licenses/by-sa/2.5/]] |
|''~CoreVersion:''|2.2.0|
***/
//{{{
// Ensure that the plugin is only installed once.
if(!version.extensions.AdaptorMacrosPlugin) {
version.extensions.AdaptorMacrosPlugin = {installed:true};
// Return an array of tiddler titles that are in the given workspace on the host
TiddlyWiki.prototype.getHostedTiddlers = function(host,workspace)
{
var results = [];
if(!this.hostedTiddlers || !this.hostedTiddlers[host])
return results;
var tiddlers = this.hostedTiddlers[host][workspace];
if(tiddlers) {
for(var i=0; i<tiddlers.length; i++) {
results.push(tiddlers[i].title);
}
}
return results;
};
config.macros.viewTiddlerFields = {};
config.macros.viewTiddlerFields.handler = function(place,macroName,params,wikifier,paramString,tiddler)
{
if(tiddler instanceof Tiddler) {
var value = '';
var comma = '';
for(i in tiddler.fields) {
if (!i.match(/^temp[\._]/)) {
value += comma + i + '=' + tiddler.fields[i];
comma = ', ';
}
}
if(tiddler.created)
value += comma + 'created=' + tiddler.created.convertToYYYYMMDDHHMM();
if(tiddler.modified)
value += ', modified=' + tiddler.modified.convertToYYYYMMDDHHMM();
if(tiddler.modifier)
value += ', modifier=' + tiddler.modifier;
value += ', touched=' + (tiddler.isTouched() ? 'true' : 'false');
highlightify(value,place,highlightHack,tiddler);
}
};
config.macros.list.updatedOffline = {};
config.macros.list.updatedOffline.handler = function(params)
{
var results = [];
store.forEachTiddler(function(title,tiddler) {
if(tiddler.fields['server.host'] && tiddler.isTouched())
results.push(tiddler);
});
results.sort();
return results;
};
config.macros.list.workspaceTiddlers = {};
config.macros.list.workspaceTiddlers.prompt = "List Tiddlers in the workspace";
config.macros.list.workspaceTiddlers.handler = function(params,wikifier,paramString,tiddler)
{
var customFields = getParam(params,'fields',false);
if(!customFields)
customFields = config.defaultCustomFields;
return store.getHostedTiddlers(customFields['server.host'],customFields['server.workspace']);
};
config.macros.updateWorkspaceTiddlerList = {};
merge(config.macros.updateWorkspaceTiddlerList,{
label: "update tiddler list",
prompt: "Update list of tiddlers in workspace",
done: "List updated"});
config.macros.updateWorkspaceTiddlerList.handler = function(place,macroName,params,wikifier,paramString,tiddler)
{
params = paramString.parseParams('anon',null,true,false,false);
var customFields = getParam(params,'fields',false);
if(!customFields)
customFields = String.encodeHashMap(config.defaultCustomFields);
var btn = createTiddlyButton(place,this.label,this.prompt,this.onClick);
btn.setAttribute('customFields',customFields);
btn.setAttribute('title',tiddler.title);
};
config.macros.updateWorkspaceTiddlerList.onClick = function(e)
{
clearMessage();
var customFields = this.getAttribute("customFields");
var fields = customFields.decodeHashMap();
var userParams = {host:fields['server.host'],workspace:fields['server.workspace'],title:this.getAttribute("title")};
return invokeAdaptor('getTiddlerList',null,null,null,userParams,config.macros.updateWorkspaceTiddlerList.callback,fields);
};
config.macros.updateWorkspaceTiddlerList.callback = function(context,userParams)
{
if(context.status) {
if(!store.hostedTiddlers)
store.hostedTiddlers = {};
if(!store.hostedTiddlers[userParams.host])
store.hostedTiddlers[userParams.host] = {};
store.hostedTiddlers[userParams.host][userParams.workspace] = context.tiddlers;
displayMessage(config.macros.updateWorkspaceTiddlerList.done);
story.displayTiddler(null,userParams.title);
story.refreshTiddler(userParams.title,1,true);
} else {
displayMessage(context.statusText);
}
};
config.macros.updateWorkspaceList = {};
merge(config.macros.updateWorkspaceList,{
label: "update workspace list",
prompt: "Update list of workspaces",
done: "List updated"});
config.macros.updateWorkspaceList.handler = function(place,macroName,params,wikifier,paramString,tiddler)
{
params = paramString.parseParams('anon',null,true,false,false);
var customFields = getParam(params,'fields',false);
if(!customFields)
customFields = String.encodeHashMap(config.defaultCustomFields);
var btn = createTiddlyButton(place,this.label,this.prompt,this.onClick);
btn.setAttribute('customFields',customFields);
btn.setAttribute('title',tiddler.title);
};
config.macros.updateWorkspaceList.onClick = function(e)
{
clearMessage();
var customFields = this.getAttribute("customFields");
var fields = customFields.decodeHashMap();
var userParams = {host:fields['server.host'],callback:config.macros.updateWorkspaceList.callback};
return invokeAdaptor('getWorkspaceList',context,fields);
};
config.macros.updateWorkspaceList.callback = function(context,userParams)
{
if(context.status) {
displayMessage(config.macros.updateWorkspaceList.done);
for(var i=0; i<context.workspaces.length; i++) {
displayMessage("workspace:"+context.workspaces[i]);
}
} else {
displayMessage(context.statusText);
}
};
} // end of 'install only once'
//}}}
|!Adaptor Plugin|!Description|
|[[ExampleAdaptorPlugin]]|Example empty adaptor. You can use this as a template to write your own adaptor|
|[[ccTiddlyAdaptorPlugin]]|Adaptor for moving and converting data to and from ccTiddly wikis|
|[[JSPWikiAdaptorPlugin]]|Adaptor for moving and converting data to and from JSP Wikis|
|[[MediaWikiAdaptorPlugin]]|Adaptor for moving and converting data from MediaWikis|
|[[SocialtextAdaptorPlugin]]|Adaptor for moving and converting data to and from Socialtext Wikis|
|[[TWikiAdaptorPlugin]]|Adaptor for moving and converting data to and from TWikis|
|!Format|!Markup|!Example|
|Bold|{{{''Bold''}}} (2 single quotes)|''Bold''|
|Italic|{{{//Italic//}}}|//Italic//|
|Bold Italic|{{{''//Bold Italic//''}}}|''//Bold Italic//''|
|Underlined|{{{__Underline__}}}(2 underscores)|__Underlined__|
|Strikethough|{{{--Strikethrough--}}}<br />{{{--}}} replaced {{{==}}} for Stikethrough in TiddlyWiki 2.1|--Strikethrough--|
|Superscript|{{{Text^^Superscript^^}}}|Text^^Superscript^^|
|Subscript|{{{Text~~Subscript~~}}}|Text~~Subscript~~|
|Monospaced text|<html><code>{{{Monospaced}}}</code></html>|{{{Monospaced}}}|
|Monospaced multiline block|Put <html><code>{{{</code></html> and <html><code>}}}</code></html> on their own lines|<html><pre>{{{<br/>Monospaced<br/>Multi-line<br/>Block<br/>}}}</pre></html>|
|Highlight|{{{@@Highlight@@}}}|@@Highlight@@|
|Color|{{{@@color(green):green text@@}}}|@@color(green):green text@@ |
|~|{{{@@bgcolor(green):text@@}}}|@@bgcolor(green):text@@ |
|~|{{{@@bgcolor(#3399ff):text@@}}}|@@bgcolor(#3399ff):text@@|
|~|{{{@@bgcolor(#39f):text@@}}}|@@bgcolor(#39f):text@@|
|CSS Extended Highlights|{{{@@some css;Highlight@@}}}<br />For backwards compatibility, the following highlight syntax is also accepted:<br />{{{@@bgcolor(#ff0000):color(#ffffff):red coloured@@}}}|@@background-color:#ff0000;color:#ffffff;red coloured@@<br /><<slider AtEg ./atEg 'Extended example ...'>>|
|Custom CSS Class|<html><code>{{wrappingClass{Text that is now accentuated}}}</code></html><br />By default, the text is placed in a <span>. To use a <div> instead, insert a line break before the text (after the single {)<br />In the CSS:<br />{{{.wrappingClass {color: red;} }}}|Add .wrappingClass to StyleSheet|
|Any HTML|{{{<html><span>any</span><br />}}}<br />{{{<b>valid</b> <em>xhtml</em></html>}}}|<html><span>any</span><br /><b>valid</b> <em>xhtml</em></html>|
PageTemplate
|>|>|SiteTitle - SiteSubtitle|
|MainMenu|DefaultTiddlers<br /><br /><br /><br />ViewTemplate<br /><br />EditTemplate|SideBarOptions|
|~|~|OptionsPanel|
|~|~|AdvancedOptions|
|~|~|<<tiddler Configuration.SideBarTabs>>|
''StyleSheet:'' StyleSheetColors - StyleSheetLayout - StyleSheetPrint
SiteUrl
SideBarTabs
|[[Timeline|TabTimeline]]|[[All|TabAll]]|[[Tags|TabTags]]|>|>|[[More|TabMore]] |
|>|>||[[Missing|TabMoreMissing]]|[[Orphans|TabMoreOrphans]]|[[Shadowed|TabMoreShadowed]]|
/***
|''Name:''|ConfluenceFormatterPlugin|
|''Description:''|Allows Tiddlers to use Confluence text formatting|
|''Author:''|Martin Budden (mjbudden (at) gmail (dot) com)|
|''Source:''|http://www.martinswiki.com/#ConfluenceFormatterPlugin |
|''CodeRepository:''|http://svn.tiddlywiki.org/Trunk/contributors/MartinBudden/formatters/ConfluenceFormatterPlugin.js |
|''Version:''|0.1.3|
|''Date:''|Dec 8, 2006|
|''Comments:''|Please make comments at http://groups.google.co.uk/group/TiddlyWikiDev |
|''License:''|[[Creative Commons Attribution-ShareAlike 2.5 License|http://creativecommons.org/licenses/by-sa/2.5/]] |
|''~CoreVersion:''|2.1.0|
This is the ConfluenceFormatterPlugin, which allows you to insert [[Confluence|http://confluence.atlassian.com/renderer/notationhelp.action?section=all]] formated
text into a TiddlyWiki. See also http://confluence.atlassian.com/display/DOC/Confluence+Notation+Guide+Overview
The aim is not to fully emulate Confluence, but to allow you to work with Confluence content off-line
and then paste the content into your Confluence wiki later on, with the expectation that only minor
edits will be required.
To use Confluence format in a Tiddler, tag the Tiddler with ConfluenceFormat. or set the tiddler's {{{wikiformat}}} extended field to {{{confluence}}}.
Please report any defects you find at http://groups.google.co.uk/group/TiddlyWikiDev
***/
//{{{
// Ensure that the ConfluenceFormatterPlugin is only installed once.
if(!version.extensions.ConfluenceFormatterPlugin) {
version.extensions.ConfluenceFormatterPlugin = {installed:true};
if(version.major < 2 || (version.major == 2 && version.minor < 1))
{alertAndThrow('ConfluenceFormatterPlugin requires TiddlyWiki 2.1 or later.');}
confluenceFormatter = {}; // 'namespace' for local functions
confluenceDebug = function(out,str)
{
createTiddlyText(out,str.replace(/\n/mg,'\\n').replace(/\r/mg,'RR'));
createTiddlyElement(out,'br');
};
confluenceFormatter.createSpan = function(w)
{
createTiddlyElement(w.output,'span').innerHTML = this.text;
};
confluenceFormatter.macros = function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var lm1 = lookaheadMatch[1];
var lm2 = lookaheadMatch[2];
switch(lm1) {
case 'anchor':
a = createTiddlyElement(w.output,'a');// drop anchor
t = w.tiddler ? w.tiddler.title + ':' : '';
a.setAttribute('name',t + lm2);
break;
case 'color':
var e = createTiddlyElement(w.output,'span');
e.style.color = lm2;
w.subWikifyTerm(e,/(\{color\})/mg);
return;
break;
case 'excerpt':
break;
case 'noformat':
case 'code':
break;
case 'panel':
case 'note':
case 'warning':
case 'info':
case 'tip':
var d = createTiddlyElement(w.output,'div');
var dp = createTiddlyElement(d,'div',null,'informationMacroPadding');
var t = createTiddlyElement(dp,'table',null,lm1+'Macro');
t.cellpadding='5';t.width='85%';t.cellspacing='0';t.border='0';
var tr = createTiddlyElement(t,'tr');
var td = createTiddlyElement(tr,'td');
td.width='16';td.valign='top';
var img = createTiddlyElement(td,'img');
img.src='/confluence/images/icons/emoticons/forbidden.gif';
img.width='16';img.height='16';img.align='absmiddle';img.alt='';img.border='0';
td = createTiddlyElement(tr,'td');
confluenceFormatter.subWikify(w,td,lm2);//'*'+lm1+'*<br/><br/>';
w.subWikifyTerm(td,new RegExp('(\{'+lm1+'\})','mg'));
return;
break;
case 'section':
// includes columns
break;
default:
w.outputText(w.output,w.matchStart,w.nextMatch);
return;
}
w.nextMatch = this.lookaheadRegExp.lastIndex;
} else {
w.outputText(w.output,w.matchStart,w.nextMatch);
}
};
confluenceFormatter.subWikify = function(w,out,src)
{
var oldSource = w.source;
var nextMatch = w.nextMatch;
w.source = src;
w.nextMatch = 0;
w.subWikifyUnterm(out);
w.source = oldSource;
w.nextMatch = nextMatch;
};
confluenceFormatter.singleCharFormat = function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart && lookaheadMatch[0].substr(lookaheadMatch[0].length-2,1) != ' ') {
w.subWikifyTerm(createTiddlyElement(w.output,this.element),this.termRegExp);
w.nextMatch = this.lookaheadRegExp.lastIndex;
} else {
w.outputText(w.output,w.matchStart,w.nextMatch);
}
};
confluenceFormatter.setAttributesFromParams = function(e,p)
{
var re = /\s*(.*?)=(?:(?:"(.*?)")|(?:'(.*?)')|((?:\w|%|#)*))/mg;
var match = re.exec(p);
while(match) {
var s = match[1].unDash();
if(s=='bgcolor') {
s = 'backgroundColor';
}
try {
if(match[2]) {
e.setAttribute(s,match[2]);
} else if(match[3]) {
e.setAttribute(s,match[3]);
} else {
e.setAttribute(s,match[4]);
}
}
catch(ex) {}
match = re.exec(p);
}
};
config.confluenceFormatters = [
{
name: 'confluenceHeading',
match: '^h[1-6](?:(?:\\(.*?\\))|(?:\\{.*?\\})|(?:\\[.*?\\]))?\\. ',
lookaheadRegExp: /^h([1-6])(?:(?:\((.*?)\))|(?:\{(.*?)\})|(?:\[(.*?)\]))?\. /mg,
termRegExp: /(\n)/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
w.subWikifyTerm(createTiddlyElement(w.output,'h'+lookaheadMatch[1]),this.termRegExp);
}
}
},
{
name: 'confluenceTable',
match: '^\\|(?:(?:.|\n)*)\\|$',
lookaheadRegExp: /^\|(?:(?:.|\n)*)\|$/mg,
cellRegExp: /(?:\|(?:[^\|]*)\|)(\n|$)?/mg,
cellTermRegExp: /((?:\x20*)\|)/mg,
handler: function(w)
{
var table = createTiddlyElement(w.output,'table');
var rowContainer = createTiddlyElement(table,'tbody');
var prevColumns = [];
w.nextMatch = w.matchStart;
this.lookaheadRegExp.lastIndex = w.nextMatch;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
while(lookaheadMatch && lookaheadMatch.index == w.nextMatch) {
var r = this.rowHandler(w,createTiddlyElement(rowContainer,'tr'),prevColumns);
if(!r) {
w.nextMatch++;
break;
}
this.lookaheadRegExp.lastIndex = w.nextMatch;
lookaheadMatch = this.lookaheadRegExp.exec(w.source);
}
},
rowHandler: function(w,e,prevColumns)
{
this.cellRegExp.lastIndex = w.nextMatch;
var cellMatch = this.cellRegExp.exec(w.source);
while(cellMatch && cellMatch.index == w.nextMatch) {
w.nextMatch++;
var cell = createTiddlyElement(e,'td');
w.subWikifyTerm(cell,this.cellTermRegExp);
if(cellMatch[1]) {
// End of row
w.nextMatch = this.cellRegExp.lastIndex;
return true;
} else {
// Cell
w.nextMatch--;
}
this.cellRegExp.lastIndex = w.nextMatch;
cellMatch = this.cellRegExp.exec(w.source);
}
return false;
}
},
{
name: 'confluenceList',
match: '^[#\\*\\-]+ ',
lookaheadRegExp: /^(?:(#)|(\*)|(\-))+ /mg,
termRegExp: /(\n)/mg,
handler: function(w)
{
var stack = [w.output];
var currLevel = 0, currType = null;
var listLevel, listType;
w.nextMatch = w.matchStart;
this.lookaheadRegExp.lastIndex = w.nextMatch;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
while(lookaheadMatch && lookaheadMatch.index == w.nextMatch) {
var style = lookaheadMatch[3] ? 'square' : null;
listType = lookaheadMatch[1] ? 'ol' : 'ul';
listLevel = lookaheadMatch[0].length;
w.nextMatch += listLevel;
if(listLevel > currLevel){
for(var i=currLevel; i<listLevel; i++) {
stack.push(createTiddlyElement(stack[stack.length-1],listType));
}
} else if(listLevel < currLevel) {
for(i=currLevel; i>listLevel; i--) {
stack.pop();
}
} else if(listLevel == currLevel && listType != currType) {
stack.pop();
stack.push(createTiddlyElement(stack[stack.length-1],listType));
}
currLevel = listLevel;
currType = listType;
var e = createTiddlyElement(stack[stack.length-1],'li');
e.style[config.browser.isIE ? 'list-style-type' : 'listStyleType'] = style;
w.subWikifyTerm(e,this.termRegExp);
this.lookaheadRegExp.lastIndex = w.nextMatch;
lookaheadMatch = this.lookaheadRegExp.exec(w.source);
}
}
},
{
name: 'confluenceBlockQuote',
match: '^bq(?:(?:\\(.*?\\))|(?:\\{.*?\\})|(?:\\[.*?\\]))?\\. ',
lookaheadRegExp: /^bq(?:(?:\((#?)(.*?)\))|(?:\{(.*?)\})|(?:\[(.*?)\]))?\. /mg,
termRegExp: /(\n)/mg,
element: 'blockquote',
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var e = createTiddlyElement(w.output,this.element);
w.subWikifyTerm(e,this.termRegExp);
}
}
},
{
name: 'confluenceQuote',
match: '^{quote}\\n',
termRegExp: /(^\{quote\}[\n|$])/mg,
element: 'blockquote',
handler: config.formatterHelpers.createElementAndWikify
},
{
name: 'confluenceNoformat',
match: '^{noformat}\\n',
lookaheadRegExp: /\{noformat\}((?:.|\n)*?)\{noformat\}/mg,
element: 'pre',
handler: config.formatterHelpers.enclosedTextHelper
},
{
name: 'confluenceRule',
match: '^---+$\\n?',
handler: function(w)
{
createTiddlyElement(w.output,'hr');
}
},
{
name: 'macro',
match: '<<',
lookaheadRegExp: /<<([^>\s]+)(?:\s*)((?:[^>]|(?:>(?!>)))*)>>/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart && lookaheadMatch[1]) {
w.nextMatch = this.lookaheadRegExp.lastIndex;
invokeMacro(w.output,lookaheadMatch[1],lookaheadMatch[2],w,w.tiddler);
}
}
},
{
name: 'confluenceExternalLink',
match: '(?:".*?" ?):?[a-z]{2,8}:',
lookaheadRegExp: /(?:\"(.*?)(?:\((.*?)\))?\" ?):?(.*?)(?=\s|$)/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var link = lookaheadMatch[3];
var text = lookaheadMatch[1] ? lookaheadMatch[1] : link;
var e = createExternalLink(w.output,link);
if(lookaheadMatch[2])
e.title = lookaheadMatch[2];
createTiddlyText(e,text);
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
},
{
name: 'confluenceUrlLink',
match: config.textPrimitives.urlPattern,
handler: function(w)
{
w.outputText(createExternalLink(w.output,w.matchText),w.matchStart,w.nextMatch);
}
},
{
name: 'confluenceExplicitLink',
match: '\\[',
lookaheadRegExp: /\[([^\|\]]*?)(?:(?:\])|(?:\|(.*?))\])/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart)
{
var text = lookaheadMatch[1];
var link = lookaheadMatch[2] ? lookaheadMatch[2] : text;
var tip = lookaheadMatch[3] ? lookaheadMatch[3] : text;
var e = config.formatterHelpers.isExternalLink(link) ? createExternalLink(w.output,link) : createTiddlyLink(w.output,link,false,null,w.isStatic);
confluenceFormatter.subWikify(w,e,text);
//createTiddlyText(e,text);
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
},
{
name: 'confluenceImage',
match: '!.*?!',
lookaheadRegExp: /!(.*?)(?:\((.*?)\))?!/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var img = createTiddlyElement(w.output,'img');
img.src = lookaheadMatch[1];
if(lookaheadMatch[2]) {
img.title = lookaheadMatch[2];
}
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
},
{
name: 'confluenceBold',
match: '\\*(?![\\s\\*])',
lookaheadRegExp: /\*(?!\s)(?:.*?)(?!\s)\*(?=[\s\._\-])/mg,
termRegExp: /((?!\s)\*(?=[\s\.\-_]))/mg,
element: 'strong',
handler: confluenceFormatter.singleCharFormat
},
{
name: 'confluenceItalic',
match: '_(?![\\s_])',
lookaheadRegExp: /_(?!\s)(?:.*?)(?!\s)_(?=[\s\.\*\-])/mg,
termRegExp: /((?!\s)_(?=[\s\.\*\-]))/mg,
element: 'em',
handler: confluenceFormatter.singleCharFormat
},
{
name: 'confluenceUnderline',
match: '\\+(?![\\s|\\+])',
lookaheadRegExp: /\+(?!\s)(?:.*?)(?!\s)\+(?=\s)/mg,
termRegExp: /((?!\s)\+(?=\s))/mg,
element: 'u',
handler: confluenceFormatter.singleCharFormat
},
{
name: 'confluenceStrike',
match: '-(?![\\s\\-])',
lookaheadRegExp: /-(?!\s)(?:.*?)(?!\s)-(?=[\s\.\*_])/mg,
termRegExp: /((?!\s)-(?=[\s\.\*_]))/mg,
element: 'strike',
handler: confluenceFormatter.singleCharFormat
},
{
name: 'confluenceSuperscript',
match: '\\^(?![\\s|\\^])',
lookaheadRegExp: /\^(?!\s)(?:.*?)(?!\s)\^(?=\s)/mg,
termRegExp: /((?!\s)\^(?=\s))/mg,
element: 'sup',
handler: confluenceFormatter.singleCharFormat
},
{
name: 'confluenceSubscript',
match: '~(?![\\s|~])',
lookaheadRegExp: /~(?!\s)(?:.*?)(?!\s)~(?=\s)/mg,
termRegExp: /((?!\s)~(?=\s))/mg,
element: 'sub',
handler: confluenceFormatter.singleCharFormat
},
{
name: 'confluenceCitation',
match: '\\?\\?',
termRegExp: /(\?\?)/mg,
element: 'cite',
handler: config.formatterHelpers.createElementAndWikify
},
{
name: 'confluenceMonospacedByChar',
match: '\\{\\{',
lookaheadRegExp: /\{\{((?:.|\n)*?)\}\}/mg,
element: 'code',
handler: config.formatterHelpers.enclosedTextHelper
},
{
name: 'confluenceParagraph',
match: '\\n{2,}',
handler: function(w)
{
createTiddlyElement(w.output,'p');
}
},
{
name: 'confluenceExplicitLineBreak',
match: '<br ?/?>|\\\\|\\n',
handler: function(w)
{
createTiddlyElement(w.output,'br');
}
},
{
name: 'confluenceComment',
match: '<!\\-\\-',
lookaheadRegExp: /<!\-\-((?:.|\n)*?)\-\-!>/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
},
{
name: 'confluenceMdash',
match: '---',
handler: function(w) {createTiddlyElement(w.output,'span').innerHTML = '—';}
},
{
name: 'confluenceNdash',
match: '--',
handler: function(w) {createTiddlyElement(w.output,'span').innerHTML = '–';}
},
{
name: 'confluenceTrademark',
match: '\\(TM\\)',
handler: function(w) {createTiddlyElement(w.output,'span').innerHTML = '™';}
},
{
name: 'confluenceRegistered',
match: '\\(R\\)',
text: '®',
handler: confluenceFormatter.createSpan
//handler: function(w) {createTiddlyElement(w.output,'span').innerHTML = '®';}
},
{
name: 'confluenceCopyright',
match: '\\(C\\)',
handler: function(w) {createTiddlyElement(w.output,'span').innerHTML = '©';}
},
{
name: 'confluenceElipsis',
match: '\\.\\.\\.',
handler: function(w) {createTiddlyElement(w.output,'span').innerHTML = '…';}
},
{
name: 'confluenceMacros',
match: '\\{(?:[a-z]{2,16})(?:: ?.*?)?\\}',
lookaheadRegExp: /\{([a-z]{2,16}): ?(.*?)\}/mg,
handler: confluenceFormatter.macros
},
{
name: 'confluenceHtmlEntitiesEncoding',
match: '&#?[a-zA-Z0-9]{2,8};',
handler: function(w)
{
createTiddlyElement(w.output,'span').innerHTML = w.matchText;
}
},
{
name: 'confluenceHtmlTag',
match: "<(?:[a-zA-Z]{2,}|a)(?:\\s*(?:(?:.*?)=[\"']?(?:.*?)[\"']?))*?>",
lookaheadRegExp: /<([a-zA-Z]+)((?:\s+(?:.*?)=["']?(?:.*?)["']?)*?)?\s*(\/)?>(?:\n?)/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var e =createTiddlyElement(w.output,lookaheadMatch[1]);
if(lookaheadMatch[2]) {
confluenceFormatter.setAttributesFromParams(e,lookaheadMatch[2]);
}
if(lookaheadMatch[3]) {
w.nextMatch = this.lookaheadRegExp.lastIndex;// empty tag
} else {
w.subWikify(e,'</'+lookaheadMatch[1]+'>');
}
}
}
}/*,
{
name: 'confluenceMatchedQuotes',
match: '(?=\s)"',
lookaheadRegExp: /\"((?:.|\n)*?)\"/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
createTiddlyElement(w.output,'span').innerHTML = '“' + lookaheadMatch[1] + '”';
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
}*/
];
config.parsers.confluenceFormatter = new Formatter(config.confluenceFormatters);
config.parsers.confluenceFormatter.format = 'confluence';
config.parsers.confluenceFormatter.formatTag = 'ConfluenceFormat';
} // end of 'install only once'
//}}}
© Martin Budden 2006,2007
This TiddlyWiki is published under a [[Creative Commons Attribution-ShareAlike 2.5 License|http://creativecommons.org/licenses/by-sa/2.5/]].
This gives you the freedom to use it pretty much however you want, including for commercial purposes, as long as you keep the copyright notice. If you do use items from this page a link back to http://www.martinswiki.com/ is appreciated.
/***
|''Name:''|CreoleFormatterPlugin|
|''Description:''|Extension of TiddlyWiki syntax to support [[Creole|http://www.wikicreole.org/]] text formatting|
|''Author:''|Martin Budden (mjbudden (at) gmail (dot) com)|
|''Source:''|http://www.martinswiki.com/#CreoleFormatterPlugin |
|''CodeRepository:''|http://svn.tiddlywiki.org/Trunk/contributors/MartinBudden/formatters/CreoleFormatterPlugin.js |
|''Version:''|0.1.8|
|''Date:''|May 7, 2007|
|''Comments:''|Please make comments at http://groups.google.co.uk/group/TiddlyWikiDev |
|''License:''|[[Creative Commons Attribution-ShareAlike 2.5 License|http://creativecommons.org/licenses/by-sa/2.5/]] |
|''~CoreVersion:''|2.1.0|
This is an early release of the CreoleFormatterPlugin, which extends the TiddlyWiki syntax to support Creole
text formatting. See [[testCreoleFormat]] for an example.
The Creole formatter is different from the other formatters in that Tiddlers are not required to be
tagged: instead the Creole format adds formatting that augments TiddlyWiki's format.
The Creole formatter adds the following:
# {{{**}}} for bold
# {{{=Heading 1=}}} with 1 to 6 equals signs for headings
# {{{[[link|title]]}}} format for links (rather than TW's {{{[[title|link]]}}}).
Since Creole augments rather than replaces TW's formatting there is a problem of how to resolve a prettyLink:
the formatter has some intelligence to determine if whether a link is a TW style link or a Creole style link.
Additionally a tiddler can be tagged 'titleThenLinkFormat' or 'linkThenTitleFormat' to force resolution one
way or the other.
See: http://www.wikicreole.org/wiki/Home
Please report any defects you find at http://groups.google.co.uk/group/TiddlyWikiDev
This is an early alpha release, with (at least) the following known issues:
# Creole image format not yet supported
***/
//{{{
// Ensure that the CreoleFormatterPlugin is only installed once.
if(!version.extensions.CreoleFormatterPlugin) {
version.extensions.CreoleFormatterPlugin = {installed:true};
if(version.major < 2 || (version.major == 2 && version.minor < 1)) {
alertAndThrow('CreoleFormatterPlugin requires TiddlyWiki 2.1 or later.');
}
creoleFormatter = {}; // 'namespace' for local functions
creoleFormatter.heading = {
name: 'creoleHeading',
match: '^={1,6}(?!=)',
termRegExp: /(={0,6}\n+)/mg,
handler: function(w) {w.subWikifyTerm(createTiddlyElement(w.output,'h' + w.matchLength),this.termRegExp);}
};
creoleFormatter.bold = {
name: 'creoleBold',
match: '\\*\\*',
termRegExp: /(\*\*|(?=\n\n))/mg,
element: 'strong',
handler: config.formatterHelpers.createElementAndWikify
};
creoleFormatter.explicitLink = {
name: 'creoleExplicitLink',
match: '\\[\\[',
lookaheadRegExp: /\[\[(.*?)(?:\|(.*?))?\]\]/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var e;
var link = lookaheadMatch[1];
var text = lookaheadMatch[2];
if(text) {
// both text and link defined, so try and workout which is which
var wlRegExp = new RegExp(config.textPrimitives.wikiLink,'mg');
wlRegExp.lastIndex = 0;
if(w.tiddler.isTagged('titleThenLinkFormat')) {
// format is [[text|link]]
link = text;
text = lookaheadMatch[1];
e = config.formatterHelpers.isExternalLink(link) ? createExternalLink(w.output,link) : createTiddlyLink(w.output,link,false,null,w.isStatic);
} else if(w.tiddler.isTagged('linkThenTitleFormat')) {
// standard format is [[link|text]]
e = config.formatterHelpers.isExternalLink(link) ? createExternalLink(w.output,link) : createTiddlyLink(w.output,link,false,null,w.isStatic);
} else if(config.formatterHelpers.isExternalLink(link)) {
e = createExternalLink(w.output,link);
} else if(config.formatterHelpers.isExternalLink(text)) {
link = text;
text = lookaheadMatch[1];
e = createExternalLink(w.output,link);
} else if(store.tiddlerExists(link)) {
e = createTiddlyLink(w.output,link,false,null,w.isStatic);
} else if(store.tiddlerExists(text)) {
link = text;
text = lookaheadMatch[1];
e = createTiddlyLink(w.output,link,false,null,w.isStatic);
} else if(wlRegExp.exec(text)) {
//text is a WikiWord, so assume its a tiddler link
link = text;
text = lookaheadMatch[1];
e = createTiddlyLink(w.output,link,false,null,w.isStatic);
} else {
// assume standard link format
e = config.formatterHelpers.isExternalLink(link) ? createExternalLink(w.output,link) : createTiddlyLink(w.output,link,false,null,w.isStatic);
}
} else {
text = link;
e = config.formatterHelpers.isExternalLink(link) ? createExternalLink(w.output,link) : createTiddlyLink(w.output,link,false,null,w.isStatic);
}
createTiddlyText(e,text);
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}//# end handler
};
creoleFormatter.replaceFormatters = function()
{
// replace formatters where necessary
for(var i=0; i<config.formatters.length; i++) {
// replace formatters as required
var name = config.formatters[i].name;
if(name == 'prettyLink') {
config.formatters[i] = creoleFormatter.explicitLink;
} else if(name == 'italicByChar') {
config.formatters[i].termRegExp = /(\/\/|(?=\n\n))/mg;
} else if(name == 'list') {
// require a space after the list character (required for '*' which otherwise clashes with bold
config.formatters[i].match = '^[\\*#;:]+ ';
}
}
};
creoleFormatter.replaceFormatters();
// add new formatters
config.formatters.push(creoleFormatter.heading);
config.formatters.push(creoleFormatter.bold);
}// end of 'install only once'
//}}}
/***
|''Name:''|CryptoTEAPlugin|
|''Description:''|TEA (Tiny Encryption Algorithm) and supporting Cryptographic functions|
|''Author:''|Martin Budden (mjbudden (at) gmail (dot) com)|
|''Source:''|http://martinswiki.com/#CryptoTEAPlugin |
|''CodeRepository:''|http://svn.tiddlywiki.org/Trunk/contributors/MartinBudden/plugins/CryptoTEAPlugin.js |
|''Version:''|0.1.7|
|''Date:''|May 7, 2007|
|''Comments:''|Please make comments at http://groups.google.co.uk/group/TiddlyWikiDev |
|''License:''|[[Creative Commons Attribution-ShareAlike 2.5 License|http://creativecommons.org/licenses/by-sa/2.5/]] |
|''~CoreVersion:''|2.1.3|
Based on [[Movable Type Script|http://www.movable-type.co.uk/scripts/TEAblock.html]]
***/
//{{{
// Ensure that the Crypto TEA Plugin is only installed once.
if(!version.extensions.CryptoTEAPlugin) {
version.extensions.CryptoTEAPlugin = {installed:true};
if(version.major < 2 || (version.major == 2 && version.minor < 1) || (version.major == 2 && version.minor == 1 && version.revision <3 ))
alertAndThrow('CryptoTEAPlugin requires TiddlyWiki 2.1.3 or later.');
Crypto.b64open = "''Base64''\n/*{{{*/\n";
Crypto.b64close = "\n/*}}}*/\n''Base64''";
Crypto.b64code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
Crypto.salt = String.fromCharCode(138,200,184,222,198,210,113,77);
Crypto.iterationCount = 4;
Crypto.passphraseToKey = function(passphrase)
// Use an iterated SHA-1 hash of the salted passphrase as a reasonably good key
{
postSalt = String.fromCharCode(23,160,248,216,146,5,102,239);
var k = Crypto.sha1Str(Crypto.salt+passphrase+postSalt);
for(var i = 1;i<Crypto.iterationCount;i++)
k = Crypto.sha1(k,k.length);
return k;
};
Crypto.base64armor = function(s)
{
return Crypto.b64open + Crypto.base64encode(s) + Crypto.b64close;
};
Crypto.base64encode = function(s)
{
b64code = Crypto.b64code;
var line = '';
var b64 = '';
var maxLen4 = 60;
var i;
for(i=0;i<=s.length-3;i+=3) {
if(line.length>maxLen4) {
b64 += line + '\n';
line = '';
}
line += b64code.charAt(s.charCodeAt(i)>>>2);
line += b64code.charAt(((s.charCodeAt(i)&3)<<4) | (s.charCodeAt(i+1)>>>4));
line += b64code.charAt(((s.charCodeAt(i+1)&0x0F)<< 2) | (s.charCodeAt(i+2)>>>6));
line += b64code.charAt(s.charCodeAt(i+2)&0x3F);
}
if(i==s.length-1) {
line += b64code.charAt(s.charCodeAt(i)>>>2);
line += b64code.charAt((s.charCodeAt(i)&3)<<4);
line += '==';
} else if(i==s.length-2) {
line += b64code.charAt(s.charCodeAt(i)>>>2);
line += b64code.charAt(((s.charCodeAt(i)&3)<<4) | (s.charCodeAt(i+1)>>>4));
line += b64code.charAt((s.charCodeAt(i+1)&0x0F)<<2);
line += '=';
}
if(b64.length > maxLen4) {
b64 += line + '\n';
line = '';
}
b64 += line;
return b64;
};
Crypto.base64decode = function(s)
{
b64code = Crypto.b64code;
var i;
if((i=s.indexOf(Crypto.b64open)) >= 0)
s = s.substring(i + Crypto.b64open.length,s.length);
if((i=s.indexOf(Crypto.b64close)) >= 0)
s = s.substring(0,i);
for(i=0;i<s.length;i++) {
if(b64code.indexOf(s.charAt(i)) != -1)
break;
}
var j,c;
var sg = 0;
var n = 0;
var b = new Array();
var d = new Array();
while(i<s.length) {
for(j=0;j<4;) {
if(i>=s.length) {
if(j>0) {
displayMessage('truncated');
return b;
}
break;
}
c = b64code.indexOf(s.charAt(i));
if(c>=0) {
d[j++] = c;
} else if(s.charAt(i)=='=') {
d[j++] = 0;
sg++;
}
i++;
}
if(j==4) {
b[n++] = ((d[0]<<2) | (d[1]>>>4)) & 0xFF;
if(sg<2) {
b[n++] = ((d[1]<<4) | (d[2]>>>2)) & 0xFF;
if(sg<1)
b[n++] = ((d[2]<<6) | d[3]) & 0xFF;
}
}
}
var r = new Array(b.length);
for(i=0;i<b.length;i++)
r[i] = String.fromCharCode(b[i]);
return r.join('');
};
Crypto.TEA = {};
Crypto.TEA.name = function()
{
return 'TEA';
};
Crypto.TEA.base64encode = Crypto.base64armor;
Crypto.TEA.base64decode = Crypto.base64decode;
Crypto.TEA.encipher = function(v,k)
// Encrypt, using TEA, array v with key k
{
if(v.length == 1) {
v[1] = 0;
}
var n = v.length;
var delta = 0x9E3779B9;
var q = Math.floor(6+52/n);
n--;
var sum = 0;
var z = v[n];
var y,mx,e;
while(q-- > 0) {
sum += delta;
e = sum>>>2 & 3;
for(var p=0; p<n; p++) {
y = v[p+1];
mx = (z>>>5 ^ y<<2) + (y>>>3 ^ z<<4) ^ (sum^y) + (k[p&3 ^ e] ^ z);
z = v[p] += mx;
}
y = v[0];
mx = (z>>>5 ^ y<<2) + (y>>>3 ^ z<<4) ^ (sum^y) + (k[p&3 ^ e] ^ z);
z = v[n] += mx;
}
};
Crypto.TEA.decipher = function(v,k)
// Decrypt, using TEA, array v with key k
{
var n = v.length;
var delta = 0x9E3779B9;
var sum = delta*Math.floor(6+52/n);
n--;
var y = v[0];
var z,mx,e;
while(sum != 0) {
e = sum>>>2 & 3;
for(var p=n; p>0; p--) {
z = v[p-1];
mx = (z>>>5 ^ y<<2) + (y>>>3 ^ z<<4) ^ (sum^y) + (k[p&3 ^ e] ^ z);
y = v[p] -= mx;
}
z = v[n];
mx = (z>>>5 ^ y<<2) + (y>>>3 ^ z<<4) ^ (sum^y) + (k[p&3 ^ e] ^ z);
y = v[0] -= mx;
sum -= delta;
}
};
Crypto.TEA.encrypt = function(plaintext,passphrase)
// Encrypt the plaintext
{
if(plaintext.length == 0)
return('');// nothing to encrypt
var v = Crypto.strToBe32s(plaintext);
Crypto.TEA.encipher(v,Crypto.passphraseToKey(passphrase));
return Crypto.be32sToStr(v);
};
Crypto.TEA.encryptPassphrase = function(passphrase)
// Encrypt the passphrase with itself
{
if(passphrase.length == 0)
return('');// nothing to encrypt
var v = Crypto.strToBe32s(passphrase);
Crypto.TEA.encipher(v,Crypto.passphraseToKey(passphrase));
var s = Crypto.base64encode(Crypto.be32sToStr(v)).substr(0,20);
return s.replace(/\+/g,'a').replace(/\//g,'a').replace(/=/g,'c');
};
Crypto.TEA.decrypt = function(ciphertext,passphrase)
// Decrypt ciphertext
{
if(ciphertext.length == 0)
return('');// nothing to decrypt
var v = Crypto.strToBe32s(ciphertext);
Crypto.TEA.decipher(v,Crypto.passphraseToKey(passphrase));
var plaintext = Crypto.be32sToStr(v);
if(plaintext.search(/\0/) != -1) {
plaintext = plaintext.slice(0,plaintext.search(/\0/));
}
return plaintext;
};
} // end of 'install only once'
//}}}
/***
|''Name:''|DisableStrikeThroughPlugin|
|''Description:''|Allows you to disable TiddlyWiki's automatic linking of WikiWords|
|''Author:''|Martin Budden (mjbudden (at) gmail (dot) com)|
|''Source:''|http://www.martinswiki.com/#DisableStrikeThroughPlugin |
|''CodeRepository:''|http://svn.tiddlywiki.org/Trunk/contributors/MartinBudden/plugins/DisableStrikeThroughPlugin.js |
|''Version:''|0.0.1|
|''Date:''|Feb 18, 2008|
|''Comments:''|Please make comments at http://groups.google.co.uk/group/TiddlyWikiDev |
|''License:''|[[Creative Commons Attribution-ShareAlike 2.5 License|http://creativecommons.org/licenses/by-sa/2.5/]] |
|''~CoreVersion:''|2.1.0|
***/
//{{{
// Ensure that the DisableStrikeThroughPlugin is only installed once.
if(!version.extensions.DisableStrikeThroughPlugin) {
version.extensions.DisableStrikeThroughPlugin = {installed:true};
if(version.major < 2 || (version.major == 2 && version.minor < 1))
{alertAndThrow('DisableStrikeThroughPlugin requires TiddlyWiki 2.1 or newer.');}
DisableStrikeThroughPlugin = {};
DisableStrikeThroughPlugin.replaceFormatters = function()
{
for(var i=0; i<config.formatters.length; i++) {
var name = config.formatters[i].name;
if(name == 'characterFormat') {
config.formatters[i].match = "''|//|__|\\^\\^|~~|\\{\\{\\{";
break;
} else if(name == 'strikeByChar') {
config.formatters.splice(i,1);
break;
}
}
};
DisableStrikeThroughPlugin.replaceFormatters();
} // end of 'install only once'
//}}}
/***
|''Name:''|DisableWikiLinksPlugin|
|''Description:''|Allows you to disable TiddlyWiki's automatic linking of WikiWords|
|''Author:''|Martin Budden (mjbudden (at) gmail (dot) com)|
|''Source:''|http://www.martinswiki.com/#DisableWikiLinksPlugin |
|''CodeRepository:''|http://svn.tiddlywiki.org/Trunk/contributors/MartinBudden/plugins/DisableWikiLinksPlugin.js |
|''Version:''|0.1.3|
|''Date:''|Aug 5, 2006|
|''Comments:''|Please make comments at http://groups.google.co.uk/group/TiddlyWikiDev |
|''License:''|[[Creative Commons Attribution-ShareAlike 2.5 License|http://creativecommons.org/licenses/by-sa/2.5/]] |
|''~CoreVersion:''|2.1.0|
|''Disable WikiLinks''|<<option chkDisableWikiLinks>>|
***/
//{{{
// Ensure that the DisableWikiLinksPlugin is only installed once.
if(!version.extensions.DisableWikiLinksPlugin) {
version.extensions.DisableWikiLinksPlugin = {installed:true};
if(version.major < 2 || (version.major == 2 && version.minor < 1))
{alertAndThrow('DisableWikiLinksPlugin requires TiddlyWiki 2.1 or newer.');}
if (config.options.chkDisableWikiLinks==undefined)
{config.options.chkDisableWikiLinks = false;}
Tiddler.prototype.autoLinkWikiWords = function()
{
if(config.options.chkDisableWikiLinks==true)
{return false;}
return !this.isTagged('systemConfig') && !this.isTagged('excludeMissing');
};
} // end of 'install only once'
//}}}
|!Format|!Markup|!Example|
|''Headings''|{{{!!Heading 2}}}<br />{{{!!!Heading 3}}}<br />{{{!!!!Heading 4}}}<br />{{{!!!!!Heading 5}}}<br /><br />Usually avoid Heading1 as Tiddler titles are nominally Heading1.|<html><h2>Heading 2</h2><h3>Heading 3</h3><h4>Heading 4</h4><h5>Heading 5</h5></html>|
|''Lists''|{{{*Bulleted list}}}|<html><ul><li>Bulleted List</li></ul></html>|
|~|{{{#Numbered list}}}|<html><ol><li>Numbered List</li></ol></html>|
|~|Definition list<br />{{{;Term}}}<br />{{{:definition}}}|<html><dl><dt>Term</dt><dd>definition</dd></dl></html>|
|~|Lists can be mixed and nested<br />{{{*}}}Bullet<br />{{{*#}}}Number<br />{{{*#;}}}Item<br />{{{*#:}}}Definition|<html><ul><li>Bullet<ol><li>Numbered<dl><dt></dt>Item<dd>Definition</dd></dl></li></ol></li></ul></html>|
|''Block quotes''|{{{>Blockquote}}}<br />{{{>>Nested quote}}}|<html><blockquote>Blockquote<blockquote>Nested<br/> quote</blockquote></blockquote></html>|
|~|{{{<<<}}}<br />{{{multi-line}}}<br />{{{blockquote}}}<br />{{{<<<}}}|<html><blockquote>multi-line<br/>blockquote</blockquote></html>|
|''Horizontal Rule''|{{{----}}} (4 dashes on a line of their own)|<html><hr></html>|
|''Links''|Any {{{WikiWord}}} creates a link to a tiddler (whether it exists or not).<br />Note that a WikiWord has to start with a capital letter and have a further mix of upper and lower case.|[[WikiWord]]|
|~|Manual link<br />{{{[[Table of Contents]]}}} (Especially for tiddlers with spaces in their titles)|[[Table of Contents]]|
|~|{{{[[Pretty Link|Link]]}}}|[[Pretty Link|Link]]|
|~|Automatic external link {{{http://www.tiddlywiki.com}}}|http://www.tiddlywiki.com|
|~|Pretty external link<br />{{{[[My Home Page|http://www.tiddlywiki.com]]}}}|[[My Home Page|http://www.tiddlywiki.com]]|
|~|OS Folder link<br />Windows Share: {{{file://///server/share}}}<br />Windows Local: {{{file:///c:/folder/file}}}<br />Un*x Local File: {{{file://folder/file}}}<br />Relative File: {{{[[folder/file]]}}}|file://///server/share <br />file:///c:/folder/file <br />file://folder/file <br /> [[folder/file]]|
|''Images''|{{{[img[favicon.ico]]}}}<br />Note that image files are always external to the TW file|[img[http://www.tiddlywiki.com/favicon.ico]]|
|~|Right aligned<br />{{{[>img[favicon.ico]]}}}|[>img[http://www.tiddlywiki.com/favicon.ico]]|
|~|Left aligned<br />{{{[<img[favicon.ico]]}}}|[<img[http://www.tiddlywiki.com/favicon.ico]]|
|''Image Links''|{{{[img[fav.ico][TiddlerName]]}}}|[img[http://www.tiddlywiki.com/favicon.ico][TiddlerName]]|
|~|{{{[img[fav.ico][Alias|TiddlerName]]}}}|[img[http://www.tiddlywiki.com/favicon.ico][Alias|TiddlerName]]|
|~|{{{[img[fav.ico][http://www.aa.com]]}}}|[img[http://www.tiddlywiki.com/favicon.ico][http://www.tiddlywiki.com]]|
|~|>|also see ''Links'' and ''Images'' sections in this table|
|''Inline''<br />''Comments''|{{{Not shown: /% hidden comment %/}}}<br />Text between the markers will not be shown|Not shown:/% hidden text %/|
You can save a complete copy of this site as a TiddlyWiki on your local drive by right clicking on [[this link|index.html]]
and selecting //Save link as...// or //Save target as...//. You can choose where to save the file, and what to call it (but make sure that it's saved in HTML format and with an HTML extension).
@@There can be confusing and subtle differences between different browsers. Some points to watch:@@
* If you're using Windows XP Service Pack 2 or Windows Vista, check for known [[ServicePack2Problems|http://www.tiddlywiki.com/#ServicePack2Problems]] and [[VistaIssues|http://www.tiddlywiki.com/#VistaIssues]]
* Do ''not'' use the File/Save command in your browser to save TiddlyWiki, because of [[SaveUnpredictabilities|http://www.tiddlywiki.com/#SaveUnpredictabilities]].
* Make sure that you're saving in HTML (or "page source" format), not one of the new-fangled archive formats
/***
|''Name:''|EncryptionCommandsPlugin|
|''Description:''|Toolbar commands for cryptographic functions|
|''Author:''|Martin Budden (mjbudden (at) gmail (dot) com)|
|''Source:''|http://martinswiki.com/#EncryptionCommandsPlugin |
|''CodeRepository:''|http://svn.tiddlywiki.org/Trunk/contributors/MartinBudden/plugins/EncryptionCommandsPlugin.js |
|''Version:''|0.1.7|
|''Date:''|Feb 4, 2007|
|''Comments:''|Please make comments at http://groups.google.co.uk/group/TiddlyWikiDev |
|''License:''|[[Creative Commons Attribution-ShareAlike 2.5 License|http://creativecommons.org/licenses/by-sa/2.5/]] |
|''~CoreVersion:''|2.1.3|
|''Requires''|[[CryptoTEAPlugin|http://svn.tiddlywiki.org/Trunk/contributors/MartinBudden/plugins/CryptoTEAPlugin.js ]]|
{{{<<tiddler EncryptionCommandsPluginDocumentation>>}}}
***/
//{{{
// Ensure that the plugin is only installed once.
if(!version.extensions.EncryptionCommandsPlugin) {
version.extensions.EncryptionCommandsPlugin = {installed:true};
if(version.major < 2 || (version.major == 2 && version.minor < 1) || (version.major == 2 && version.minor == 1 && version.revision <3 ))
alertAndThrow("EncryptionCommandsPlugin requires TiddlyWiki 2.1.3 or later.");
config.commands.editTiddler.isEnabled = function(tiddler)
{
return tiddler.fields.encryption ? false : true;
};
config.commands.encryptTiddler = {
hideReadOnly: true,
hideShadow: true,
encryptableTag: 'encryptable',
base64Tag: 'base64',
base64encode: null,
encryption: null
};
merge(config.commands.encryptTiddler,{
text: "encrypt",
tooltip: "Encrypt this tiddler",
passphrasePrompt: "Enter encryption passphrase"
});
config.commands.encryptTiddler.isEnabled = function(tiddler)
{
return this.encryption &&
!tiddler.isTagged('systemConfig') && !store.getValue(tiddler,'encryption') &&
(tiddler.isTagged(this.encryptableTag) || tiddler.isTagged(this.base64Tag));
};
config.commands.encryptTiddler.handler = function(event,src,title)
{
var tiddler = store.fetchTiddler(title);
if(!this.isEnabled(tiddler))
return;
if(tiddler.isTagged(this.base64Tag)) {
tiddler.text = this.base64encode(tiddler.text);
var name = 'base64';
} else {
if(!this.encryption || !this.encryption.encrypt)
return;
var passphrase = prompt(this.passphrasePrompt,'');
if(!passphrase)
return;
if(this.encryption.encryptPassphrase) {
store.setValue(tiddler,'passphrase',this.encryption.encryptPassphrase(passphrase));
}
var text = this.encryption.encrypt(tiddler.text,passphrase);
tiddler.text = this.base64encode(text);
name = this.encryption.name();
}
var i = tiddler.tags.indexOf(this.encryptableTag);
if(i!=-1)
tiddler.tags.splice(i,1);
store.setValue(tiddler,'encryption',name);
store.addTiddler(tiddler);
story.saveTiddler(title,event.shiftKey);
story.refreshTiddler(title,1,true);
};
config.commands.decryptTiddler = {
hideReadOnly: true,
hideShadow: true,
encryptableTag: 'encryptable',
base64Tag: 'base64',
base64decode: null,
encryption: null
};
// localization
merge(config.commands.decryptTiddler,{
text: "decrypt",
tooltip: "Decrypt this tiddler",
passphrasePrompt: "Enter decryption passphrase",
incorrectPassphrase: "Incorrect passphrase"
});
config.commands.decryptTiddler.isEnabled = function(tiddler)
{
return store.getValue(tiddler,'encryption');
};
config.commands.decryptTiddler.handler = function(event,src,title)
{
var tiddler = store.fetchTiddler(title);
if(!this.isEnabled(tiddler))
return;
if(store.getValue(tiddler,'encryption') == 'base64') {
tiddler.text = this.base64decode(tiddler.text);
var tag = 'base64';
} else {
var encryption = Crypto[store.getValue(tiddler,'encryption')];
if(!encryption || !encryption.decrypt || !encryption.base64decode)
return;
var passphrase = prompt(this.passphrasePrompt,'');
if(!passphrase)
return;
if(store.getValue(tiddler,'passphrase') && encryption.encryptPassphrase) {
if(encryption.encryptPassphrase(passphrase)!=store.getValue(tiddler,'passphrase')) {
displayMessage(config.commands.displayDecryptedTiddler.incorrectPassphrase);
return;
}
}
tiddler.text = encryption.decrypt(encryption.base64decode(tiddler.text),passphrase);
tag = this.encryptableTag;
}
tiddler.tags.pushUnique(tag);
store.setValue(tiddler,'encryption',null);
store.setValue(tiddler,'passphrase',null);
store.addTiddler(tiddler);
story.saveTiddler(title,event.shiftKey);
story.refreshTiddler(tiddler.title,1,true);
};
config.commands.displayDecryptedTiddler = {
encryptedTag: 'encryption',
base64Tag: 'base64',
base64decode: null,
encryption: null
};
// localization
merge(config.commands.displayDecryptedTiddler,{
text: "display",
tooltip: "Display this tiddler decrypted",
passphrasePrompt: "Enter decryption passphrase",
incorrectPassphrase: "Incorrect passphrase"
});
config.commands.displayDecryptedTiddler.isEnabled = function(tiddler)
{
return this.base64decode && store.getValue(tiddler,'encryption');
};
config.commands.displayDecryptedTiddler.handler = function(event,src,title)
{
var tiddler = store.fetchTiddler(title);
if(!this.isEnabled(tiddler))
return;
if(tiddler.isTagged(this.base64Tag)) {
var text = this.base64decode(tiddler.text);
} else {
var encryption = Crypto[store.getValue(tiddler,'encryption')];
if(!encryption || !encryption.decrypt || !encryption.base64decode)
return;
var passphrase = prompt(this.passphrasePrompt,'');
if(!passphrase)
return;
if(store.getValue(tiddler,'passphrase') && encryption.encryptPassphrase) {
if(encryption.encryptPassphrase(passphrase)!=store.getValue(tiddler,'passphrase')) {
displayMessage(config.commands.displayDecryptedTiddler.incorrectPassphrase);
return;
}
}
text = encryption.decrypt(encryption.base64decode(tiddler.text),passphrase);
}
var oldText = tiddler.text;
tiddler.text = text;
story.refreshTiddler(tiddler.title,DEFAULT_VIEW_TEMPLATE,true);
tiddler.text = oldText;
};
//}}}
// //Setup
//{{{
encryptionCommandPluginUpdateViewTemplate = function()
{
var title = 'ViewTemplate';
var tiddler = store.fetchTiddler(title);
if(!tiddler) {
tiddler = new Tiddler();
tiddler.title = title;
tiddler.text = config.shadowTiddlers[title];
tiddler.tags.pushUnique('excludeLists');
}
if(tiddler.text.indexOf('encryptTiddler') == -1) {
tiddler.text = tiddler.text.replace("<div class='toolbar' macro='toolbar ","<div class='toolbar' macro='toolbar encryptTiddler displayDecryptedTiddler decryptTiddler ");
store.addTiddler(tiddler);
store.setDirty(true);
}
};
encryptionCommandPluginSetFunctions = function()
{
config.commands.encryptTiddler.base64encode = Crypto.base64armor;
config.commands.encryptTiddler.encryption = Crypto.TEA;
config.commands.decryptTiddler.base64decode = Crypto.base64decode;
config.commands.displayDecryptedTiddler.base64decode = Crypto.base64decode;
};
encryptionCommandPluginUpdateViewTemplate();
encryptionCommandPluginSetFunctions();
//}}}
} // end of 'install only once'
//}}}
/***
|''Name:''|ExampleAdaptorPlugin|
|''Description:''|Example Adaptor which can be used as a basis for creating a new Adaptor|
|''Author:''|Martin Budden (mjbudden (at) gmail (dot) com)|
|''Source:''|http://www.martinswiki.com/#ExampleAdaptorPlugin|
|''CodeRepository:''|http://svn.tiddlywiki.org/Trunk/contributors/MartinBudden/adaptors/ExampleAdaptorPlugin.js|
|''Version:''|0.5.3|
|''Status:''|Not for release - this is a template for creating new adaptors|
|''Date:''|Mar 11, 2007|
|''Comments:''|Please make comments at http://groups.google.co.uk/group/TiddlyWikiDev|
|''License:''|[[Creative Commons Attribution-ShareAlike 2.5 License|http://creativecommons.org/licenses/by-sa/2.5/]]|
|''~CoreVersion:''|2.2.0|
To make this example into a real TiddlyWiki adaptor, you need to:
# Globally search and replace ExampleAdpator with the name of your adaptor
# Delete any functionality not supported by you host (for example, putTiddler may not be supported)
# Do the actions indicated by the !!TODO comments, namely:
## Set the values of the main variables, eg ExampleAdaptor.serverType etc
## Fill in the uri templates in the .prototype functions
## Parse the responseText returned in the Callback functions and put the results in the appropriate variables
***/
//{{{
if(!version.extensions.ExampleAdaptorPlugin) {
version.extensions.ExampleAdaptorPlugin = {installed:true};
function ExampleAdaptor()
{
this.host = null;
this.workspace = null;
return this;
}
// !!TODO set the variables below
ExampleAdaptor.mimeType = 'text/x.';
ExampleAdaptor.serverType = 'example'; // MUST BE LOWER CASE
ExampleAdaptor.serverParsingErrorMessage = "Error parsing result from server";
ExampleAdaptor.errorInFunctionMessage = "Error in function ExampleAdaptor.%0";
ExampleAdaptor.prototype.setContext = function(context,userParams,callback)
{
if(!context) context = {};
context.userParams = userParams;
if(callback) context.callback = callback;
context.adaptor = this;
if(!context.host)
context.host = this.host;
context.host = ExampleAdaptor.fullHostName(context.host);
if(!context.workspace)
context.workspace = this.workspace;
return context;
};
ExampleAdaptor.doHttpGET = function(uri,callback,params,headers,data,contentType,username,password)
{
return doHttp('GET',uri,data,contentType,username,password,callback,params,headers);
};
ExampleAdaptor.doHttpPOST = function(uri,callback,params,headers,data,contentType,username,password)
{
return doHttp('POST',uri,data,contentType,username,password,callback,params,headers);
};
ExampleAdaptor.fullHostName = function(host)
{
if(!host)
return '';
if(!host.match(/:\/\//))
host = 'http://' + host;
if(host.substr(host.length-1) != '/')
host = host + '/';
return host;
};
ExampleAdaptor.minHostName = function(host)
{
return host ? host.replace(/^http:\/\//,'').replace(/\/$/,'') : '';
};
// Convert a page title to the normalized form used in uris
ExampleAdaptor.normalizedTitle = function(title)
{
var n = title.toLowerCase();
n = n.replace(/\s/g,'_').replace(/\//g,'_').replace(/\./g,'_').replace(/:/g,'').replace(/\?/g,'');
if(n.charAt(0)=='_')
n = n.substr(1);
return String(n);
};
// Convert a date in YYYY-MM-DD hh:mm format into a JavaScript Date object
ExampleAdaptor.dateFromEditTime = function(editTime)
{
var dt = editTime;
return new Date(Date.UTC(dt.substr(0,4),dt.substr(5,2)-1,dt.substr(8,2),dt.substr(11,2),dt.substr(14,2)));
};
ExampleAdaptor.prototype.openHost = function(host,context,userParams,callback)
{
this.host = ExampleAdaptor.fullHostName(host);
context = this.setContext(context,userParams,callback);
if(context.callback) {
context.status = true;
window.setTimeout(function() {callback(context,userParams);},0);
}
return true;
};
ExampleAdaptor.prototype.openWorkspace = function(workspace,context,userParams,callback)
{
this.workspace = workspace;
context = this.setContext(context,userParams,callback);
if(context.callback) {
context.status = true;
window.setTimeout(function() {callback(context,userParams);},0);
}
return true;
};
ExampleAdaptor.prototype.getWorkspaceList = function(context,userParams,callback)
{
context = this.setContext(context,userParams,callback);
// !!TODO set the uriTemplate
var uriTemplate = '%0';
var uri = uriTemplate.format([context.host]);
var req = ExampleAdaptor.doHttpGET(uri,ExampleAdaptor.getWorkspaceListCallback,context);
return typeof req == 'string' ? req : true;
};
ExampleAdaptor.getWorkspaceListCallback = function(status,context,responseText,uri,xhr)
{
context.status = false;
context.statusText = ExampleAdaptor.errorInFunctionMessage.format(['getWorkspaceListCallback']);
if(status) {
try {
// !!TODO: parse the responseText here
var list = [];
var item = {
title:'exampleTitle',
name:'exampleName'
};
list.push(item);
} catch (ex) {
context.statusText = exceptionText(ex,ExampleAdaptor.serverParsingErrorMessage);
if(context.callback)
context.callback(context,context.userParams);
return;
}
context.workspaces = list;
context.status = true;
} else {
context.statusText = xhr.statusText;
}
if(context.callback)
context.callback(context,context.userParams);
};
ExampleAdaptor.prototype.getTiddlerList = function(context,userParams,callback)
{
context = this.setContext(context,userParams,callback);
// !!TODO set the uriTemplate
var uriTemplate = '%0%1';
var uri = uriTemplate.format([context.host,context.workspace]);
var req = ExampleAdaptor.doHttpGET(uri,ExampleAdaptor.getTiddlerListCallback,context);
return typeof req == 'string' ? req : true;
};
ExampleAdaptor.getTiddlerListCallback = function(status,context,responseText,uri,xhr)
{
context.status = false;
context.statusText = ExampleAdaptor.errorInFunctionMessage.format(['getTiddlerListCallback']);
if(status) {
try {
// !!TODO: parse the responseText here
var list = [];
var tiddler = new Tiddler('example');
list.push(tiddler);
} catch (ex) {
context.statusText = exceptionText(ex,ExampleAdaptor.serverParsingErrorMessage);
if(context.callback)
context.callback(context,context.userParams);
return;
}
context.tiddlers = list;
context.status = true;
} else {
context.statusText = xhr.statusText;
}
if(context.callback)
context.callback(context,context.userParams);
};
ExampleAdaptor.prototype.generateTiddlerInfo = function(tiddler)
{
var info = {};
var host = this && this.host ? this.host : ExampleAdaptor.fullHostName(tiddler.fields['server.host']);
var workspace = this && this.workspace ? this.workspace : tiddler.fields['server.workspace'];
// !!TODO set the uriTemplate
uriTemplate = '%0%1%2';
info.uri = uriTemplate.format([host,workspace,tiddler.title]);
return info;
};
ExampleAdaptor.prototype.getTiddlerRevision = function(title,revision,context,userParams,callback)
{
context = this.setContext(context,userParams,callback);
if(revision)
context.revision = revision;
return this.getTiddler(title,context,userParams,callback);
};
ExampleAdaptor.prototype.getTiddler = function(title,context,userParams,callback)
{
context = this.setContext(context,userParams,callback);
if(title)
context.title = title;
if(context.revision) {
// !!TODO set the uriTemplate
var uriTemplate = '%0%1%2%3';
} else {
// !!TODO set the uriTemplate
uriTemplate = '%0%1%2';
}
uri = uriTemplate.format([context.host,context.workspace,ExampleAdaptor.normalizedTitle(title),context.revision]);
context.tiddler = new Tiddler(title);
context.tiddler.fields.wikiformat = 'exampleformat';
context.tiddler.fields['server.type'] = ExampleAdaptor.serverType;
context.tiddler.fields['server.host'] = ExampleAdaptor.minHostName(context.host);
context.tiddler.fields['server.workspace'] = context.workspace;
var req = ExampleAdaptor.doHttpGET(uri,ExampleAdaptor.getTiddlerCallback,context);
return typeof req == 'string' ? req : true;
};
ExampleAdaptor.getTiddlerCallback = function(status,context,responseText,uri,xhr)
{
context.status = false;
context.statusText = ExampleAdaptor.errorInFunctionMessage.format(['getTiddlerCallback']);
if(status) {
try {
// !!TODO: parse the responseText here
// !!TODO: fill in tiddler fields as available
//context.tiddler.tags = ;
//context.tiddler.fields['server.page.id'] = ;
//context.tiddler.fields['server.page.name'] = ;
//context.tiddler.fields['server.page.revision'] = String(...);
//context.tiddler.modifier = ;
//context.tiddler.modified = ExampleAdaptor.dateFromEditTime(...);
} catch (ex) {
context.statusText = exceptionText(ex,ExampleAdaptor.serverParsingErrorMessage);
if(context.callback)
context.callback(context,context.userParams);
return;
}
context.status = true;
} else {
context.statusText = xhr.statusText;
if(context.callback)
context.callback(context,context.userParams);
return;
}
if(context.callback)
context.callback(context,context.userParams);
};
ExampleAdaptor.prototype.getTiddlerRevisionList = function(title,limit,context,userParams,callback)
{
context = this.setContext(context,userParams,callback);
// !!TODO set the uriTemplate
var uriTemplate = '%0%1%2';
if(!limit)
limit = 10;
var uri = uriTemplate.format([context.host,context.workspace,ExampleAdaptor.normalizedTitle(title),limit]);
var req = ExampleAdaptor.doHttpGET(uri,ExampleAdaptor.getTiddlerRevisionListCallback,context);
return typeof req == 'string' ? req : true;
};
ExampleAdaptor.getTiddlerRevisionListCallback = function(status,context,responseText,uri,xhr)
{
context.status = false;
if(status) {
var content = null;
try {
// !!TODO: parse the responseText here
var list = [];
var tiddler = new Tiddler('example');
// !!TODO: fill in tiddler fields as available
//tiddler.modified = ExampleAdaptor.dateFromEditTime();
//tiddler.modifier = ;
//tiddler.tags = ;
//tiddler.fields['server.page.id'] = ;
//tiddler.fields['server.page.name'] = ;
//tiddler.fields['server.page.revision'] = ;
list.push(tiddler);
} catch (ex) {
context.statusText = exceptionText(ex,ExampleAdaptor.serverParsingErrorMessage);
if(context.callback)
context.callback(context,context.userParams);
return;
}
var sortField = 'server.page.revision';
list.sort(function(a,b) {return a.fields[sortField] < b.fields[sortField] ? +1 : (a.fields[sortField] == b.fields[sortField] ? 0 : -1);});
context.revisions = list;
context.status = true;
} else {
context.statusText = xhr.statusText;
}
if(context.callback)
context.callback(context,context.userParams);
};
ExampleAdaptor.prototype.putTiddler = function(tiddler,context,userParams,callback)
{
context = this.setContext(context,userParams,callback);
context.title = tiddler.title;
// !!TODO set the uriTemplate
var uriTemplate = '%0%1%2';
var host = context.host ? context.host : ExampleAdaptor.fullHostName(tiddler.fields['server.host']);
var workspace = context.workspace ? context.workspace : tiddler.fields['server.workspace'];
var uri = uriTemplate.format([host,workspace,tiddler.title,tiddler.text]);
var req = ExampleAdaptor.doHttpPOST(uri,ExampleAdaptor.putTiddlerCallback,context,{"X-Http-Method": "PUT"},tiddler.text,ExampleAdaptor.mimeType);
return typeof req == 'string' ? req : true;
};
ExampleAdaptor.putTiddlerCallback = function(status,context,responseText,uri,xhr)
{
if(status) {
context.status = true;
} else {
context.status = false;
context.statusText = xhr.statusText;
}
if(context.callback)
context.callback(context,context.userParams);
};
ExampleAdaptor.prototype.close = function()
{
return true;
};
config.adaptors[ExampleAdaptor.serverType] = ExampleAdaptor;
} //# end of 'install only once'
//}}}
/***
|''Name:''|ExampleFormatterPlugin|
|''Description:''|Example Formatter which can be used as a basis for creating a new Formatter. Allows Tiddlers to use [[example|http://www.example.com/wikitext]] text formatting|
|''Author:''|Martin Budden (mjbudden (at) gmail (dot) com)|
|''Source:''|http://www.martinswiki.com/#ExampleFormatterPlugin |
|''CodeRepository:''|http://svn.tiddlywiki.org/Trunk/contributors/MartinBudden/formatters/ExampleFormatterPlugin.js |
|''Version:''|0.1.10|
|''Status:''|Not for release - this is a template for creating new formatters|
|''Date:''|Nov 5, 2006|
|''Comments:''|Please make comments at http://groups.google.co.uk/group/TiddlyWikiDev |
|''License:''|[[Creative Commons Attribution-ShareAlike 2.5 License|http://creativecommons.org/licenses/by-sa/2.5/]] |
|''~CoreVersion:''|2.1.0|
To make this example into a real TiddlyWiki formatter, you need to:
# Globally search and replace ExampleAdpator with the name of your formatter
# Remove any format entries that are not required
# Change the existing format entries as required
# Add any new format entries that are required
***/
//{{{
// Ensure that the ExampleFormatterPlugin is only installed once.
if(!version.extensions.ExampleFormatterPlugin) {
version.extensions.ExampleFormatterPlugin = {installed:true};
if(version.major < 2 || (version.major == 2 && version.minor < 1))
{alertAndThrow('ExampleFormatterPlugin requires TiddlyWiki 2.1 or later.');}
exampleFormatter = {}; // 'namespace' for local functions
exampleDebug = function(out,str)
{
createTiddlyText(out,str.replace(/\n/mg,'\\n').replace(/\r/mg,'RR'));
createTiddlyElement(out,'br');
};
wikify = function(source,output,highlightRegExp,tiddler)
{
if(source && source !== '') {
var w = new Wikifier(source,getParser(tiddler),highlightRegExp,tiddler);
w.output = tiddler ? createTiddlyElement(output,'p') : output;
w.subWikifyUnterm(w.output);
}
};
config.formatterHelpers.setAttributesFromParams = function(e,p)
{
var re = /\s*(.*?)=(?:(?:"(.*?)")|(?:'(.*?)')|((?:\w|%|#)*))/mg;
var match = re.exec(p);
while(match) {
var s = match[1].unDash();
if(s=='bgcolor') {
s = 'backgroundColor';
}
try {
if(match[2]) {
e.setAttribute(s,match[2]);
} else if(match[3]) {
e.setAttribute(s,match[3]);
} else {
e.setAttribute(s,match[4]);
}
}
catch(ex) {}
match = re.exec(p);
}
};
config.exampleFormatters = [
{
name: 'exampleHeading',
match: '^={1,6}(?!=)',
termRegExp: /(={0,6} *\n+)/mg,
handler: function(w)
{
w.subWikifyTerm(createTiddlyElement(w.output,'h'+w.matchLength),this.termRegExp);
}
},
{
name: 'exampleList',
match: '^[\\*#;:]+ ',
lookaheadRegExp: /^([\*#;:])+ /mg,
termRegExp: /(\n)/mg,
handler: function(w)
{
var stack = [w.output];
var currLevel = 0, currType = null;
var listLevel, listType, itemType, baseType;
w.nextMatch = w.matchStart;
this.lookaheadRegExp.lastIndex = w.nextMatch;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
while(lookaheadMatch && lookaheadMatch.index == w.nextMatch) {
switch(lookaheadMatch[1]) {
case '*':
listType = 'ul';
itemType = 'li';
break;
case '#':
listType = 'ol';
itemType = 'li';
break;
case ';':
listType = 'dl';
itemType = 'dt';
break;
case ':':
listType = 'dl';
itemType = 'dd';
break;
default:
break;
}
if(!baseType)
baseType = listType;
listLevel = lookaheadMatch[0].length;
w.nextMatch += lookaheadMatch[0].length;
var t;
if(listLevel > currLevel) {
for(t=currLevel; t<listLevel; t++) {
var target = (currLevel == 0) ? stack[stack.length-1] : stack[stack.length-1].lastChild;
stack.push(createTiddlyElement(target,listType));
}
} else if(listType!=baseType && listLevel==1) {
w.nextMatch -= lookaheadMatch[0].length;
return;
} else if(listLevel < currLevel) {
for(t=currLevel; t>listLevel; t--)
stack.pop();
} else if(listLevel == currLevel && listType != currType) {
stack.pop();
stack.push(createTiddlyElement(stack[stack.length-1].lastChild,listType));
}
currLevel = listLevel;
currType = listType;
var e = createTiddlyElement(stack[stack.length-1],itemType);
w.subWikifyTerm(e,this.termRegExp);
this.lookaheadRegExp.lastIndex = w.nextMatch;
lookaheadMatch = this.lookaheadRegExp.exec(w.source);
}
}
},
{
name: 'exampleRule',
match: '^---+$\\n?',
handler: function(w)
{
createTiddlyElement(w.output,'hr');
}
},
{
name: 'macro',
match: '<<',
lookaheadRegExp: /<<([^>\s]+)(?:\s*)((?:[^>]|(?:>(?!>)))*)>>/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart && lookaheadMatch[1]) {
w.nextMatch = this.lookaheadRegExp.lastIndex;
invokeMacro(w.output,lookaheadMatch[1],lookaheadMatch[2],w,w.tiddler);
}
}
},
{
name: 'exampleExplicitLink',
match: '\\[\\[',
lookaheadRegExp: /\[\[(.*?)(?:\|(.*?))?\]\]/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var link = lookaheadMatch[1];
var text = lookaheadMatch[2] ? lookaheadMatch[2] : link;
var e = config.formatterHelpers.isExternalLink(link) ? createExternalLink(w.output,link) : createTiddlyLink(w.output,link,false,null,w.isStatic);
createTiddlyText(e,text);
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
},
{
name: 'exampleNotWikiLink',
match: '!' + config.textPrimitives.wikiLink,
handler: function(w)
{
w.outputText(w.output,w.matchStart+1,w.nextMatch);
}
},
{
name: 'exampleWikiLink',
match: config.textPrimitives.wikiLink,
handler: function(w)
{
if(w.matchStart > 0) {
var preRegExp = new RegExp(config.textPrimitives.anyLetter,'mg');
preRegExp.lastIndex = w.matchStart-1;
var preMatch = preRegExp.exec(w.source);
if(preMatch.index == w.matchStart-1) {
w.outputText(w.output,w.matchStart,w.nextMatch);
return;
}
}
var output = w.output;
if(w.autoLinkWikiWords == true || store.isShadowTiddler(w.matchText)) {
output = createTiddlyLink(w.output,w.matchText,false,null,w.isStatic);
}
w.outputText(output,w.matchStart,w.nextMatch);
}
},
{
name: 'exampleUrlLink',
match: config.textPrimitives.urlPattern,
handler: function(w)
{
w.outputText(createExternalLink(w.output,w.matchText),w.matchStart,w.nextMatch);
}
},
{
name: 'exampleBold',
match: '\\*\\*',
termRegExp: /(\*\*|(?=\n\n))/mg,
element: 'strong',
handler: config.formatterHelpers.createElementAndWikify
},
{
name: 'exampleItalic',
match: '//',
termRegExp: /(\/\/|(?=\n\n))/mg,
element: 'em',
handler: config.formatterHelpers.createElementAndWikify
},
{
name: 'exampleUnderline',
match: '__',
termRegExp: /(__|(?=\n\n))/mg,
element: 'u',
handler: config.formatterHelpers.createElementAndWikify
},
{
name: 'exampleStrikeBy',
match: '--(?!\\s|$)',
termRegExp: /((?!\s)--|(?=\n\n))/mg,
element: 'strike',
handler: config.formatterHelpers.createElementAndWikify
},
{
name: 'exampleSuperscript',
match: '\\^\\^',
termRegExp: /(\^\^|(?=\n\n))/mg,
element: 'sup',
handler: config.formatterHelpers.createElementAndWikify
},
{
name: 'exampleSubscript',
match: '~~',
termRegExp: /(~~|(?=\n\n))/mg,
element: 'sub',
handler: config.formatterHelpers.createElementAndWikify
},
{
name: 'exampleMonospaced',
match: '\\{\\{\\{',
lookaheadRegExp: /\{\{\{((?:.|\n)*?)\}\}\}/mg,
element: 'code',
handler: config.formatterHelpers.enclosedTextHelper
},
{
name: 'exampleParagraph',
match: '\\n{2,}',
handler: function(w)
{
w.output = createTiddlyElement(w.output,'p');
}
},
{
name: 'exampleLineBreak',
match: '\\n|<br ?/?>',
handler: function(w)
{
createTiddlyElement(w.output,'br');
}
},
{
name: 'exampleComment',
match: '<!\\-\\-',
lookaheadRegExp: /<!\-\-((?:.|\n)*?)\-\-!>/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
},
{
name: 'exampleHtmlEntitiesEncoding',
match: '&#?[a-zA-Z0-9]{2,8};',
handler: function(w)
{
createTiddlyElement(w.output,'span').innerHTML = w.matchText;
}
},
{
name: "html",
match: "<[Hh][Tt][Mm][Ll]>",
lookaheadRegExp: /<[Hh][Tt][Mm][Ll]>((?:.|\n)*?)<\/[Hh][Tt][Mm][Ll]>/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
createTiddlyElement(w.output,"span").innerHTML = lookaheadMatch[1];
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
}
];
config.parsers.exampleFormatter = new Formatter(config.exampleFormatters);
config.parsers.exampleFormatter.format = 'example';
config.parsers.exampleFormatter.formatTag = 'ExampleFormat';
} // end of 'install only once'
//}}}
/***
|''Name:''|ExamplePlugin|
|''Description:''|My Description|
|''Author:''|My Name|
|''Source:''|http://www.MyWebSite.com/#ExamplePlugin |
|''CodeRepository:''|http://svn.tiddlywiki.org/Trunk/contributors/MyDirectory/plugins/ExamplePlugin.js |
|''Version:''|0.0.1|
|''Status:''|Not for release - this is a template for creating new plugins|
|''Date:''|Jan 25, 2008|
|''Comments:''|Please make comments at http://groups.google.co.uk/group/TiddlyWikiDev |
|''License:''|[[Creative Commons Attribution-ShareAlike 3.0 License|http://creativecommons.org/licenses/by-sa/3.0/]] |
|''~CoreVersion:''|2.3|
To make this example into a real TiddlyWiki plugin, you need to:
# Globally search and replace ExamplePlugin with the name of your plugin
# Globally search and replace example with the name of your macro
# Update the header text above with your description, name etc
# Do the actions indicated by the !!TODO comments, namely:
## Write the code for the plugin
## Write the documentation for the plugin
!!Description
//!!TODO write a brief description of the plugin here
!!Usage
//!!TODO describe how to use the plugin - how a user should include it in their TiddlyWiki, parameters to the plugin etc
***/
//{{{
if(!version.extensions.ExamplePlugin) {
version.extensions.ExamplePlugin = {installed:true};
config.macros.example = {};
config.macros.example.handler = function(place,macroName,params,wikifier,paramString,tiddler)
{
//!!TODO write the code for the macro here
};
} //# end of 'install only once'
//}}}
|!Formatter Plugin|!Description|
|[[SnipSnapFormatterPlugin]]|Allows Tiddlers to use [[SnipSnap|http://snipsnap.org/space/snipsnap-help]] text formatting|
|[[TextileFormatterPlugin]]|Allows Tiddlers to use [[Textile|http://www.textism.com/tools/textile/]] text formatting|
|!Formatter Plugin|!Description|
|[[ExampleFormatterPlugin]]|Example empty formatter. You can use this as a template to write your own formatter|
|[[CreoleFormatterPlugin]]|Allows Tiddlers to use [[Creole|http://www.wikicreole.org/]] text formatting|
|[[ConfluenceFormatterPlugin]]|Allows Tiddlers to use [[Confluence|http://confluence.atlassian.com/renderer/notationhelp.action?section=all]] text formatting|
|[[JSPWikiFormatterPlugin]]|Allows Tiddlers to use [[JSPWiki|http://www.jspwiki.org/wiki/TextFormattingRules]] text formatting|
|[[MediaWikiFormatterPlugin]]|Allows Tiddlers to use [[MediaWiki|http://en.wikipedia.org/wiki/Help:Wikitext_quick_reference#Basic_text_formatting]] ([[WikiPedia|http://www.wikipedia.org]]) text formatting|
|[[PmWikiFormatterPlugin]]|Allows Tiddlers to use [[PmWiki|http://pmwiki.org/wiki/PmWiki/TextFormattingRules]] text formatting|
|[[PBWikiFormatterPlugin]]|Allows Tiddlers to use [[PBWiki|http://yummy.pbwiki.com/WikiStyle]] text formatting|
|[[SocialtextFormatterPlugin]]|Allows Tiddlers to use [[Socialtext|http://www.socialtext.com/]] text formatting|
|[[TracFormatterPlugin]]|Allows Tiddlers to use [[Trac|http://trac.edgewall.org/wiki/WikiFormatting]] text formatting|
|[[TWikiFormatterPlugin]]|Allows Tiddlers to use [[TWiki|http://twiki.org/cgi-bin/view/TWiki/TextFormattingRules]] text formatting|
|[[WikispacesFormatterPlugin]]|Allows Tiddlers to use [[Wikispaces|http://www.wikispaces.com]] text formatting|
Welcome.
This is where I post [[TiddlyWiki]] macros, plugins and other extensions to make them available to other TiddlyWiki users.
<<tiddler [[Plugins]]>>
See http://solarsystem.tiddlypedia.com and http://nordic.tiddlypedia.com for examples of TiddlyWikis using Wikipedia format and content.
See [[Experimental]] for plugins under development.
© 2006,2007 Martin Budden
^^[img[http://www.tiddlywiki.com/favicon.ico]] TiddlyWiki <<version>>^^
/***
|''Name:''|JSPWikiAdaptorPlugin|
|''Description:''|Adaptor for moving and converting data to and from JSP Wikis|
|''Author:''|Martin Budden (mjbudden (at) gmail (dot) com)|
|''Source:''|http://www.martinswiki.com/#JSPWikiAdaptorPlugin |
|''CodeRepository:''|http://svn.tiddlywiki.org/Trunk/contributors/MartinBudden/adaptors/JSPWikiAdaptorPlugin.js |
|''Version:''|0.5.2|
|''Date:''|May 7, 2007|
|''Comments:''|Please make comments at http://groups.google.co.uk/group/TiddlyWikiDev |
|''License:''|[[Creative Commons Attribution-ShareAlike 2.5 License|http://creativecommons.org/licenses/by-sa/2.5/]]|
|''~CoreVersion:''|2.2.0|
JSPWiki RPC documentation is at:
http://www.JSPWiki.org/wiki/WikiRPCInterface2
http://www.JSPWiki.org/RPC2/
''For debug:''
|''Default JSPWiki Server''|<<option txtJSPWikiDefaultServer>>|
|''Default JSPWiki username''|<<option txtJSPWikiUsername>>|
|''Default JSPWiki password''|<<option txtJSPWikiPassword>>|
***/
//{{{
if(!config.options.txtJSPWikiDefaultServer)
{config.options.txtJSPWikiDefaultServer = 'www.jspwiki.org';}
if(!config.options.txtJSPWikiUsername)
{config.options.txtJSPWikiUsername = '';}
if(!config.options.txtJSPWikiPassword)
{config.options.txtJSPWikiPassword = '';}
if(!config.options.chkJSPWikiPasswordRequired)
{config.options.chkJSPWikiPasswordRequired = true;}
//}}}
//{{{
if(!version.extensions.JSPWikiAdaptorPlugin) {
version.extensions.JSPWikiAdaptorPlugin = {installed:true};
function JSPWikiAdaptor()
{
this.host = null;
this.workspace = null;
return this;
}
JSPWikiAdaptor.serverType = 'jspwiki';
JSPWikiAdaptor.serverParsingErrorMessage = "Error parsing result from server";
JSPWikiAdaptor.errorInFunctionMessage = "Error in function JSPWikiAdaptor.%0";
JSPWikiAdaptor.prototype.setContext = function(context,userParams,callback)
{
if(!context) context = {};
context.userParams = userParams;
if(callback) context.callback = callback;
context.adaptor = this;
if(!context.host)
context.host = this.host;
if(!context.workspace && this.workspace)
context.workspace = this.workspace;
return context;
};
JSPWikiAdaptor.doHttpGET = function(uri,callback,params,headers,data,contentType,username,password)
{
return doHttp('GET',uri,data,contentType,username,password,callback,params,headers);
};
JSPWikiAdaptor.doHttpPOST = function(uri,callback,params,headers,data,contentType,username,password)
{
return doHttp('POST',uri,data,contentType,username,password,callback,params,headers);
};
JSPWikiAdaptor.fullHostName = function(host)
{
if(!host)
return '';
if(!host.match(/:\/\//))
host = 'http://' + host;
if(host.substr(host.length-1) != '/')
host = host + '/';
return host;
};
JSPWikiAdaptor.minHostName = function(host)
{
return host ? host.replace(/^http:\/\//,'').replace(/\/$/,'') : '';
};
JSPWikiAdaptor.normalizedTitle = function(title)
{
return title;
};
JSPWikiAdaptor.prototype.openHost = function(host,context,userParams,callback)
{
this.host = JSPWikiAdaptor.fullHostName(host);
context = this.setContext(context,userParams,callback);
this.username = config.options.txttwikiUsername;
this.password = config.options.txttwikiPassword;
if(context.callback) {
context.status = true;
window.setTimeout(function() {callback(context,userParams);},0);
}
return true;
};
JSPWikiAdaptor.prototype.openWorkspace = function(workspace,context,userParams,callback)
{
this.workspace = workspace;
context = this.setContext(context,userParams,callback);
if(context.callback) {
context.status = true;
window.setTimeout(function() {callback(context,userParams);},0);
}
return true;
};
JSPWikiAdaptor.prototype.getWorkspaceList = function(context,userParams,callback)
{
context = this.setContext(context,userParams,callback);
var list = [];
list.push({title:"Main",name:"Main"});
context.workspaces = list;
if(context.callback) {
context.status = true;
window.setTimeout(function() {callback(context,userParams);},0);
}
return true;
};
JSPWikiAdaptor.prototype.getTiddlerList = function(context,userParams,callback)
{
context = this.setContext(context,userParams,callback);
var uriTemplate = '%0RPCU/';
var uri = uriTemplate.format([context.host]);
var fn = 'wiki.getAllPages';
var fnTemplate = '<?xml version="1.0"?><methodCall><methodName>%0</methodName></methodCall>';
var payload = fnTemplate.format([fn]);
var req =doHttp('POST',uri,payload,null,null,null,JSPWikiAdaptor.getTiddlerListCallback,context);
return typeof req == 'string' ? req : true;
};
//*<?xml version="1.0" encoding="UTF-8"?><methodResponse><params><param><value><array><data>
JSPWikiAdaptor.getTiddlerListCallback = function(status,context,responseText,uri,xhr)
{
context.status = false;
context.statusText = JSPWikiAdaptor.errorInFunctionMessage.format(['getTiddlerListCallback']);
if(status) {
try {
var text = responseText;
text = text.replace('<?xml version="1.0" encoding="UTF-8"?><methodResponse><params><param><value><array><data>','');
text = text.replace('</data></array></value></param></params></methodResponse>','');
var list = [];
var matchRegExp = /<value>([^<]*)<\/value>/mg;
matchRegExp.lastIndex = 0;
var match = matchRegExp.exec(text);
while(match) {
var tiddler = new Tiddler(match[1]);
list.push(tiddler);
match = matchRegExp.exec(text);
}
} catch (ex) {
context.statusText = exceptionText(ex,config.messages.serverParsingError);
if(context.callback)
context.callback(context,context.userParams);
return;
}
context.tiddlers = list;
context.status = true;
} else {
context.statusText = xhr.statusText;
}
if(context.callback)
context.callback(context,context.userParams);
};
JSPWikiAdaptor.prototype.generateTiddlerInfo = function(tiddler)
{
var info = {};
var host = this && this.host ? this.host : JSPWikiAdaptor.fullHostName(tiddler.fields['server.host']);
var workspace = this && this.workspace ? this.workspace : tiddler.fields['server.workspace'];
uriTemplate = '%0wiki/%2';
info.uri = uriTemplate.format([host,workspace,tiddler.title]);
return info;
};
JSPWikiAdaptor.prototype.getTiddler = function(title,context,userParams,callback)
{
context = this.setContext(context,userParams,callback);
var uriTemplate = '%0RPCU/';
var uri = uriTemplate.format([context.host]);
var fn = 'wiki.getPage';
var fnParamsTemplate ='<params><param><value><string>%0</string></value></param></params>';
var fnParams = fnParamsTemplate.format([title]);
var fnTemplate = '<?xml version="1.0"?><methodCall><methodName>%0</methodName>%1</methodCall>';
var payload = fnTemplate.format([fn,fnParams]);
context.tiddler = new Tiddler(title);
context.tiddler.fields.wikiformat = 'jspwiki';
context.tiddler.fields['server.host'] = JSPWikiAdaptor.minHostName(context.host);
//context.tiddler.fields['server.workspace'] = workspace;
var req =doHttp('POST',uri,payload,null,null,null,JSPWikiAdaptor.getTiddlerCallback,context);
return typeof req == 'string' ? req : true;
};
JSPWikiAdaptor.getTiddlerCallback = function(status,context,responseText,uri,xhr)
{
if(status) {
var text = responseText;
text = text.replace('<?xml version="1.0" encoding="UTF-8"?><methodResponse><params><param><value>','');
text = text.replace('</value></param></params></methodResponse>','');
context.tiddler.text = text;
context.status = true;
} else {
context.status = false;
context.statusText = xhr.statusText;
}
if(context.callback)
context.callback(context,context.userParams);
};
JSPWikiAdaptor.prototype.putTiddler = function(tiddler,context,callback)
{
context = this.setContext(context,userParams,callback);
context.title = tiddler.title;
var fn = 'wiki.putPage';
var uriTemplate = '%0RPC2/';
var host = context.host ? context.host : JSPWikiAdaptor.fullHostName(context.tiddler.fields['server.host']);
var workspace = context.workspace ? context.workspace : context.tiddler.fields['server.workspace'];
var uri = uriTemplate.format([host,workspace,tiddler.title]);
var fnParamsTemplate ='<params>';
fnParamsTemplate += '<param><value><string>%0</string></value></param>';
fnParamsTemplate += '<param><value><string>%1</string></value></param>';
fnParamsTemplate += '</params>';
var fnParams = fnParamsTemplate.format([tiddler.title,tiddler.text]);
var fnTemplate = '<?xml version="1.0"?><methodCall><methodName>%0</methodName>%1</methodCall>';
var payload = fnTemplate.format([fn,fnParams]);
var req = doHttp('POST',uri,payload,null,this.username,this.password,JSPWikiAdaptor.putTiddlerCallback,tiddler);
return typeof req == 'string' ? req : true;
};
JSPWikiAdaptor.putTiddlerCallback = function(status,context,responseText,uri,xhr)
{
if(status) {
context.status = true;
} else {
context.status = false;
context.statusText = xhr.statusText;
}
if(context.callback)
context.callback(context,context.userParams);
};
JSPWikiAdaptor.prototype.close = function() {return true;};
config.adaptors[JSPWikiAdaptor.serverType] = JSPWikiAdaptor;
} // end of 'install only once'
//}}}
/***
|''Name:''|JSPWikiFormatterPlugin|
|''Description:''|Allows Tiddlers to use [[JSPWiki|http://www.jspwiki.org/wiki/TextFormattingRules]] text formatting|
|''Author:''|Martin Budden (mjbudden (at) gmail (dot) com)|
|''Source:''|http://www.martinswiki.com/#JSPWikiFormatterPlugin |
|''CodeRepository:''|http://svn.tiddlywiki.org/Trunk/contributors/MartinBudden/formatters/JSPWikiFormatterPlugin.js |
|''Version:''|0.1.2|
|''Date:''|May 7, 2007|
|''Comments:''|Please make comments at http://groups.google.co.uk/group/TiddlyWikiDev |
|''License:''|[[Creative Commons Attribution-ShareAlike 2.5 License|http://creativecommons.org/licenses/by-sa/2.5/]]|
|''~CoreVersion:''|2.1.0|
|''Display unsupported macros''|<<option chkJSPWikiFormatterDisplayUnsupportedMacros>>|
This is an early release of the JSPWikiFormatterPlugin, which allows you to insert JSPWiki formated text into
a TiddlyWiki.
The aim is not to fully emulate JSPWiki, but to allow you to work with JSPWiki content off-line and then resync the content with your JSPWiki later on, with the expectation that only minor edits will be required.
To use JSPWiki format in a Tiddler, tag the Tiddler with JSPWikiFormat or set the tiddler's {{{wikiformat}}} extended field to {{{jspwiki}}}.
Please report any defects you find at http://groups.google.co.uk/group/TiddlyWikiDev
***/
//{{{
// Ensure that the JSPWikiFormatterPlugin is only installed once.
if(!version.extensions.JSPWikiFormatterPlugin) {
version.extensions.JSPWikiFormatterPlugin = {installed:true};
if(version.major < 2 || (version.major == 2 && version.minor < 1))
{alertAndThrow('JSPWikiFormatterPlugin requires TiddlyWiki 2.1 or later.');}
if(config.options.chkJspFormatterDisplayUnsupportedMacros == undefined)
{config.options.chkJspFormatterDisplayUnsupportedMacros = false;}
JSPWikiFormatter = {}; // 'namespace' for local functions
config.macros.list.jspWikiTalkPages = {};
config.macros.list.jspWikiTalkPages.handler = function(params)
{
return store.getJSPWikiTalkPages();
};
TiddlyWiki.prototype.getJSPWikiTalkPages = function()
{
var results = [];
this.forEachTiddler(function(title,tiddler) {
if(tiddler.title.substr(0,5)=='Talk.')
results.push(tiddler);
});
results.sort(function(a,b) {return a.title < b.title ? -1 : (a.title == b.title ? 0 : +1);});
return results;
};
TiddlyWiki.prototype.getJSPWikiPages = function()
{
var results = [];
this.forEachTiddler(function(title,tiddler) {
if(!tiddler.isTagged("excludeLists") && tiddler.title.substr(0,5)!='Talk.')
results.push(tiddler);
});
results.sort(function(a,b) {return a.title < b.title ? -1 : (a.title == b.title ? 0 : +1);});
return results;
};
config.commands.jspWikiDiscussion = {};
merge(config.commands.jspWikiDiscussion,{
text: "discussion",
tooltip: "Discussion",
readOnlyText: "discussion",
readOnlyTooltip: "Discussion"});
config.commands.jspWikiDiscussion.handler = function(event,src,title)
{
clearMessage();
story.displayTiddler(null,"Talk."+title,DEFAULT_VIEW_TEMPLATE);
//story.focusTiddler(title,"text");
return false;
};
config.commands.jspWikiDiscussion.isEnabled = function(tiddler)
{
if(!tiddler)
return false;
if(tiddler.isTagged(config.parsers.jspwikiFormatter.formatTag)||(tiddler.fields&&config.parsers.jspwikiFormatter.format&&tiddler.fields["wikiformat"]==config.parsers.jspwikiFormatter.format)) {
if(tiddler.title.indexOf("Talk.") != 0)
return true;
}
return false;
};
JSPWikiFormatter.hijackListAll = function ()
{
JSPWikiFormatter.oldListAll = config.macros.list.all.handler;
config.macros.list.all.handler = function(params) {
return store.getJSPWikiPages();
};
};
JSPWikiFormatter.hijackListAll();
jspDebug = function(out,str)
{
createTiddlyText(out,str.replace(/\n/mg,'\\n').replace(/\r/mg,'RR'));
createTiddlyElement(out,'br');
};
JSPWikiFormatter.isExternalLink = function(link)
{
if(store.tiddlerExists(link) || store.isShadowTiddler(link)) {
return false;
}
var urlRegExp = new RegExp(config.textPrimitives.urlPattern,'mg');
if(urlRegExp.exec(link)) {
return true;
}
if (link.indexOf('\\')!=-1){
return true;
}
return false;
};
JSPWikiFormatter.inlineCssHelper = function(e,fm)
{
cssRegExp = /(?:([a-z_\-]+):([^;\|\n]+);)/mg;
var nm = 0;
cssRegExp.lastIndex = nm;
var lookaheadMatch = cssRegExp.exec(fm);
while(lookaheadMatch && lookaheadMatch.index == nm) {
var s = lookaheadMatch[1];
var v = lookaheadMatch[2];
s = s=='bgcolor' ? 'backgroundColor' : s.unDash();
e.style[s] = v;
nm = cssRegExp.lastIndex;
lookaheadMatch = cssRegExp.exec(fm);
}
};
JSPWikiFormatter.wikiStyle = function(w)
// see http://www.jspwiki.org/wiki/JSPWikiStyles
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var lm1 = lookaheadMatch[1];
var lm2 = lookaheadMatch[2];
if(lm2) {
e = createTiddlyElement(w.output,'span');
JSPWikiFormatter.inlineCssHelper(e,lm2);
w.subWikifyTerm(e,this.termRegExp);
return;
}
switch(lm1) {
case 'sortable':
w.subWikifyTerm(w.output,this.termRegExp);
break;
case 'information':
case 'warning':
case 'error':
case 'commentbox':
case 'center':
case 'ltr':
case 'rtl':
case 'small':
w.subWikifyTerm(createTiddlyElement(w.output,'span',null,lm1),this.termRegExp);
break;
case 'sup':
w.subWikifyTerm(createTiddlyElement(w.output,'sup'),this.termRegExp);
break;
case 'sub':
w.subWikifyTerm(createTiddlyElement(w.output,'sub'),this.termRegExp);
break;
case 'strike':
w.subWikifyTerm(createTiddlyElement(w.output,'strike'),this.termRegExp);
break;
default:
w.outputText(w.output,w.matchStart,w.nextMatch);
break;
}
} else {
w.outputText(w.output,w.matchStart,w.nextMatch);
}
};
JSPWikiFormatter.macros = function(w)
// see http://www.jspwiki.org/wiki/JSPWikiPlugins
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var lm1 = lookaheadMatch[1];
switch(lm1) {
default:
if(config.options.chkJspFormatterDisplayUnsupportedMacros)
w.outputText(w.output,w.matchStart,w.nextMatch);
else
w.nextMatch = this.lookaheadRegExp.lastIndex;
break;
}
}
};
config.jspwiki = {};
config.jspwiki.formatters = [
{
name: 'jspHeading',
match: '^!{1,3}',
termRegExp: /($\n)/mg,
handler: function(w)
{
w.subWikifyTerm(createTiddlyElement(w.output,'h'+(4-w.matchLength)),this.termRegExp);
}
},
{
name: 'jspList',
match: '^(?:[\\*#;:]+)',
lookaheadRegExp: /^(?:(?:(\*)|(#)|(;)|(:))+)/mg,
termRegExp: /(\n)/mg,
handler: function(w)
{
var stack = [w.output];
var currLevel = 0, currType = null;
var listLevel, listType, itemType;
w.nextMatch = w.matchStart;
this.lookaheadRegExp.lastIndex = w.nextMatch;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
while(lookaheadMatch && lookaheadMatch.index == w.nextMatch) {
if(lookaheadMatch[1]) {
listType = 'ul';
itemType = 'li';
} else if(lookaheadMatch[2]) {
listType = 'ol';
itemType = 'li';
} else if(lookaheadMatch[3]) {
listType = 'dl';
itemType = 'dt';
} else if(lookaheadMatch[4]) {
listType = 'dl';
itemType = 'dd';
}
listLevel = lookaheadMatch[0].length;
w.nextMatch += lookaheadMatch[0].length;
var t;
if(listLevel > currLevel) {
for(t=currLevel; t<listLevel; t++)
stack.push(createTiddlyElement(stack[stack.length-1],listType));
} else if(listLevel < currLevel) {
for(t=currLevel; t>listLevel; t--)
stack.pop();
} else if(listLevel == currLevel && listType != currType) {
stack.pop();
stack.push(createTiddlyElement(stack[stack.length-1],listType));
}
currLevel = listLevel;
currType = listType;
var e = createTiddlyElement(stack[stack.length-1],itemType);
w.subWikifyTerm(e,this.termRegExp);
this.lookaheadRegExp.lastIndex = w.nextMatch;
lookaheadMatch = this.lookaheadRegExp.exec(w.source);
}
}
},
{
name: 'jspTable',
match: '^\\|',
lookaheadRegExp: /^\|/mg,
cellRegExp: /\|.*?\|?[$\n]?/mg,
cellTermRegExp: /($|\n|\|)/mg,
debug: null,
handler: function(w)
{
var table = createTiddlyElement(w.output,'table',null,'wikitable');
var prevColumns = [];
var rowContainer = createTiddlyElement(table,'tbody');
var rowIndex = 0;
w.nextMatch = w.matchStart;
this.lookaheadRegExp.lastIndex = w.nextMatch;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
while(lookaheadMatch && lookaheadMatch.index == w.nextMatch) {
rowIndex++;
var r = this.rowHandler(w,createTiddlyElement(rowContainer,'tr',null,rowIndex&1?'odd':null),prevColumns);
if(!r) {
w.nextMatch++;
break;
}
this.lookaheadRegExp.lastIndex = w.nextMatch;
lookaheadMatch = this.lookaheadRegExp.exec(w.source);
}
},
rowHandler: function(w,e,prevColumns)
{
this.cellRegExp.lastIndex = w.nextMatch;
var cellMatch = this.cellRegExp.exec(w.source);
while(cellMatch && cellMatch.index == w.nextMatch) {
w.nextMatch++;// skip the |
var chr = w.source.substr(w.nextMatch,1);
// another | indicates a table heading
if(chr == '|') {
cell = createTiddlyElement(e,'th');
w.nextMatch++;
} else {
cell = createTiddlyElement(e,'td');
}
w.subWikifyTerm(cell,this.cellTermRegExp);
chr = w.source.substr(w.nextMatch,1);
if(!chr||chr=='\n') {
// End of row
w.nextMatch++; // skip over the \n
return true;
}
// Cell
w.nextMatch--;// rewind to before the |
this.cellRegExp.lastIndex = w.nextMatch;
cellMatch = this.cellRegExp.exec(w.source);
}
return false;
}
},
{
name: 'jspRule',
match: '^---+$\\n?',
handler: function(w)
{
createTiddlyElement(w.output,'hr');
}
},
{
name: 'jspMonospacedByLine',
match: '^\\{\\{\\{\\n',
lookaheadRegExp: /^\{\{\{\n((?:^[^\n]*\n)+?)(^\}\}\}$\n?)/mg,
element: 'pre',
handler: config.formatterHelpers.enclosedTextHelper
},
{
name: 'macro',
match: '<<',
lookaheadRegExp: /<<([^>\s]+)(?:\s*)((?:[^>]|(?:>(?!>)))*)>>/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart && lookaheadMatch[1]) {
w.nextMatch = this.lookaheadRegExp.lastIndex;
invokeMacro(w.output,lookaheadMatch[1],lookaheadMatch[2],w,w.tiddler);
}
}
},
{
name: 'jspMacro',
match: '\\[\\{',
lookaheadRegExp: /\[\{(.*?)\}\]/mg,
handler: JSPWikiFormatter.macros
},
{
name: 'jspExplicitLink',
match: '\\[',
lookaheadRegExp: /\[(.*?)(?:\|(.*?))?\]/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var text = lookaheadMatch[1];
var link = lookaheadMatch[2] ? lookaheadMatch[2] : text;
var e = JSPWikiFormatter.isExternalLink(link) ? createExternalLink(w.output,link) : createTiddlyLink(w.output,link,false,null,w.isStatic,w.tiddler);
createTiddlyText(e,text);
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
},
{
name: 'jspUnWikiLink',
match: config.textPrimitives.unWikiLink+config.textPrimitives.wikiLink,
handler: function(w)
{
w.outputText(w.output,w.matchStart+1,w.nextMatch);
}
},
{
name: 'jspWikiLink',
match: config.textPrimitives.wikiLink,
handler: function(w)
{
if(w.matchStart > 0) {
var preRegExp = new RegExp(config.textPrimitives.anyLetter,'mg');
preRegExp.lastIndex = w.matchStart-1;
var preMatch = preRegExp.exec(w.source);
if(preMatch.index == w.matchStart-1) {
w.outputText(w.output,w.matchStart,w.nextMatch);
return;
}
}
var output = w.output;
if(w.autoLinkWikiWords == true || store.isShadowTiddler(w.matchText)) {
output = createTiddlyLink(w.output,w.matchText,false,null,w.isStatic,w.tiddler);
}
w.outputText(output,w.matchStart,w.nextMatch);
}
},
{
name: 'jspUrlLink',
match: config.textPrimitives.urlPattern,
handler: function(w)
{
w.outputText(createExternalLink(w.output,w.matchText),w.matchStart,w.nextMatch);
}
},
{
name: 'jspBold',
match: '__',
termRegExp: /(__|(?=\n\n))/mg,
element: 'strong',
handler: config.formatterHelpers.createElementAndWikify
},
{
name: 'jspItalic',
match: "''",
termRegExp: /(''|(?=\n\n))/mg,
element: 'em',
handler: config.formatterHelpers.createElementAndWikify
},
{
name: 'jspMonospaced',
match: '\\{\\{\\{',
lookaheadRegExp: /\{\{\{((?:.|\n)*?)\}\}\}/mg,
element: 'code',
handler: config.formatterHelpers.enclosedTextHelper
},
{
name: 'jspWikiStyle',
match: '%%(?:(?:[a-z]+)|(?:\\([a-z:;\\-]+\\)))',
lookaheadRegExp: /%%(?:([a-z]+)|(?:\(([a-z:;\-]+)\)))/mg,
termRegExp: /(\%\%)/mg,
handler: JSPWikiFormatter.wikiStyle
},
{
name: 'jspParagraph',
match: '\\n\\n',
handler: function(w)
{
w.output = createTiddlyElement(w.output,'p');
}
},
{
name: 'jspLineBreak',
match: '\\\\|<br ?/?>',
handler: function(w)
{
createTiddlyElement(w.output,'br');
}
},
{
name: 'jspComment',
match: '<!\\-\\-',
lookaheadRegExp: /<!\-\-((?:.|\n)*?)\-\-!>/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
},
{
name: 'jspHtmlEntitiesEncoding',
match: '&#?[a-zA-Z0-9]{2,8};',
handler: function(w)
{
createTiddlyElement(w.output,'span').innerHTML = w.matchText;
}
}
];
config.parsers.jspwikiFormatter = new Formatter(config.jspwiki.formatters);
config.parsers.jspwikiFormatter.format = 'jspwiki';
config.parsers.jspwikiFormatter.formatTag = 'JSPWikiFormat';
} // end of 'install only once'
//}}}
[[Home]]
[[Plugins]]
[[Experimental]]
[[Basic Formatting]]
[[Document Formatting]]
[[Table Formatting]]
[[Configuration]]
<!--{{{-->
<style type="text/css">
#contentWrapper {display:none;}
#splashScreen {display:block;}
body {background:#fff; color:#000;}
a {color:#04b;}a:hover {background-color:#04b; color:#fff;}.title {color:#841;}
.subtitle {color:#666;}
.header {background:#04b;}
.headerShadow {color:#000;}
.headerShadow a {font-weight:normal; color:#000;}
.headerForeground {color:#fff;}
.headerForeground a {font-weight:normal; color:#8cf;}
.shadow .title {color:#666;}
.viewer table, table.twtable {border:2px solid #666;}.viewer th, .viewer thead td, .twtable th, .twtable thead td {background:#db4; border:1px solid #666; color:#fff;}.viewer td, .viewer tr, .twtable td, .twtable tr {border:1px solid #666;}
/*{{{*/
h1 {font-size:1.5em;font-variant:small-caps;}
h2 {font-size:1.35em;font-variant:small-caps;}
h3 {font-size:1.25em;font-variant:small-caps;}
h4 {font-size:1.1em;}
h5 {font-size:1em;}
/*element,padding,border,margin*/
h1, h2, h3, h4, h5 {
color:#014;background:transparent;
padding-left:0;padding-bottom:1px;
margin-top:1.2em;margin-bottom:0.3em;margin-left:0em;
}
h1 {border-bottom:2px solid #ccc;}
h2, h3 {border-bottom:1px solid #ccc;}
h4, h5 {border-bottom:0px;margin-top:1em;margin-bottom:0em;}
hr {height:0px;border:0;border-top:1px solid silver;}
.headerShadow {padding:1.5em 0em .5em 1em;}
.headerForeground {padding:1.5em 0em .5em 1em;}
.header {background:darkblue;}
/*.headerShadow {color:white;}
.headerForeground {color:black;}*/
#displayArea .tiddlyLinkExisting {text-decoration:underline;}
/* Tiddler title */
.title {color:black;border-bottom:2px solid #ddd;}
/* Tiddler subtitle */
.subtitle {font-size:0.9em;text-align:right;border-bottom:1px solid #ddd;}
.toolbar {padding-top:0px;padding-bottom:0px;color:#04b;}
/* Tiddler body */
.tiddler {-moz-border-radius:1em;border:1px solid #ccc;margin:0.5em;background:#fff;padding:0.5em;}
.tabContents {white-space:nowrap;}
.viewer pre {padding:0;margin-left:0;}
.viewer hr {border:solid 1px silver;}
/*.toolbar {visibility:visible}*/
.selected .toolbar {visibility:visible;color:#00f;}
.toolbar .button {color:#dee;}
.selected .toolbar .button {color:#014}
.tagging, .tagged, .selected .tagging, .selected .tagged {
font-size:75%;padding:0.3em;background-color:#eee;
border-top:1px solid #ccc;border-left:1px solid #ccc;
border-bottom:3px solid #ccc;border-right:3px solid #ccc;
max-width:45%;-moz-border-radius:1em;
}
/*}}}*/#mainMenu {position:relative;left:auto;width:auto;text-align:left;line-height:normal;padding 0em 1em 0em 1em;font-size:normal;}
#mainMenu br {display:none;}
#mainMenu {background:#336699;}
#mainMenu {padding:2px;}
#mainMenu .button, #mainMenu .tiddlyLink {padding-left:0.5em;padding-right:0.5em;color:white;font-size:115%;}
#displayArea {margin-top:0;margin-right:15.5em;margin-bottom:0;margin-left:1em;padding-top:.1em;padding-bottom:.1em;}</style>
<!--}}}-->
<!--{{{-->
<div id="splashScreen">
<div class='header' macro='gradient vert [[ColorPalette::PrimaryLight]] [[ColorPalette::PrimaryMid]]'>
<div class='headerShadow'>
<span class="siteTitle">Martin's wiki</span>
<span class="siteSubtitle">Martin Budden's plugins and extensions for ~TiddlyWiki</span>
</div>
<div class='headerForeground'>
<span class="siteTitle">Martin's wiki</span>
<span class="siteSubtitle">Martin Budden's plugins and extensions for ~TiddlyWiki</span>
</div>
</div>
<div id='mainMenu' refresh='content' tiddler='MainMenu'></div>
<div id='sidebar'>
<div id='sidebarOptions' refresh='content' tiddler='SideBarOptions'></div>
<div id='sidebarTabs' refresh='content' force='true' tiddler='SideBarTabs'></div>
</div>
<div id='displayArea'>
<div id='messageArea'></div>
<div id="s_tiddlerDisplay">
<div class="toolbar"><br></div>
<div class="title" macro="view title">Home</div>
<div class="viewer" macro="view text wikified">Welcome.<br><br>This is where I post <a tiddlylink="TiddlyWiki" refresh="link" class="tiddlyLink tiddlyLinkNonExisting" title="The tiddler 'TiddlyWiki' doesn't yet exist" href="javascript:;">TiddlyWiki</a> macros, plugins and other extensions to make them available to other TiddlyWiki users.<br><span tiddler="Plugins" refresh="content"><span tiddler="Formatters" refresh="content"><table class="twtable"><tbody><tr class="evenRow"><th>Formatter Plugin</th><th>Description</th></tr><tr class="oddRow"><td><a tiddlylink="ExampleFormatterPlugin" refresh="link" class="tiddlyLink tiddlyLinkExisting" title="ExampleFormatterPlugin - MartinBudden, Fri Jul 21 01:00:00 2006" href="javascript:;">ExampleFormatterPlugin</a></td><td>Example empty formatter. You can use this as a template to write your own formatter</td></tr><tr class="evenRow"><td><a tiddlylink="CreoleFormatterPlugin" refresh="link" class="tiddlyLink tiddlyLinkExisting" title="CreoleFormatterPlugin - MartinBudden, Sat Oct 28 01:00:00 2006" href="javascript:;">CreoleFormatterPlugin</a></td><td>Allows Tiddlers to use <a target="_blank" title="External link to http://www.wikicreole.org/" href="http://www.wikicreole.org/" class="externalLink">Creole</a> text formatting</td></tr><tr class="oddRow"><td><a tiddlylink="ConfluenceFormatterPlugin" refresh="link" class="tiddlyLink tiddlyLinkExisting" title="ConfluenceFormatterPlugin - MartinBudden, Sat Dec 9 00:00:00 2006" href="javascript:;">ConfluenceFormatterPlugin</a></td><td>Allows Tiddlers to use <a target="_blank" title="External link to http://confluence.atlassian.com/renderer/notationhelp.action?section=all" href="http://confluence.atlassian.com/renderer/notationhelp.action?section=all" class="externalLink">Confluence</a> text formatting</td></tr><tr class="evenRow"><td><a tiddlylink="JSPWikiFormatterPlugin" refresh="link" class="tiddlyLink tiddlyLinkExisting" title="JSPWikiFormatterPlugin - MartinBudden, Fri Dec 22 00:00:00 2006" href="javascript:;">JSPWikiFormatterPlugin</a></td><td>Allows Tiddlers to use <a target="_blank" title="External link to http://www.jspwiki.org/wiki/TextFormattingRules" href="http://www.jspwiki.org/wiki/TextFormattingRules" class="externalLink">JSPWiki</a> text formatting</td></tr><tr class="oddRow"><td><a tiddlylink="MediaWikiFormatterPlugin" refresh="link" class="tiddlyLink tiddlyLinkExisting" title="MediaWikiFormatterPlugin - MartinBudden, Thu Aug 17 01:00:00 2006" href="javascript:;">MediaWikiFormatterPlugin</a></td><td>Allows Tiddlers to use <a target="_blank" title="External link to http://en.wikipedia.org/wiki/Help:Wikitext_quick_reference#Basic_text_formatting" href="http://en.wikipedia.org/wiki/Help:Wikitext_quick_reference#Basic_text_formatting" class="externalLink">MediaWiki</a> (<a target="_blank" title="External link to http://www.wikipedia.org" href="http://www.wikipedia.org" class="externalLink">WikiPedia</a>) text formatting</td></tr><tr class="evenRow"><td><a tiddlylink="PmWikiFormatterPlugin" refresh="link" class="tiddlyLink tiddlyLinkExisting" title="PmWikiFormatterPlugin - MartinBudden, Sun Sep 3 01:00:00 2006" href="javascript:;">PmWikiFormatterPlugin</a></td><td>Allows Tiddlers to use <a target="_blank" title="External link to http://pmwiki.org/wiki/PmWiki/TextFormattingRules" href="http://pmwiki.org/wiki/PmWiki/TextFormattingRules" class="externalLink">PmWiki</a> text formatting</td></tr><tr class="oddRow"><td><a tiddlylink="PBWikiFormatterPlugin" refresh="link" class="tiddlyLink tiddlyLinkExisting" title="PBWikiFormatterPlugin - MartinBudden, Sun Sep 3 01:00:00 2006" href="javascript:;">PBWikiFormatterPlugin</a></td><td>Allows Tiddlers to use <a target="_blank" title="External link to http://yummy.pbwiki.com/WikiStyle" href="http://yummy.pbwiki.com/WikiStyle" class="externalLink">PBWiki</a> text formatting</td></tr><tr class="evenRow"><td><a tiddlylink="SocialtextFormatterPlugin" refresh="link" class="tiddlyLink tiddlyLinkExisting" title="SocialtextFormatterPlugin - MartinBudden, Sun Jan 21 00:00:00 2007" href="javascript:;">SocialtextFormatterPlugin</a></td><td>Allows Tiddlers to use <a target="_blank" title="External link to http://www.socialtext.com/" href="http://www.socialtext.com/" class="externalLink">Socialtext</a> text formatting</td></tr><tr class="oddRow"><td><a tiddlylink="TracFormatterPlugin" refresh="link" class="tiddlyLink tiddlyLinkExisting" title="TracFormatterPlugin - MartinBudden, Fri Jul 21 01:00:00 2006" href="javascript:;">TracFormatterPlugin</a></td><td>Allows Tiddlers to use <a target="_blank" title="External link to http://trac.edgewall.org/wiki/WikiFormatting" href="http://trac.edgewall.org/wiki/WikiFormatting" class="externalLink">Trac</a> text formatting</td></tr><tr class="evenRow"><td><a tiddlylink="TWikiFormatterPlugin" refresh="link" class="tiddlyLink tiddlyLinkExisting" title="TWikiFormatterPlugin - MartinBudden, Fri Jul 21 01:00:00 2006" href="javascript:;">TWikiFormatterPlugin</a></td><td>Allows Tiddlers to use <a target="_blank" title="External link to http://twiki.org/cgi-bin/view/TWiki/TextFormattingRules" href="http://twiki.org/cgi-bin/view/TWiki/TextFormattingRules" class="externalLink">TWiki</a> text formatting</td></tr><tr class="oddRow"><td><a tiddlylink="WikispacesFormatterPlugin" refresh="link" class="tiddlyLink tiddlyLinkExisting" title="WikispacesFormatterPlugin - MartinBudden, Fri Nov 23 00:00:00 2007" href="javascript:;">WikispacesFormatterPlugin</a></td><td>Allows Tiddlers to use <a target="_blank" title="External link to http://www.wikispaces.com" href="http://www.wikispaces.com" class="externalLink">Wikispaces</a> text formatting</td></tr></tbody></table></span><br><span tiddler="Adaptors" refresh="content"><table class="twtable"><tbody><tr class="evenRow"><th>Adaptor Plugin</th><th>Description</th></tr><tr class="oddRow"><td><a tiddlylink="ExampleAdaptorPlugin" refresh="link" class="tiddlyLink tiddlyLinkExisting" title="ExampleAdaptorPlugin - MartinBudden, Sun Mar 11 00:00:00 2007" href="javascript:;">ExampleAdaptorPlugin</a></td><td>Example empty adaptor. You can use this as a template to write your own adaptor</td></tr><tr class="evenRow"><td><a tiddlylink="ccTiddlyAdaptorPlugin" refresh="link" class="tiddlyLink tiddlyLinkExisting" title="ccTiddlyAdaptorPlugin - MartinBudden, Sun Feb 25 00:00:00 2007" href="javascript:;">ccTiddlyAdaptorPlugin</a></td><td>Adaptor for moving and converting data to and from ccTiddly wikis</td></tr><tr class="oddRow"><td><a tiddlylink="JSPWikiAdaptorPlugin" refresh="link" class="tiddlyLink tiddlyLinkExisting" title="JSPWikiAdaptorPlugin - MartinBudden, Sun Feb 25 00:00:00 2007" href="javascript:;">JSPWikiAdaptorPlugin</a></td><td>Adaptor for moving and converting data to and from JSP Wikis</td></tr><tr class="evenRow"><td><a tiddlylink="MediaWikiAdaptorPlugin" refresh="link" class="tiddlyLink tiddlyLinkExisting" title="MediaWikiAdaptorPlugin - MartinBudden, Sat Mar 17 00:00:00 2007" href="javascript:;">MediaWikiAdaptorPlugin</a></td><td>Adaptor for moving and converting data from MediaWikis</td></tr><tr class="oddRow"><td><a tiddlylink="SocialtextAdaptorPlugin" refresh="link" class="tiddlyLink tiddlyLinkExisting" title="SocialtextAdaptorPlugin - MartinBudden, Sun Feb 25 00:00:00 2007" href="javascript:;">SocialtextAdaptorPlugin</a></td><td>Adaptor for moving and converting data to and from Socialtext Wikis</td></tr><tr class="evenRow"><td><a tiddlylink="TWikiAdaptorPlugin" refresh="link" class="tiddlyLink tiddlyLinkExisting" title="TWikiAdaptorPlugin - MartinBudden, Sun Feb 25 00:00:00 2007" href="javascript:;">TWikiAdaptorPlugin</a></td><td>Adaptor for moving and converting data to and from TWikis</td></tr></tbody></table></span><br><br><table class="twtable"><tbody><tr class="evenRow"><th>Plugin</th><th>Description</th></tr><tr class="oddRow"><td><a tiddlylink="ExamplePlugin" refresh="link" class="tiddlyLink tiddlyLinkExisting" title="ExamplePlugin - MartinBudden, Mon Jul 31 01:00:00 2006" href="javascript:;">ExamplePlugin</a></td><td>Example empty plugin. You can use this as a template to write your own plugin</td></tr><tr class="evenRow"><td><a tiddlylink="DisableWikiLinksPlugin" refresh="link" class="tiddlyLink tiddlyLinkExisting" title="DisableWikiLinksPlugin - MartinBudden, Fri Jul 21 01:00:00 2006" href="javascript:;">DisableWikiLinksPlugin</a></td><td>Allows you to disable TiddlyWiki's automatic linking of WikiWords</td></tr><tr class="oddRow"><td><a tiddlylink="DisableStrikeThroughPlugin" refresh="link" class="tiddlyLink tiddlyLinkExisting" title="DisableStrikeThroughPlugin - MartinBudden, Mon Feb 18 00:00:00 2008" href="javascript:;">DisableStrikeThroughPlugin</a></td><td>Allows you to disable TiddlyWiki's strikethrough formatting</td></tr><tr class="evenRow"><td><a tiddlylink="SHA-1UnwoundPlugin" refresh="link" class="tiddlyLink tiddlyLinkExisting" title="SHA-1UnwoundPlugin - MartinBudden, Fri Jul 21 01:00:00 2006" href="javascript:;">SHA-1UnwoundPlugin</a></td><td>Faster wersion of SHA-1 with unwound loops</td></tr><tr class="oddRow"><td><a tiddlylink="CryptoTEAPlugin" refresh="link" class="tiddlyLink tiddlyLinkExisting" title="CryptoTEAPlugin - MartinBudden, Sun Feb 4 00:00:00 2007" href="javascript:;">CryptoTEAPlugin</a></td><td>TEA (Tiny Encryption Algorithm) and supporting Cryptographic functions</td></tr><tr class="evenRow"><td><a tiddlylink="EncryptionCommandsPlugin" refresh="link" class="tiddlyLink tiddlyLinkExisting" title="EncryptionCommandsPlugin - Martin Budden, Sat Jan 6 00:00:00 2007" href="javascript:;">EncryptionCommandsPlugin</a></td><td>Use this in association with CryptoTEAPlugin to encrypt individual tiddlers</td></tr></tbody></table></span><br><br>See <a target="_blank" title="External link to http://solarsystem.tiddlypedia.com" href="http://solarsystem.tiddlypedia.com" class="externalLink">http://solarsystem.tiddlypedia.com</a> and <a target="_blank" title="External link to http://nordic.tiddlypedia.com" href="http://nordic.tiddlypedia.com" class="externalLink">http://nordic.tiddlypedia.com</a> for examples of TiddlyWikis using Wikipedia format and content.<br><br>See <a tiddlylink="Experimental" refresh="link" class="tiddlyLink tiddlyLinkExisting" title="Experimental - MartinBudden, Fri Apr 18 00:00:00 2008" href="javascript:;">Experimental</a> for plugins under development.<br><br><span>©</span> 2006,2007 Martin Budden<br><sup><img src="http://www.tiddlywiki.com/favicon.ico"> TiddlyWiki <span>2.4.0 (beta 2)</span></sup></div>
<div class="toolbar"><br></div>
</div>
</div>
</div>
<!--}}}-->
/***
|''Name:''|MediaWikiAdaptorPlugin|
|''Description:''|Adaptor for moving and converting data from MediaWikis|
|''Author:''|Martin Budden (mjbudden (at) gmail (dot) com)|
|''Source:''|http://www.martinswiki.com/#MediaWikiAdaptorPlugin |
|''CodeRepository:''|http://svn.tiddlywiki.org/Trunk/contributors/MartinBudden/adaptors/MediaWikiAdaptorPlugin.js |
|''Version:''|0.5.8|
|''Date:''|Jul 27, 2007|
|''Comments:''|Please make comments at http://groups.google.co.uk/group/TiddlyWikiDev |
|''License:''|[[Creative Commons Attribution-ShareAlike 2.5 License|http://creativecommons.org/licenses/by-sa/2.5/]] |
|''~CoreVersion:''|2.2.0|
|''Max number of tiddlers to download''|<<option txtMediaAdaptorLimit>>|
MediaWiki REST documentation is at:
http://meta.wikimedia.org/w/api.php
http://meta.wikimedia.org/w/query.php
***/
//{{{
if(!version.extensions.MediaWikiAdaptorPlugin) {
version.extensions.MediaWikiAdaptorPlugin = {installed:true};
if(config.options.txtMediaAdaptorLimit == undefined)
{config.options.txtMediaAdaptorLimit = '500';}
function MediaWikiAdaptor()
{
this.host = null;
this.workspace = null;
return this;
}
MediaWikiAdaptor.serverType = 'mediawiki';
MediaWikiAdaptor.serverParsingErrorMessage = "Error parsing result from server";
MediaWikiAdaptor.errorInFunctionMessage = "Error in function MediaWikiAdaptor.%0";
MediaWikiAdaptor.doHttpGET = function(uri,callback,params,headers,data,contentType,username,password)
{
return doHttp('GET',uri,data,contentType,username,password,callback,params,headers);
};
MediaWikiAdaptor.prototype.setContext = function(context,userParams,callback)
{
if(!context) context = {};
context.userParams = userParams;
if(callback) context.callback = callback;
context.adaptor = this;
if(!context.host)
context.host = this.host;
if(!context.workspace && this.workspace)
context.workspace = this.workspace;
return context;
};
MediaWikiAdaptor.fullHostName = function(host)
{
if(!host)
return '';
if(!host.match(/:\/\//))
host = 'http://' + host;
if(host.substr(host.length-1) != '/')
host = host + '/';
return host;
};
MediaWikiAdaptor.minHostName = function(host)
{
return host ? host.replace(/^http:\/\//,'').replace(/\/$/,'') : '';
};
MediaWikiAdaptor.normalizedTitle = function(title)
{
var n = title.charAt(0).toUpperCase() + title.substr(1);
return n.replace(/\s/g,'_');
};
// Convert a MediaWiki timestamp in YYYY-MM-DDThh:mm:ssZ format into a JavaScript Date object
MediaWikiAdaptor.dateFromTimestamp = function(timestamp)
{
var dt = timestamp;
return new Date(Date.UTC(dt.substr(0,4),dt.substr(5,2)-1,dt.substr(8,2),dt.substr(11,2),dt.substr(14,2)));
};
MediaWikiAdaptor.anyChild = function(obj)
{
for(var key in obj) {
return obj[key];
}
return null;
};
MediaWikiAdaptor.prototype.openHost = function(host,context,userParams,callback)
{
this.host = MediaWikiAdaptor.fullHostName(host);
context = this.setContext(context,userParams,callback);
if(context.callback) {
context.status = true;
window.setTimeout(function() {callback(context,userParams);},0);
}
return true;
};
MediaWikiAdaptor.getWorkspaceId = function(workspace)
{
var workspaces = {
"media": -2, "special":-1,
"":0, "talk":1,"user":2,"user talk":3,"meta":4,"meta talk":5,"image":6,"image talk":7,
"mediawiki":8,"mediawiki talk":9,"template":10,"template talk":11,"help":12,"help talk":13,
"category":14,"category talk":15};
workspace = workspace.toLowerCase();
var id = workspaces[workspace];
if(!id) {
if(workspace=="" || workspace=="main")
id = 0;
else if(workspace.lastIndexOf("talk") != -1)
id = 5;
else
id = 4;
}
return id;
};
MediaWikiAdaptor.prototype.openWorkspace = function(workspace,context,userParams,callback)
{
if(!workspace)
workspace = "";
this.workspace = workspace;
context = this.setContext(context,userParams,callback);
if(workspace) {
if(context.workspaces) {
for(var i=0;i<context.workspaces.length;i++) {
if(context.workspaces[i].name == workspace) {
this.workspaceId = context.workspaces[i].id;
break;
}
}
} else {
workspace = workspace.toLowerCase();
this.workspaceId = MediaWikiAdaptor.getWorkspaceId(workspace);
}
}
if(!this.workspaceId) {
if(workspace=="" || workspace.toLowerCase()=="main")
this.workspaceId = 0;
else if(workspace.lastIndexOf("talk") != -1)
this.workspaceId = 5;
else
this.workspaceId = 4;
}
if(context.callback) {
context.status = true;
window.setTimeout(function() {callback(context,userParams);},0);
}
return true;
};
MediaWikiAdaptor.prototype.getWorkspaceList = function(context,userParams,callback)
{
context = this.setContext(context,userParams,callback);
if(context.workspace) {
context.status = true;
context.workspaces = [{name:context.workspace,title:context.workspace}];
if(context.callback)
window.setTimeout(function() {callback(context,userParams);},0);
return true;
}
var uriTemplate = '%0api.php?format=json&action=query&meta=siteinfo&siprop=namespaces';
var uri = uriTemplate.format([context.host]);
var req = MediaWikiAdaptor.doHttpGET(uri,MediaWikiAdaptor.getWorkspaceListCallback,context);
return typeof req == 'string' ? req : true;
};
MediaWikiAdaptor.getWorkspaceListCallback = function(status,context,responseText,uri,xhr)
{
context.status = false;
if(status) {
try {
eval('var info=' + responseText);
} catch (ex) {
context.statusText = exceptionText(ex,MediaWikiAdaptor.serverParsingErrorMessage);
if(context.callback)
context.callback(context,context.userParams);
return;
}
var namespaces = info.query.namespaces;
var list = [];
for(var i in namespaces) {
item = {};
item.id = namespaces[i]['id'];
item.title = namespaces[i]['*'];
item.name = item.title;
list.push(item);
}
context.workspaces = list;
context.status = true;
} else {
context.statusText = xhr.statusText;
}
if(context.callback)
context.callback(context,context.userParams);
};
// get a list of the tiddlers in the current workspace
MediaWikiAdaptor.prototype.getTiddlerList = function(context,userParams,callback,filter)
{
context = this.setContext(context,userParams,callback);
if(!context.tiddlerLimit)
context.tiddlerLimit = config.options.txtMediaAdaptorLimit==0 ? null : config.options.txtMediaAdaptorLimit;
var limit = context.tiddlerLimit;
if(filter) {
var re = /\[(\w+)\[([ \w]+)\]\]/;
var match = re.exec(filter);
if(match) {
var filterParams = MediaWikiAdaptor.normalizedTitle(match[2]);
switch(match[1]) {
case 'tag':
context.responseType = 'pages';
var uriTemplate = '%0query.php?format=json&what=category&cpnamespace=%1&cplimit=%2&cptitle=%3';
break;
case 'template':
context.responseType = 'query.embeddedin';
uriTemplate = '%0api.php?format=json&action=query&list=embeddedin&einamespace=0&eititle=Template:%3';
if(limit)
uriTemplate += '&eilimit=%2';
break;
default:
break;
}
} else {
var list = [];
var params = filter.parseParams('anon',null,false);
for(var i=1; i<params.length; i++) {
var tiddler = new Tiddler(params[i].value);
tiddler.fields.workspaceId = this.workspaceId;
list.push(tiddler);
}
context.tiddlers = list;
context.status = true;
if(context.callback)
window.setTimeout(function() {callback(context,userParams);},0);
return true;
}
} else {
context.responseType = 'query.allpages';
uriTemplate = '%0api.php?format=json&action=query&list=allpages';
if(this.workspaceId != 0)
uriTemplate += '&apnamespace=%1';
if(limit)
uriTemplate += '&aplimit=%2';
}
var host = MediaWikiAdaptor.fullHostName(this.host);
var uri = uriTemplate.format([host,this.workspaceId,limit,filterParams]);
var req = MediaWikiAdaptor.doHttpGET(uri,MediaWikiAdaptor.getTiddlerListCallback,context);
return typeof req == 'string' ? req : true;
};
MediaWikiAdaptor.getTiddlerListCallback = function(status,context,responseText,uri,xhr)
{
context.status = false;
context.statusText = MediaWikiAdaptor.errorInFunctionMessage.format(['getTiddlerListCallback']);
if(status) {
try {
eval('var info=' + responseText);
var pages;
if(context.responseType == 'query.embeddedin')
pages = info.query.embeddedin;
else if(context.responseType == 'query.allpages')
pages = info.query.allpages;
else
pages = info.pages;
var list = [];
for(i in pages) {
var title = pages[i].title;
if(title && !store.isShadowTiddler(title)) {
tiddler = new Tiddler(title);
tiddler.fields.workspaceId = pages[i].ns;
list.push(tiddler);
}
}
context.tiddlers = list;
} catch (ex) {
context.statusText = exceptionText(ex,MediaWikiAdaptor.serverParsingErrorMessage);
if(context.callback)
context.callback(context,context.userParams);
return;
}
context.status = true;
} else {
context.statusText = xhr.statusText;
}
if(context.callback)
context.callback(context,context.userParams);
};
MediaWikiAdaptor.prototype.generateTiddlerInfo = function(tiddler)
{
var info = {};
var host = this && this.host ? this.host : MediaWikiAdaptor.fullHostName(tiddler.fields['server.host']);
if(host.match(/w\/$/)) {
host = host.replace(/w\/$/,'');
var uriTemplate = '%0wiki/%2';
} else {
uriTemplate = '%0index.php?title=%2';
}
info.uri = uriTemplate.format([host,this.workspace,tiddler.title]);
return info;
};
MediaWikiAdaptor.prototype.getTiddlerRevision = function(title,revision,context,userParams,callback)
{
context = this.setContext(context,userParams,callback);
context.revision = revision;
return this.getTiddlerInternal(title,context,userParams,callback);
};
MediaWikiAdaptor.prototype.getTiddler = function(title,context,userParams,callback)
{
context = this.setContext(context,userParams,callback);
context.title = title;
var host = MediaWikiAdaptor.fullHostName(context.host);
var uriTemplate = '%0api.php?format=json&action=query&prop=revisions&titles=%1&rvprop=content|timestamp|user';
if(context.revision)
uriTemplate += '&rvstartid=%2&rvlimit=1';
uri = uriTemplate.format([host,MediaWikiAdaptor.normalizedTitle(context.title),context.revision]);
context.tiddler = new Tiddler(context.title);
context.tiddler.fields.wikiformat = 'mediawiki';
context.tiddler.fields['server.host'] = MediaWikiAdaptor.minHostName(host);
var req = MediaWikiAdaptor.doHttpGET(uri,MediaWikiAdaptor.getTiddlerCallback,context);
return typeof req == 'string' ? req : true;
};
MediaWikiAdaptor.prototype.getTiddlerPostProcess = function(context)
{
return context.tiddler;
};
MediaWikiAdaptor.getTiddlerCallback = function(status,context,responseText,uri,xhr)
{
context.status = false;
if(status) {
var content = null;
try {
eval('var info=' + responseText);
var page = MediaWikiAdaptor.anyChild(info.query.pages);
var revision = MediaWikiAdaptor.anyChild(page.revisions);
var text = revision['*'];
context.tiddler.fields['server.page.revision'] = String(revision['revid']);
var host = context.tiddler.fields['server.host'];
if(host.indexOf('wikipedia')==-1) {
context.tiddler.modified = MediaWikiAdaptor.dateFromTimestamp(revision['timestamp']);
context.tiddler.modifier = revision['user'];
} else {
// content is from wikipedia
context.tiddler.created = version.date;
context.tiddler.modified= version.date;
// remove links to other language articles
text = text.replace(/\[\[[a-z\-]{2,12}:(?:.*?)\]\](?:\r?)(?:\n?)/g,'');
}
context.tiddler.text = text;
var catRegExp = /\[\[(Category:[^|\]]*?)\]\]/mg;
var tags = '';
var delim = '';
catRegExp.lastIndex = 0;
var match = catRegExp.exec(text);
while(match) {
tags += delim;
if(match[1].indexOf(' ')==-1)
tags += match[1];
else
tags += '[[' + match[1] + ']]';
delim = ' ';
match = catRegExp.exec(text);
}
context.tiddler.tags = tags;
context.tiddler = context.adaptor.getTiddlerPostProcess.call(context.adaptor,context);
} catch (ex) {
context.statusText = exceptionText(ex,MediaWikiAdaptor.serverParsingErrorMessage);
if(context.callback)
context.callback(context,context.userParams);
return;
}
context.status = true;
} else {
context.statusText = xhr.statusText;
}
if(context.callback)
context.callback(context,context.userParams);
};
MediaWikiAdaptor.prototype.getTiddlerRevisionList = function(title,limit,context,userParams,callback)
// get a list of the revisions for a tiddler
{
context = this.setContext(context,userParams,callback);
var uriTemplate = '%0api.php?format=json&action=query&prop=revisions&titles=%1&rvlimit=%2&rvprop=timestamp|user|comment';
if(!limit)
limit = 5;
var host = MediaWikiAdaptor.fullHostName(context.host);
var uri = uriTemplate.format([host,MediaWikiAdaptor.normalizedTitle(title),limit]);
var req = MediaWikiAdaptor.doHttpGET(uri,MediaWikiAdaptor.getTiddlerRevisionListCallback,context);
return typeof req == 'string' ? req : true;
};
MediaWikiAdaptor.getTiddlerRevisionListCallback = function(status,context,responseText,uri,xhr)
{
context.status = false;
if(status) {
var content = null;
try {
eval('var info=' + responseText);
var page = MediaWikiAdaptor.anyChild(info.query.pages);
var title = page.title;
var revisions = page.revisions;
var list = [];
for(var i in revisions) {
var tiddler = new Tiddler(title);
tiddler.modified = MediaWikiAdaptor.dateFromTimestamp(revisions[i].timestamp);
tiddler.modifier = revisions[i].user;
//�displayMessage("tm"+tiddler.modifier);
tiddler.fields.comment = revisions[i].comment;
tiddler.fields['server.page.id'] = MediaWikiAdaptor.normalizedTitle(title);
tiddler.fields['server.page.name'] = title;
//tiddler.fields['server.page.revision'] = String(revisions[i].revid);
list.push(tiddler);
}
context.revisions = list;
} catch (ex) {
context.statusText = exceptionText(ex,MediaWikiAdaptor.serverParsingErrorMessage);
if(context.callback)
context.callback(context,context.userParams);
return;
}
context.status = true;
} else {
context.statusText = xhr.statusText;
}
if(context.callback)
context.callback(context,context.userParams);
};
// MediaWikiAdaptor.prototype.putTiddler not supported
MediaWikiAdaptor.prototype.close = function()
{
return true;
};
config.adaptors[MediaWikiAdaptor.serverType] = MediaWikiAdaptor;
} // end of 'install only once'
//}}}
/***
|''Name:''|MediaWikiFormatterPlugin|
|''Description:''|Allows Tiddlers to use [[MediaWiki|http://meta.wikimedia.org/wiki/Help:Wikitext]] ([[WikiPedia|http://meta.wikipedia.org/]]) text formatting|
|''Author:''|Martin Budden (mjbudden (at) gmail (dot) com)|
|''Source:''|http://www.martinswiki.com/#MediaWikiFormatterPlugin |
|''CodeRepository:''|http://svn.tiddlywiki.org/Trunk/contributors/MartinBudden/formatters/MediaWikiFormatterPlugin.js |
|''Version:''|0.4.6|
|''Date:''|Jul 27, 2007|
|''Comments:''|Please make comments at http://groups.google.co.uk/group/TiddlyWikiDev |
|''License:''|[[Creative Commons Attribution-ShareAlike 2.5 License|http://creativecommons.org/licenses/by-sa/3.0/]] |
|''~CoreVersion:''|2.1.0|
|''Display instrumentation''|<<option chkDisplayInstrumentation>>|
|''Display empty template links:''|<<option chkMediaWikiDisplayEmptyTemplateLinks>>|
|''Allow zooming of thumbnail images''|<<option chkMediaWikiDisplayEnableThumbZoom>>|
|''List references''|<<option chkMediaWikiListReferences>>|
|''Display unsupported magic words''|<<option chkDisplayMediaWikiMagicWords>>|
This is the MediaWikiFormatterPlugin, which allows you to insert MediaWiki formated text into a TiddlyWiki.
The aim is not to fully emulate MediaWiki, but to allow you to work with MediaWiki content off-line and then resync the content with your MediaWiki later on, with the expectation that only minor edits will be required.
To use MediaWiki format in a Tiddler, tag the Tiddler with MediaWikiFormat or set the tiddler's {{{wikiformat}}} extended field to {{{mediawiki}}}.
!!!Issues
There are (at least) the following known issues:
# Not all styles from http://meta.wikimedia.org/wiki/MediaWiki:Common.css incorporated
## Styles for tables don't yet match Wikipedia styles.
## Styles for image galleries don't yet match Wikipedia styles.
# Anchors not yet supported.
!!!Not supported
# Template parser functions (also called colon functions) http://meta.wikimedia.org/wiki/ParserFunctions eg {{ #functionname: argument 1 | argument 2 | argument 3... }}
# Magic words and variables http://meta.wikimedia.org/wiki/Help:Magic_words eg {{{__TOC__}}}, {{CURRENTDAY}}, {{PAGENAME}}
# {{{^''}}} (italic at start of line) indents, makes italic and quotes with guilmot quote
!!!No plans to support
# Template substitution on save http://meta.wikimedia.org/wiki/Help:Substitution eg {{ subst: templatename }}
***/
//{{{
// Ensure that the MediaWikiFormatter Plugin is only installed once.
if(!version.extensions.MediaWikiFormatterPlugin) {
version.extensions.MediaWikiFormatterPlugin = {installed:true};
if(version.major < 2 || (version.major == 2 && version.minor < 1))
{alertAndThrow('MediaWikiFormatterPlugin requires TiddlyWiki 2.1 or later.');}
if(config.options.chkDisplayInstrumentation == undefined)
{config.options.chkDisplayInstrumentation = false;}
if(config.options.chkMediaWikiDisplayEmptyTemplateLinks == undefined)
{config.options.chkMediaWikiDisplayEmptyTemplateLinks = false;}
if(config.options.chkMediaWikiDisplayEnableThumbZoom == undefined)
{config.options.chkMediaWikiDisplayEnableThumbZoom = false;}
if(config.options.chkMediaWikiListReferences == undefined)
{config.options.chkMediaWikiListReferences = false;}
if(config.options.chkDisplayMediaWikiMagicWords == undefined)
{config.options.chkDisplayMediaWikiMagicWords = false;}
//<div class='viewer' macro='view text wikified'></div>;
config.macros.include = {};
config.macros.include.handler = function(place,macroName,params,wikifier,paramString,tiddler)
{
if((tiddler instanceof Tiddler) && params[0]) {
var host = store.getValue(tiddler,'server.host');
if(host && host.indexOf('wikipedia')!=-1) {
var t = store.fetchTiddler(params[0]);
var text = store.getValue(t,'text');
wikify(text,place,highlightHack,tiddler);
}
}
};
MediaWikiFormatter = {}; // 'namespace' for local functions
mwDebug = function(out,str)
{
createTiddlyText(out,str.replace(/\n/mg,'\\n').replace(/\r/mg,'RR'));
createTiddlyElement2(out,'br');
};
MediaWikiFormatter.Tiddler_changed = Tiddler.prototype.changed;
Tiddler.prototype.changed = function()
{
if((this.fields.wikiformat==config.parsers.mediawikiFormatter.format) || this.isTagged(config.parsers.mediawikiFormatter.formatTag)) {
this.links = [];
var tiddlerLinkRegExp = /\[\[(?::?([A-Za-z]{2,}:)?)(#?)([^\|\]]*?)(?:(\]\])|(\|(.*?)\]\]))/mg;
tiddlerLinkRegExp.lastIndex = 0;
var match = tiddlerLinkRegExp.exec(this.text);
while(match) {
if(!match[1] && !match[2])
this.links.pushUnique(match[3]);
match = tiddlerLinkRegExp.exec(this.text);
}
} else if(!this.isTagged('systemConfig')) {
MediaWikiFormatter.Tiddler_changed.apply(this,arguments);
return;
}
this.linksUpdated = true;
};
TiddlyWiki.prototype.getMediaWikiPagesInNamespace = function(namespace)
{
var results = [];
this.forEachTiddler(function(title,tiddler) {
if(tiddler.title.indexOf(namespace)==0)
results.push(tiddler);
});
results.sort(function(a,b) {return a.title < b.title ? -1 : +1;});
return results;
};
TiddlyWiki.prototype.getMediaWikiPages = function()
{
var results = [];
this.forEachTiddler(function(title,tiddler) {
if(!tiddler.isTagged('excludeLists') && tiddler.title.indexOf(':')==-1)
results.push(tiddler);
});
results.sort(function(a,b) {return a.title < b.title ? -1 : +1;});
return results;
};
TiddlyWiki.prototype.getMediaWikiOtherPages = function()
{
var results = [];
this.forEachTiddler(function(title,tiddler) {
if(!tiddler.isTagged('excludeLists') && tiddler.title.indexOf(':')!=-1)
results.push(tiddler);
});
results.sort(function(a,b) {return a.title < b.title ? -1 : +1;});
return results;
};
config.macros.list.otherpages = {};
config.macros.list.otherpages.handler = function(params)
{
return store.getMediaWikiOtherPages();
};
config.macros.list.templates = {};
config.macros.list.templates.handler = function(params)
{
return store.getMediaWikiPagesInNamespace('Template:');
};
config.macros.list.categories = {};
config.macros.list.categories.handler = function(params)
{
return store.getMediaWikiPagesInNamespace('Category:');
};
function createTiddlyElement2(parent,element)
{
return parent.appendChild(document.createElement(element));
}
config.formatterHelpers.createElementAndWikify = function(w)
{
w.subWikifyTerm(createTiddlyElement2(w.output,this.element),this.termRegExp);
};
MediaWikiFormatter.hijackListAll = function ()
{
MediaWikiFormatter.oldListAll = config.macros.list.all.handler;
config.macros.list.all.handler = function(params) {
return store.getMediaWikiPages();
};
};
MediaWikiFormatter.hijackListAll();
MediaWikiFormatter.normalizedTitle = function(title)
{
title = title.trim();
var n = title.charAt(0).toUpperCase() + title.substr(1);
return n.replace(/\s/g,'_');
};
MediaWikiFormatter.expandVariable = function(w,variable)
{
switch(variable) {
case 'PAGENAME':
createTiddlyText(w.output,w.tiddler.title);
break;
case 'PAGENAMEE':
createTiddlyText(w.output,MediaWikiFormatter.normalizedTitle(w.tiddler.title));
break;
case 'REVISIONID':
var text = w.tiddler.fields['server.revision'];
if(text)
createTiddlyText(w.output,text);
break;
default:
return false;
}
return true;
};
MediaWikiFormatter.getParserFunctionParams = function(text)
{
var params = [];
// #if: foo | do if true | do if false
text += '|';
//var fRegExp = / ? # ?([a-z]*) ?:/mg;
//var fRegExp = /#(if) : (foo) :/mg;
var fRegExp = /(#([a-z]*) *: ([^\|]*))\|/mg;
fRegExp.lastIndex = 0;
var match = fRegExp.exec(text);
var pRegExp = /([^\|]*)\|/mg;
if(match) {
pRegExp.lastIndex = fRegExp.lastIndex;
match = pRegExp.exec(text);
}
var i = 1;
while(match) {
params[i] = match[1].trim();
i++;
match = pRegExp.exec(text);
}
return params;
};
MediaWikiFormatter.getTemplateParams = function(text)
{
var params = {};
text += '|';
var pRegExp = /(?:([^\|]*)=)?([^\|]*)\|/mg;
var match = pRegExp.exec(text);
if(match) {
match = pRegExp.exec(text);
}
var i = 1;
while(match) {
if(match[1]) {
params[match[1]] = match[2];
} else {
params[i] = match[2];
i++;
}
match = pRegExp.exec(text);
}
return params;
};
MediaWikiFormatter.expandParserFunction = function(w,text,expr,params)
{
var fnRegExp = / *#(if) */mg;
var t = '';//params[0];
fnRegExp.lastIndex = 0;
var match = fnRegExp.exec(text);
if(match) {
switch(match[1]) {
case 'if':
t = expr.trim()=='' ? params[2] : params[1];
break;
default:
break;
}
}
return t;
};
MediaWikiFormatter.expandTemplate = function(w,templateText,params)
{
var text = templateText;
text = text.replace(/<noinclude>((?:.|\n)*?)<\/noinclude>/mg,'');// remove text between noinclude tags
var includeOnlyRegExp = /<includeonly>((?:.|\n)*?)<\/includeonly>/mg;
var t = '';
var match = includeOnlyRegExp.exec(text);
while(match) {
t += match[1];
match = includeOnlyRegExp.exec(text);
}
text = t == '' ? text : t;
var paramsRegExp = /\{\{\{(.*?)(?:\|(.*?))?\}\}\}/mg;
t = '';
var pi = 0;
match = paramsRegExp.exec(text);
while(match) {
var name = match[1];
var val = params[name];
if(!val) {
val = match[2];
}
if(!val) {
val = '';//val = match[0];
}
t += text.substring(pi,match.index) + val;
pi = paramsRegExp.lastIndex;
match = paramsRegExp.exec(text);
}
t += text.substring(pi);
return t;
//return t == '' ? text : t;
/* //displayMessage("ss:"+text.substring(pi));
t += text.substring(pi);
t = MediaWikiFormatter.evaluateTemplateParserFunctions(t);
//{{#if: {{{perihelion|}}} | <tr><th>[[Perihelion|Perihelion distance]]:</th><td>{{{perihelion}}}</td></tr>}}
//{{#if:{{{symbol|}}} | {{{symbol}}} | }}
text = t == '' ? text : t;
displayMessage("t2:"+text);
return text;
*/
};
MediaWikiFormatter.endOfParams = function(w,text)
{
var p = 0;
var i = text.indexOf('|');
if(i==-1) {return -1;}
var n = text.indexOf('\n');
if(n!=-1 && n<i) {return -1;}
var b = text.indexOf('[[');
if(b!=-1 && b<i) {return -1;}
b = text.indexOf('{{');
while(b!=-1 && b<i) {
p += b;
text = text.substr(b);
var c = text.indexOf('}}');
p += c;
text = text.substr(c);
i = text.indexOf('|');
if(i==-1) {return -1;}
n = text.indexOf('\n');
if(n!=-1 && n<i) {return -1;}
b = text.indexOf('{{');
i = -1;
}
return i;
};
MediaWikiFormatter.readToDelim = function(w)
//!!! this is a bit rubish, needs doing properly.
{
var dRegExp = /\|/mg;
var sRegExp = /\[\[/mg;
var tRegExp = /\]\]/mg;
dRegExp.lastIndex = w.startMatch;
var dMatch = dRegExp.exec(w.source);
sRegExp.lastIndex = w.startMatch;
var sMatch = sRegExp.exec(w.source);
tRegExp.lastIndex = w.startMatch;
var tMatch = tRegExp.exec(w.source);
if(!tMatch) {
return false;
}
while(sMatch && sMatch.index<tMatch.index) {
if(dMatch && dMatch.index<sMatch.index) {
w.nextMatch = dRegExp.lastIndex;
w.matchLength = dMatch.index - w.startMatch;
return true;
}
tRegExp.lastIndex = sRegExp.lastIndex;
tMatch = tRegExp.exec(w.source);
w.nextMatch = tRegExp.lastIndex;
dRegExp.lastIndex = w.nextMatch;
dMatch = dRegExp.exec(w.source);
sRegExp.lastIndex = w.nextMatch;
sMatch = sRegExp.exec(w.source);
tRegExp.lastIndex = w.nextMatch;
tMatch = tRegExp.exec(w.source);
}
if(dMatch && dMatch.index<tMatch.index) {
w.nextMatch = dRegExp.lastIndex;
w.matchLength = dMatch.index - w.startMatch;
return true;
}
if(tMatch) {
w.nextMatch = tRegExp.lastIndex;
w.matchLength = tMatch.index - w.startMatch;
return false;
}
w.nextMatch = tRegExp.lastIndex;
w.matchLength = -1;
return false;
};
MediaWikiFormatter.getParams = function(w)
{
var params = [];
var i = 1;
w.startMatch = w.nextMatch;
var read = MediaWikiFormatter.readToDelim(w);
if(w.matchLength!=-1) {
params[i] = w.source.substr(w.startMatch,w.matchLength);
}
while(read) {
i++;
w.startMatch = w.nextMatch;
read = MediaWikiFormatter.readToDelim(w);
if(w.matchLength!=-1) {
params[i] = w.source.substr(w.startMatch,w.matchLength);
}
}
return params;
};
MediaWikiFormatter.setFromParams = function(w,p)
{
var r = {};
var re = /\s*(.*?)=(?:(?:"(.*?)")|(?:'(.*?)')|((?:\w|%|#)*))/mg;
var match = re.exec(p);
while(match)
{
var s = match[1].unDash();
if(match[2]) {
r[s] = match[2];
} else if(match[3]) {
r[s] = match[3];
} else {
r[s] = match[4];
}
match = re.exec(p);
}
return r;
};
MediaWikiFormatter.setAttributesFromParams = function(e,p)
{
var re = /\s*(.*?)=(?:(?:"(.*?)")|(?:'(.*?)')|((?:\w|%|#)*))/mg;
var match = re.exec(p);
while(match) {
var s = match[1].unDash();
if(s == 'bgcolor') {
s = 'backgroundColor';
}
try {
if(match[2]) {
e.setAttribute(s,match[2]);
} else if(match[3]) {
e.setAttribute(s,match[3]);
} else {
e.setAttribute(s,match[4]);
}
}
catch(ex) {}
match = re.exec(p);
}
};
config.mediawiki = {};
config.mediawiki.formatters = [
{
name: 'mediaWikiHeading',
match: '^={1,6}(?!=)\\n?',
termRegExp: /(={1,6}\n?)/mg,
handler: function(w)
{
var output = w.output;
var e = createTiddlyElement2(output,'h' + w.matchLength);
var a = createTiddlyElement2(e,'a');
var t = w.tiddler ? MediaWikiFormatter.normalizedTitle(w.tiddler.title) + ':' : '';
var len = w.source.substr(w.nextMatch).indexOf('=');
a.setAttribute('name',t+MediaWikiFormatter.normalizedTitle(w.source.substr(w.nextMatch,len)));
w.subWikifyTerm(e,this.termRegExp);
}
},
{
name: 'mediaWikiTable',
// see http://www.mediawiki.org/wiki/Help:Tables, http://meta.wikimedia.org/wiki/Help:Table
match: '^\\{\\|', // ^{|
tableTerm: '\\n\\|\\}', // |}
rowStart: '\\n\\|\\-', // \n|-
cellStart: '\\n!|!!|\\|\\||\\n\\|', //\n! or !! or || or \n|
caption: '\\n\\|\\+',
rowTerm: null,
cellTerm: null,
inCellTerm: null,
tt: 0,
debug: null,
rowTermRegExp: null,
handler: function(w)
{
if(!this.rowTermRegExp) {
this.rowTerm = '(' + this.tableTerm +')|(' + this.rowStart + ')';
this.cellTerm = this.rowTerm + '|(' + this.cellStart + ')';
this.inCellTerm = '(' + this.match + ')|' + this.rowTerm + '|(' + this.cellStart + ')';
this.caption = '(' + this.caption + ')|' + this.cellTerm;
this.rowTermRegExp = new RegExp(this.rowTerm,'mg');
this.cellTermRegExp = new RegExp(this.cellTerm,'mg');
this.inCellTermRegExp = new RegExp(this.inCellTerm,'mg');
this.captionRegExp = new RegExp(this.caption,'mg');
}
this.captionRegExp.lastIndex = w.nextMatch;
var match = this.captionRegExp.exec(w.source);
if(!match) {return;}
var output = w.output;
var table = createTiddlyElement2(output,'table');
var rowContainer = table;
var i = w.source.indexOf('\n',w.nextMatch);
if(i>w.nextMatch) {
MediaWikiFormatter.setAttributesFromParams(table,w.source.substring(w.nextMatch,i));
w.nextMatch = i;
}
var rowCount = 0;
var eot = false;
if(match[1]) {
var caption = createTiddlyElement2(table,'caption');
w.nextMatch = this.captionRegExp.lastIndex;
var captionText = w.source.substring(w.nextMatch);
var n = captionText.indexOf('\n');
captionText = captionText.substr(0,n);
i = MediaWikiFormatter.endOfParams(w,captionText);
if(i!=-1) {
captionText = w.source.substr(w.nextMatch,i);
w.nextMatch += i+1;
}
if(caption != table.firstChild) {
table.insertBefore(caption,table.firstChild);
}
w.subWikify(caption,this.cellTerm);
w.nextMatch -= w.matchLength;
this.cellTermRegExp.lastIndex = w.nextMatch;
var match2 = this.cellTermRegExp.exec(w.source);
if(match2) {
if(match2[3]) {
eot = this.rowHandler(w,createTiddlyElement2(rowContainer,'tr'));
rowCount++;
}
}
} else if(match[3]) {
w.nextMatch = this.captionRegExp.lastIndex-match[3].length;
} else if(match[4]) {
w.nextMatch = this.captionRegExp.lastIndex-match[4].length;
eot = this.rowHandler(w,createTiddlyElement2(rowContainer,'tr'));
rowCount++;
}
this.rowTermRegExp.lastIndex = w.nextMatch;
match = this.rowTermRegExp.exec(w.source);
while(match && eot==false) {
if(match[1]) {
w.nextMatch = this.rowTermRegExp.lastIndex;
if(w.tableDepth==0) {
return;
}
} else if(match[2]) {
var rowElement = createTiddlyElement2(rowContainer,'tr');
w.nextMatch += match[2].length;
i = w.source.indexOf('\n',w.nextMatch);
if(i>w.nextMatch) {
MediaWikiFormatter.setAttributesFromParams(rowElement,w.source.substring(w.nextMatch,i));
w.nextMatch = i;
}
eot = this.rowHandler(w,rowElement);
}
rowCount++;
this.rowTermRegExp.lastIndex = w.nextMatch;
match = this.rowTermRegExp.exec(w.source);
}//# end while
if(w.tableDepth==0) {
w.nextMatch +=3;
}
},//# end handler
rowHandler: function(w,e)
{
var cell;
this.inCellTermRegExp.lastIndex = w.nextMatch;
var match = this.inCellTermRegExp.exec(w.source);
while(match) {
if(match[1]) {
w.tableDepth++;
w.subWikify(cell,this.tableTerm);
w.nextMatch = this.tt;
w.tableDepth--;
return false;
} else if(match[2]) {
this.tt = this.inCellTermRegExp.lastIndex;
return true;
} else if(match[3]) {
return false;
} else if(match[4]) {
var len = match[4].length;
cell = createTiddlyElement2(e,match[4].substr(len-1)=='!'?'th':'td');
w.nextMatch += len;
this.inCellTermRegExp.lastIndex = w.nextMatch;
var lookahead = this.inCellTermRegExp.exec(w.source);
if(!lookahead) {
return false;
}
var cellText = w.source.substr(w.nextMatch,lookahead.index-w.nextMatch);
var oldSource = w.source;
var i = MediaWikiFormatter.endOfParams(w,cellText);//cellText.indexOf('|');
if(i!=-1) {
cellText = cellText.replace(/^\+/mg,''); //!!hack until I fix this properly
MediaWikiFormatter.setAttributesFromParams(cell,cellText.substr(0,i-1));
cellText = cellText.substring(i+1);
}
cellText = cellText.replace(/^\s*/mg,'');
w.source = cellText;
w.nextMatch = 0;
w.subWikifyUnterm(cell);
w.source = oldSource;
w.nextMatch = lookahead.index;
}
this.inCellTermRegExp.lastIndex = w.nextMatch;
match = this.inCellTermRegExp.exec(w.source);
}//# end while
return false;
}//# end rowHandler
},
{
name: 'mediaWikiList',
match: '^[\\*#;:]+',
lookaheadRegExp: /(?:(?:(\*)|(#)|(;)|(:))+)(?: ?)/mg,
termRegExp: /(\n)/mg,
handler: function(w)
{
var stack = [w.output];
var currLevel = 0, currType = null;
var listType, itemType;
w.nextMatch = w.matchStart;
this.lookaheadRegExp.lastIndex = w.nextMatch;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
while(lookaheadMatch && lookaheadMatch.index == w.nextMatch) {
if(lookaheadMatch[1]) {
listType = 'ul';
itemType = 'li';
} else if(lookaheadMatch[2]) {
listType = 'ol';
itemType = 'li';
} else if(lookaheadMatch[3]) {
listType = 'dl';
itemType = 'dt';
} else if(lookaheadMatch[4]) {
listType = 'dl';
itemType = 'dd';
}
var listLevel = lookaheadMatch[0].length;
w.nextMatch += listLevel;
if(listLevel > currLevel) {
for(var i=currLevel; i<listLevel; i++) {
stack.push(createTiddlyElement2(stack[stack.length-1],listType));
}
} else if(listLevel < currLevel) {
for(i=currLevel; i>listLevel; i--) {
stack.pop();
}
} else if(listLevel == currLevel && listType != currType) {
stack.pop();
stack.push(createTiddlyElement2(stack[stack.length-1],listType));
}
currLevel = listLevel;
currType = listType;
var e = createTiddlyElement2(stack[stack.length-1],itemType);
var ci = w.source.indexOf(':',w.nextMatch);
var ni = w.source.indexOf('\n',w.nextMatch);
if(itemType=='dt' && (ni==-1 || (ci!=-1 && ci<ni))) {
w.subWikifyTerm(e,/(:)/mg);
w.nextMatch--;
} else {
w.subWikifyTerm(e,this.termRegExp);
}
this.lookaheadRegExp.lastIndex = w.nextMatch;
lookaheadMatch = this.lookaheadRegExp.exec(w.source);
}
}
},
{
name: 'mediaWikiRule',
match: '^----+$\\n?',
handler: function(w)
{
createTiddlyElement2(w.output,'hr');
}
},
{
name: 'mediaWikiLeadingSpaces',
match: '^ ',
lookaheadRegExp: /^ /mg,
termRegExp: /(\n)/mg,
handler: function(w)
{
var e = createTiddlyElement2(w.output,'pre');
while(true) {
w.subWikifyTerm(e,this.termRegExp);
createTiddlyElement2(e,'br');
this.lookaheadRegExp.lastIndex = w.nextMatch;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.nextMatch) {
w.nextMatch += lookaheadMatch[0].length;
} else {
break;
}
}
}
},
{
name: 'mediaWikiImage',
match: '\\[\\[(?:[Ii]mage|Bild):',
lookaheadRegExp: /\[\[(?:[Ii]mage|Bild):/mg,
defaultPx: 180,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var params = MediaWikiFormatter.getParams(w);
var src = params[1];
src = src.trim().replace(/ /mg,'_');
src = src.substr(0,1).toUpperCase() + src.substring(1);
var palign = null;
var ptitle = null;
var psrc = false;
var px = null;
var pthumb = false;
var pframed = false;
for(var i=2;i<params.length;i++) {
var p = params[i];
if(p=='right'||p=='left'||p=='center'||p=='none') {
palign = p;
} else if(p=='thumbnail'||p=='thumb') {
pthumb = true;
} else if(p=='framed') {
pframed = true;
} else if(/\d{1,4} ?px/.exec(p)) {
px = p.substr(0,p.length-2).trim();
} else {
ptitle = p;
}
}//#end for
if(pthumb) {
var output = w.output;
if(!palign) {
palign = 'right';
}
if(!px) {
px = 180;
}
psrc = px + 'px-' + src;
var t = createTiddlyElement(output,'div',null,'thumb'+(palign?' t'+palign:''));
var s = createTiddlyElement2(t,'div');
s.style['width'] = Number(px) + 2 + 'px';
var a = createTiddlyElement(s,'a',null,'internal');
if(config.options.chkMediaWikiDisplayEnableThumbZoom) {
a.href = src;
}
a.title = ptitle;
var img = createTiddlyElement2(a,'img');
img.src = 'images/' + psrc;
img.width = px;
img.longdesc = 'Image:' + src;
img.alt = ptitle;
var tc = createTiddlyElement(s,'div',null,'thumbcaption');
var oldSource = w.source; var oldMatch = w.nextMatch;
w.source = ptitle; w.nextMatch = 0;
w.subWikifyUnterm(tc);
w.source = oldSource; w.nextMatch = oldMatch;
if(config.options.chkMediaWikiDisplayEnableThumbZoom) {
var tm = createTiddlyElement(tc,'div',null,'magnify');
tm.style['float'] = 'right';
var ta = createTiddlyElement(tm,'a',null,'internal');
ta.title = 'Enlarge';
timg = createTiddlyElement2(ta,'img'); timg.src = 'magnify-clip.png'; timg.alt = 'Enlarge'; timg.width = '15'; timg.height = '11';
ta.href = src;
}
} else {
a = createTiddlyElement(w.output,'a',null,'image');
a.title = ptitle;
img = createTiddlyElement2(a,'img');
if(palign) {img.align = palign;}
img.src = px ? 'images/' + px + 'px-' + src : 'images/' + src;
if(px) {img.width = px;}
img.longdesc = 'Image:' + src;
img.alt = ptitle;
}
}
}//#end image handler
},
{
name: 'mediaWikiExplicitLink',
match: '\\[\\[',
lookaheadRegExp: /\[\[(?:([a-z]{2,3}:)?)(#?)([^\|\]]*?)(?:(\]\](\w*))|(\|(.*?)\]\]))/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
if(!lookaheadMatch[1]) {
var e;
var link = lookaheadMatch[3];
var text = link;
link = link.substr(0,1).toUpperCase() + link.substring(1);
if(lookaheadMatch[4]) {
if(lookaheadMatch[2]) {
var a = createTiddlyElement(w.output,'a');
var t = w.tiddler ? MediaWikiFormatter.normalizedTitle(w.tiddler.title) + ':' : '';
t = '#' + t + MediaWikiFormatter.normalizedTitle(link);
a.setAttribute('href',t);
a.title = '#' + MediaWikiFormatter.normalizedTitle(link);
createTiddlyText(a,'#'+link);
} else {
e = createTiddlyLink(w.output,link,false,null,w.isStatic,w.tiddler);
if(lookaheadMatch[5]) {
text += lookaheadMatch[5];
}
createTiddlyText(e,text);
}
} else if(lookaheadMatch[6]) {
if(link.charAt(0)==':')
link = link.substring(1);
e = createTiddlyLink(w.output,link,false,null,w.isStatic,w.tiddler);
var oldSource = w.source; var oldMatch = w.nextMatch;
w.source = lookaheadMatch[7].trim(); w.nextMatch = 0;
w.subWikifyUnterm(e);
w.source = oldSource; w.nextMatch = oldMatch;
}
}
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
},
{
name: 'mediaWikiTemplate',
match: '\\{\\{[^\\{]',
lookaheadRegExp: /\{\{((?:.|\n)*?)\}\}/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var lastIndex = this.lookaheadRegExp.lastIndex;
var contents = lookaheadMatch[1];
if(MediaWikiFormatter.expandVariable(w,contents)) {
w.nextMatch = lastIndex;
return;
}
var i = contents.indexOf('|');
var title = i==-1 ? contents : contents.substr(0,i);
title = title.trim().replace(/_/mg,' ');
if(title.substr(0,1)=='#') {
var parserFn = true;
var j = contents.indexOf(':');
var expr = contents.substring(j+1,i);
i = title.indexOf(':');
title = title.substr(0,i);
} else {
title = 'Template:' + title.substr(0,1).toUpperCase() + title.substring(1);
var tiddler = store.fetchTiddler(title);
}
var oldSource = w.source;
if(tiddler) {
var params = {};
if(i!=-1) {
params = MediaWikiFormatter.getTemplateParams(lookaheadMatch[1]);
}
w.source = MediaWikiFormatter.expandTemplate(w,tiddler.text,params);
w.nextMatch = 0;
w.subWikifyUnterm(w.output);
} else if(parserFn) {
if(i!=-1) {
params = MediaWikiFormatter.getParserFunctionParams(lookaheadMatch[1]);
}
w.source = MediaWikiFormatter.expandParserFunction(w,title,expr,params);
w.nextMatch = 0;
w.subWikifyUnterm(w.output);
} else {
if(config.options.chkMediaWikiDisplayEmptyTemplateLinks) {
w.source = '[['+title+']]';
w.nextMatch = 0;
w.subWikifyUnterm(w.output);
}
}
w.source = oldSource;
w.nextMatch = lastIndex;
}
}
},
{
name: 'mediaWikiParagraph',
match: '\\n{2,}',
handler: function(w)
{
w.output = createTiddlyElement2(w.output,'p');
}
},
{
name: 'mediaWikiExplicitLineBreak',
match: '<br ?/?>',
handler: function(w)
{
createTiddlyElement2(w.output,'br');
}
},
{
name: 'mediaWikiExplicitLineBreakWithParams',
match: "<br(?:\\s*(?:(?:.*?)=[\"']?(?:.*?)[\"']?))*?\\s*/?>",
lookaheadRegExp: /<br((?:\s+(?:.*?)=["']?(?:.*?)["']?)*?)?\s*\/?>/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var e =createTiddlyElement2(w.output,'br');
if(lookaheadMatch[1]) {
MediaWikiFormatter.setAttributesFromParams(e,lookaheadMatch[1]);
}
w.nextMatch = this.lookaheadRegExp.lastIndex;// empty tag
}
}
},
{
name: 'mediaWikiTitledUrlLink',
match: '\\[' + config.textPrimitives.urlPattern + '(?:\\s+[^\\]]+)?' + '\\]',
handler: function(w)
{
var lookaheadRegExp = new RegExp('\\[(' + config.textPrimitives.urlPattern + ')(?:\\s+([^\[]+))?' + '\\]','mg');
lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index==w.matchStart) {
var link = lookaheadMatch[1];
if(lookaheadMatch[2]) {
var e = createExternalLink(w.output,link);
var oldSource = w.source; var oldMatch = w.nextMatch;
w.source = lookaheadMatch[2].trim(); w.nextMatch = 0;
w.subWikifyUnterm(e);
w.source = oldSource; w.nextMatch = oldMatch;
} else {
e = createExternalLink(createTiddlyElement2(w.output,'sup'),link);
w.linkCount++;
createTiddlyText(e,'['+w.linkCount+']');
}
w.nextMatch = lookaheadRegExp.lastIndex;
}
}
},
{
name: 'mediaWikiUrlLink',
match: config.textPrimitives.urlPattern,
handler: function(w)
{
w.outputText(createExternalLink(w.output,w.matchText),w.matchStart,w.nextMatch);
}
},
{
name: "mediaWikiCharacterFormat",
match: "'{2,5}|(?:<[usbi]>)",
handler: function(w)
{
switch(w.matchText) {
case "'''''":
var e = createTiddlyElement(w.output,'strong');
w.subWikifyTerm(createTiddlyElement(e,'em'),/('''''|(?=\n))/mg);
break;
case "'''":
w.subWikifyTerm(createTiddlyElement(w.output,'strong'),/('''|(?=\n))/mg);
break;
case "''":
w.subWikifyTerm(createTiddlyElement(w.output,'em'),/((?:''(?!'))|(?=\n))/mg);
break;
case '<u>':
w.subWikifyTerm(createTiddlyElement(w.output,'u'),/(<\/u>|(?=\n))/mg);
break;
case '<s>':
w.subWikifyTerm(createTiddlyElement(w.output,'del'),/(<\/s>|(?=\n))/mg);
break;
case '<b>':
w.subWikifyTerm(createTiddlyElement(w.output,'b'),/(<\/b>|(?=\n))/mg);
break;
case '<i>':
w.subWikifyTerm(createTiddlyElement(w.output,'i'),/(<\/i>|(?=\n))/mg);
break;
}
}
},
{
name: 'mediaWikiTemplateParam',
match: '\\{\\{\\{',
lookaheadRegExp: /(\{\{\{(?:.|\n)*?\}\}\})/mg,
element: 'span',
handler: config.formatterHelpers.enclosedTextHelper
},
{
name: 'mediaWikiInsertReference',
match: '<ref[^/]*>',
lookaheadRegExp: /<ref(\s+(?:.*?)=["']?(?:.*?)["']?)?>([^<]*?)<\/ref>/mg,
handler: function(w)
{
if(config.browser.isIE) {
refRegExp = /<ref[^\/]*>((?:.|\n)*?)<\/ref>/mg;
refRegExp.lastIndex = w.matchStart;
var refMatch = refRegExp.exec(w.source);
if(refMatch && refMatch.index == w.matchStart) {
w.nextMatch = refRegExp.lastIndex;
return;
}
}
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var x = {id:'',value:''};
w.nextMatch = this.lookaheadRegExp.lastIndex;
if(!w.referenceCount) {
w.referenceCount = 0;
w.references = {};
}
var s = createTiddlyElement(w.output,'sup',null,'reference');
var a = createTiddlyElement2(s,'a');
var prefix = w.tiddler ? w.tiddler.title + ':' : '';
var name;
if(lookaheadMatch[1]) {
var r = MediaWikiFormatter.setFromParams(w,lookaheadMatch[1]);
name = r.name ? r.name.trim() : '';
name = name.replace(/ /g,'_');
s.id = prefix + '_ref-' + name;// + '_' + nameCount;(w.referenceCount+1);
if(!w.references[name]) {
w.references[name] = x;
w.references[name].id = w.referenceCount;
w.references[name].value = lookaheadMatch[2].trim();
}
} else {
w.references[w.referenceCount] = x;
w.references[w.referenceCount].id = w.referenceCount;
w.references[w.referenceCount].value = lookaheadMatch[2].trim();
name = w.referenceCount;
s.id = prefix + '_ref-' + w.referenceCount;
}
w.referenceCount++;
a.title = lookaheadMatch[2].trim();//mb, extra to wikipedia
a.href = '#' + prefix + '_note-' + name;
a.innerHTML = '['+w.referenceCount+']';
}
}
},
{
name: 'mediaWikiListReferences',
match: '<references ?/>',
lookaheadRegExp: /<references ?\/>/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(config.options.chkMediaWikiListReferences && w.referenceCount) {
var ol = createTiddlyElement(w.output,'ol',null,'references');
var oldSource = w.source;
if(w.referenceCount>0) {
for(var i in w.references) {
var li = createTiddlyElement2(ol,'li');
var prefix = w.tiddler ? w.tiddler.title + ':' : '';
var b = createTiddlyElement2(li,'b');
var a = createTiddlyElement2(b,'a');
li.id = prefix + '_note-' + i;
a.href = '#' + prefix + '_ref-' + i;
a.innerHTML = '^';
w.source = w.references[i].value;
w.nextMatch = 0;
w.subWikifyUnterm(li);
}
}
w.source = oldSource;
}
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
},
{
name: 'mediaWikiRepeatReference',
match: '<ref[^/]*/>',
lookaheadRegExp: /<ref(\s+(?:.*?)=["'](?:.*?)["'])?\s*\/>/mg,
handler: function(w)
{
if(config.browser.isIE) {
refRegExp = /<ref.*?\/>/mg;
refRegExp.lastIndex = w.matchStart;
var refMatch = refRegExp.exec(w.source);
if(refMatch && refMatch.index == w.matchStart) {
w.nextMatch = refRegExp.lastIndex;
return;
}
}
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var x = {id:'',value:''};
w.nextMatch = this.lookaheadRegExp.lastIndex;
var s = createTiddlyElement(w.output,"sup",null,"reference");
var a = createTiddlyElement2(s,"a");
var prefix = w.tiddler ? w.tiddler.title : '';
if(lookaheadMatch[1]) {
var r = {};
r = MediaWikiFormatter.setFromParams(w,lookaheadMatch[1]);
var name = r.name ? r.name.trim() : '';
name = name.replace(/ /g,'_');
s.id = prefix + '_ref-' + name +'_' + (w.referenceCount+1);
var count = w.references && w.references[name] ? (w.references[name].id+1) : '?';
}
a.href = '#' + prefix + '_note-' + name;
a.innerHTML = '['+count+']';
a.title = name;
}
}//# end handler
},
{
name: 'mediaWikiHtmlEntitiesEncoding',
match: '&#?[a-zA-Z0-9]{2,8};',
handler: function(w)
{
if(!config.browser.isIE)
createTiddlyElement(w.output,"span").innerHTML = w.matchText;
}
},
{
name: 'mediaWikiComment',
match: '<!\\-\\-',
lookaheadRegExp: /<!\-\-((?:.|\n)*?)\-\->/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
},
{
name: 'mediaWikiIncludeOnly',
match: '<includeonly>',
lookaheadRegExp: /<includeonly>((?:.|\n)*?)<\/includeonly>/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
},
{
name: 'mediaWikiNoWiki',
match: '<nowiki>',
lookaheadRegExp: /<nowiki>((?:.|\n)*?)<\/nowiki>/mg,
element: 'span',
handler: config.formatterHelpers.enclosedTextHelper
},
{
name: 'mediaWikiPreNoWiki',
match: '<pre>\s*<nowiki>',
lookaheadRegExp: /<pre>\s*<nowiki>((?:.|\n)*?)<\/nowiki>\s*<\/pre>/mg,
element: 'pre',
handler: config.formatterHelpers.enclosedTextHelper
},
{
name: 'mediaWikiPre',
match: '<pre>',
lookaheadRegExp: /<pre>((?:.|\n)*?)<\/pre>/mg,
element: 'pre',
handler: config.formatterHelpers.enclosedTextHelper
},
{
name: 'mediaWikiMagicWords',
match: '__',
lookaheadRegExp: /__([A-Z]*?)__/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
if(lookaheadMatch[1]=='NOTOC') {
} else if(config.options.chkDisplayMediaWikiMagicWords) {
w.outputText(w.output,w.matchStart,w.nextMatch);
}
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
},
{
name: 'mediaWikiGallery',
match: '<gallery>',
lookaheadRegExp: /[Ii]mage:(.*?)\n/mg,
handler: function(w)
{
var table = createTiddlyElement(w.output,'table',null,'gallery');
table.cellspacing = '0';
table.cellpadding = '0';
var rowElem = createTiddlyElement2(table,'tr');
var col = 0;
this.lookaheadRegExp.lastIndex = w.matchStart;
var nM = w.nextMatch;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
var oldSource = w.source;
while(lookaheadMatch) {
nM += lookaheadMatch[1].length;
w.source = lookaheadMatch[1] +']]';//!! ]] is hack until getParams is working
w.nextMatch = 0;
var params = MediaWikiFormatter.getParams(w);
var src = params[1];
src = src.trim().replace(/ /mg,'_');
src = src.substr(0,1).toUpperCase() + src.substring(1);
var palign = 'right';
var psrc = '120px-'+src;
var px = 120;
var pframed = false;
ptitle = null;
for(var i=2;i<params.length;i++) {
var p = params[i];
if(p=='right'||p=='left'||p=='center'||p=='none') {
palign = p;
} else if(p=='framed') {
pframed = true;
} else if(/\d{1,4}px/.exec(p)) {
px = p.substr(0,p.length-2).trim();
psrc = px + 'px-' + src;
} else {
ptitle = p;
}
}//#end for
var td = createTiddlyElement2(rowElem,'td');
var gb = createTiddlyElement(td,'div',null,'gallerybox');
var t = createTiddlyElement(gb,'div',null,'thumb');
t.style['padding'] = '26px 0';
var a = createTiddlyElement2(t,'a');
if(config.options.chkMediaWikiDisplayEnableThumbZoom) {
a.href = src;
}
a.title = ptitle;
var img = createTiddlyElement2(a,'img');
img.src = psrc;
img.width = px;
img.alt = '';
var gt = createTiddlyElement(gb,'div',null,'gallerytext');
p = createTiddlyElement2(gt,'p');
var oldSource2 = w.source; var oldMatch = w.nextMatch;
w.source = ptitle; w.nextMatch = 0;
w.subWikifyUnterm(p);
w.source = oldSource2; w.nextMatch = oldMatch;
col++;
if(col>3) {
rowElem = createTiddlyElement2(table,'tr');
col = 0;
}
w.source = oldSource;
lookaheadMatch = this.lookaheadRegExp.exec(w.source);
}
w.nextMatch = nM + '<gallery>'.length*2+1+'Image:'.length;//!! hack
}
},
{
name: 'mediaWikiHtmlTag',
match: "<[a-zA-Z]{2,}(?:\\s*(?:(?:.*?)=[\"']?(?:.*?)[\"']?))*?>",
lookaheadRegExp: /<([a-zA-Z]{2,})((?:\s+(?:.*?)=["']?(?:.*?)["']?)*?)?\s*(\/)?>/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var e =createTiddlyElement2(w.output,lookaheadMatch[1]);
if(lookaheadMatch[2]) {
MediaWikiFormatter.setAttributesFromParams(e,lookaheadMatch[2]);
}
if(lookaheadMatch[3]) {
w.nextMatch = this.lookaheadRegExp.lastIndex;
} else {
w.subWikify(e,'</'+lookaheadMatch[1]+'>');
}
}
}
}
];
config.parsers.mediawikiFormatter = new Formatter(config.mediawiki.formatters);
config.parsers.mediawikiFormatter.format = 'mediawiki';
config.parsers.mediawikiFormatter.formatTag = 'MediaWikiFormat';
} //# end of 'install only once'
//}}}
/***
|''Name:''|PBWikiFormatterPlugin|
|''Description:''|Allows Tiddlers to use [[PBWiki|http://yummy.pbwiki.com/WikiStyle]] text formatting|
|''Author:''|Martin Budden (mjbudden (at) gmail (dot) com)|
|''Source:''|http://www.martinswiki.com/#PBWikiFormatterPlugin |
|''CodeRepository:''|http://svn.tiddlywiki.org/Trunk/contributors/MartinBudden/formatters/PBWikiFormatterPlugin.js |
|''Version:''|0.2.1|
|''Date:''|May 7, 2007|
|''Comments:''|Please make comments at http://groups.google.co.uk/group/TiddlyWikiDev |
|''License:''|[[Creative Commons Attribution-ShareAlike 2.5 License|http://creativecommons.org/licenses/by-sa/2.5/]]|
|''~CoreVersion:''|2.1.0|
This is an early release of the PBWikiFormatterPlugin, which allows you to insert PBWiki formated text
into a TiddlyWiki.
The aim is not to fully emulate PBWiki, but to allow you to work with PBWiki content off-line and then resync the content with your PBWiki later on, with the expectation that only minor edits will be required.
To use PBWiki format in a Tiddler, tag the Tiddler with PBWikiFormat or set the tiddler's {{{wikiformat}}} extended field to {{{pbwiki}}}
Please report any defects you find at http://groups.google.co.uk/group/TiddlyWikiDev
!!!Issues
There are (at least) the following known issues:
# Strikethrough yet not supported.
# Vertical bars to create |boxes| not supported.
# Space at the begining of a line to create a box not supported.
# email links not supported.
# <top>, <toc>, <random> and <views> not supported.
***/
//{{{
// Ensure that the PBWikiFormatterPlugin is only installed once.
if(!version.extensions.PBWikiFormatterPlugin) {
version.extensions.PBWikiFormatterPlugin = {installed:true};
if(version.major < 2 || (version.major == 2 && version.minor < 1))
{alertAndThrow('PBWikiFormatterPlugin requires TiddlyWiki 2.1 or later.');}
PBWikiFormatter = {}; // 'namespace' for local functions
pbDebug = function(out,str)
{
createTiddlyText(out,str.replace(/\n/mg,'\\n').replace(/\r/mg,'RR'));
createTiddlyElement(out,'br');
};
PBWikiFormatter.setAttributesFromParams = function(e,p)
{
var re = /\s*(.*?)=(?:(?:"(.*?)")|(?:'(.*?)')|((?:\w|%|#)*))/mg;
var match = re.exec(p);
while(match) {
var s = match[1].unDash();
if(s=='bgcolor') {
s = 'backgroundColor';
}
try {
if(match[2]) {
e.setAttribute(s,match[2]);
} else if(match[3]) {
e.setAttribute(s,match[3]);
} else {
e.setAttribute(s,match[4]);
}
}
catch(ex) {}
match = re.exec(p);
}
};
config.pbwiki = {};
config.pbwiki.formatters = [
{
name: 'PBWikiHeading',
match: '^!{1,6}',
termRegExp: /(\n)/mg,
handler: function(w)
{
w.subWikifyTerm(createTiddlyElement(w.output,'h' + w.matchLength),this.termRegExp);
}
},
{
name: 'PBWikiTable',
match: '^\\|(?:[^\\n]*)\\|$',
lookaheadRegExp: /^\|([^\n]*)\|$/mg,
rowTermRegExp: /(\|$\n?)/mg,
cellRegExp: /(?:\|([^\n\|]*)\|)|(\|$\n?)/mg,
cellTermRegExp: /((?:\x20*)\|)/mg,
handler: function(w)
{
var table = createTiddlyElement(w.output,'table');
var rowContainer = createTiddlyElement(table,'tbody');
var prevColumns = [];
w.nextMatch = w.matchStart;
this.lookaheadRegExp.lastIndex = w.nextMatch;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
while(lookaheadMatch && lookaheadMatch.index == w.nextMatch) {
this.rowHandler(w,createTiddlyElement(rowContainer,'tr'),prevColumns);
this.lookaheadRegExp.lastIndex = w.nextMatch;
lookaheadMatch = this.lookaheadRegExp.exec(w.source);
}
},
rowHandler: function(w,e,prevColumns)
{
var col = 0;
this.cellRegExp.lastIndex = w.nextMatch;
var cellMatch = this.cellRegExp.exec(w.source);
while(cellMatch && cellMatch.index == w.nextMatch) {
if(cellMatch[2]) {
// End of row
w.nextMatch = this.cellRegExp.lastIndex;
break;
} else {
// Cell
w.nextMatch++;
var spaceLeft = false;
var chr = w.source.substr(w.nextMatch,1);
while(chr == ' ') {
spaceLeft = true;
w.nextMatch++;
chr = w.source.substr(w.nextMatch,1);
}
var cell = createTiddlyElement(e,'td');
prevColumns[col] = {rowSpanCount:1, element:cell};
w.subWikifyTerm(cell,this.cellTermRegExp);
if(w.matchText.substr(w.matchText.length-2,1) == ' ') {
// spaceRight
cell.align = spaceLeft ? 'center' : 'left';
} else if(spaceLeft) {
cell.align = 'right';
}
w.nextMatch--;
}
col++;
this.cellRegExp.lastIndex = w.nextMatch;
cellMatch = this.cellRegExp.exec(w.source);
}
}
},
{
name: 'PBWikiList',
match: '^[\\*#]+ ',
lookaheadRegExp: /^([\*#])+ /mg,
termRegExp: /(\n)/mg,
handler: function(w)
{
var stack = [w.output];
var currLevel = 0, currType = null;
var listLevel, listType;
var itemType = 'li';
w.nextMatch = w.matchStart;
this.lookaheadRegExp.lastIndex = w.nextMatch;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
while(lookaheadMatch && lookaheadMatch.index == w.nextMatch) {
listType = lookaheadMatch[1] == '*' ? 'ul' : 'ol';
listLevel = lookaheadMatch[0].length;
w.nextMatch += listLevel;
if(listLevel > currLevel) {
for(var i=currLevel; i<listLevel; i++) {
stack.push(createTiddlyElement(stack[stack.length-1],listType));
}
} else if(listLevel < currLevel) {
for(i=currLevel; i>listLevel; i--) {
stack.pop();
}
} else if(listLevel == currLevel && listType != currType) {
stack.pop();
stack.push(createTiddlyElement(stack[stack.length-1],listType));
}
currLevel = listLevel;
currType = listType;
var e = createTiddlyElement(stack[stack.length-1],itemType);
w.subWikifyTerm(e,this.termRegExp);
this.lookaheadRegExp.lastIndex = w.nextMatch;
lookaheadMatch = this.lookaheadRegExp.exec(w.source);
}
}
},
{
name: 'PBWikiRule',
match: '^---+$\\n?',
handler: function(w) {createTiddlyElement(w.output,'hr');}
},
{
name: 'macro',
match: '<<',
lookaheadRegExp: /<<([^>\s]+)(?:\s*)((?:[^>]|(?:>(?!>)))*)>>/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart && lookaheadMatch[1]) {
w.nextMatch = this.lookaheadRegExp.lastIndex;
invokeMacro(w.output,lookaheadMatch[1],lookaheadMatch[2],w,w.tiddler);
}
}
},
{
name: 'PBWikiExplicitLink',
match: '\\[',
lookaheadRegExp: /\[(.*?)(?:\|(.*?))?\]/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var link = lookaheadMatch[1];
var text = lookaheadMatch[2] ? lookaheadMatch[2] : link;
if(/.*\.(?:gif|jpg|png)/g.exec(link)) {
var img = createTiddlyElement(w.output,'img');
if(lookaheadMatch[2]) {
img.title = text;
}
img.src = link;
} else {
var e = config.formatterHelpers.isExternalLink(link) ? createExternalLink(w.output,link) : createTiddlyLink(w.output,link,false,null,w.isStatic);
createTiddlyText(e,text);
}
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
},
{
name: 'PBWikiNotWikiLink',
match: '~' + config.textPrimitives.wikiLink,
handler: function(w) {w.outputText(w.output,w.matchStart+1,w.nextMatch);}
},
{
name: 'PBWikiWikiLink',
match: config.textPrimitives.wikiLink,
handler: function(w)
{
if(w.matchStart > 0) {
var preRegExp = new RegExp(config.textPrimitives.anyLetter,'mg');
preRegExp.lastIndex = w.matchStart-1;
var preMatch = preRegExp.exec(w.source);
if(preMatch.index == w.matchStart-1) {
w.outputText(w.output,w.matchStart,w.nextMatch);
return;
}
}
var output = w.output;
if(w.autoLinkWikiWords == true || store.isShadowTiddler(w.matchText)) {
output = createTiddlyLink(w.output,w.matchText,false,null,w.isStatic);
}
w.outputText(output,w.matchStart,w.nextMatch);
}
},
{
name: 'PBWikiUrlLink',
match: config.textPrimitives.urlPattern,
handler: function(w) {w.outputText(createExternalLink(w.output,w.matchText),w.matchStart,w.nextMatch);}
},
{
name: 'PBWikiBoldByChar',
match: '\\*\\*',
termRegExp: /(\*\*)/mg,
element: 'strong',
handler: config.formatterHelpers.createElementAndWikify
},
{
name: 'PBWikiItalicByChar',
match: "''",
termRegExp: /('')/mg,
element: 'em',
handler: config.formatterHelpers.createElementAndWikify
},
{
name: 'PBWikiUnderlineByChar',
match: '__',
termRegExp: /(__)/mg,
element: 'u',
handler: config.formatterHelpers.createElementAndWikify
},
/*{
name: 'PBWikiStrikeByChar',
match: ' -',
termRegExp: /(- )/mg,
element: 'strike',
handler: config.formatterHelpers.createElementAndWikify
},*/
{
name: 'PBWikiParagraph',
match: '\\n{2,}',
handler: function(w) {createTiddlyElement(w.output,'p');}
},
{
name: 'PBWikiExplicitLineBreak',
match: '<br ?/?>',
handler: function(w) {createTiddlyElement(w.output,'br');}
},
{
name: 'PBWikiLineBreak',
match: '\\n',
handler: function(w) {createTiddlyElement(w.output,'br');}
},
{
name: 'PBWikiHtmlEntitiesEncoding',
match: '&#?[a-zA-Z0-9]{2,8};',
handler: function(w) {createTiddlyElement(w.output,'span').innerHTML = w.matchText;}
},
{
name: 'PBWikiNotSupported',
match: '<(?:toc|top|random|views).*?>',
handler: function(w) {createTiddlyText(w.output,w.matchText);}
},
{
name: 'PBWikiRaw',
match: '<raw>',
lookaheadRegExp: /<raw>((?:.|\n)*?)<\/raw>/mg,
element: 'span',
handler: config.formatterHelpers.enclosedTextHelper
},
{
name: 'PBWikiVerbatim',
match: '<verbatim>',
lookaheadRegExp: /<verbatim>((?:.|\n)*?)<\/verbatim>/mg,
element: 'span',
handler: config.formatterHelpers.enclosedTextHelper
},
{
name: 'PBWikiHtmlTag',
match: "<[a-zA-Z]{2,}(?:\\s*(?:(?:.*?)=[\"']?(?:.*?)[\"']?))*?>",
lookaheadRegExp: /<([a-zA-Z]{2,})((?:\s+(?:.*?)=["']?(?:.*?)["']?)*?)?\s*(\/)?>/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var e =createTiddlyElement(w.output,lookaheadMatch[1]);
if(lookaheadMatch[2]) {
PBWikiFormatter.setAttributesFromParams(e,lookaheadMatch[2]);
}
if(lookaheadMatch[3]) {
w.nextMatch = this.lookaheadRegExp.lastIndex;// empty tag
} else {
w.subWikify(e,'</'+lookaheadMatch[1]+'>');
}
}
}
}
];
config.parsers.pbwikiFormatter = new Formatter(config.pbwiki.formatters);
config.parsers.pbwikiFormatter.format = 'pbwiki';
config.parsers.pbwikiFormatter.formatTag = 'PBWikiFormat';
} // end of 'install only once'
//}}}
/***
|<html><a name="Top"/></html>''Name:''|PartTiddlerPlugin|
|''Version:''|1.0.6 (2006-11-07)|
|''Source:''|http://tiddlywiki.abego-software.de/#PartTiddlerPlugin|
|''Author:''|UdoBorkowski (ub [at] abego-software [dot] de)|
|''Licence:''|[[BSD open source license]]|
|''TiddlyWiki:''|2.0|
|''Browser:''|Firefox 1.0.4+; InternetExplorer 6.0|
!Table of Content<html><a name="TOC"/></html>
* <html><a href="javascript:;" onclick="window.scrollAnchorVisible('Description',null, event)">Description, Syntax</a></html>
* <html><a href="javascript:;" onclick="window.scrollAnchorVisible('Applications',null, event)">Applications</a></html>
** <html><a href="javascript:;" onclick="window.scrollAnchorVisible('LongTiddler',null, event)">Refering to Paragraphs of a Longer Tiddler</a></html>
** <html><a href="javascript:;" onclick="window.scrollAnchorVisible('Citation',null, event)">Citation Index</a></html>
** <html><a href="javascript:;" onclick="window.scrollAnchorVisible('TableCells',null, event)">Creating "multi-line" Table Cells</a></html>
** <html><a href="javascript:;" onclick="window.scrollAnchorVisible('Tabs',null, event)">Creating Tabs</a></html>
** <html><a href="javascript:;" onclick="window.scrollAnchorVisible('Sliders',null, event)">Using Sliders</a></html>
* <html><a href="javascript:;" onclick="window.scrollAnchorVisible('Revisions',null, event)">Revision History</a></html>
* <html><a href="javascript:;" onclick="window.scrollAnchorVisible('Code',null, event)">Code</a></html>
!Description<html><a name="Description"/></html>
With the {{{<part aPartName> ... </part>}}} feature you can structure your tiddler text into separate (named) parts.
Each part can be referenced as a "normal" tiddler, using the "//tiddlerName//''/''//partName//" syntax (e.g. "About/Features"). E.g. you may create links to the parts, use it in {{{<<tiddler...>>}}} or {{{<<tabs...>>}}} macros etc.
''Syntax:''
|>|''<part'' //partName// [''hidden''] ''>'' //any tiddler content// ''</part>''|
|//partName//|The name of the part. You may reference a part tiddler with the combined tiddler name "//nameOfContainerTidder//''/''//partName//.|
|''hidden''|When defined the content of the part is not displayed in the container tiddler. But when the part is explicitly referenced (e.g. in a {{{<<tiddler...>>}}} macro or in a link) the part's content is displayed.|
|<html><i>any tiddler content</i></html>|<html>The content of the part.<br>A part can have any content that a "normal" tiddler may have, e.g. you may use all the formattings and macros defined.</html>|
|>|~~Syntax formatting: Keywords in ''bold'', optional parts in [...]. 'or' means that exactly one of the two alternatives must exist.~~|
<html><sub><a href="javascript:;" onclick="window.scrollAnchorVisible('Top',null, event)">[Top]</sub></a></html>
!Applications<html><a name="Applications"/></html>
!!Refering to Paragraphs of a Longer Tiddler<html><a name="LongTiddler"/></html>
Assume you have written a long description in a tiddler and now you want to refer to the content of a certain paragraph in that tiddler (e.g. some definition.) Just wrap the text with a ''part'' block, give it a nice name, create a "pretty link" (like {{{[[Discussion Groups|Introduction/DiscussionGroups]]}}}) and you are done.
Notice this complements the approach to first writing a lot of small tiddlers and combine these tiddlers to one larger tiddler in a second step (e.g. using the {{{<<tiddler...>>}}} macro). Using the ''part'' feature you can first write a "classic" (longer) text that can be read "from top to bottom" and later "reuse" parts of this text for some more "non-linear" reading.
<html><sub><a href="javascript:;" onclick="window.scrollAnchorVisible('Top',null, event)">[Top]</sub></a></html>
!!Citation Index<html><a name="Citation"/></html>
Create a tiddler "Citations" that contains your "citations".
Wrap every citation with a part and a proper name.
''Example''
{{{
<part BAX98>Baxter, Ira D. et al: //Clone Detection Using Abstract Syntax Trees.//
in //Proc. ICSM//, 1998.</part>
<part BEL02>Bellon, Stefan: //Vergleich von Techniken zur Erkennung duplizierten Quellcodes.//
Thesis, Uni Stuttgart, 2002.</part>
<part DUC99>Ducasse, St�fane et al: //A Language Independent Approach for Detecting Duplicated Code.//
in //Proc. ICSM//, 1999.</part>
}}}
You may now "cite" them just by using a pretty link like {{{[[Citations/BAX98]]}}} or even more pretty, like this {{{[[BAX98|Citations/BAX98]]}}}.
<html><sub><a href="javascript:;" onclick="window.scrollAnchorVisible('Top',null, event)">[Top]</sub></a></html>
!!Creating "multi-line" Table Cells<html><a name="TableCells"/></html>
You may have noticed that it is hard to create table cells with "multi-line" content. E.g. if you want to create a bullet list inside a table cell you cannot just write the bullet list
{{{
* Item 1
* Item 2
* Item 3
}}}
into a table cell (i.e. between the | ... | bars) because every bullet item must start in a new line but all cells of a table row must be in one line.
Using the ''part'' feature this problem can be solved. Just create a hidden part that contains the cells content and use a {{{<<tiddler >>}}} macro to include its content in the table's cell.
''Example''
{{{
|!Subject|!Items|
|subject1|<<tiddler ./Cell1>>|
|subject2|<<tiddler ./Cell2>>|
<part Cell1 hidden>
* Item 1
* Item 2
* Item 3
</part>
...
}}}
Notice that inside the {{{<<tiddler ...>>}}} macro you may refer to the "current tiddler" using the ".".
BTW: The same approach can be used to create bullet lists with items that contain more than one line.
<html><sub><a href="javascript:;" onclick="window.scrollAnchorVisible('Top',null, event)">[Top]</sub></a></html>
!!Creating Tabs<html><a name="Tabs"/></html>
The build-in {{{<<tabs ...>>}}} macro requires that you defined an additional tiddler for every tab it displays. When you want to have "nested" tabs you need to define a tiddler for the "main tab" and one for every tab it contains. I.e. the definition of a set of tabs that is visually displayed at one place is distributed across multiple tiddlers.
With the ''part'' feature you can put the complete definition in one tiddler, making it easier to keep an overview and maintain the tab sets.
''Example''
The standard tabs at the sidebar are defined by the following eight tiddlers:
* SideBarTabs
* TabAll
* TabMore
* TabMoreMissing
* TabMoreOrphans
* TabMoreShadowed
* TabTags
* TabTimeline
Instead of these eight tiddlers one could define the following SideBarTabs tiddler that uses the ''part'' feature:
{{{
<<tabs txtMainTab
Timeline Timeline SideBarTabs/Timeline
All 'All tiddlers' SideBarTabs/All
Tags 'All tags' SideBarTabs/Tags
More 'More lists' SideBarTabs/More>>
<part Timeline hidden><<timeline>></part>
<part All hidden><<list all>></part>
<part Tags hidden><<allTags>></part>
<part More hidden><<tabs txtMoreTab
Missing 'Missing tiddlers' SideBarTabs/Missing
Orphans 'Orphaned tiddlers' SideBarTabs/Orphans
Shadowed 'Shadowed tiddlers' SideBarTabs/Shadowed>></part>
<part Missing hidden><<list missing>></part>
<part Orphans hidden><<list orphans>></part>
<part Shadowed hidden><<list shadowed>></part>
}}}
Notice that you can easily "overwrite" individual parts in separate tiddlers that have the full name of the part.
E.g. if you don't like the classic timeline tab but only want to see the 100 most recent tiddlers you could create a tiddler "~SideBarTabs/Timeline" with the following content:
{{{
<<forEachTiddler
sortBy 'tiddler.modified' descending
write '(index < 100) ? "* [["+tiddler.title+"]]\n":""'>>
}}}
<html><sub><a href="javascript:;" onclick="window.scrollAnchorVisible('Top',null, event)">[Top]</sub></a></html>
!!Using Sliders<html><a name="Sliders"/></html>
Very similar to the build-in {{{<<tabs ...>>}}} macro (see above) the {{{<<slider ...>>}}} macro requires that you defined an additional tiddler that holds the content "to be slid". You can avoid creating this extra tiddler by using the ''part'' feature
''Example''
In a tiddler "About" we may use the slider to show some details that are documented in the tiddler's "Details" part.
{{{
...
<<slider chkAboutDetails About/Details details "Click here to see more details">>
<part Details hidden>
To give you a better overview ...
</part>
...
}}}
Notice that putting the content of the slider into the slider's tiddler also has an extra benefit: When you decide you need to edit the content of the slider you can just doubleclick the content, the tiddler opens for editing and you can directly start editing the content (in the part section). In the "old" approach you would doubleclick the tiddler, see that the slider is using tiddler X, have to look for the tiddler X and can finally open it for editing. So using the ''part'' approach results in a much short workflow.
<html><sub><a href="javascript:;" onclick="window.scrollAnchorVisible('Top',null, event)">[Top]</sub></a></html>
!Revision history<html><a name="Revisions"/></html>
* v1.0.6 (2006-11-07)
** Bugfix: cannot edit tiddler when UploadPlugin by Bidix is installed. Thanks to Jos� Luis Gonz�lez Castro for reporting the bug.
* v1.0.5 (2006-03-02)
** Bugfix: Example with multi-line table cells does not work in IE6. Thanks to Paulo Soares for reporting the bug.
* v1.0.4 (2006-02-28)
** Bugfix: Shadow tiddlers cannot be edited (in TW 2.0.6). Thanks to Torsten Vanek for reporting the bug.
* v1.0.3 (2006-02-26)
** Adapt code to newly introduced Tiddler.prototype.isReadOnly() function (in TW 2.0.6). Thanks to Paulo Soares for reporting the problem.
* v1.0.2 (2006-02-05)
** Also allow other macros than the "tiddler" macro use the "." in the part reference (to refer to "this" tiddler)
* v1.0.1 (2006-01-27)
** Added Table of Content for plugin documentation. Thanks to RichCarrillo for suggesting.
** Bugfix: newReminder plugin does not work when PartTiddler is installed. Thanks to PauloSoares for reporting.
* v1.0.0 (2006-01-25)
** initial version
<html><sub><a href="javascript:;" onclick="window.scrollAnchorVisible('Top',null, event)">[Top]</sub></a></html>
!Code<html><a name="Code"/></html>
<html><sub><a href="javascript:;" onclick="window.scrollAnchorVisible('Top',null, event)">[Top]</sub></a></html>
***/
//{{{
//============================================================================
// PartTiddlerPlugin
// Ensure that the PartTiddler Plugin is only installed once.
//
if (!version.extensions.PartTiddlerPlugin) {
version.extensions.PartTiddlerPlugin = {
major: 1, minor: 0, revision: 6,
date: new Date(2006, 10, 7),
type: 'plugin',
source: "http://tiddlywiki.abego-software.de/#PartTiddlerPlugin"
};
if (!window.abego) window.abego = {};
if (version.major < 2) alertAndThrow("PartTiddlerPlugin requires TiddlyWiki 2.0 or newer.");
//============================================================================
// Common Helpers
// Looks for the next newline, starting at the index-th char of text.
//
// If there are only whitespaces between index and the newline
// the index behind the newline is returned,
// otherwise (or when no newline is found) index is returned.
//
var skipEmptyEndOfLine = function(text, index) {
var re = /(\n|[^\s])/g;
re.lastIndex = index;
var result = re.exec(text);
return (result && text.charAt(result.index) == '\n')
? result.index+1
: index;
}
//============================================================================
// Constants
var partEndOrStartTagRE = /(<\/part>)|(<part(?:\s+)((?:[^>])+)>)/mg;
var partEndTagREString = "<\\/part>";
var partEndTagString = "</part>";
//============================================================================
// Plugin Specific Helpers
// Parse the parameters inside a <part ...> tag and return the result.
//
// @return [may be null] {partName: ..., isHidden: ...}
//
var parseStartTagParams = function(paramText) {
var params = paramText.readMacroParams();
if (params.length == 0 || params[0].length == 0) return null;
var name = params[0];
var paramsIndex = 1;
var hidden = false;
if (paramsIndex < params.length) {
hidden = params[paramsIndex] == "hidden";
paramsIndex++;
}
return {
partName: name,
isHidden: hidden
};
}
// Returns the match to the next (end or start) part tag in the text,
// starting the search at startIndex.
//
// When no such tag is found null is returned, otherwise a "Match" is returned:
// [0]: full match
// [1]: matched "end" tag (or null when no end tag match)
// [2]: matched "start" tag (or null when no start tag match)
// [3]: content of start tag (or null if no start tag match)
//
var findNextPartEndOrStartTagMatch = function(text, startIndex) {
var re = new RegExp(partEndOrStartTagRE);
re.lastIndex = startIndex;
var match = re.exec(text);
return match;
}
//============================================================================
// Formatter
// Process the <part ...> ... </part> starting at (w.source, w.matchStart) for formatting.
//
// @return true if a complete part section (including the end tag) could be processed, false otherwise.
//
var handlePartSection = function(w) {
var tagMatch = findNextPartEndOrStartTagMatch(w.source, w.matchStart);
if (!tagMatch) return false;
if (tagMatch.index != w.matchStart || !tagMatch[2]) return false;
// Parse the start tag parameters
var arguments = parseStartTagParams(tagMatch[3]);
if (!arguments) return false;
// Continue processing
var startTagEndIndex = skipEmptyEndOfLine(w.source, tagMatch.index + tagMatch[0].length);
var endMatch = findNextPartEndOrStartTagMatch(w.source, startTagEndIndex);
if (endMatch && endMatch[1]) {
if (!arguments.isHidden) {
w.nextMatch = startTagEndIndex;
w.subWikify(w.output,partEndTagREString);
}
w.nextMatch = skipEmptyEndOfLine(w.source, endMatch.index + endMatch[0].length);
return true;
}
return false;
}
config.formatters.push( {
name: "part",
match: "<part\\s+[^>]+>",
handler: function(w) {
if (!handlePartSection(w)) {
w.outputText(w.output,w.matchStart,w.matchStart+w.matchLength);
}
}
} )
//============================================================================
// Extend "fetchTiddler" functionality to also recognize "part"s of tiddlers
// as tiddlers.
var currentParent = null; // used for the "." parent (e.g. in the "tiddler" macro)
// Return the match to the first <part ...> tag of the text that has the
// requrest partName.
//
// @return [may be null]
//
var findPartStartTagByName = function(text, partName) {
var i = 0;
while (true) {
var tagMatch = findNextPartEndOrStartTagMatch(text, i);
if (!tagMatch) return null;
if (tagMatch[2]) {
// Is start tag
// Check the name
var arguments = parseStartTagParams(tagMatch[3]);
if (arguments && arguments.partName == partName) {
return tagMatch;
}
}
i += tagMatch[0].length;
}
}
// Return the part "partName" of the given parentTiddler as a "readOnly" Tiddler
// object, using fullName as the Tiddler's title.
//
// All remaining properties of the new Tiddler (tags etc.) are inherited from
// the parentTiddler.
//
// @return [may be null]
//
var getPart = function(parentTiddler, partName, fullName) {
var text = parentTiddler.text;
var startTag = findPartStartTagByName(text, partName);
if (!startTag) return null;
var endIndexOfStartTag = skipEmptyEndOfLine(text, startTag.index+startTag[0].length);
var indexOfEndTag = text.indexOf(partEndTagString, endIndexOfStartTag);
if (indexOfEndTag >= 0) {
var partTiddlerText = text.substring(endIndexOfStartTag,indexOfEndTag);
var partTiddler = new Tiddler();
partTiddler.set(
fullName,
partTiddlerText,
parentTiddler.modifier,
parentTiddler.modified,
parentTiddler.tags,
parentTiddler.created);
partTiddler.abegoIsPartTiddler = true;
return partTiddler;
}
return null;
}
// Hijack the store.fetchTiddler to recognize the "part" addresses.
//
var oldFetchTiddler = store.fetchTiddler ;
store.fetchTiddler = function(title) {
var result = oldFetchTiddler.apply(this, arguments);
if (!result && title) {
var i = title.lastIndexOf('/');
if (i > 0) {
var parentName = title.substring(0, i);
var partName = title.substring(i+1);
var parent = (parentName == ".")
? currentParent
: oldFetchTiddler.apply(this, [parentName]);
if (parent) {
return getPart(parent, partName, parent.title+"/"+partName);
}
}
}
return result;
};
// The user must not edit a readOnly/partTiddler
//
config.commands.editTiddler.oldIsReadOnlyFunction = Tiddler.prototype.isReadOnly;
Tiddler.prototype.isReadOnly = function() {
// Tiddler.isReadOnly was introduced with TW 2.0.6.
// For older version we explicitly check the global readOnly flag
if (config.commands.editTiddler.oldIsReadOnlyFunction) {
if (config.commands.editTiddler.oldIsReadOnlyFunction.apply(this, arguments)) return true;
} else {
if (readOnly) return true;
}
return this.abegoIsPartTiddler;
}
config.commands.editTiddler.handler = function(event,src,title)
{
var t = store.getTiddler(title);
// Edit the tiddler if it either is not a tiddler (but a shadowTiddler)
// or the tiddler is not readOnly
if(!t || !t.abegoIsPartTiddler)
{
clearMessage();
story.displayTiddler(null,title,DEFAULT_EDIT_TEMPLATE);
story.focusTiddler(title,"text");
return false;
}
}
// To allow the "./partName" syntax in macros we need to hijack
// the invokeMacro to define the "currentParent" while it is running.
//
var oldInvokeMacro = window.invokeMacro;
function myInvokeMacro(place,macro,params,wikifier,tiddler) {
var oldCurrentParent = currentParent;
if (tiddler) currentParent = tiddler;
try {
oldInvokeMacro.apply(this, arguments);
} finally {
currentParent = oldCurrentParent;
}
}
window.invokeMacro = myInvokeMacro;
// Scroll the anchor anchorName in the viewer of the given tiddler visible.
// When no tiddler is defined use the tiddler of the target given event is used.
window.scrollAnchorVisible = function(anchorName, tiddler, evt) {
var tiddlerElem = null;
if (tiddler) {
tiddlerElem = document.getElementById(story.idPrefix + tiddler);
}
if (!tiddlerElem && evt) {
var target = resolveTarget(evt);
tiddlerElem = story.findContainingTiddler(target);
}
if (!tiddlerElem) return;
var children = tiddlerElem.getElementsByTagName("a");
for (var i = 0; i < children.length; i++) {
var child = children[i];
var name = child.getAttribute("name");
if (name == anchorName) {
var y = findPosY(child);
window.scrollTo(0,y);
return;
}
}
}
} // of "install only once"
//}}}
/***
<html><sub><a href="javascript:;" onclick="scrollAnchorVisible('Top',null, event)">[Top]</sub></a></html>
!Licence and Copyright
Copyright (c) abego Software ~GmbH, 2006 ([[www.abego-software.de|http://www.abego-software.de]])
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
Neither the name of abego Software nor the names of its contributors may be
used to endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
<html><sub><a href="javascript:;" onclick="scrollAnchorVisible('Top',null, event)">[Top]</sub></a></html>
***/
<<tiddler [[Formatters]]>>
<<tiddler [[Adaptors]]>>
|!Plugin|!Description|
|[[ExamplePlugin]]|Example empty plugin. You can use this as a template to write your own plugin|
|[[DisableWikiLinksPlugin]]|Allows you to disable TiddlyWiki's automatic linking of WikiWords|
|[[DisableStrikeThroughPlugin]]|Allows you to disable TiddlyWiki's strikethrough formatting|
|[[SHA-1UnwoundPlugin]]|Faster wersion of SHA-1 with unwound loops|
|[[CryptoTEAPlugin]]|TEA (Tiny Encryption Algorithm) and supporting Cryptographic functions|
|[[EncryptionCommandsPlugin]]|Use this in association with CryptoTEAPlugin to encrypt individual tiddlers|
/***
|''Name:''|PmWikiFormatterPlugin|
|''Description:''|Allows Tiddlers to use [[PmWiki|http://pmwiki.org/wiki/PmWiki/TextFormattingRules]] text formatting|
|''Author:''|Martin Budden (mjbudden (at) gmail (dot) com)|
|''Source:''|http://www.martinswiki.com/#PmWikiFormatterPlugin |
|''CodeRepository:''|http://svn.tiddlywiki.org/Trunk/contributors/MartinBudden/formatters/PmWikiFormatterPlugin.js |
|''Version:''|0.2.8|
|''Date:''|May 7, 2007|
|''Comments:''|Please make comments at http://groups.google.co.uk/group/TiddlyWikiDev |
|''License:''|[[Creative Commons Attribution-ShareAlike 2.5 License|http://creativecommons.org/licenses/by-sa/2.5/]]|
|''~CoreVersion:''|2.1.0|
This is an early release of the PmWikiFormatterPlugin, which allows you to insert PmWiki formated text
into a TiddlyWiki.
The aim is not to fully emulate PmWiki, but to allow you to work with PmWiki content off-line and then resync the content with your PmWiki later on, with the expectation that only minor edits will be required.
To use PmWiki format in a Tiddler, tag the Tiddler with PmWikiFormat or set the tiddler's {{{wikiformat}}} extended field to {{{pmwiki}}}
See http://www.pmwiki.org/wiki/PmWiki/MarkupMasterIndex for PmWiki Markup.
!!!Issues
There are (at least) the following known issues:
# Proper paragraph handling requires fix to TiddlyWiki that will be available in TiddlyWiki v2.2
# Tables not fully supported
## Table attributes not supported (eg || border=1)
## Table captions not supported
# Anchors not supported.
# Images not supported.
# Image links not supported
# Leading spaces to preserve formatting only work partially.
# Directives not supported eg {{{(:directive (attr...):)}}} - except for the {{{(:markup:)...(:markupend:)}}} directive
# White space list rules not supported
# Definition lists not supported
***/
//{{{
// Ensure that the PmWikiFormatter Plugin is only installed once.
if(!version.extensions.PmWikiFormatterPlugin) {
version.extensions.PmWikiFormatterPlugin = {installed:true};
if(version.major < 2 || (version.major == 2 && version.minor < 1))
{alertAndThrow('PmWikiFormatterPlugin requires TiddlyWiki 2.1 or later.');}
PmWikiFormatter = {}; // 'namespace' for local functions
pmDebug = function(out,str)
{
createTiddlyText(out,str.replace(/\n/mg,'\\n').replace(/\r/mg,'RR'));
createTiddlyElement(out,'br');
};
PmWikiFormatter.directives = function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var lm1 = lookaheadMatch[1];
var lm2 = lookaheadMatch[2];
switch(lm1) {
case 'directive':
break;
default:
w.outputText(w.output,w.matchStart,w.nextMatch);
return;
}
w.nextMatch = this.lookaheadRegExp.lastIndex;
} else {
w.outputText(w.output,w.matchStart,w.nextMatch);
}
};
PmWikiFormatter.setFromParams = function(w,p)
{
var r = {};
var re = /\s*(.*?)=(?:(?:"(.*?)")|(?:'(.*?)')|((?:\w|%|#)*))/mg;
var match = re.exec(p);
while(match) {
var s = match[1].unDash();
if(match[2]) {
r[s] = match[2];
} else if(match[3]) {
r[s] = match[3];
} else {
r[s] = match[4];
}
match = re.exec(p);
}
return r;
};
config.formatterHelpers.setAttributesFromParams = function(e,p)
{
var re = /\s*(.*?)=(?:(?:"(.*?)")|(?:'(.*?)')|((?:\w|%|#)*))/mg;
var match = re.exec(p);
while(match)
{
var s = match[1].unDash();
if(s=='bgcolor') {
s = 'backgroundColor';
}
try {
if(match[2]) {
e.setAttribute(s,match[2]);
} else if(match[3]) {
e.setAttribute(s,match[3]);
} else {
e.setAttribute(s,match[4]);
}
}
catch(ex) {}
match = re.exec(p);
}
};
config.pmwiki = {};
config.pmwiki.formatters = [
{
name: 'pmWikiMarkup',
match: '\\(:markup:\\)\\s*\\n',
lookaheadRegExp: /\(:markup:\)\s*\n((?:.|\n)*?)\(:markupend:\)/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var text = lookaheadMatch[1];
if(config.browser.isIE) {
text = text.replace(/\n/g,'\r');
}
var t = createTiddlyElement(w.output,'table',null,'markup vert');
var tr1 = createTiddlyElement(t,'tr');
var td1 = createTiddlyElement(tr1,'td',null,'markup1');
var tr2 = createTiddlyElement(t,'tr');
var td2 = createTiddlyElement(tr2,'td',null,'markup2');
createTiddlyElement(td1,'pre',null,null,text);
var oldSource = w.source;
w.source = text; w.nextMatch = 0;
w.subWikifyUnterm(td2);
w.source = oldSource;
w.nextMatch = lookaheadMatch.index + lookaheadMatch[0].length;
}
}
},
{
name: 'pmWikiHeading',
match: '^!{1,6}',
termRegExp: /(\n)/mg,
handler: function(w)
{
var e = createTiddlyElement(w.output,'h' + w.matchLength);
w.subWikifyTerm(e,this.termRegExp);
}
},
{
name: 'pmWikiTableParams',
match: '^\\|\\|(?:[^\\n\\|]*)\\n',
lookaheadRegExp: /^\|\|([^\n\|]*)\n/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
/*if(!w.tableParams)
w.tableParams = {};
w.tableParams = PmWikiFormatter.setFromParams(w,lookaheadMatch[1]);*/
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
},
{
name: 'pmWikiTable',
match: '^\\|\\|(?:[^\\n]*)\\|\\|$',
lookaheadRegExp: /^\|\|([^\n]*)\|\|$/mg,
rowTermRegExp: /(\|\|$\n?)/mg,
cellRegExp: /(?:\|\|([^\n]*)\|\|)|(\|\|$\n?)/mg,
cellTermRegExp: /((?:\x20*)\|\|)/mg,
handler: function(w)
{
var table = createTiddlyElement(w.output,'table');
/*for(var i in w.tableParams) {
table.setAttribut(i,w.tableParams[i])
}*/
var rowContainer = createTiddlyElement(table,'tbody');
var rowCount = 0;
w.nextMatch = w.matchStart;
this.lookaheadRegExp.lastIndex = w.nextMatch;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
while(lookaheadMatch && lookaheadMatch.index == w.nextMatch) {
this.rowHandler(w,createTiddlyElement(rowContainer,'tr',null,(rowCount&1)?'oddRow':'evenRow'));
rowCount++;
this.lookaheadRegExp.lastIndex = w.nextMatch;
lookaheadMatch = this.lookaheadRegExp.exec(w.source);
}
},//# end handler
rowHandler: function(w,e)
{
var col = 0;
var colSpanCount = 1;
var prevCell = null;
this.cellRegExp.lastIndex = w.nextMatch;
var cellMatch = this.cellRegExp.exec(w.source);
while(cellMatch && cellMatch.index == w.nextMatch) {
if(w.source.substr(w.nextMatch,4) == '||||') {
// Colspan
colSpanCount++;
w.nextMatch += 2;
} else if(cellMatch[2]) {// End of row
if(colSpanCount > 1) {
prevCell.setAttribute('colspan',colSpanCount);
prevCell.setAttribute('colSpan',colSpanCount); // Needed for IE
}
w.nextMatch = this.cellRegExp.lastIndex;
break;
} else {
// Cell
w.nextMatch += 2; //skip over ||
var chr = w.source.substr(w.nextMatch,1);
var cell;
if(chr == '!') {
cell = createTiddlyElement(e,'th');
w.nextMatch++;
chr = w.source.substr(w.nextMatch,1);
} else {
cell = createTiddlyElement(e,'td');
}
var spaceLeft = false;
while(chr == ' ') {
spaceLeft = true;
w.nextMatch++;
chr = w.source.substr(w.nextMatch,1);
}
if(colSpanCount > 1) {
cell.setAttribute('colspan',colSpanCount);
cell.setAttribute('colSpan',colSpanCount); // Needed for IE
colSpanCount = 1;
}
w.subWikifyTerm(cell,this.cellTermRegExp);
if(w.matchText.substr(w.matchText.length-3,1) == ' ') {
// spaceRight
cell.align = spaceLeft ? 'center' : 'left';
} else if(spaceLeft) {
cell.align = 'right';
}
prevCell = cell;
w.nextMatch -= 2;
}
col++;
this.cellRegExp.lastIndex = w.nextMatch;
cellMatch = this.cellRegExp.exec(w.source);
}
}//# end rowHandler
},
{
name: 'pmWikilist',
match: '^(?:(?:(?:\\*)|(?:#))+)',
lookaheadRegExp: /^(?:(?:(\*)|(#))+)/mg,
termRegExp: /(\n)/mg,
handler: function(w)
{
var placeStack = [w.output];
var currLevel = 0, currType = null;
var listLevel, listType, itemType;
w.nextMatch = w.matchStart;
this.lookaheadRegExp.lastIndex = w.nextMatch;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
while(lookaheadMatch && lookaheadMatch.index == w.nextMatch) {
if(lookaheadMatch[1]) {
listType = 'ul';
itemType = 'li';
} else if(lookaheadMatch[2]) {
listType = 'ol';
itemType = 'li';
}
listLevel = lookaheadMatch[0].length;
w.nextMatch += lookaheadMatch[0].length;
if(listLevel > currLevel) {
for(var i=currLevel; i<listLevel; i++)
{placeStack.push(createTiddlyElement(placeStack[placeStack.length-1],listType));}
} else if(listLevel < currLevel) {
for(i=currLevel; i>listLevel; i--)
{placeStack.pop();}
} else if(listLevel == currLevel && listType != currType) {
placeStack.pop();
placeStack.push(createTiddlyElement(placeStack[placeStack.length-1],listType));
}
currLevel = listLevel;
currType = listType;
var e = createTiddlyElement(placeStack[placeStack.length-1],itemType);
w.subWikifyTerm(e,this.termRegExp);
this.lookaheadRegExp.lastIndex = w.nextMatch;
lookaheadMatch = this.lookaheadRegExp.exec(w.source);
}
}
},
{
name: 'pmWikiRule',
match: '^----+$\\n?',
handler: function(w)
{
createTiddlyElement(w.output,'hr');
}
},
{
name: 'pmWikiIndent',
match: '^-+>',
termRegExp: /(\n)/mg,
handler: function(w)
{
var e = createTiddlyElement(w.output,'div',null,'indent');
w.subWikifyTerm(e,this.termRegExp);
}
},
{
name: 'pmWikiOutdent',
match: '^-+<',
termRegExp: /(\n)/mg,
handler: function(w)
{
var e = createTiddlyElement(w.output,'div',null,'outdent');
w.subWikifyTerm(e,this.termRegExp);
}
},
{
name: 'pmWikiLeadingSpaces',
match: '^ ',
lookaheadRegExp: /^ /mg,
termRegExp: /(\n)/mg,
handler: function(w)
{
var e = createTiddlyElement(w.output,'pre');
while(true) {
w.subWikifyTerm(e,this.termRegExp);
createTiddlyElement(e,'br');
this.lookaheadRegExp.lastIndex = w.nextMatch;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.nextMatch) {
w.nextMatch += lookaheadMatch[0].length;
} else {
break;
}
}
}
},
{
name: 'pmWikiExplicitLink',
match: '\\[\\[',
lookaheadRegExp: /\[\[(.*?)(?:\|(.*?))?\]\]/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var link = lookaheadMatch[1];
if(lookaheadMatch[2]) {
var e = config.formatterHelpers.isExternalLink(link) ? createExternalLink(w.output,link) : createTiddlyLink(w.output,link,false,null,w.isStatic);
var text = lookaheadMatch[2];
} else {
e = createTiddlyLink(w.output,link,false,null,w.isStatic);
text = link;
}
createTiddlyText(e,text);
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
},
{
name: 'pmWikiNotWikiLink',
match: '`' + config.textPrimitives.wikiLink,
handler: function(w)
{
w.outputText(w.output,w.matchStart+1,w.nextMatch);
}
},
{
name: 'pmWikiLink',
match: config.textPrimitives.wikiLink,
handler: function(w)
{
if(w.matchStart > 0) {
var preRegExp = new RegExp(config.textPrimitives.anyLetter,'mg');
preRegExp.lastIndex = w.matchStart-1;
preMatch = preRegExp.exec(w.source);
if(preMatch.index == w.matchStart-1) {
w.outputText(w.output,w.matchStart,w.nextMatch);
return;
}
}
var output = w.output;
if(w.autoLinkWikiWords == true || store.isShadowTiddler(w.matchText)) {
output = createTiddlyLink(w.output,w.matchText,false,null,w.isStatic);
}
w.outputText(output,w.matchStart,w.nextMatch);
}
},
{
name: 'urlLink',
match: config.textPrimitives.urlPattern,
handler: function(w)
{
w.outputText(createExternalLink(w.output,w.matchText),w.matchStart,w.nextMatch);
}
},
{
name: 'pmWikiBoldByChar',
match: "'''",
termRegExp: /('''|\n)/mg,
element: 'strong',
handler: config.formatterHelpers.createElementAndWikify
},
{
name: 'pmWikiItalicByChar',
match: "''",
termRegExp: /(''|\n)/mg,
element: 'em',
handler: config.formatterHelpers.createElementAndWikify
},
{
name: 'pmWikiMonospacedByChar',
match: '@@',
termRegExp: /(@@|\n)/mg,
element: 'code',
handler: config.formatterHelpers.createElementAndWikify
},
{
name: 'pmWikiUnderlineByChar',
match: '\\{\\+',
termRegExp: /(\+\}|\n)/mg,
element: 'u',
handler: config.formatterHelpers.createElementAndWikify
},
{
name: 'pmWikiStrikeByChar',
match: '\\{-',
termRegExp: /(-\}|\n)/mg,
element: 'strike',
handler: config.formatterHelpers.createElementAndWikify
},
{
name: 'pmWikiSuperscriptByChar',
match: "\\'\\^",
termRegExp: /(\^\'|\n)/mg,
element: 'sup',
handler: config.formatterHelpers.createElementAndWikify
},
{
name: 'pmWikiSubscriptByChar',
match: "\\'_",
termRegExp: /(_\'|\n)/mg,
element: 'sub',
handler: config.formatterHelpers.createElementAndWikify
},
{
name: 'pmWikiBigByChar',
match: "\\'\\+",
termRegExp: /(\+\'|\n)/mg,
element: 'big',
handler: config.formatterHelpers.createElementAndWikify
},
{
name: 'pmWikiSmallByChar',
match: "\\'\\-",
termRegExp: /(\-\'|\n)/mg,
element: 'small',
handler: config.formatterHelpers.createElementAndWikify
},
{
name: 'pmWikiLargerFont',
match: '\\[\\+{1,2}',
termRegExp: /(\+{1,2}\]|\n)/mg,
handler: function(w)
{
var e = createTiddlyElement(w.output,'span');
e.style['fontSize'] = w.matchLength==2 ? '120%' : '144%';
w.subWikifyTerm(e,this.termRegExp);
}
},
{
name: 'pmWikiSmallerFont',
match: '\\[\\-{1,2}',
termRegExp: /(\-{1,2}\]|\n)/mg,
element: 'span',
handler: function(w)
{
var e = createTiddlyElement(w.output,'span');
e.style['fontSize'] = w.matchLength==2 ? '83%' : '69%';
w.subWikifyTerm(e,this.termRegExp);
}
},
{
name: 'pmWikiExplicitLineBreak',
match: '\\{2,3}\\n',
handler: function(w)
{
createTiddlyElement(w.output,'br');
if(w.matchLength==4) {
createTiddlyElement(w.output,'br');
}
}
},
{
name: 'pmWikiParagraph',
match: '\\n{2,}',
handler: function(w)
{
createTiddlyElement(w.output,'p');
}
},
{
name: 'pmWikiEscapedText',
match: '\\[=',
lookaheadRegExp: /\[=((?:.|\n)*?)=\]/mg,
element: 'span',
cls: 'escaped',
handler: config.formatterHelpers.enclosedTextHelper
},
{
name: 'pmWikiEscapedCode',
match: '\\[@',
lookaheadRegExp: /\[@((?:.|\n)*?)@\]/mg,
element: 'code',
cls: 'escaped',
handler: config.formatterHelpers.enclosedTextHelper
},
{
name: 'pmWikiComment',
match: '<!\\-\\-',
lookaheadRegExp: /<!\-\-((?:.|\n)*?)\-\-!>/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
},
{
name: 'pmWikiDirectives',
match: '\\(:(?:[a-z]{2,16}):\\)',
lookaheadRegExp: /\(:(?:[a-z]{2,16}):\)/mg,
handler: PmWikiFormatter.directives
},
{
name: 'pmWikiHtmlEntitiesEncoding',
match: '&#?[a-zA-Z0-9]{2,8};',
handler: function(w)
{
createTiddlyElement(w.output,'span').innerHTML = w.matchText;
}
}
];
config.parsers.pmwikiFormatter = new Formatter(config.pmwiki.formatters);
config.parsers.pmwikiFormatter.format = 'pmwiki';
config.parsers.pmwikiFormatter.formatTag = 'PmWikiFormat';
} // end of 'install only once'
//}}}
/***
|''Name:''|SHA-1 Unwound Plugin|
|''Description:''|Faster wersion of SHA-1 with unwound loops|
|''Author:''|Martin Budden (mjbudden (at) gmail (dot) com)|
|''Source:''|http://www.martinswiki.com/martinswiki.html#SHA-1UnwoundPlugin |
|''CodeRepository:''|http://svn.tiddlywiki.org/Trunk/contributors/MartinBudden/plugins/SHA-1UnwoundPlugin.js |
|''Version:''|1.0.2|
|''Date:''|Jul 21, 2006|
|''Comments:''|Please make comments at http://groups.google.co.uk/group/TiddlyWikiDev |
|''License:''|[[Creative Commons Attribution-ShareAlike 2.5 License|http://creativecommons.org/licenses/by-sa/2.5/]] |
|''~CoreVersion:''|2.1.0|
SHA1UnwoundPlugin is a faster (but larger) SHA-1 hash algorithm with unwound loops.
***/
//{{{
// Ensure that the SHA1UnwoundPlugin is only installed once.
if(!version.extensions.SHA1UnwoundPlugin) {
version.extensions.SHA1UnwoundPlugin = {installed:true};
if(version.major < 2 || (version.major == 2 && version.minor < 1))
{alertAndThrow("SHA-1UnwoundPlugin requires TiddlyWiki 2.1 or newer.");}
// Calculate the SHA-1 hash of an array of blen bytes of big-endian 32-bit words
Crypto.sha1 = function(x,blen)
{
if(blen==null)
return null;
// Add 32-bit integers, wrapping at 32 bits
function a32(a,b)
{
var lsw = (a&0xFFFF)+(b&0xFFFF);
var msw = (a>>16)+(b>>16)+(lsw>>16);
return (msw<<16)|(lsw&0xFFFF);
}
function AA(a,b,c,d,e)
{
b=(b>>>27)|(b<<5);
var lsw=(a&0xFFFF)+(b&0xFFFF)+(c&0xFFFF)+(d&0xFFFF)+(e&0xFFFF);
var msw=(a>>16)+(b>>16)+(c>>16)+(d>>16)+(e>>16)+(lsw>>16);
return (msw<<16)|(lsw&0xFFFF);
}
function R1(n) { return (n<<1)|(n>>>31); }
var len=blen*8;
x[len>>5] |= 0x80<<(24-len%32);
x[((len+64>>9)<<4)+15] = len;
var k1=0x5A827999;
var k2=0x6ED9EBA1;
var k3=0x8F1BBCDC;
var k4=0xCA62C1D6;
var h0=0x67452301;
var h1=0xEFCDAB89;
var h2=0x98BADCFE;
var h3=0x10325476;
var h4=0xC3D2E1F0;
var w0,w1,w2,w3,w4,w5,w6,w7,w8,w9,wA,wB,wC,wD,wE,wF;
for(var i=0;i<x.length;i+=16) {
var a=h0;
var b=h1;
var c=h2;
var d=h3;
var e=h4;
w0=x[i]; e=AA(e,a,d^(b&(c^d)),w0,k1);b=(b>>>2)|(b<<30);
w1=x[i+1]; d=AA(d,e,c^(a&(b^c)),w1,k1);a=(a>>>2)|(a<<30);
w2=x[i+2]; c=AA(c,d,b^(e&(a^b)),w2,k1);e=(e>>>2)|(e<<30);
w3=x[i+3]; b=AA(b,c,a^(d&(e^a)),w3,k1);d=(d>>>2)|(d<<30);
w4=x[i+4]; a=AA(a,b,e^(c&(d^e)),w4,k1);c=(c>>>2)|(c<<30);
w5=x[i+5]; e=AA(e,a,d^(b&(c^d)),w5,k1);b=(b>>>2)|(b<<30);
w6=x[i+6]; d=AA(d,e,c^(a&(b^c)),w6,k1);a=(a>>>2)|(a<<30);
w7=x[i+7]; c=AA(c,d,b^(e&(a^b)),w7,k1);e=(e>>>2)|(e<<30);
w8=x[i+8]; b=AA(b,c,a^(d&(e^a)),w8,k1);d=(d>>>2)|(d<<30);
w9=x[i+9]; a=AA(a,b,e^(c&(d^e)),w9,k1);c=(c>>>2)|(c<<30);
wA=x[i+10];e=AA(e,a,d^(b&(c^d)),wA,k1);b=(b>>>2)|(b<<30);
wB=x[i+11];d=AA(d,e,c^(a&(b^c)),wB,k1);a=(a>>>2)|(a<<30);
wC=x[i+12];c=AA(c,d,b^(e&(a^b)),wC,k1);e=(e>>>2)|(e<<30);
wD=x[i+13];b=AA(b,c,a^(d&(e^a)),wD,k1);d=(d>>>2)|(d<<30);
wE=x[i+14];a=AA(a,b,e^(c&(d^e)),wE,k1);c=(c>>>2)|(c<<30);
wF=x[i+15];e=AA(e,a,d^(b&(c^d)),wF,k1);b=(b>>>2)|(b<<30);
w0=R1(wD^w8^w2^w0);d=AA(d,e,c^(a&(b^c)),w0,k1);a=(a>>>2)|(a<<30);
w1=R1(wE^w9^w3^w1);c=AA(c,d,b^(e&(a^b)),w1,k1);e=(e>>>2)|(e<<30);
w2=R1(wF^wA^w4^w2);b=AA(b,c,a^(d&(e^a)),w2,k1);d=(d>>>2)|(d<<30);
w3=R1(w0^wB^w5^w3);a=AA(a,b,e^(c&(d^e)),w3,k1);c=(c>>>2)|(c<<30);
w4=R1(w1^wC^w6^w4);e=AA(e,a,b^c^d,w4,k2);b=(b>>>2)|(b<<30);
w5=R1(w2^wD^w7^w5);d=AA(d,e,a^b^c,w5,k2);a=(a>>>2)|(a<<30);
w6=R1(w3^wE^w8^w6);c=AA(c,d,e^a^b,w6,k2);e=(e>>>2)|(e<<30);
w7=R1(w4^wF^w9^w7);b=AA(b,c,d^e^a,w7,k2);d=(d>>>2)|(d<<30);
w8=R1(w5^w0^wA^w8);a=AA(a,b,c^d^e,w8,k2);c=(c>>>2)|(c<<30);
w9=R1(w6^w1^wB^w9);e=AA(e,a,b^c^d,w9,k2);b=(b>>>2)|(b<<30);
wA=R1(w7^w2^wC^wA);d=AA(d,e,a^b^c,wA,k2);a=(a>>>2)|(a<<30);
wB=R1(w8^w3^wD^wB);c=AA(c,d,e^a^b,wB,k2);e=(e>>>2)|(e<<30);
wC=R1(w9^w4^wE^wC);b=AA(b,c,d^e^a,wC,k2);d=(d>>>2)|(d<<30);
wD=R1(wA^w5^wF^wD);a=AA(a,b,c^d^e,wD,k2);c=(c>>>2)|(c<<30);
wE=R1(wB^w6^w0^wE);e=AA(e,a,b^c^d,wE,k2);b=(b>>>2)|(b<<30);
wF=R1(wC^w7^w1^wF);d=AA(d,e,a^b^c,wF,k2);a=(a>>>2)|(a<<30);
w0=R1(wD^w8^w2^w0);c=AA(c,d,e^a^b,w0,k2);e=(e>>>2)|(e<<30);
w1=R1(wE^w9^w3^w1);b=AA(b,c,d^e^a,w1,k2);d=(d>>>2)|(d<<30);
w2=R1(wF^wA^w4^w2);a=AA(a,b,c^d^e,w2,k2);c=(c>>>2)|(c<<30);
w3=R1(w0^wB^w5^w3);e=AA(e,a,b^c^d,w3,k2);b=(b>>>2)|(b<<30);
w4=R1(w1^wC^w6^w4);d=AA(d,e,a^b^c,w4,k2);a=(a>>>2)|(a<<30);
w5=R1(w2^wD^w7^w5);c=AA(c,d,e^a^b,w5,k2);e=(e>>>2)|(e<<30);
w6=R1(w3^wE^w8^w6);b=AA(b,c,d^e^a,w6,k2);d=(d>>>2)|(d<<30);
w7=R1(w4^wF^w9^w7);a=AA(a,b,c^d^e,w7,k2);c=(c>>>2)|(c<<30);
w8=R1(w5^w0^wA^w8);e=AA(e,a,(b&c)|(d&(b|c)),w8,k3);b=(b>>>2)|(b<<30);
w9=R1(w6^w1^wB^w9);d=AA(d,e,(a&b)|(c&(a|b)),w9,k3);a=(a>>>2)|(a<<30);
wA=R1(w7^w2^wC^wA);c=AA(c,d,(e&a)|(b&(e|a)),wA,k3);e=(e>>>2)|(e<<30);
wB=R1(w8^w3^wD^wB);b=AA(b,c,(d&e)|(a&(d|e)),wB,k3);d=(d>>>2)|(d<<30);
wC=R1(w9^w4^wE^wC);a=AA(a,b,(c&d)|(e&(c|d)),wC,k3);c=(c>>>2)|(c<<30);
wD=R1(wA^w5^wF^wD);e=AA(e,a,(b&c)|(d&(b|c)),wD,k3);b=(b>>>2)|(b<<30);
wE=R1(wB^w6^w0^wE);d=AA(d,e,(a&b)|(c&(a|b)),wE,k3);a=(a>>>2)|(a<<30);
wF=R1(wC^w7^w1^wF);c=AA(c,d,(e&a)|(b&(e|a)),wF,k3);e=(e>>>2)|(e<<30);
w0=R1(wD^w8^w2^w0);b=AA(b,c,(d&e)|(a&(d|e)),w0,k3);d=(d>>>2)|(d<<30);
w1=R1(wE^w9^w3^w1);a=AA(a,b,(c&d)|(e&(c|d)),w1,k3);c=(c>>>2)|(c<<30);
w2=R1(wF^wA^w4^w2);e=AA(e,a,(b&c)|(d&(b|c)),w2,k3);b=(b>>>2)|(b<<30);
w3=R1(w0^wB^w5^w3);d=AA(d,e,(a&b)|(c&(a|b)),w3,k3);a=(a>>>2)|(a<<30);
w4=R1(w1^wC^w6^w4);c=AA(c,d,(e&a)|(b&(e|a)),w4,k3);e=(e>>>2)|(e<<30);
w5=R1(w2^wD^w7^w5);b=AA(b,c,(d&e)|(a&(d|e)),w5,k3);d=(d>>>2)|(d<<30);
w6=R1(w3^wE^w8^w6);a=AA(a,b,(c&d)|(e&(c|d)),w6,k3);c=(c>>>2)|(c<<30);
w7=R1(w4^wF^w9^w7);e=AA(e,a,(b&c)|(d&(b|c)),w7,k3);b=(b>>>2)|(b<<30);
w8=R1(w5^w0^wA^w8);d=AA(d,e,(a&b)|(c&(a|b)),w8,k3);a=(a>>>2)|(a<<30);
w9=R1(w6^w1^wB^w9);c=AA(c,d,(e&a)|(b&(e|a)),w9,k3);e=(e>>>2)|(e<<30);
wA=R1(w7^w2^wC^wA);b=AA(b,c,(d&e)|(a&(d|e)),wA,k3);d=(d>>>2)|(d<<30);
wB=R1(w8^w3^wD^wB);a=AA(a,b,(c&d)|(e&(c|d)),wB,k3);c=(c>>>2)|(c<<30);
wC=R1(w9^w4^wE^wC);e=AA(e,a,b^c^d,wC,k4);b=(b>>>2)|(b<<30);
wD=R1(wA^w5^wF^wD);d=AA(d,e,a^b^c,wD,k4);a=(a>>>2)|(a<<30);
wE=R1(wB^w6^w0^wE);c=AA(c,d,e^a^b,wE,k4);e=(e>>>2)|(e<<30);
wF=R1(wC^w7^w1^wF);b=AA(b,c,d^e^a,wF,k4);d=(d>>>2)|(d<<30);
w0=R1(wD^w8^w2^w0);a=AA(a,b,c^d^e,w0,k4);c=(c>>>2)|(c<<30);
w1=R1(wE^w9^w3^w1);e=AA(e,a,b^c^d,w1,k4);b=(b>>>2)|(b<<30);
w2=R1(wF^wA^w4^w2);d=AA(d,e,a^b^c,w2,k4);a=(a>>>2)|(a<<30);
w3=R1(w0^wB^w5^w3);c=AA(c,d,e^a^b,w3,k4);e=(e>>>2)|(e<<30);
w4=R1(w1^wC^w6^w4);b=AA(b,c,d^e^a,w4,k4);d=(d>>>2)|(d<<30);
w5=R1(w2^wD^w7^w5);a=AA(a,b,c^d^e,w5,k4);c=(c>>>2)|(c<<30);
w6=R1(w3^wE^w8^w6);e=AA(e,a,b^c^d,w6,k4);b=(b>>>2)|(b<<30);
w7=R1(w4^wF^w9^w7);d=AA(d,e,a^b^c,w7,k4);a=(a>>>2)|(a<<30);
w8=R1(w5^w0^wA^w8);c=AA(c,d,e^a^b,w8,k4);e=(e>>>2)|(e<<30);
w9=R1(w6^w1^wB^w9);b=AA(b,c,d^e^a,w9,k4);d=(d>>>2)|(d<<30);
wA=R1(w7^w2^wC^wA);a=AA(a,b,c^d^e,wA,k4);c=(c>>>2)|(c<<30);
wB=R1(w8^w3^wD^wB);e=AA(e,a,b^c^d,wB,k4);b=(b>>>2)|(b<<30);
wC=R1(w9^w4^wE^wC);d=AA(d,e,a^b^c,wC,k4);a=(a>>>2)|(a<<30);
wD=R1(wA^w5^wF^wD);c=AA(c,d,e^a^b,wD,k4);e=(e>>>2)|(e<<30);
wE=R1(wB^w6^w0^wE);b=AA(b,c,d^e^a,wE,k4);d=(d>>>2)|(d<<30);
wF=R1(wC^w7^w1^wF);a=AA(a,b,c^d^e,wF,k4);c=(c>>>2)|(c<<30);
h0=a32(h0,a);
h1=a32(h1,b);
h2=a32(h2,c);
h3=a32(h3,d);
h4=a32(h4,e);
}
return [h0,h1,h2,h3,h4];
};
} // end of "install only once"
//}}}
Martin Budden's plugins and extensions for ~TiddlyWiki
/***
|''Name:''|SnipSnapFormatterPlugin|
|''Description:''|Allows Tiddlers to use [[SnipSnap|http://snipsnap.org/space/snipsnap-help]] text formatting|
|''Author:''|Martin Budden (mjbudden (at) gmail (dot) com)|
|''Source:''|http://www.martinswiki.com/#SnipSnapFormatterPlugin|
|''CodeRepository:''|http://svn.tiddlywiki.org/Trunk/contributors/MartinBudden/formatters/SnipSnapFormatterPlugin.js|
|''Version:''|0.1.8|
|''Status:''|alpha pre-release|
|''Date:''|Oct 28, 2006|
|''Comments:''|Please make comments at http://groups.google.co.uk/group/TiddlyWikiDev|
|''License:''|[[Creative Commons Attribution-ShareAlike 2.5 License|http://creativecommons.org/licenses/by-sa/2.5/]]|
|''~CoreVersion:''|2.1.0|
This is an early release of the SnipSnapFormatterPlugin, which allows you to insert SnipSnap formated text
into a TiddlyWiki.
The aim is not to fully emulate SnipSnap, but to allow you to create SnipSnap content off-line and then paste
the content into your SnipSnap later on, with the expectation that only minor edits will be required.
To use SnipSnap format in a Tiddler, tag the Tiddler with SnipSnapFormat. See [[testSnipSnapFormat]] for an
example.
See http://snipsnap.org/theme/default.css and especially http://snipsnap.org/theme/css/wiki.css for css.
This is an early alpha release, with (at least) the following known issues:
#Tables not supported
***/
//{{{
// Ensure that the SnipSnapFormatterPlugin is only installed once.
if(!version.extensions.SnipSnapFormatterPlugin) {
version.extensions.SnipSnapFormatterPlugin = {installed:true};
if(version.major < 2 || (version.major == 2 && version.minor < 1))
{alertAndThrow("SnipSnapFormatterPlugin requires TiddlyWiki 2.1 or later.");}
snipSnapDebug = function(out,str)
{
createTiddlyText(out,str.replace(/\n/mg,"\\n").replace(/\r/mg,"RR"));
createTiddlyElement(out,"br");
};
config.snipSnapFormatters = [
{
name: "snipSnapHeading",
match: "^(?:(?:1 )|(?:1\\.1 ))",
lookaheadRegExp: /^(?:(1 )|(1\.1 ))/mg,
termRegExp: /(\n)/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var h = "h1";
if(lookaheadMatch[2]) {
//1.1
h = "h2";
}
w.subWikifyTerm(createTiddlyElement(w.output,h),this.termRegExp);
}
}
},
{
name: "snipSnapList",
match: "^(?:(?:\\* )|(?:\\- )|(?:1\\. )|(?:A\\. )|(?:a\\. )|(?:I\\. )|(?:i\\. )|(?:g\\. )|(?:h\\. )|(?:k\\. )|(?:j\\. ))",
lookaheadRegExp: /^(?:(\* )|(\- )|(1\. )|(A\. )|(a\. )|(I\. )|(i\. )|(g\. )|(h\. )|(k\. )|(j\. ))/mg,
termRegExp: /(\n)/mg,
handler: function(w)
{
var placeStack = [w.output];
var currLevel = 0;
var currType = null;
var listLevel, listType, itemType;
w.nextMatch = w.matchStart;
this.lookaheadRegExp.lastIndex = w.nextMatch;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
while(lookaheadMatch && lookaheadMatch.index == w.nextMatch) {
listType = "ol";
itemType = "li";
listLevel = lookaheadMatch[0].length-2;
var style = null;
if(lookaheadMatch[1]) {
//*
listType = "ul";
listLevel = lookaheadMatch[0].length-1;
style = "circle";
} else if(lookaheadMatch[2]) {
//-
listType = "ul";
listLevel = lookaheadMatch[0].length-1;
style = "square";
} else if(lookaheadMatch[3]) {
//1.
style = "decimal";
} else if(lookaheadMatch[4]) {
//A.
style = "upper-alpha";
} else if(lookaheadMatch[5]) {
//a.
style = "lower-alpha";
} else if(lookaheadMatch[6]) {
//I.
style = "upper-roman";
} else if(lookaheadMatch[7]) {
//i.
style = "lower-roman";
} else if(lookaheadMatch[8]) {
//g.
style = "lower-greek";
} else if(lookaheadMatch[9]) {
//h.
style = "hiragana";
} else if(lookaheadMatch[10]) {
//k.
style = "katakana";
} else if(lookaheadMatch[11]) {
//j.
style = "hebrew";
}
w.nextMatch += lookaheadMatch[0].length;
if(listLevel > currLevel) {
for(var i=currLevel; i<listLevel; i++) {
placeStack.push(createTiddlyElement(placeStack[placeStack.length-1],listType));
}
} else if(listLevel < currLevel) {
for(i=currLevel; i>listLevel; i--) {
placeStack.pop();
}
} else if(listLevel == currLevel && listType != currType) {
placeStack.pop();
placeStack.push(createTiddlyElement(placeStack[placeStack.length-1],listType));
}
currLevel = listLevel;
currType = listType;
var e = createTiddlyElement(placeStack[placeStack.length-1],itemType);
if(config.browser.isIE)
{
e.style["list-style-type"] = style;
} else {
e.style["listStyleType"] = style;
}
w.subWikifyTerm(e,this.termRegExp);
this.lookaheadRegExp.lastIndex = w.nextMatch;
lookaheadMatch = this.lookaheadRegExp.exec(w.source);
}
}
},
{
name: "snipSnapRule",
match: "^----+$\\n?",
handler: function(w)
{
createTiddlyElement(w.output,"hr");
}
},
{
name: "macro",
match: "<<",
lookaheadRegExp: /<<([^>\s]+)(?:\s*)((?:[^>]|(?:>(?!>)))*)>>/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart && lookaheadMatch[1]) {
w.nextMatch = this.lookaheadRegExp.lastIndex;
invokeMacro(w.output,lookaheadMatch[1],lookaheadMatch[2],w,w.tiddler);
}
}
},
{
name: "snipSnapExplicitLineBreak",
match: "\\\\\\\\\\\\",
handler: function(w)
{
createTiddlyElement(w.output,"br");
}
},
{
name: "snipSnapEscapeChar",
match: "\\\\.",
handler: function(w)
{
w.outputText(w.output,w.matchStart+1,w.nextMatch);
}
},
{
name: "snipSnapExplicitLink",
match: "\\[",
lookaheadRegExp: /\[(.*?)\]/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var link = lookaheadMatch[1];
var text = link;
createTiddlyText(createTiddlyLink(w.output,link,false,null,w.isStatic),text);
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
},
{
name: "snipSnapExternalLink",
match: "{link:",
lookaheadRegExp: /\{link:(?:(.*?)\|)(.*?)\}/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var link = lookaheadMatch[2];
var text = lookaheadMatch[1] ? lookaheadMatch[1] : link;
var e = createExternalLink(w.output,link);
createTiddlyText(e,text);
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
},
{
name: "snipSnapNotWikiLink",
match: "!" + config.textPrimitives.wikiLink,
handler: function(w)
{
w.outputText(w.output,w.matchStart+1,w.nextMatch);
}
},
{
name: "snipSnapWikiLink",
match: config.textPrimitives.wikiLink,
handler: function(w)
{
if(w.matchStart > 0) {
var preRegExp = new RegExp(config.textPrimitives.anyLetter,"mg");
preRegExp.lastIndex = w.matchStart-1;
var preMatch = preRegExp.exec(w.source);
if(preMatch.index == w.matchStart-1) {
w.outputText(w.output,w.matchStart,w.nextMatch);
return;
}
}
var output = w.output;
if(w.autoLinkWikiWords == true || store.isShadowTiddler(w.matchText)) {
output = createTiddlyLink(w.output,w.matchText,false,null,w.isStatic);
}
w.outputText(output,w.matchStart,w.nextMatch);
}
},
{
name: "snipSnapUrlLink",
match: config.textPrimitives.urlPattern,
handler: function(w)
{
w.outputText(createExternalLink(w.output,w.matchText),w.matchStart,w.nextMatch);
}
},
{
name: "snipSnapBoldByChar",
match: "__",
termRegExp: /(__)/mg,
element: "strong",
handler: config.formatterHelpers.createElementAndWikify
},
{
name: "snipSnapItalicByChar",
match: "~~",
termRegExp: /(~~)/mg,
element: "em",
handler: config.formatterHelpers.createElementAndWikify
},
{
name: "snipSnapStrikeByChar",
match: "--(?!\\s|$)",
termRegExp: /((?!\s)--|(?=\n\n))/mg,
element: "strike",
handler: config.formatterHelpers.createElementAndWikify
},
{
name: "snipSnapMonospacedByChar",
match: "\\{\\{\\{",
lookaheadRegExp: /\{\{\{((?:.|\n)*?)\}\}\}/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
createTiddlyElement(w.output,"code",null,null,lookaheadMatch[1]);
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
},
{
name: "snipSnapParagraph",
match: "\\n{2,}",
handler: function(w)
{
w.output = createTiddlyElement(w.output,"p");
}
},
{
name: "snipSnapHtmlEntitiesEncoding",
match: "&#?[a-zA-Z0-9]{2,8};",
handler: function(w)
{
createTiddlyElement(w.output,"span").innerHTML = w.matchText;
}
}
];
config.parsers.snipSnapFormatter = new Formatter(config.snipSnapFormatters);
config.parsers.snipSnapFormatter.format = 'snipsnap';
config.parsers.snipSnapFormatter.formatTag = "SnipSnapFormat";
} // end of "install only once"
//}}}
/***
|''Name:''|SocialtextAdaptorPlugin|
|''Description:''|Adaptor for moving and converting data to and from Socialtext Wikis|
|''Author:''|Martin Budden (mjbudden (at) gmail (dot) com) and JeremyRuston (jeremy (at) osmosoft (dot) com)|
|''Source:''|http://www.martinswiki.com/#SocialtextAdaptorPlugin|
|''CodeRepository:''|http://svn.tiddlywiki.org/Trunk/contributors/MartinBudden/adaptors/SocialtextAdaptorPlugin.js|
|''Version:''|0.5.1|
|''Date:''|Feb 25, 2007|
|''Comments:''|Please make comments at http://groups.google.co.uk/group/TiddlyWikiDev|
|''License:''|[[Creative Commons Attribution-ShareAlike 2.5 License|http://creativecommons.org/licenses/by-sa/2.5/]]|
|''~CoreVersion:''|2.2.0|
Socialtext REST documentation is at:
http://www.eu.socialtext.net/st-rest-docs/index.cgi?socialtext_rest_documentation
***/
//{{{
if(!version.extensions.SocialtextAdaptorPlugin) {
version.extensions.SocialtextAdaptorPlugin = {installed:true};
function SocialtextAdaptor()
{
this.host = null;
this.workspace = null;
return this;
}
SocialtextAdaptor.mimeType = 'text/x.socialtext-wiki';
SocialtextAdaptor.serverType = 'socialtext';
SocialtextAdaptor.serverParsingErrorMessage = "Error parsing result from server";
SocialtextAdaptor.errorInFunctionMessage = "Error in function SocialtextAdaptor.%0";
SocialtextAdaptor.prototype.setContext = function(context,userParams,callback)
{
if(!context) context = {};
context.userParams = userParams;
if(callback) context.callback = callback;
context.adaptor = this;
if(!context.host)
context.host = this.host;
if(!context.workspace && this.workspace)
context.workspace = this.workspace;
return context;
};
SocialtextAdaptor.doHttpGET = function(uri,callback,params,headers,data,contentType,username,password)
{
return doHttp('GET',uri,data,contentType,username,password,callback,params,headers);
};
SocialtextAdaptor.doHttpPOST = function(uri,callback,params,headers,data,contentType,username,password)
{
return doHttp('POST',uri,data,contentType,username,password,callback,params,headers);
};
SocialtextAdaptor.fullHostName = function(host)
{
if(!host)
return '';
if(!host.match(/:\/\//))
host = 'http://' + host;
if(host.substr(host.length-1) != '/')
host = host + '/';
return host;
};
SocialtextAdaptor.minHostName = function(host)
{
return host ? host.replace(/^http:\/\//,'').replace(/\/$/,'') : '';
};
// Convert a page title to the normalized form used in uris
SocialtextAdaptor.normalizedTitle = function(title)
{
var n = title.toLowerCase();
n = n.replace(/\s/g,'_').replace(/\//g,'_').replace(/\./g,'_').replace(/:/g,'').replace(/\?/g,'');
if(n.charAt(0)=='_')
n = n.substr(1);
return String(n);
};
// Convert a Socialtext date in YYYY-MM-DD hh:mm format into a JavaScript Date object
SocialtextAdaptor.dateFromEditTime = function(editTime)
{
var dt = editTime;
return new Date(Date.UTC(dt.substr(0,4),dt.substr(5,2)-1,dt.substr(8,2),dt.substr(11,2),dt.substr(14,2)));
};
SocialtextAdaptor.prototype.openHost = function(host,context,userParams,callback)
{
this.host = SocialtextAdaptor.fullHostName(host);
context = this.setContext(context,userParams,callback);
if(context.callback) {
context.status = true;
window.setTimeout(function() {callback(context,userParams);},0);
}
return true;
};
SocialtextAdaptor.prototype.openWorkspace = function(workspace,context,userParams,callback)
{
this.workspace = workspace;
context = this.setContext(context,userParams,callback);
if(context.callback) {
context.status = true;
window.setTimeout(function() {callback(context,userParams);},0);
}
return true;
};
SocialtextAdaptor.prototype.getWorkspaceList = function(context,userParams,callback)
{
context = this.setContext(context,userParams,callback);
var uriTemplate = '%0data/workspaces';
var uri = uriTemplate.format([context.host]);
var req = SocialtextAdaptor.doHttpGET(uri,SocialtextAdaptor.getWorkspaceListCallback,context,{'accept':'application/json'});
return typeof req == 'string' ? req : true;
};
SocialtextAdaptor.getWorkspaceListCallback = function(status,context,responseText,uri,xhr)
{
context.status = false;
context.statusText = SocialtextAdaptor.errorInFunctionMessage.format(['getWorkspaceListCallback']);
if(status) {
try {
eval('var info=' + responseText);
} catch (ex) {
context.statusText = exceptionText(ex,SocialtextAdaptor.serverParsingErrorMessage);
if(context.callback)
context.callback(context,context.userParams);
return;
}
var list = [];
for(var i=0; i<info.length; i++) {
var item = {
title:info[i].title,
name:info[i].name,
modified:SocialtextAdaptor.dateFromEditTime(info[i].modified_time)
};
list.push(item);
}
context.workspaces = list;
context.status = true;
} else {
context.statusText = xhr.statusText;
}
if(context.callback)
context.callback(context,context.userParams);
};
SocialtextAdaptor.prototype.getTiddlerList = function(context,userParams,callback)
{
context = this.setContext(context,userParams,callback);
var uriTemplate = '%0data/workspaces/%1/pages?order=newest';//!! ? or ;
var uri = uriTemplate.format([context.host,context.workspace]);
var req = SocialtextAdaptor.doHttpGET(uri,SocialtextAdaptor.getTiddlerListCallback,context,{'accept':'application/json'});
return typeof req == 'string' ? req : true;
};
SocialtextAdaptor.getTiddlerListCallback = function(status,context,responseText,uri,xhr)
{
context.status = false;
context.statusText = SocialtextAdaptor.errorInFunctionMessage.format(['getTiddlerListCallback']);
if(status) {
try {
eval('var info=' + responseText);
} catch (ex) {
context.statusText = exceptionText(ex,SocialtextAdaptor.serverParsingErrorMessage);
if(context.callback)
context.callback(context,context.userParams);
return;
}
var list = [];
for(var i=0; i<info.length; i++) {
var tiddler = new Tiddler(info[i].name);
tiddler.modified = SocialtextAdaptor.dateFromEditTime(info[i].last_edit_time);
tiddler.modifier = info[i].last_editor;
tiddler.tags = info[i].tags;
tiddler.fields['server.page.id'] = info[i].page_id;
tiddler.fields['server.page.name'] = info[i].name;
tiddler.fields['server.page.revision'] = String(info[i].revision_id);
list.push(tiddler);
}
context.tiddlers = list;
context.status = true;
} else {
context.statusText = xhr.statusText;
}
if(context.callback)
context.callback(context,context.userParams);
};
SocialtextAdaptor.prototype.generateTiddlerInfo = function(tiddler)
{
var info = {};
var host = this && this.host ? this.host : SocialtextAdaptor.fullHostName(tiddler.fields['server.host']);
var workspace = this && this.workspace ? this.workspace : tiddler.fields['server.workspace'];
uriTemplate = '%0%1/index.cgi?%2';
info.uri = uriTemplate.format([host,workspace,SocialtextAdaptor.normalizedTitle(tiddler.title)]);
return info;
};
SocialtextAdaptor.prototype.getTiddler = function(title,context,userParams,callback)
{
return this.getTiddlerRevision(title,null,context,userParams,callback);
};
SocialtextAdaptor.prototype.getTiddlerRevision = function(title,revision,context,userParams,callback)
{
context = this.setContext(context,userParams,callback);
// request the page in json format to get the page attributes
if(revision) {
var uriTemplate = '%0data/workspaces/%1/pages/%2/revisions/%3';
context.revision = revision;
} else {
uriTemplate = '%0data/workspaces/%1/pages/%2';
context.revision = null;
}
uri = uriTemplate.format([context.host,context.workspace,SocialtextAdaptor.normalizedTitle(title),revision]);
context.tiddler = new Tiddler(title);
context.tiddler.fields.wikiformat = 'socialtext';
context.tiddler.fields['server.host'] = SocialtextAdaptor.minHostName(context.host);
context.tiddler.fields['server.workspace'] = context.workspace;
var req = SocialtextAdaptor.doHttpGET(uri,SocialtextAdaptor.getTiddlerCallback,context,{'accept':'application/json'});
return typeof req == 'string' ? req : true;
};
SocialtextAdaptor.getTiddlerCallback = function(status,context,responseText,uri,xhr)
{
context.status = false;
context.statusText = SocialtextAdaptor.errorInFunctionMessage.format(['getTiddlerCallback']);
if(status) {
try {
eval('var info=' + responseText);
context.tiddler.tags = info.tags;
context.tiddler.fields['server.page.id'] = info.page_id;
context.tiddler.fields['server.page.name'] = info.name;
context.tiddler.fields['server.page.revision'] = String(info.revision_id);
context.tiddler.modifier = info.last_editor;
context.tiddler.modified = SocialtextAdaptor.dateFromEditTime(info.last_edit_time);
} catch (ex) {
context.statusText = exceptionText(ex,SocialtextAdaptor.serverParsingErrorMessage);
if(context.callback)
context.callback(context,context.userParams);
return;
}
context.status = true;
} else {
context.statusText = xhr.statusText;
if(context.callback)
context.callback(context,context.userParams);
return;
}
var uriTemplate = context.revision ? '%0data/workspaces/%1/pages/%2/revisions/%3' : '%0data/workspaces/%1/pages/%2';
var host = SocialtextAdaptor.fullHostName(context.tiddler.fields['server.host']);
var workspace = context.workspace ? context.workspace : context.tiddler.fields['server.workspace'];
uri = uriTemplate.format([host,workspace,SocialtextAdaptor.normalizedTitle(context.tiddler.title),context.revision]);
var req = SocialtextAdaptor.doHttpGET(uri,SocialtextAdaptor.getTiddlerCallback2,context,{'accept':SocialtextAdaptor.mimeType});
};
SocialtextAdaptor.getTiddlerCallback2 = function(status,context,responseText,uri,xhr)
{
context.tiddler.text = responseText;
if(status) {
context.status = true;
} else {
context.status = false;
context.statusText = xhr.statusText;
}
if(context.callback)
context.callback(context,context.userParams);
};
SocialtextAdaptor.prototype.getTiddlerRevisionList = function(title,limit,context,userParams,callback)
{
context = this.setContext(context,userParams,callback);
var uriTemplate = '%0data/workspaces/%1/pages/%2/revisions?accept=application/json';
if(!limit)
limit = 5;
var uri = uriTemplate.format([context.host,context.workspace,SocialtextAdaptor.normalizedTitle(title),limit]);
var req = SocialtextAdaptor.doHttpGET(uri,SocialtextAdaptor.getTiddlerRevisionListCallback,context);
return typeof req == 'string' ? req : true;
};
SocialtextAdaptor.getTiddlerRevisionListCallback = function(status,context,responseText,uri,xhr)
{
context.status = false;
if(status) {
var content = null;
try {
eval('var info=' + responseText);
} catch (ex) {
context.statusText = exceptionText(ex,SocialtextAdaptor.serverParsingErrorMessage);
if(context.callback)
context.callback(context,context.userParams);
return;
}
list = [];
for(var i=0; i<info.length; i++) {
var tiddler = new Tiddler(info[i].name);
tiddler.modified = SocialtextAdaptor.dateFromEditTime(info[i].last_edit_time);
tiddler.modifier = info[i].last_editor;
tiddler.tags = info[i].tags;
tiddler.fields['server.page.id'] = info[i].page_id;
tiddler.fields['server.page.name'] = info[i].name;
tiddler.fields['server.page.revision'] = info[i].revision_id;
list.push(tiddler);
}
var sortField = 'server.page.revision';
list.sort(function(a,b) {return a.fields[sortField] < b.fields[sortField] ? +1 : (a.fields[sortField] == b.fields[sortField] ? 0 : -1);});
context.revisions = list;
context.status = true;
} else {
context.statusText = xhr.statusText;
}
if(context.callback)
context.callback(context,context.userParams);
};
SocialtextAdaptor.prototype.putTiddler = function(tiddler,context,userParams,callback)
{
context = this.setContext(context,userParams,callback);
context.tiddler = tiddler;
context.title = tiddler.title;
var uriTemplate = '%0data/workspaces/%1/pages/%2';
var host = context.host ? context.host : SocialtextAdaptor.fullHostName(tiddler.fields['server.host']);
var workspace = context.workspace ? context.workspace : tiddler.fields['server.workspace'];
var uri = uriTemplate.format([host,workspace,tiddler.title,tiddler.text]);
//var req = doHttp('POST',uri,tiddler.text,SocialtextAdaptor.mimeType,null,null,SocialtextAdaptor.putTiddlerCallback,context,{"X-Http-Method": "PUT"});
var req = SocialtextAdaptor.doHttpPOST(uri,SocialtextAdaptor.putTiddlerCallback,context,{"X-Http-Method": "PUT"},tiddler.text,SocialtextAdaptor.mimeType);
return typeof req == 'string' ? req : true;
};
SocialtextAdaptor.putTiddlerCallback = function(status,context,responseText,uri,xhr)
{
if(status) {
context.status = true;
} else {
context.status = false;
context.statusText = xhr.statusText;
}
if(context.callback)
context.callback(context,context.userParams);
};
SocialtextAdaptor.prototype.close = function()
{
return true;
};
config.adaptors[SocialtextAdaptor.serverType] = SocialtextAdaptor;
} //# end of 'install only once'
//}}}
/***
|''Name:''|SocialtextFormatterPlugin|
|''Description:''|Allows Tiddlers to use [[Socialtext|http://www.socialtext.com/]] text formatting|
|''Author:''|Martin Budden (mjbudden (at) gmail (dot) com)|
|''Source:''|http://www.martinswiki.com/#SocialtextFormatterPlugin|
|''CodeRepository:''|http://svn.tiddlywiki.org/Trunk/contributors/MartinBudden/formatters/SocialtextFormatterPlugin.js|
|''Version:''|0.9.4|
|''Date:''|Jan 21, 2007|
|''Comments:''|Please make comments at http://groups.google.co.uk/group/TiddlyWikiDev|
|''License:''|[[Creative Commons Attribution-ShareAlike 2.5 License|http://creativecommons.org/licenses/by-sa/2.5/]]|
|''~CoreVersion:''|2.1.0|
This is the SocialtextFormatterPlugin, which allows you to insert Socialtext formated text into a TiddlyWiki.
The aim is not to fully emulate Socialtext, but to allow you to work with Socialtext content off-line and then resync the content with your Socialtext wiki later on, with the expectation that only minor edits will be required.
To use Socialtext format in a Tiddler, tag the Tiddler with SocialtextFormat or set the tiddler's {{{wikiformat}}} extended field to {{{socialtext}}}
Please report any defects you find at http://groups.google.co.uk/group/TiddlyWikiDev
***/
//{{{
// Ensure that the SocialtextFormatter Plugin is only installed once.
if(!version.extensions.SocialtextFormatterPlugin) {
version.extensions.SocialtextFormatterPlugin = {installed:true};
if(version.major < 2 || (version.major == 2 && version.minor < 1))
{alertAndThrow('SocialtextFormatterPlugin requires TiddlyWiki 2.1 or later.');}
SocialtextFormatter = {}; // 'namespace' for local functions
wikify = function(source,output,highlightRegExp,tiddler)
{
if(source && source != '') {
var w = new Wikifier(source,getParser(tiddler),highlightRegExp,tiddler);
var out = output;
if(tiddler && (tiddler.isTagged(config.parsers.socialtextFormatter.formatTag) || (tiddler.fields.wikiformat==config.parsers.socialtextFormatter.format)) ) {
var d1 = createTiddlyElement(output,'div','content-display-body','content-section-visible');
var d2 = createTiddlyElement(d1,'div','wikipage');
out = createTiddlyElement(d2,'div',null,'wiki');
}
var time1,time0 = new Date();
w.subWikifyUnterm(out);
if(tiddler && config.options.chkDisplayInstrumentation) {
time1 = new Date();
var t = tiddler ? tiddler.title : source.substr(0,10);
displayMessage("Wikify '"+t+"' in " + (time1-time0) + " ms");
}
}
};
stDebug = function(out,str)
{
createTiddlyText(out,str.replace(/\n/mg,'\\n').replace(/\r/mg,'RR'));
createTiddlyElement(out,'br');
};
SocialtextFormatter.Tiddler_changed = Tiddler.prototype.changed;
Tiddler.prototype.changed = function()
{
if((this.fields.wikiformat==config.parsers.socialtextFormatter.format) || this.isTagged(config.parsers.socialtextFormatter.formatTag)) {
// update the links array, by checking for Socialtext format links
this.links = [];
var tiddlerLinkRegExp = /(?:\"(.*?)\" ?)?\[([^\]]*?)\]/mg;
tiddlerLinkRegExp.lastIndex = 0;
var match = tiddlerLinkRegExp.exec(this.text);
while(match) {
var link = match[2];
this.links.pushUnique(link);
match = tiddlerLinkRegExp.exec(this.text);
}
}/* else {
return SocialtextFormatter.Tiddler_changed.apply(this,arguments);
}*/
this.linksUpdated = true;
};
SocialtextFormatter.wafl = function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var lm2 = lookaheadMatch[2];
switch(lookaheadMatch[1]) {
case 'image':
var img = createTiddlyElement(w.output,'img');
img.src = w.tiddler.title + '/' + lm2;
createTiddlyText(img,lm2);
break;
case 'file':
var s = createTiddlyElement(w.output,'span',null,'nlw_phrase');
var a = createTiddlyElement(s,'a');
a.href = w.tiddler.title + '/' + lm2;
createTiddlyText(a,lm2);
break;
case 'link':
s = createTiddlyElement(w.output,'span',null,'nlw_phrase');
a = createTiddlyElement(s,'a');
var t = w.tiddler ? w.tiddler.title + ':' : '';
a.setAttribute('href','#' + t + lm2);
a.title = 'section link';
createTiddlyText(a,lm2);
break;
case 'weblog':
s = createTiddlyElement(w.output,'span',null,'nlw_phrase');
var text = lm2;
var link = 'Weblog: ' + lm2;
createTiddlyText(createTiddlyLink(s,link,false,null,w.isStatic),text);
break;
case 'section':
a = createTiddlyElement(w.output,'a');// drop anchor
t = w.tiddler ? w.tiddler.title + ':' : '';
a.setAttribute('name',t + lm2);
break;
case 'date':
createTiddlyText(w.output,lm2);
break;
case 'user':
var oldSource = w.source;
w.source = lm2;
w.nextMatch = 0;
w.subWikifyUnterm(w.output);
w.source = oldSource;
break;
// Shortcut expansions - not strictly syntax
case 'google':
s = createTiddlyElement(w.output,'span',null,'nlw_phrase');
a = createExternalLink(s,'http://www.google.com/search?q='+lm2);
createTiddlyText(a,lm2);
break;
case 'fedex':
s = createTiddlyElement(w.output,'span',null,'nlw_phrase');
a = createExternalLink(s,'http://www.fedex.com/Tracking?tracknumbers='+lm2);
createTiddlyText(a,lm2);
break;
case 'map':
s = createTiddlyElement(w.output,'span',null,'nlw_phrase');
a = createExternalLink(s,'http://maps.google.com/maps?q='+lm2);
createTiddlyText(a,lm2);
break;
case 'wikipedia':
s = createTiddlyElement(w.output,'span',null,'nlw_phrase');
a = createExternalLink(s,'http://en.wikipedia.org/wiki/'+lm2);
createTiddlyText(a,lm2);
break;
case 'rt':
s = createTiddlyElement(w.output,'span',null,'nlw_phrase');
a = createExternalLink(s,'http://rt.socialtext.net/Ticket/Display.html?id='+lm2);
createTiddlyText(a,lm2);
break;
case 'stcal':
s = createTiddlyElement(w.output,'span',null,'nlw_phrase');
a = createExternalLink(s,'https://calendar.socialtext.net:445/view_t.php?timeb=1&id=3&date='+lm2);
createTiddlyText(a,lm2);
break;
case 'svn':
s = createTiddlyElement(w.output,'span',null,'nlw_phrase');
a = createExternalLink(s,'https://repo.socialtext.net/listing.php?rev='+lm2+'sc=1');
createTiddlyText(a,lm2);
break;
default:
w.outputText(w.output,w.matchStart,w.nextMatch);
return;
}
w.nextMatch = this.lookaheadRegExp.lastIndex;
} else {
w.outputText(w.output,w.matchStart,w.nextMatch);
}
};
SocialtextFormatter.presence = function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var p = lookaheadMatch[1];
var text = lookaheadMatch[2];
var link;
var src;
if(p=='aim') {
link = 'aim:goim?screenname=' + text + '&message=hello';
src = 'http://big.oscar.aol.com/sleepleft?on_url=http://www.aim.com/remote/gr/MNB_online.gif&off_url=http://www.aim.com/remote/gr/MNB_offline.gif';
} else if(p=='yahoo'||p=='ymsgr') {
link = 'ymsgr:sendIM?'+text;
src = 'http://opi.yahoo.com/online?u=chrislondonbridge&f=.gif';
} else if(p=='skype'||p=='callto') {
link = 'callto:'+text;
src = 'http://goodies.skype.com/graphics/skypeme_btn_small_green.gif';
} else if(p=='asap') {
link = 'http://asap2.convoq.com/AsapLinks/Meet.aspx?l='+text;
src = 'http://asap2.convoq.com/AsapLinks/Presence.aspx?l='+text;
}
var s = createTiddlyElement(w.output,'span',null,'nlw_phrase');
var a = createExternalLink(s,link);
var img = createTiddlyElement(a,'img');
createTiddlyText(a,text);
img.src = src;
img.border='0';
img.alt = '(' + lookaheadMatch[1] + ')';
if(p=='aim') {
img.width='11'; img.height='13';
}
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
};
config.formatterHelpers.singleCharFormat = function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart && lookaheadMatch[0].substr(lookaheadMatch[0].length-2,1) != ' ') {
w.subWikifyTerm(createTiddlyElement(w.output,this.element),this.termRegExp);
} else {
w.outputText(w.output,w.matchStart,w.nextMatch);
}
};
config.socialtext = {};
config.socialtext.formatters = [
{
name: 'socialtextHeading',
match: '^\\^{1,6} ?',
termRegExp: /(\n+)/mg,
handler: function(w)
{
var len = w.matchText.trim().length;
var e = createTiddlyElement(w.output,'h' + len);
var a = createTiddlyElement(e,'a');// drop anchor
var t = w.tiddler ? w.tiddler.title + ':' : '';
len = w.source.substr(w.nextMatch).indexOf('\n');
a.setAttribute('name',t+w.source.substr(w.nextMatch,len));
w.subWikifyTerm(e,this.termRegExp);
}
},
{
name: 'socialtextTable',
match: '^\\|(?:(?:.|\n)*)\\|$',
lookaheadRegExp: /^\|(?:(?:.|\n)*)\|$/mg,
cellRegExp: /(?:\|(?:[^\|]*)\|)(\n|$)?/mg,
cellTermRegExp: /((?:\x20*)\|)/mg,
handler: function(w)
{
var table = createTiddlyElement(w.output,'table');
var rowContainer = createTiddlyElement(table,'tbody');
var prevColumns = [];
w.nextMatch = w.matchStart;
this.lookaheadRegExp.lastIndex = w.nextMatch;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
while(lookaheadMatch && lookaheadMatch.index == w.nextMatch) {
var r = this.rowHandler(w,createTiddlyElement(rowContainer,'tr'),prevColumns);
if(!r) {
w.nextMatch++;
break;
}
this.lookaheadRegExp.lastIndex = w.nextMatch;
lookaheadMatch = this.lookaheadRegExp.exec(w.source);
}
},
rowHandler: function(w,e,prevColumns)
{
this.cellRegExp.lastIndex = w.nextMatch;
var cellMatch = this.cellRegExp.exec(w.source);
while(cellMatch && cellMatch.index == w.nextMatch) {
w.nextMatch++;
var cell = createTiddlyElement(e,'td');
w.subWikifyTerm(cell,this.cellTermRegExp);
if(cellMatch[1]) {
// End of row
w.nextMatch = this.cellRegExp.lastIndex;
return true;
}
// Cell
w.nextMatch--;
this.cellRegExp.lastIndex = w.nextMatch;
cellMatch = this.cellRegExp.exec(w.source);
}
return false;
}
},
{
name: 'socialtextList',
match: '^[\\*#]+ ',
lookaheadRegExp: /^([\*#])+ /mg,
termRegExp: /(\n+)/mg,
handler: function(w)
{
var stack = [w.output];
var currLevel = 0, currType = null;
var itemType = 'li';
w.nextMatch = w.matchStart;
this.lookaheadRegExp.lastIndex = w.nextMatch;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
while(lookaheadMatch && lookaheadMatch.index == w.nextMatch) {
var listType = lookaheadMatch[1] == '*' ? 'ul' : 'ol';
var listLevel = lookaheadMatch[0].length;
w.nextMatch += listLevel;
if(listLevel > currLevel) {
for(var i=currLevel; i<listLevel; i++) {
stack.push(createTiddlyElement(stack[stack.length-1],listType));
}
} else if(listLevel < currLevel) {
for(i=currLevel; i>listLevel; i--) {
stack.pop();
}
} else if(listLevel == currLevel && listType != currType) {
stack.pop();
stack.push(createTiddlyElement(stack[stack.length-1],listType));
}
currLevel = listLevel;
currType = listType;
var e = createTiddlyElement(stack[stack.length-1],itemType);
w.subWikifyTerm(e,this.termRegExp);
this.lookaheadRegExp.lastIndex = w.nextMatch;
lookaheadMatch = this.lookaheadRegExp.exec(w.source);
}
}
},
{
name: 'socialtextQuoteByLine',
match: '^>+',
lookaheadRegExp: /^>+/mg,
termRegExp: /(\n)/mg,
element: 'blockquote',
handler: function(w)
{
var stack = [w.output];
var currLevel = 0;
var newLevel = w.matchLength;
var i;
do {
if(newLevel > currLevel) {
for(i=currLevel; i<newLevel; i++) {
stack.push(createTiddlyElement(stack[stack.length-1],this.element));
}
} else if(newLevel < currLevel) {
for(i=currLevel; i>newLevel; i--) {
stack.pop();
}
}
currLevel = newLevel;
w.subWikifyTerm(stack[stack.length-1],this.termRegExp);
createTiddlyElement(stack[stack.length-1],'br');
this.lookaheadRegExp.lastIndex = w.nextMatch;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
var matched = lookaheadMatch && lookaheadMatch.index == w.nextMatch;
if(matched) {
newLevel = lookaheadMatch[0].length;
w.nextMatch += newLevel;
}
} while(matched);
}
},
{
name: 'socialtextRule',
match: '^----+$\\n+',
handler: function(w)
{
createTiddlyElement(w.output,'hr');
}
},
{
name: 'socialtextPreformatted',
match: '^\\.pre\\s*\\n',
lookaheadRegExp: /^.pre\s*\n((?:.|\n)*?)\n.pre\s*\n/mg,
element: 'pre',
handler: config.formatterHelpers.enclosedTextHelper
},
{
name: 'socialtextHtml',
match: '^\\.html',
lookaheadRegExp: /\.html((?:.|\n)*?)\.html/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
createTiddlyElement(w.output,'span').innerHTML = lookaheadMatch[1];
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
},
{
name: 'macro',
match: '<<',
lookaheadRegExp: /<<([^>\s]+)(?:\s*)((?:[^>]|(?:>(?!>)))*)>>/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart && lookaheadMatch[1]) {
w.nextMatch = this.lookaheadRegExp.lastIndex;
invokeMacro(w.output,lookaheadMatch[1],lookaheadMatch[2],w,w.tiddler);
}
}
},
{
name: 'socialtextExplicitLink',
match: '(?:".*?" ?)?\\[',
lookaheadRegExp: /(?:\"(.*?)\" ?)?\[([^\]]*?)\]/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var link = lookaheadMatch[2];
var text = lookaheadMatch[1] ? lookaheadMatch[1] : link;
createTiddlyText(createTiddlyLink(w.output,link,false,null,w.isStatic,w.tiddler),text);
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
},
{
name: 'socialtextExternalLink',
match: '(?:".*?" ?)?<[a-z]{2,8}:',
lookaheadRegExp: /(?:\"(.*?)\" ?)?<([a-z]{2,8}:.*?)>/mg,
imgRegExp: /\.(?:gif|ico|jpg|png)/g,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var link = lookaheadMatch[2];
var text = lookaheadMatch[1] ? lookaheadMatch[1] : link;
this.imgRegExp.lastIndex = 0;
if(this.imgRegExp.exec(link)) {
var img = createTiddlyElement(w.output,'img');
if(lookaheadMatch[1]) {
img.title = text;
}
img.alt = text;
img.src = link;
} else {
createTiddlyText(createExternalLink(w.output,link),text);
}
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
},
{
name: 'socialtextUrlLink',
match: config.textPrimitives.urlPattern,
handler: function(w)
{
w.outputText(createExternalLink(w.output,w.matchText),w.matchStart,w.nextMatch);
}
},
{
name: 'socialtextBold',
match: '\\*(?![\\s\\*])',
lookaheadRegExp: /\*(?!\s)(?:.*?)(?!\s)\*(?=[$\s\|\._\-,])/mg,
termRegExp: /((?!\s)\*(?=[$\s\|\.\-_,]))/mg,
element: 'strong',
handler: config.formatterHelpers.singleCharFormat
},
{
name: 'socialtextItalic',
match: '_(?![\\s_])',
lookaheadRegExp: /_(?!\s)(?:.*?)(?!\s)_(?=[$\s\|\.\*\-,])/mg,
termRegExp: /((?!\s)_(?=[$\s\|\.\*\-,]))/mg,
element: 'em',
handler: config.formatterHelpers.singleCharFormat
},
{
name: 'socialtextStrike',
match: '-(?![\\s\\-])',
lookaheadRegExp: /-(?!\s)(?:.*?)(?!\s)-(?=[$\s\|\.\*_,])/mg,
termRegExp: /((?!\s)-(?=[$\s\|\.\*_,]))/mg,
element: 'del',
handler: config.formatterHelpers.singleCharFormat
},
{
name: 'socialtextMonoSpaced',
match: '`(?![\\s`])',
lookaheadRegExp: /`(?!\s)(?:.*?)(?!\s)`(?=[$\s\.\*\-_,])/mg,
termRegExp: /((?!\s)`(?=[$\s\.\*\-_,]))/mg,
element: 'tt',
handler: config.formatterHelpers.singleCharFormat
},
{
name: 'socialtextParagraph',
match: '\\n{2,}',
handler: function(w)
{
createTiddlyElement(w.output,'p');
}
},
{
name: 'socialtextLineBreak',
match: '\\n',
handler: function(w)
{
createTiddlyElement(w.output,'br');
}
},
{
name: 'socialtextNoWiki',
match: '\\{\\{',
lookaheadRegExp: /\{\{((?:.|\n)*?)\}\}/mg,
element: 'span',
handler: config.formatterHelpers.enclosedTextHelper
},
{
name: 'socialtextTrademark',
match: '\\{tm\\}',
handler: function(w)
{
createTiddlyElement(w.output,'span').innerHTML = '™';
}
},
{
name: 'socialtextWafl',
match: '\\{(?:[a-z]{2,16}): ?.*?\\}',
lookaheadRegExp: /\{([a-z]{2,16}): ?(.*?)\}/mg,
handler: SocialtextFormatter.wafl
},
{
name: 'socialtextPresence',
match: '(?:aim|yahoo|ymsgr|skype|callto|asap):\\w+',
lookaheadRegExp: /(aim|yahoo|ymsgr|skype|callto|asap):(\w+)/mg,
handler: SocialtextFormatter.presence
},
{
name: 'socialtextMailTo',
match: '[\\w\.]+@[\\w]+\.[\\w\.]+',
lookaheadRegExp: /([\w\.]+@[\w]+\.[\w\.]+)/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var text = lookaheadMatch[1];
createTiddlyText(createExternalLink(w.output,'mailto:'+text),text);
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
},
{
name: 'socialtextHtmlEntitiesEncoding',
match: '&#?[a-zA-Z0-9]{2,8};',
handler: function(w)
{
createTiddlyElement(w.output,'span').innerHTML = w.matchText;
}
}
];
config.parsers.socialtextFormatter = new Formatter(config.socialtext.formatters);
config.parsers.socialtextFormatter.format = 'socialtext';
config.parsers.socialtextFormatter.formatTag = 'SocialtextFormat';
} // end of 'install only once'
//}}}
/***
|''Name:''|SplashScreenPlugin|
|''Description:''|Provides a splash screen that consists of the rendered default tiddlers|
|''Author:''|Martin Budden|
|''~CodeRepository:''|http://svn.tiddlywiki.org/Trunk/contributors/MartinBudden/plugins/SplashScreenPlugin.js |
|''Version:''|0.0.4|
|''Date:''|April 17, 2008|
|''Comments:''|Please make comments at http://groups.google.co.uk/group/TiddlyWikiDev |
|''License:''|[[Creative Commons Attribution-ShareAlike 3.0 License|http://creativecommons.org/licenses/by-sa/3.0/]] |
|''~CoreVersion:''|2.4|
To make this example into a real TiddlyWiki plugin, you need to:
# Do the actions indicated by the !!TODO comments, namely:
## Write the documentation for the plugin
!!Description
Provides a splash screen that consists of the default tiddlers while TiddlyWiki is loading
!!Usage
!!TODO describe how to use the plugin - how a user should include it in their TiddlyWiki, parameters to the plugin etc
***/
//{{{
if(!version.extensions.SplashScreenPlugin) {
version.extensions.SplashScreenPlugin = {installed:true};
//config.macros.splashScreen = {};
//config.macros.splashScreen.init = function()
version.extensions.SplashScreenPlugin.setup = function()
{
if(store.tiddlerExists("MarkupPostHead"))
return;
var text = "<!--{{{-->\n\n";
text += "<style type=\"text/css\">\n";
text += "#contentWrapper {display:none;}\n";
text += "#splashScreen {display:block;}\n";
/*
text += ".title {color:#841;}\n";
text += ".subtitle {color:#666;}\n";
text += ".header {background:#04b;}\n";
text += ".headerShadow {color:#000;}\n";
text += ".headerShadow a {font-weight:normal; color:#000;}\n";
text += ".headerForeground {color:#fff;}\n";
text += ".headerForeground a {font-weight:normal; color:#8cf;}\n";
text += ".shadow .title {color:#666;}\n";
*/
var cp = "ColorPalette";
var pm = store.getTiddlerSlice(cp,"PrimaryMid");
var bg = store.getTiddlerSlice(cp,"Background");
var fg = store.getTiddlerSlice(cp,"Foreground");
var pp = store.getTiddlerSlice(cp,"PrimaryPale");
var sm = store.getTiddlerSlice(cp,"SecondaryMid");
var sd = store.getTiddlerSlice(cp,"SecondaryDark");
var td = store.getTiddlerSlice(cp,"TertiaryDark");
text += "body {background:"+bg+"; color:"+fg+";}\n";
text += "a {color:"+pm+";}";
text += "a:hover {background-color:"+pm+"; color:"+bg+";}";
text += ".title {color:"+sd+";}\n";
text += ".subtitle {color:"+td+";}\n";
text += ".header {background:"+pm+";}\n";
text += ".headerShadow {color:"+fg+";}\n";
text += ".headerShadow a {font-weight:normal; color:"+fg+";}\n";
text += ".headerForeground {color:"+bg+";}\n";
text += ".headerForeground a {font-weight:normal; color:"+pp+";}\n";
text += ".shadow .title {color:"+td+";}\n";
text += ".viewer table, table.twtable {border:2px solid "+td+";}";
text += ".viewer th, .viewer thead td, .twtable th, .twtable thead td {background:"+sm+"; border:1px solid "+td+"; color:"+bg+";}";
text += ".viewer td, .viewer tr, .twtable td, .twtable tr {border:1px solid "+td+";}";
console.log(store.getTiddlerText("StyleSheet"));
var tiddlers = store.filterTiddlers(store.getTiddlerText("StyleSheet"));
for(var i=0;i<tiddlers.length;i++) {
text += tiddlers[i].text;
}
text += "</style>\n";
text += "<!--}}}-->\n\n";
var tiddler = store.createTiddler("MarkupPostHead");
tiddler.set(tiddler.title,text,config.options.txtUserName,null,"excludeLists excludeSearch");
var sitetitle = store.getTiddlerText("SiteTitle");
var sitesubtitle = store.getTiddlerText("SiteSubtitle");
var pt = store.getTiddlerText("PageTemplate");
pt = pt.replace(/<span class='siteTitle' refresh='content' tiddler='SiteTitle'><\/span>/mg,"<span class=\"siteTitle\">"+sitetitle+"</span>");
pt = pt.replace(/<span class='siteSubtitle' refresh='content' tiddler='SiteSubtitle'><\/span>/mg,"<span class=\"siteSubtitle\">"+sitesubtitle+"</span>");
pt = pt.replace(/<!--\{\{\{-->/mg,"").replace(/<!--\}\}\}-->/mg,"");
text = "";
tiddlers = store.filterTiddlers(store.getTiddlerText("DefaultTiddlers"));
for(i=0;i<tiddlers.length;i++) {
tiddler = tiddlers[i];
var title = tiddler.title;
var tiddlerElem = createTiddlyElement(null,"div","tempId"+tiddler.title,"tiddler");
tiddlerElem.style.display = "none";
tiddlerElem.setAttribute("refresh","tiddler");
var template = story.chooseTemplateForTiddler(title);
tiddlerElem.setAttribute("tiddler",title);
tiddlerElem.setAttribute("template",template);
var t = story.getTemplateForTiddler(title,template,tiddler);
t = t.replace(/<div class=['"]toolbar[^<]*<\/div>/mg,"<div class=\"toolbar\"><br /></div>");
t = t.replace(/<div class=['"]tagging['"][^>]*><\/div>\n/mg,"");
t = t.replace(/<div class=['"]tagged['"][^>]*><\/div>\n/mg,"");
tiddlerElem.innerHTML = t;
applyHtmlMacros(tiddlerElem,tiddler);
text += tiddlerElem.innerHTML;
}
text = text.replace(/<!--\{\{\{-->/mg,"").replace(/<!--\}\}\}-->/mg,"");
var splash = "<!--{{{-->\n\n";
splash += "<div id=\"splashScreen\">\n";
splash += pt;
splash = splash.replace(/<div id='tiddlerDisplay'><\/div>/mg,"<div id=\"s_tiddlerDisplay\">"+text+"</div>");
splash += "</div>\n";
splash += "<!--}}}-->\n\n";
tiddler = store.createTiddler("MarkupPreBody");
tiddler.set(tiddler.title,splash,config.options.txtUserName,null,"excludeLists excludeSearch");
store.setDirty(true);
};
version.extensions.SplashScreenPlugin.saveChanges = saveChanges;
function saveChanges()
{
version.extensions.SplashScreenPlugin.setup();
version.extensions.SplashScreenPlugin.saveChanges();
}
} //# end of 'install only once'
//}}}
/***
Place your custom CSS here
***/
/*{{{*/
[[StyleSheetMB]]
[[Styles HorizontalMainMenu]]
/*}}}*/
/*{{{*/
h1 {font-size:1.5em;font-variant:small-caps;}
h2 {font-size:1.35em;font-variant:small-caps;}
h3 {font-size:1.25em;font-variant:small-caps;}
h4 {font-size:1.1em;}
h5 {font-size:1em;}
/*element,padding,border,margin*/
h1, h2, h3, h4, h5 {
color:#014;background:transparent;
padding-left:0;padding-bottom:1px;
margin-top:1.2em;margin-bottom:0.3em;margin-left:0em;
}
h1 {border-bottom:2px solid #ccc;}
h2, h3 {border-bottom:1px solid #ccc;}
h4, h5 {border-bottom:0px;margin-top:1em;margin-bottom:0em;}
hr {height:0px;border:0;border-top:1px solid silver;}
.headerShadow {padding:1.5em 0em .5em 1em;}
.headerForeground {padding:1.5em 0em .5em 1em;}
.header {background:darkblue;}
/*.headerShadow {color:white;}
.headerForeground {color:black;}*/
#displayArea .tiddlyLinkExisting {text-decoration:underline;}
/* Tiddler title */
.title {color:black;border-bottom:2px solid #ddd;}
/* Tiddler subtitle */
.subtitle {font-size:0.9em;text-align:right;border-bottom:1px solid #ddd;}
.toolbar {padding-top:0px;padding-bottom:0px;color:#04b;}
/* Tiddler body */
.tiddler {-moz-border-radius:1em;border:1px solid #ccc;margin:0.5em;background:#fff;padding:0.5em;}
.tabContents {white-space:nowrap;}
.viewer pre {padding:0;margin-left:0;}
.viewer hr {border:solid 1px silver;}
/*.toolbar {visibility:visible}*/
.selected .toolbar {visibility:visible;color:#00f;}
.toolbar .button {color:#dee;}
.selected .toolbar .button {color:#014}
.tagging, .tagged, .selected .tagging, .selected .tagged {
font-size:75%;padding:0.3em;background-color:#eee;
border-top:1px solid #ccc;border-left:1px solid #ccc;
border-bottom:3px solid #ccc;border-right:3px solid #ccc;
max-width:45%;-moz-border-radius:1em;
}
/*}}}*/
#mainMenu {position:relative;left:auto;width:auto;text-align:left;line-height:normal;padding 0em 1em 0em 1em;font-size:normal;}
#mainMenu br {display:none;}
#mainMenu {background:#336699;}
#mainMenu {padding:2px;}
#mainMenu .button, #mainMenu .tiddlyLink {padding-left:0.5em;padding-right:0.5em;color:white;font-size:115%;}
#displayArea {margin-top:0;margin-right:15.5em;margin-bottom:0;margin-left:1em;padding-top:.1em;padding-bottom:.1em;}
/***
|''Name:''|TWikiAdaptorPlugin|
|''Description:''|Adaptor for moving and converting data to and from TWikis|
|''Author:''|Martin Budden (mjbudden (at) gmail (dot) com)|
|''Source:''|http://www.martinswiki.com/#TWikiAdaptorPlugin |
|''CodeRepository:''|http://svn.tiddlywiki.org/Trunk/contributors/MartinBudden/adaptors/TWikiAdaptorPlugin.js |
|''Version:''|0.6.1|
|''Date:''|Aug 16, 2007|
|''Comments:''|Please make comments at http://groups.google.co.uk/group/TiddlyWikiDev |
|''License:''|[[Creative Commons Attribution-ShareAlike 2.5 License|http://creativecommons.org/licenses/by-sa/2.5/]] |
|''~CoreVersion:''|2.2.0|
TWiki REST documentation is at:
http://twiki.org/cgi-bin/view/TWiki04/TWikiScripts
''For debug:''
|''Default TWiki Server''|<<option txttwikiDefaultServer>>|
|''Default TWiki Web(workspace)''|<<option txttwikiDefaultWorkspace>>|
|''Default TWiki username''|<<option txttwikiUsername>>|
|''Default TWiki password''|<<option txttwikiPassword>>|
***/
//{{{
if(!config.options.txttwikiDefaultServer)
{config.options.txttwikiDefaultServer = 'twiki.org';}
if(!config.options.txttwikiDefaultWorkspace)
{config.options.txttwikiDefaultWorkspace = 'Main';}
if(!config.options.txttwikiUsername)
{config.options.txttwikiUsername = '';}
if(!config.options.txttwikiPassword)
{config.options.txttwikiPassword = '';}
//}}}
//{{{
// Ensure that the plugin is only installed once.
if(!version.extensions.TWikiAdaptorPlugin) {
version.extensions.TWikiAdaptorPlugin = {installed:true};
function TWikiAdaptor()
{
this.host = null;
this.workspace = null;
// for debug
this.username = config.options.txttwikiUsername;
this.password = config.options.txttwikiPassword;
return this;
}
TWikiAdaptor.serverType = 'twiki';
TWikiAdaptor.serverParsingErrorMessage = "Error parsing result from server";
TWikiAdaptor.errorInFunctionMessage = "Error in function TWikiAdaptor.%0";
TWikiAdaptor.doHttpGET = function(uri,callback,params,headers,data,contentType,username,password)
{
return doHttp('GET',uri,data,contentType,username,password,callback,params,headers);
};
TWikiAdaptor.prototype.setContext = function(context,userParams,callback)
{
if(!context) context = {};
context.userParams = userParams;
if(callback) context.callback = callback;
context.adaptor = this;
if(!context.host)
context.host = this.host;
if(!context.workspace && this.workspace)
context.workspace = this.workspace;
return context;
};
TWikiAdaptor.fullHostName = function(host)
{
if(!host)
return '';
if(!host.match(/:\/\//))
host = 'http://' + host;
if(!host.match(/\/bin/) && !host.match(/\/cgi-bin/))
host = host.replace(/\/$/,'') + '/cgi-bin/';
if(host.substr(host.length-1) != '/')
host = host + '/';
return host;
};
TWikiAdaptor.minHostName = function(host)
{
return host ? host.replace(/^http:\/\//,'').replace(/cgi-bin\/$/,'').replace(/\/$/,'') : '';
};
TWikiAdaptor.normalizedTitle = function(title)
{
return title;
};
TWikiAdaptor.prototype.openHost = function(host,context,userParams,callback)
{
this.host = TWikiAdaptor.fullHostName(host);
context = this.setContext(context,userParams,callback);
if(context.callback) {
context.status = true;
window.setTimeout(function() {callback(context,userParams);},0);
}
return true;
};
TWikiAdaptor.prototype.openWorkspace = function(workspace,context,userParams,callback)
{
this.workspace = workspace;
context = this.setContext(context,userParams,callback);
if(context.callback) {
context.status = true;
window.setTimeout(function() {callback(context,userParams);},0);
}
return true;
};
TWikiAdaptor.prototype.getWorkspaceList = function(context,userParams,callback)
{
context = this.setContext(context,userParams,callback);
if(context.workspace) {
context.status = true;
context.workspace = [{name:context.workspace,title:context.workspace}];
if(context.callback)
window.setTimeout(function() {callback(context,userParams);},0);
return true;
}
var list = [];
context.workspaces = list;
context.status = true;
if(context && callback) {
window.setTimeout(function() {callback(context,userParams);},0);
}
return true;
};
TWikiAdaptor.getWorkspaceListCallback = function(status,context,responseText,uri,xhr)
{
context.status = false;
if(status) {
try {
eval('var info=' + responseText);
} catch (ex) {
context.statusText = exceptionText(ex,TWikiAdaptor.serverParsingErrorMessage);
if(context.callback)
context.callback(context,context.userParams);
return;
}
var list = [];
for(var i=0; i<info.length; i++) {
list.push({title:info[i].title});
}
context.workspaces = list;
context.status = true;
} else {
context.statusText = xhr.statusText;
}
if(context.callback)
context.callback(context,context.userParams);
};
TWikiAdaptor.prototype.getTiddlerList = function(context,userParams,callback,filter)
{
context = this.setContext(context,userParams,callback);
var limit = context.tiddlerLimit ? context.tiddlerLimit : 50;
if(filter) {
var list = [];
var params = filter.parseParams('anon',null,false);
for(var i=1; i<params.length; i++) {
var tiddler = new Tiddler(params[i].value);
list.push(tiddler);
}
context.tiddlers = list;
context.status = true;
if(context.callback)
window.setTimeout(function() {callback(context,userParams);},0);
return true;
}
var uriTemplate = '%0search/%1/?scope=topic&format="$topic"®ex=on&search=\\.*';
var uri = uriTemplate.format([context.host,context.workspace]);
var req = TWikiAdaptor.doHttpGET(uri,TWikiAdaptor.getTiddlerListCallback,context);
//return "getTiddlerList not supported";
return typeof req == 'string' ? req : true;
};
/*<div id="patternMainContents">Search: <b> ^a </b><p />
"ATasteOfTWiki"
"ATasteOfTWikiTemplate"
"AccessKeys"
"AdminDocumentationCategory"
"AdminSkillsAssumptions"
"AdminToolsCategory"
"AnApplicationWithWikiForm"
"AppendixEncodeURLsWithUTF8"
<div class="patternSearchResultCount" id="twikiBottomResultCount">Number of topics: <b>8</b></div><!--/patternSearchResultCount-->
*/
TWikiAdaptor.getTiddlerListCallback = function(status,context,responseText,uri,xhr)
{
context.status = false;
context.statusText = TWikiAdaptor.errorInFunctionMessage.format(['getTiddlerListCallback']);
if(status) {
try {
var text = responseText;
var mRegExp = /<div id=\"patternMainContents\">((?:.|\n)*?)<div class=\"patternSearchResultCount\"/mg;
mRegExp.lastIndex = 0;
var m = mRegExp.exec(text);
if(m) {
text = m[1];
} else {
if(context.callback)
context.callback(context,context.userParams);
return;
}
var list = [];
var matchRegExp = /\"([^\"]*)\"/mg;
matchRegExp.lastIndex = 0;
match = matchRegExp.exec(text);
while(match) {
var tiddler = new Tiddler(match[1]);
list.push(tiddler);
match = matchRegExp.exec(text);
}
context.tiddlers = list;
context.status = true;
} catch (ex) {
context.statusText = exceptionText(ex,TWikiAdaptor.serverParsingErrorMessage);
if(context.callback)
context.callback(context,context.userParams);
return;
}
} else {
context.statusText = xhr.statusText;
}
if(context.callback)
context.callback(context,context.userParams);
};
TWikiAdaptor.prototype.generateTiddlerInfo = function(tiddler)
{
var info = {};
var host = this && this.host ? this.host : TWikiAdaptor.fullHostName(tiddler.fields['server.host']);
var workspace = this && this.workspace ? this.workspace : tiddler.fields['server.workspace'];
var uriTemplate = '%0view/%1/%2';
info.uri = uriTemplate.format([host,workspace,tiddler.title]);
return info;
};
/*TWikiAdaptor.prototype.getTiddler = function(title,context,userParams,callback)
{
return this.getTiddlerRevision(title,null,context,userParams,callback);
};*/
TWikiAdaptor.prototype.getTiddler = function(title,context,userParams,callback)
{
context = this.setContext(context,userParams,callback);
var host = TWikiAdaptor.fullHostName(context.host);
var uriTemplate = '%0view/%1/%2?raw=text';
var uri = uriTemplate.format([host,context.workspace,title]);
context.tiddler = new Tiddler(title);
context.tiddler.fields.wikiformat = 'twiki';
context.tiddler.fields['server.host'] = TWikiAdaptor.minHostName(host);
context.tiddler.fields['server.workspace'] = context.workspace;
var req = TWikiAdaptor.doHttpGET(uri,TWikiAdaptor.getTiddlerCallback,context);
return typeof req == 'string' ? req : true;
};
TWikiAdaptor.getTiddlerCallback = function(status,context,responseText,uri,xhr)
{
context.status = false;
if(status) {
var content = responseText;
var contentRegExp = /<textarea.*?>((?:.|\n)*?)<\/textarea>/mg;
contentRegExp.lastIndex = 0;
var match = contentRegExp.exec(responseText);
if(match) {
content = match[1].htmlDecode();
}
context.tiddler.text = content;
context.status = true;
} else {
context.statusText = xhr.statusText;
}
if(context.callback)
context.callback(context,context.userParams);
};
TWikiAdaptor.prototype.putTiddler = function(tiddler,context,callback)
{
context = this.setContext(context,userParams,callback);
context.title = tiddler.title;
var uriTemplate = '%0save/%1/%2?text=%3';
var host = context.host ? context.host : TWikiApaptor.fullHostName(tiddler.fields['server.host']);
var workspace = context.workspace ? context.workspace : tiddler.fields['server.workspace'];
var uri = uriTemplate.format([host,workspace,tiddler.title,tiddler.text]);
context.tiddler = tiddler;
context.tiddler.fields.wikiformat = 'twiki';
context.tiddler.fields['server.host'] = TWikiAdaptor.minHostName(context.host);
context.tiddler.fields['server.workspace'] = workspace;
var req = TWikiAdaptor.doHttpGET(uri,TWikiAdaptor.putTiddlerCallback,context,null,null,null,this.username,this.password);
return typeof req == 'string' ? req : true;
};
TWikiAdaptor.putTiddlerCallback = function(status,context,responseText,uri,xhr)
{
if(status) {
context.status = true;
} else {
context.status = false;
context.statusText = xhr.statusText;
}
if(context.callback)
context.callback(context,context.userParams);
};
TWikiAdaptor.prototype.close = function()
{
return true;
};
config.adaptors[TWikiAdaptor.serverType] = TWikiAdaptor;
} //# end of 'install only once'
//}}}
/***
|''Name:''|TWikiFormatterPlugin|
|''Description:''|Allows Tiddlers to use [[TWiki|http://twiki.org/cgi-bin/view/TWiki/TextFormattingRules]] text formatting|
|''Author:''|Martin Budden (mjbudden (at) gmail (dot) com)|
|''Source:''|http://www.martinswiki.com/#TWikiFormatterPlugin|
|''CodeRepository:''|http://svn.tiddlywiki.org/Trunk/contributors/MartinBudden/formatters/TWikiFormatterPlugin.js|
|''Version:''|0.2.5|
|''Date:''|Nov 5, 2006|
|''Comments:''|Please make comments at http://groups.google.co.uk/group/TiddlyWikiDev|
|''License:''|[[Creative Commons Attribution-ShareAlike 2.5 License|http://creativecommons.org/licenses/by-sa/2.5/]]|
|''~CoreVersion:''|2.1.3|
|''Display unsupported TWiki variables''|<<option chkDisplayTWikiVariables>>|
This the TWikiFormatterPlugin, which allows you to insert TWiki formated text into a TiddlyWiki.
The aim is not to fully emulate TWiki, but to allow you to work with TWiki content off-line and then resync the content with your TWiki later on, with the expectation that only minor edits will be required.
To use TWiki format in a Tiddler, tag the Tiddler with TWikiFormat or set the tiddler's {{{wikiformat}}} extended field to {{{twiki}}}.
Please report any defects you find at http://groups.google.co.uk/group/TiddlyWikiDev
!!!Issues
There are (at least) the following known issues:
# Table code is incomplete.
## Table headings not yet supported.
# Anchors not yet supported.
# TWiki variables not supported
***/
//{{{
// Ensure that the TWikiFormatter Plugin is only installed once.
if(!version.extensions.TWikiFormatterPlugin) {
version.extensions.TWikiFormatterPlugin = {installed:true};
if(version.major < 2 || (version.major == 2 && version.minor < 1))
{alertAndThrow('TWikiFormatterPlugin requires TiddlyWiki 2.1 or later.');}
if(config.options.chkDisplayTWikiVariables == undefined)
{config.options.chkDisplayTWikiVariables = false;}
TWikiFormatter = {}; // 'namespace' for local functions
twDebug = function(out,str)
{
createTiddlyText(out,str.replace(/\n/mg,'\\n').replace(/\r/mg,'RR'));
createTiddlyElement(out,'br');
};
TWikiFormatter.Tiddler_changed = Tiddler.prototype.changed;
Tiddler.prototype.changed = function()
{
if((this.fields.wikiformat==config.parsers.twikiFormatter.format) || this.isTagged(config.parsers.twikiFormatter.formatTag)) {
this.links = [];
var tiddlerLinkRegExp = /\[\[(.*?)(?:\]\[(?:.*?))?\]\]/mg;
tiddlerLinkRegExp.lastIndex = 0;
var match = tiddlerLinkRegExp.exec(this.text);
while(match) {
this.links.pushUnique(match[1]);
match = tiddlerLinkRegExp.exec(this.text);
}
} else if(!this.isTagged('systemConfig')) {
TWikiFormatter.Tiddler_changed.apply(this,arguments);
return;
}
this.linksUpdated = true;
};
Tiddler.prototype.escapeLineBreaks = function()
{
var r = this.text.escapeLineBreaks();
if(this.isTagged(config.parsers.twikiFormatter.formatTag)) {
r = r.replace(/\x20\x20\x20/mg,'\\b \\b');
r = r.replace(/\x20\x20/mg,'\\b ');
}
return r;
};
config.textPrimitives.twikiLink = '(?:' +
config.textPrimitives.upperLetter + '+' + config.textPrimitives.lowerLetter + '+' +
config.textPrimitives.upperLetter + config.textPrimitives.anyLetter + '*)';
TWikiFormatter.setAttributesFromParams = function(e,p)
{
var re = /\s*(.*?)=(?:(?:"(.*?)")|(?:'(.*?)')|((?:\w|%|#)*))/mg;
var match = re.exec(p);
while(match) {
var s = match[1].unDash();
if(s == 'bgcolor') {
s = 'backgroundColor';
}
try {
if(match[2]) {
e.setAttribute(s,match[2]);
} else if(match[3]) {
e.setAttribute(s,match[3]);
} else {
e.setAttribute(s,match[4]);
}
}
catch(ex) {}
match = re.exec(p);
}
};
config.formatterHelpers.singleCharFormat = function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart && lookaheadMatch[0].substr(lookaheadMatch[0].length-2,1) != ' ') {
w.subWikifyTerm(createTiddlyElement(w.output,this.element),this.termRegExp);
w.nextMatch = this.lookaheadRegExp.lastIndex;
} else {
w.outputText(w.output,w.matchStart,w.nextMatch);
}
};
config.formatterHelpers.doubleCharFormat = function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
//twDebug(w.output,'dcmt:'+w.matchText);
//twDebug(w.output,'lm:'+lookaheadMatch);
//twDebug(w.output,'lm0:'+lookaheadMatch[0]+' lm:'+lookaheadMatch[0].length);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart &&
lookaheadMatch[0].substr(lookaheadMatch[0].length-3,1) != ' ') {
var e = createTiddlyElement(w.output,this.element);
w.subWikifyTerm(createTiddlyElement(e,this.element2),this.termRegExp);
w.nextMatch = this.lookaheadRegExp.lastIndex;
} else {
w.outputText(w.output,w.matchStart,w.nextMatch);
}
};
config.twiki = {};
config.twiki.formatters = [
{
name: 'twikiTable',
match: '^\\|(?:[^\\n]*)\\|$',
lookaheadRegExp: /^\|([^\n]*)\|$/mg,
rowTermRegExp: /(\|$\n?)/mg,
cellRegExp: /(?:\|([^\n\|]*)\|)|(\|$\n?)/mg,
cellTermRegExp: /((?:\x20*)\|)/mg,
handler: function(w)
{
var table = createTiddlyElement(w.output,'table');
var rowContainer = table;//createTiddlyElement(table,'tbody');
var prevColumns = [];
var rowCount = 0;
w.nextMatch = w.matchStart;
this.lookaheadRegExp.lastIndex = w.nextMatch;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
while(lookaheadMatch && lookaheadMatch.index == w.nextMatch) {
var rowClass = (rowCount&1) ? 'TD.odd' : 'TD.even';
if(rowCount==1) rowClass = 'TD.heading';
if(rowCount==3) rowClass = 'TD.third';
this.rowHandler(w,createTiddlyElement(rowContainer,'tr',null,rowClass),prevColumns);
rowCount++;
this.lookaheadRegExp.lastIndex = w.nextMatch;
lookaheadMatch = this.lookaheadRegExp.exec(w.source);
}
},
rowHandler: function(w,e,prevColumns)
{
var col = 0;
var colSpanCount = 1;
var prevCell = null;
this.cellRegExp.lastIndex = w.nextMatch;
var cellMatch = this.cellRegExp.exec(w.source);
while(cellMatch && cellMatch.index == w.nextMatch) {
if(cellMatch[1] == '^') {
// Rowspan
var last = prevColumns[col];
if(last) {
last.rowSpanCount++;
last.element.setAttribute('rowspan',last.rowSpanCount);
last.element.setAttribute('rowSpan',last.rowSpanCount); // Needed for IE
last.element.valign = 'center';
}
w.nextMatch = this.cellRegExp.lastIndex-1;
} else if(cellMatch[1] === '') {
// Colspan
colSpanCount++;
w.nextMatch = this.cellRegExp.lastIndex-1;
} else if(cellMatch[2]) {
// End of row
if(prevCell && colSpanCount > 1) {
prevCell.setAttribute('colspan',colSpanCount);
prevCell.setAttribute('colSpan',colSpanCount); // Needed for IE
}
w.nextMatch = this.cellRegExp.lastIndex;
break;
} else {
// Cell
w.nextMatch++;
var spaceLeft = false;
var chr = w.source.substr(w.nextMatch,1);
while(chr == ' ') {
spaceLeft = true;
w.nextMatch++;
chr = w.source.substr(w.nextMatch,1);
}
var cell = createTiddlyElement(e,'td');
prevCell = cell;
prevColumns[col] = {rowSpanCount:1, element:cell};
if(colSpanCount > 1) {
cell.setAttribute('colspan',colSpanCount);
cell.setAttribute('colSpan',colSpanCount); // Needed for IE
colSpanCount = 1;
}
w.subWikifyTerm(cell,this.cellTermRegExp);
if(w.matchText.substr(w.matchText.length-2,1) == ' ') {
// spaceRight
cell.align = spaceLeft ? 'center' : 'left';
} else if(spaceLeft) {
cell.align = 'right';
}
w.nextMatch--;
}
col++;
this.cellRegExp.lastIndex = w.nextMatch;
cellMatch = this.cellRegExp.exec(w.source);
}
}
},
{
name: 'twikiRule',
match: '^---+$\\n?',
handler: function(w)
{
createTiddlyElement(w.output,'hr');
}
},
{
//<h1><a name='TWiki_Text_Formatting'></a> TWiki Text Formatting </h1>
name: 'twikiHeading',
match: '^---[\\+#]{0,5}',
lookaheadRegExp: /^---[\+#]{0,5}(?:!!)? ?(.*?)\n/mg,
termRegExp: /(\n)/mg,
handler: function(w)
{
var h = createTiddlyElement(w.output,'h' + (w.matchLength-2));
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var a = createTiddlyElement(w.output,'a');
var prefix = w.tiddler ? w.tiddler.title : '';
var name = '#'+ prefix + lookaheadMatch[1];
name = name.replace(/ /g,'_');
a.name = name;
w.nextMatch = this.lookaheadRegExp.lastIndex - lookaheadMatch[1].length - 1;
w.subWikifyTerm(h,this.termRegExp);
}
}
},
{
name: 'twikiAnchor',
match: '^#' + config.textPrimitives.wikiLink + '\\s',
lookaheadRegExp: /^#(.*?)\s/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var a = createTiddlyElement(w.output,'a');
var prefix = w.tiddler ? w.tiddler.title : '';
var name = '#'+ prefix + lookaheadMatch[1];
name = name.replace(/ /g,'_');
a.name = name;
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
},
{
name: 'twikiDefinitionList',
match: '^ \\$ .+?:.+?\\n',
lookaheadRegExp: /^ \$ (.+?):(.+?)\n/mg,
termRegExp: /(\n)/mg,
handler: function(w)
{
var li = createTiddlyElement(w.output,'dl');
w.nextMatch = w.matchStart;
this.lookaheadRegExp.lastIndex = w.nextMatch;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
while(lookaheadMatch && lookaheadMatch.index == w.nextMatch) {
w.nextMatch += 5;
w.subWikifyTerm(createTiddlyElement(li,'dt'),/(:)/mg);
w.subWikifyTerm(createTiddlyElement(li,'dd'),this.termRegExp);
lookaheadMatch = this.lookaheadRegExp.exec(w.source);
}
}
},
{
name: 'twikiList',
match: '^(?: )+(?:(?:\\*)|(?:[1AaIi](?:\\.)?)) ',
lookaheadRegExp: /^(?: )+(?:(\*)|(?:([1AaIi])(\.)?)) /mg,
//termRegExp: /(\n\n|\n(?=(?: )+[\\*1AaIi]))/mg,
termRegExp: /(\n)/mg,
handler: function(w)
{
//twDebug(w.output,'mt:'+w.matchText);
var stack = [w.output];
var currLevel = 0;
var currType = null;
var listLevel, listType;
var itemType = 'li';
w.nextMatch = w.matchStart;
this.lookaheadRegExp.lastIndex = w.nextMatch;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
while(lookaheadMatch && lookaheadMatch.index == w.nextMatch) {
//twDebug(w.output,'lm0:'+lookaheadMatch[0]);
listType = 'ol';
listLevel = (lookaheadMatch[0].length-(lookaheadMatch[3]?3:2))/3;
var style = null;
if(lookaheadMatch[1]=='*') {
listType = 'ul';
} else if(lookaheadMatch[2]=='1') {
style = 'decimal';
} else if(lookaheadMatch[2]=='A') {
style = 'upper-alpha';
} else if(lookaheadMatch[2]=='a') {
style = 'lower-alpha';
} else if(lookaheadMatch[2]=='I') {
style = 'upper-roman';
} else if(lookaheadMatch[2]=='i') {
style = 'lower-roman';
}
w.nextMatch += lookaheadMatch[0].length;
if(listLevel > currLevel) {
for(var i=currLevel; i<listLevel; i++) {
stack.push(createTiddlyElement(stack[stack.length-1],listType));
}
} else if(listLevel < currLevel) {
for(i=currLevel; i>listLevel; i--) {
stack.pop();
}
} else if(listLevel == currLevel && listType != currType) {
stack.pop();
stack.push(createTiddlyElement(stack[stack.length-1],listType));
}
currLevel = listLevel;
currType = listType;
var e = createTiddlyElement(stack[stack.length-1],itemType);
e.style[config.browser.isIE ? 'list-style-type' : 'listStyleType'] = style;
w.subWikifyTerm(e,this.termRegExp);
this.lookaheadRegExp.lastIndex = w.nextMatch;
lookaheadMatch = this.lookaheadRegExp.exec(w.source);
}
}
},
{
name: 'twikiNoAutoLink',
match: '^\\s*<noautolink>',
lookaheadRegExp: /\s*<noautolink>((?:.|\n)*?)<\/noautolink>/mg,
termRegExp: /(<\/noautolink>)/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var autoLinkWikiWords = w.autoLinkWikiWords;
w.autoLinkWikiWords = false;
w.subWikifyTerm(w.output,this.termRegExp);
w.autoLinkWikiWords = autoLinkWikiWords;
w.nextMatch = this.lookaheadRegExp.lastIndex;
} else {
w.outputText(w.output,w.matchStart,w.nextMatch);
}
}
},
{
name: 'macro',
match: '<<',
lookaheadRegExp: /<<([^>\s]+)(?:\s*)((?:[^>]|(?:>(?!>)))*)>>/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart && lookaheadMatch[1]) {
w.nextMatch = this.lookaheadRegExp.lastIndex;
invokeMacro(w.output,lookaheadMatch[1],lookaheadMatch[2],w,w.tiddler);
}
}
},
{
name: 'twikiNotExplicitLink',
match: '!\\[\\[',
handler: function(w)
{
w.outputText(w.output,w.matchStart+1,w.nextMatch);
}
},
//[[WikiWord#NotThere]]
//[[#MyAnchor][Jump]]
//<a href='/cgi-bin/view/Sandbox/WebHome#Sandbox_Web_Site_Tools'> Sandbox Web Site Tools </a>
//<a href='/cgi-bin/view/Sandbox/MeetingMinutes' class='twikiLink'>MeetingMinutes</a>
{
name: 'twikiAnchorLink',
match: '\\[\\[(?:'+ config.textPrimitives.twikiLink +')?#',
lookaheadRegExp: /\[\[(.*?)?#(.*?)(?:\]\[(.*?))?\]\]/mg,
handler: function(w)
{
//twDebug(w.output,'al:'+w.matchText);
//twDebug(w.output,'lm:'+lookaheadMatch);
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
//twDebug(w.output,'lm0:'+lookaheadMatch[0]);
var a = createTiddlyElement(w.output,'a');
var prefix = w.tiddler ? w.tiddler.title : '';
var href = lookaheadMatch[1] ? lookaheadMatch[1] : '';
href += '#' + prefix + lookaheadMatch[2];
href = href.replace(/ /g,'_');
//twDebug(w.output,'hr:'+href);
a.href = href;
a.innerHTML = lookaheadMatch[3] ? lookaheadMatch[3] : lookaheadMatch[2];
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
},
{
name: 'twikiExplicitLink',
match: '\\[\\[',
lookaheadRegExp: /\[\[(.*?)(?:\]\[(.*?))?\]\]/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var e = null;
var link = lookaheadMatch[1];
if (lookaheadMatch[2]) {
// titled bracketted link
var text = lookaheadMatch[2];
e = config.formatterHelpers.isExternalLink(link) ? createExternalLink(w.output,link) : createTiddlyLink(w.output,link,false,null,w.isStatic,w.tiddler);
} else {
// simple bracketted link
text = link;
var s = text.indexOf(' ');
if(s!=-1) {
link = text.substring(0,s).trim();
if(config.formatterHelpers.isExternalLink(link)) {
e = createExternalLink(w.output,link);
text = text.substring(s+1).trim();
} else {
e = createTiddlyLink(w.output,text,false,null,w.isStatic,w.tiddler);
}
} else {
e = createTiddlyLink(w.output,link,false,null,w.isStatic,w.tiddler);
}
}
createTiddlyText(e,text);
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
},
{
name: 'twikiNotWikiLink',
match: '(?:!|<nop>)' + config.textPrimitives.wikiLink,
handler: function(w)
{
w.outputText(w.output,w.matchStart+(w.matchText.substr(0,1)=='!'?1:5),w.nextMatch);
}
},
{
name: 'twikiWikiLink',
match: config.textPrimitives.twikiLink,
handler: function(w)
{
if(w.matchStart > 0) {
var preRegExp = new RegExp(config.textPrimitives.anyLetter,'mg');
preRegExp.lastIndex = w.matchStart-1;
var preMatch = preRegExp.exec(w.source);
if(preMatch.index == w.matchStart-1) {
w.outputText(w.output,w.matchStart,w.nextMatch);
return;
}
}
if(w.autoLinkWikiWords == true || store.isShadowTiddler(w.matchText)) {
var link = createTiddlyLink(w.output,w.matchText,false,null,w.isStatic,w.tiddler);
w.outputText(link,w.matchStart,w.nextMatch);
} else {
w.outputText(w.output,w.matchStart,w.nextMatch);
}
}
},
{
name: 'twikiUrlLink',
match: config.textPrimitives.urlPattern,
handler: function(w)
{
w.outputText(createExternalLink(w.output,w.matchText),w.matchStart,w.nextMatch);
}
},
{
name: 'twikiBoldByChar',
match: '\\*(?!\\s)',
lookaheadRegExp: /\*(?!\s)(?:.*?)(?!\s)\*(?=\W)/mg,
termRegExp: /((?!\s)\*(?=\W))/mg,
element: 'strong',
handler: config.formatterHelpers.singleCharFormat
},
{
name: 'twikiBoldTag',
match: '<b>',
termRegExp: /(<\/b>)/mg,
element: 'b',
handler: config.formatterHelpers.createElementAndWikify
},
{
name: 'twikiBoldItalicByChar',
match: '__(?!\\s)',
lookaheadRegExp: /__(?!\s)(?:.*?)(?!\s)__(?=\W)/mg,
termRegExp: /((?!\s)__(?=\W))/mg,
element: 'strong',
element2: 'em',
handler: config.formatterHelpers.doubleCharFormat
},
{
name: 'twikiItalicByChar',
match: '_(?![\\s|_])',
lookaheadRegExp: /_(?!\s)(?:.*?)(?!\s)_(?=\W)/mg,
termRegExp: /((?!\s)_(?=\W))/mg,
element: 'em',
handler: config.formatterHelpers.singleCharFormat
},
{
name: 'twikiBoldMonoSpacedByChar',
match: '==(?!\\s)',
lookaheadRegExp: /==(?!\s)(?:.*?)(?!\s)==(?=\W)/mg,
termRegExp: /((?!\s)==(?=\W))/mg,
element: 'strong',
element2: 'code',
handler: config.formatterHelpers.doubleCharFormat
},
{
name: 'twikiMonoSpacedByChar',
match: '=(?![\\s=])',
lookaheadRegExp: /=(?!\s)(?:.*?)(?!\s)=(?!\w|\'|\")/mg,
termRegExp: /((?!\s)=(?!\w|\'|\"))/mg,
element: 'code',
handler: config.formatterHelpers.singleCharFormat
},
{
name: 'twikiPreByChar',
match: '<pre>',
lookaheadRegExp: /<pre>((?:.|\n)*?)<\/pre>/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
createTiddlyElement(w.output,'pre',null,null,lookaheadMatch[1]);
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
},
{
name: 'twikiVerbatimByChar',
match: '<verbatim>',
lookaheadRegExp: /\<verbatim>((?:.|\n)*?)<\/verbatim>/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
createTiddlyElement(w.output,'span',null,null,lookaheadMatch[1]);
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
},
{
name: 'twikiParagraph',
match: '\\n{2,}',
handler: function(w)
{
createTiddlyElement(w.output,'p');
}
},
{
name: 'twikiNop',
match: '<nop>',
handler: function(w)
{
w.outputText(w.output,w.matchStart+5,w.nextMatch);
}
},
{
name: 'twikiExplicitLineBreak',
match: '%BR%|<br ?/?>|<BR ?/?>',
handler: function(w)
{
createTiddlyElement(w.output,'br');
}
},
{
name: 'twikiColorByChar',
match: '%(?:YELLOW|ORANGE|RED|PINK|PURPLE|TEAL|NAVY|BLUE|AQUA|LIME|GREEN|OLIVE|MAROON|BROWN|BLACK|GRAY|SILVER|WHITE)%',
lookaheadRegExp: /%(YELLOW|ORANGE|RED|PINK|PURPLE|TEAL|NAVY|BLUE|AQUA|LIME|GREEN|OLIVE|MAROON|BROWN|BLACK|GRAY|SILVER|WHITE)/mg,
termRegExp: /(%ENDCOLOR%)/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var e = createTiddlyElement(w.output,'span');
e.style.color = lookaheadMatch[1];
w.subWikifyTerm(e,this.termRegExp);
}
}
},
{
name: 'twikiVariable',
match: '(?:!)?%(?:<nop>)?[A-Z]+(?:\\{.*?\\})?%',
lookaheadRegExp: /(!)?%(<nop>)?([A-Z]+)(?:\{(.*?)\})?%/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
if(lookaheadMatch[1]) {
// ! - escape variable
w.outputText(w.output,w.matchStart+1,w.nextMatch);
} else if(lookaheadMatch[2]) {
//nop
var text = w.matchText.replace(/<nop>/g,'');
createTiddlyText(w.output,text);
} else {
// deal with variables by name here
if(lookaheadMatch[3]=='BB') {
createTiddlyElement(w.output,'br');
createTiddlyElement(w.output,'span').innerHTML = '•';
} else if(config.options.chkDisplayTWikiVariables) {
// just output the text of any variables that are not understood
w.outputText(w.output,w.matchStart,w.nextMatch);
}
}
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
},
{
name: 'twikiHtmlEntitiesEncoding',
match: '&#?[a-zA-Z0-9]{2,8};',
handler: function(w)
{
createTiddlyElement(w.output,'span').innerHTML = w.matchText;
}
},
{
name: 'twikiComment',
match: '<!\\-\\-',
lookaheadRegExp: /<!\-\-((?:.|\n)*?)\-\->/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
},
{
name: 'twikiHtmlTag',
match: "<(?:[a-zA-Z]{2,}|a)(?:\\s*(?:[a-zA-Z]*?=[\"']?[^>]*?[\"']?))*?>",
lookaheadRegExp: /<([a-zA-Z]+)((?:\s+[a-zA-Z]*?=["']?[^>\/\"\']*?["']?)*?)?\s*(\/)?>/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var e =createTiddlyElement(w.output,lookaheadMatch[1]);
if(lookaheadMatch[2]) {
TWikiFormatter.setAttributesFromParams(e,lookaheadMatch[2]);
}
if(lookaheadMatch[3]) {
w.nextMatch = this.lookaheadRegExp.lastIndex;// empty tag
} else {
w.subWikify(e,'</'+lookaheadMatch[1]+'>');
}
}
}
}
];
config.parsers.twikiFormatter = new Formatter(config.twiki.formatters);
config.parsers.twikiFormatter.format = 'twiki';
config.parsers.twikiFormatter.formatTag = 'TWikiFormat';
} // end of 'install only once'
//}}}
|!Markup|!Explanation|
| {{{|}}} |Column Seperator |
| {{{!}}} |Heading (Row or Column) |
| {{{>}}} |Column Span |
| {{{~}}} |Row Span |
| {{{|Left |}}} |Left Align |
| {{{| Right|}}} |Right Align|
| {{{| Center |}}} |Center Align |
| {{{|Caption|c}}} |Table Caption (Can be at top or bottom)|
| {{{|Header|h}}} |Marks the row as being a header row (will be wrapped with a {{{<thead>}}} and so all entries are automatically formatted as per {{{|!}}} cells)|
| {{{|Footer|f}}} |Marks the row as being a footer row (will be wrapped with a {{{<tfoot>}}}, no special formatting is pre-defined for this but can be added to your own CSS)|
| {{{|CSSclass|k}}} |Applies a CSS class to the table to allow additional formatting (NB: only works if no whitespace after the k)|
|>|To have a table with no borders at all. Use {{{|noBorder|k}}} with the CSS (in your StyleSheet tiddler):<br />{{{ .noBorder,.noBorder td,.noBorder th,.noBorder tr{border:0} }}}|
|>|!Sample Table|
|>|{{{|table caption|c}}}<br />{{{|header|header|h}}}<br />{{{|text|more text|}}}<br />{{{|!heading|!heading|}}}<br />{{{|>|colspan|}}}<br />{{{|rowspan|left align |}}}<br />{{{|~| center |}}}<br />{{{|bgcolor(green):green| right|}}}<br />{{{|footer|footer|f}}} |
|>|<<tiddler ./tblShow>>|
!Notes
You can use the custom CSS formatter in combination with headers and lists to allow new lines within the entry. e.g.:
{{{
#{{block{
Bullet 1
Some text in the same bullet
(Note that "block" can be anything, it is the formatters CSS class name)
}}}
# Bullet 2
}}}
#{{block{
Bullet 1
Some text in the same bullet
}}}
# Bullet 2
(Julian Knight, 2006-05-11)
<part atEg hidden>
{{{
This is before the indented text
@@display:block;margin-left:2em;This text will be indented...
...and can even span across several lines...
...or even include blank lines.
@@This is after the indented text
}}}
This is before the indented text
@@display:block;margin-left:2em;This text will be indented...
...and can even span across several lines...
...or even include blank lines.
@@This is after the indented text
</part>
<part tblMarkup hidden>
{{{
|table caption|c
|header|header|h
|text|more text|
|!heading|!heading|
|>|colspan|
|rowspan|left align |
|~| center |
|bgcolor(green):green| right|
|footer|footer|f
}}}
</part>
<part tblShow hidden>
|table caption|c
|header|header|h
|text|more text|
|!heading|!heading|
|>|colspan|
|rowspan|left align |
|~| center |
|bgcolor(green):green| right|
|footer|footer|f
</part>
/***
|''Name:''|TextileFormatterPlugin|
|''Description:''|Allows Tiddlers to use [[Textile|http://www.textism.com/tools/textile/]] text formatting|
|''Author:''|Martin Budden (mjbudden (at) gmail (dot) com)|
|''Source:''|http://www.martinswiki.com/#TextileFormatterPlugin |
|''CodeRepository:''|http://svn.tiddlywiki.org/Trunk/contributors/MartinBudden/formatters/TexttileFormatterPlugin.js |
|''Version:''|0.1.3|
|''Date:''|May 7, 2007|
|''Comments:''|Please make comments at http://groups.google.co.uk/group/TiddlyWikiDev |
|''License:''|[[Creative Commons Attribution-ShareAlike 2.5 License|http://creativecommons.org/licenses/by-sa/2.5/]]|
|''~CoreVersion:''|2.1.0|
This is an early release of the TextileFormatterPlugin, which allows you to insert Textile formated text into a
TiddlyWiki.
The aim is not to fully emulate Textile, but to allow you to create Textile content off-line
and then paste the content into your Textile wiki later on, with the expectation that only minor
edits will be required.
To use Textile format in a Tiddler, tag the Tiddler with TextileFormat.
See [[testTextileFormat]] for an example.
Please report any defects you find at http://groups.google.co.uk/group/TiddlyWikiDev
This is an early alpha release, with (at least) the following known issues:
***/
//{{{
// Ensure that the TextileFormatterPlugin is only installed once.
if(!version.extensions.TextileFormatterPlugin) {
version.extensions.TextileFormatterPlugin = {installed:true};
if(version.major < 2 || (version.major == 2 && version.minor < 1))
{alertAndThrow("TextileFormatterPlugin requires TiddlyWiki 2.1 or later.");}
textileFormatter = {}; // "namespace" for local functions
textileDebug = function(out,str)
{
createTiddlyText(out,str.replace(/\n/mg,"\\n").replace(/\r/mg,"RR"));
createTiddlyElement(out,"br");
};
config.formatterHelpers.singleCharFormat = function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart && lookaheadMatch[0].substr(lookaheadMatch[0].length-2,1) != " ") {
w.subWikifyTerm(createTiddlyElement(w.output,this.element),this.termRegExp);
w.nextMatch = this.lookaheadRegExp.lastIndex;
} else {
w.outputText(w.output,w.matchStart,w.nextMatch);
}
};
textileFormatter.setAttributesFromParams = function(e,p)
{
var re = /\s*(.*?)=(?:(?:"(.*?)")|(?:'(.*?)')|((?:\w|%|#)*))/mg;
var match = re.exec(p);
while(match) {
var s = match[1].unDash();
if(s=="bgcolor") {
s = "backgroundColor";
}
try {
if(match[2]) {
e.setAttribute(s,match[2]);
} else if(match[3]) {
e.setAttribute(s,match[3]);
} else {
e.setAttribute(s,match[4]);
}
}
catch(ex) {}
match = re.exec(p);
}
};
config.textile = {};
config.textile.formatters = [
{
name: "textileHeading",
match: "^h[1-6](?:(?:\\(.*?\\))|(?:\\{.*?\\})|(?:\\[.*?\\]))?\\. ",
lookaheadRegExp: /^h([1-6])(?:(?:\((.*?)\))|(?:\{(.*?)\})|(?:\[(.*?)\]))?\. /mg,
// match: "^h[1-6]. ",
// lookaheadRegExp: /^h([1-6])\. /mg,
termRegExp: /(\n)/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
w.subWikifyTerm(createTiddlyElement(w.output,"h"+lookaheadMatch[1]),this.termRegExp);
}
}
},
{
name: "textiletTable",
match: "^\\|(?:(?:.|\n)*)\\|$",
lookaheadRegExp: /^\|(?:(?:.|\n)*)\|$/mg,
cellRegExp: /(?:\|(?:[^\|]*)\|)(\n|$)?/mg,
cellTermRegExp: /((?:\x20*)\|)/mg,
handler: function(w)
{
var table = createTiddlyElement(w.output,"table");
var rowContainer = createTiddlyElement(table,"tbody");
var prevColumns = [];
w.nextMatch = w.matchStart;
this.lookaheadRegExp.lastIndex = w.nextMatch;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
while(lookaheadMatch && lookaheadMatch.index == w.nextMatch) {
var r = this.rowHandler(w,createTiddlyElement(rowContainer,"tr"),prevColumns);
if(!r) {
w.nextMatch++;
break;
}
this.lookaheadRegExp.lastIndex = w.nextMatch;
lookaheadMatch = this.lookaheadRegExp.exec(w.source);
}
},
rowHandler: function(w,e,prevColumns)
{
this.cellRegExp.lastIndex = w.nextMatch;
var cellMatch = this.cellRegExp.exec(w.source);
while(cellMatch && cellMatch.index == w.nextMatch) {
w.nextMatch++;
var cell = createTiddlyElement(e,"td");
w.subWikifyTerm(cell,this.cellTermRegExp);
if(cellMatch[1]) {
// End of row
w.nextMatch = this.cellRegExp.lastIndex;
return true;
} else {
// Cell
w.nextMatch--;
}
this.cellRegExp.lastIndex = w.nextMatch;
cellMatch = this.cellRegExp.exec(w.source);
}
return false;
}
},
{
name: "textileList",
match: "^[\\*#]+ ",
lookaheadRegExp: /^([\*#])+ /mg,
termRegExp: /(\n)/mg,
handler: function(w)
{
var stack = [w.output];
var currLevel = 0, currType = null;
var listLevel, listType;
w.nextMatch = w.matchStart;
this.lookaheadRegExp.lastIndex = w.nextMatch;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
while(lookaheadMatch && lookaheadMatch.index == w.nextMatch) {
listType = lookaheadMatch[1] == "*" ? "ul" : "ol";
listLevel = lookaheadMatch[0].length;
w.nextMatch += listLevel;
if(listLevel > currLevel){
for(var i=currLevel; i<listLevel; i++) {
stack.push(createTiddlyElement(stack[stack.length-1],listType));
}
} else if(listLevel < currLevel) {
for(i=currLevel; i>listLevel; i--) {
stack.pop();
}
} else if(listLevel == currLevel && listType != currType) {
stack.pop();
stack.push(createTiddlyElement(stack[stack.length-1],listType));
}
currLevel = listLevel;
currType = listType;
var e = createTiddlyElement(stack[stack.length-1],"li");
w.subWikifyTerm(e,this.termRegExp);
this.lookaheadRegExp.lastIndex = w.nextMatch;
lookaheadMatch = this.lookaheadRegExp.exec(w.source);
}
}
},
{
//(class)(#id){style}[language]
name: "textileBlockQuote",
match: "^bq(?:(?:\\(.*?\\))|(?:\\{.*?\\})|(?:\\[.*?\\]))?\\. ",
lookaheadRegExp: /^bq(?:(?:\((#?)(.*?)\))|(?:\{(.*?)\})|(?:\[(.*?)\]))?\. /mg,
termRegExp: /(\n)/mg,
element: "blockquote",
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var e = createTiddlyElement(w.output,this.element);
w.subWikifyTerm(e,this.termRegExp);
}
}
},
{
name: "textileRule",
match: "^---+$\\n?",
handler: function(w)
{
createTiddlyElement(w.output,"hr");
}
},
{
name: "macro",
match: "<<",
lookaheadRegExp: /<<([^>\s]+)(?:\s*)((?:[^>]|(?:>(?!>)))*)>>/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart && lookaheadMatch[1]) {
w.nextMatch = this.lookaheadRegExp.lastIndex;
invokeMacro(w.output,lookaheadMatch[1],lookaheadMatch[2],w,w.tiddler);
}
}
},
{
//"This is a link (optional title)":http://www.textism.com
name: "textileExternalLink",
match: '(?:".*?" ?):?[a-z]{2,8}:',
lookaheadRegExp: /(?:\"(.*?)(?:\((.*?)\))?\" ?):?(.*?)(?=\s|$)/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var link = lookaheadMatch[3];
var text = lookaheadMatch[1] ? lookaheadMatch[1] : link;
var e = createExternalLink(w.output,link);
if(lookaheadMatch[2])
e.title = lookaheadMatch[2];
createTiddlyText(e,text);
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
},
{
name: "textileUrlLink",
match: config.textPrimitives.urlPattern,
handler: function(w)
{
w.outputText(createExternalLink(w.output,w.matchText),w.matchStart,w.nextMatch);
}
},
{
// !/common/textist.gif(optional alt text)!
name: "textileImage",
match: "!.*?!",
lookaheadRegExp: /!(.*?)(?:\((.*?)\))?!/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var img = createTiddlyElement(w.output,"img");
img.src = lookaheadMatch[1];
if(lookaheadMatch[2]) {
img.title = lookaheadMatch[2];
}
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
},
{
name: "textileBold",//checked
match: "\\*(?![\\s\\*])",
lookaheadRegExp: /\*(?!\s)(?:.*?)(?!\s)\*(?=[\s\._\-])/mg,
termRegExp: /((?!\s)\*(?=[\s\.\-_]))/mg,
element: "strong",
handler: config.formatterHelpers.singleCharFormat
},
{
name: "textileItalic",//checked
match: "_(?![\\s_])",
lookaheadRegExp: /_(?!\s)(?:.*?)(?!\s)_(?=[\s\.\*\-])/mg,
termRegExp: /((?!\s)_(?=[\s\.\*\-]))/mg,
element: "em",
handler: config.formatterHelpers.singleCharFormat
},
{
name: "textileUnderline",
match: "_(?![\\s|_])",
lookaheadRegExp: /_(?!\s)(?:.*?)(?!\s)_(?=\s)/mg,
termRegExp: /((?!\s)_(?=\s))/mg,
element: "u",
handler: config.formatterHelpers.singleCharFormat
},
{
name: "textileStrike",//checked
match: "-(?![\\s\\-])",
lookaheadRegExp: /-(?!\s)(?:.*?)(?!\s)-(?=[\s\.\*_])/mg,
termRegExp: /((?!\s)-(?=[\s\.\*_]))/mg,
element: "strike",
handler: config.formatterHelpers.singleCharFormat
},
{
name: "textileSuperscript",
match: "\\^(?![\\s|\\^])",
lookaheadRegExp: /\^(?!\s)(?:.*?)(?!\s)\^(?=\s)/mg,
termRegExp: /((?!\s)\^(?=\s))/mg,
element: "sup",
handler: config.formatterHelpers.singleCharFormat
},
{
name: "textileSubscript",
match: "~(?![\\s|~])",
lookaheadRegExp: /~(?!\s)(?:.*?)(?!\s)~(?=\s)/mg,
termRegExp: /((?!\s)~(?=\s))/mg,
element: "sub",
handler: config.formatterHelpers.singleCharFormat
},
{
name: "textileCitation",
match: "\\?\\?",
termRegExp: /(\?\?)/mg,
element: "cite",
handler: config.formatterHelpers.createElementAndWikify
},
{
name: "textileMonospacedByChar",
match: "\\{\\{",
lookaheadRegExp: /\{\{((?:.|\n)*?)\}\}/mg,
element: "code",
handler: config.formatterHelpers.enclosedTextHelper
},
{
name: "textileParagraph",
match: "\\n{2,}",
handler: function(w)
{
createTiddlyElement(w.output,"p");
}
},
{
name: "textileExplicitLineBreak",
match: "<br ?/?>|\\n",
handler: function(w)
{
createTiddlyElement(w.output,"br");
}
},
{
name: "textileComment",
match: "<!\\-\\-",
lookaheadRegExp: /<!\-\-((?:.|\n)*?)\-\-!>/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
},
{
name: "textilemdash",
match: "--",
handler: function(w) {createTiddlyElement(w.output,"span").innerHTML = "—";}
},
{
name: "textilendash",
match: " - ",
handler: function(w) {createTiddlyElement(w.output,"span").innerHTML = " – ";}
},
{
name: "textileTrademark",
match: "\\(TM\\)",
handler: function(w) {createTiddlyElement(w.output,"span").innerHTML = "™";}
},
{
name: "textileRegistered",
match: "\\(R\\)",
handler: function(w) {createTiddlyElement(w.output,"span").innerHTML = "®";}
},
{
name: "textileCopyright",
match: "\\(C\\)",
handler: function(w) {createTiddlyElement(w.output,"span").innerHTML = "©";}
},
{
name: "textileElipsis",
match: "\\.\\.\\.",
handler: function(w) {createTiddlyElement(w.output,"span").innerHTML = "…";}
},
{
name: "textileHtmlEntitiesEncoding",
match: "&#?[a-zA-Z0-9]{2,8};",
handler: function(w)
{
createTiddlyElement(w.output,"span").innerHTML = w.matchText;
}
},
{
name: "textileHtmlTag",
match: "<(?:[a-zA-Z]{2,}|a)(?:\\s*(?:(?:.*?)=[\"']?(?:.*?)[\"']?))*?>",
lookaheadRegExp: /<([a-zA-Z]+)((?:\s+(?:.*?)=["']?(?:.*?)["']?)*?)?\s*(\/)?>(?:\n?)/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var e =createTiddlyElement(w.output,lookaheadMatch[1]);
if(lookaheadMatch[2]) {
textileFormatter.setAttributesFromParams(e,lookaheadMatch[2]);
}
if(lookaheadMatch[3]) {
w.nextMatch = this.lookaheadRegExp.lastIndex;// empty tag
} else {
w.subWikify(e,"</"+lookaheadMatch[1]+">");
}
}
}
}/*,
{
name: "textileMatchedQuotes",
match: '(?=\s)"',
lookaheadRegExp: /\"((?:.|\n)*?)\"/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
createTiddlyElement(w.output,"span").innerHTML = "“" + lookaheadMatch[1] + "”";
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
}*/
];
config.parsers.textileFormatter = new Formatter(config.textile.formatters);
config.parsers.textileFormatter.format = 'textile';
config.parsers.textileFormatter.formatTag = 'TextileFormat';
} // end of "install only once"
//}}}
/***
|''Name:''|TodoListPlugin|
|''Description:''|Simple tabbed todo list|
|''Author:''|Martin Budden ( mjbudden [at] gmail [dot] com)|
|''Source:''|http://martinwiki.com/#TodoListPlugin |
|''CodeRepository:''|http://svn.tiddlywiki.org/Trunk/contributors/MartinBudden/plugins/TodoListPluging.js |
|''Version:''|0.0.3|
|''Date:''|July 31, 2006|
|''Comments:''|Please make comments at http://groups.google.co.uk/group/TiddlyWikiDev |
|''License:''|[[Creative Commons Attribution-ShareAlike 2.5 License|http://creativecommons.org/licenses/by-sa/2.5/]] |
|''~CoreVersion:''|2.0+|
***/
//{{{
config.macros.listTodos = {
todoTag:"Todo",
todoCompletedTag:"TodoCompleted",
todoAbandonedTag:"TodoAbandoned",
todoOnHoldTag:"TodoOnHold"
};
config.macros.listTodos.handler = function(place,macroName,params,wikifier,paramString,aTiddler)
{
var tag0 = params[0];
var tag1 = params[1];
var tag2 = params[2];
var tag3 = params[3];
var results = [];
var fn = function(title,tiddler) {
if(tiddler.isTagged(config.macros.listTodos.todoTag) &&
(!tiddler.isTagged(config.macros.listTodos.todoCompletedTag)) &&
(!tiddler.isTagged(config.macros.listTodos.todoAbandonedTag)) &&
(!tiddler.isTagged(config.macros.listTodos.todoOnHoldTag)) &&
(!tag0 || tiddler.isTagged(tag0)) &&
(!tag1 || tiddler.isTagged(tag1)) &&
(!tag2 || tiddler.isTagged(tag2)) &&
(!tag3 || tiddler.isTagged(tag3)) ) {
results.push(tiddler);
}
};
store.forEachTiddler(fn);
var ul = createTiddlyElement(place,'ul');
for(var i=0;i<results.length;i++) {
var li = createTiddlyElement(ul,'li');
createTiddlyLink(li,results[i].title,true);
}
};
//}}}
//{{{
config.macros.listCompletedTodos = {};
config.macros.listCompletedTodos.handler = function(place,macroName,params,wikifier,paramString,aTiddler)
{
var tag1 = params[1];
var tag2 = params[2];
var tag3 = params[3];
var results = [];
var fn = function(title,tiddler) {
if(tiddler.isTagged(config.macros.listTodos.todoTag) && tiddler.isTagged(config.macros.listTodos.todoCompletedTag) &&
(!tag1 || tiddler.isTagged(tag1)) && (!tag2|| tiddler.isTagged(tag2)) && (!tag3 || tiddler.isTagged(tag3)) ) {
results.push(tiddler);
}
};
store.forEachTiddler(fn);
var ul = createTiddlyElement(place,'ul');
for(var i=0;i<results.length;i++) {
var li = createTiddlyElement(ul,'li');
createTiddlyLink(li,results[i].title,true);
}
};
//}}}
//{{{
config.macros.listTags = {};
config.macros.listTags.handler = function(place,macroName,params)
{
var tags = store.getTaggedTiddlers(params[0],params[1]); // Second parameter is field to sort by (eg, title, modified, modifier or text)
var ul = createTiddlyElement(place,'ul');
for(var i=0;i<tags.length;i++) {
var li = createTiddlyElement(ul,'li');
createTiddlyLink(li,tags[i].title,true);
}
};
//}}}
//{{{
config.macros.newTodo = {
label: "new todo",
prompt: "new todo",
title: "New Todo"
};
config.macros.newTodo.handler = function(place,macroName,params)
{
if (readOnly) {return;}
var title = params[0] ? params[0] : config.macros.newTodo.title;
var btn = createTiddlyButton(place,this.label,this.prompt,this.onClick);
btn.setAttribute('title',config.macros.newTodo.title);
btn.setAttribute('params',params.join('|'));
};
config.macros.newTodo.onClick = function(e)
{
//var title = this.getAttribute('title');
var title = config.macros.newTodo.title;
var params = this.getAttribute('params').split('|');
story.displayTiddler(null,title,DEFAULT_EDIT_TEMPLATE);
for(var i=1;i<params.length;i++) {
story.setTiddlerTag(title,params[i],+1);
}
story.setTiddlerTag(title,config.macros.listTodos.todoTag,+1);
story.focusTiddler(title,'text');
return false;
};
//}}}
/***
|''Name:''|TracFormatterPlugin|
|''Description:''|Allows Tiddlers to use [[Trac|http://trac.edgewall.org/wiki/WikiFormatting]] text formatting|
|''Author:''|Martin Budden (mjbudden (at) gmail (dot) com)|
|''Source:''|http://www.martinswiki.com/#TracFormatterPlugin |
|''CodeRepository:''|http://svn.tiddlywiki.org/Trunk/contributors/MartinBudden/formatters/TracFormatterPlugin.js |
|''Version:''|0.1.7|
|''Date:''|May 7, 2007|
|''Comments:''|Please make comments at http://groups.google.co.uk/group/TiddlyWikiDev |
|''License:''|[[Creative Commons Attribution-ShareAlike 2.5 License|http://creativecommons.org/licenses/by-sa/2.5/]]|
|''~CoreVersion:''|2.1.0|
This is an early release of the TracFormatterPlugin, which allows you to insert Trac formated text into a TiddlyWiki.
The aim is not to fully emulate Trac, but to allow you to work with Trac content off-line and then resync the content with your Trac wiki later on, with the expectation that only minor edits will be required.
To use Trac format in a Tiddler, tag the Tiddler with TracFormat or set the tiddler's {{{wikiformat}}} extended field to {{{trac}}}.
Please report any defects you find at http://groups.google.co.uk/group/TiddlyWikiDev
!!!Issues
There are (at least) the following known issues:
# Citations yet not supported.
!!!No plans to support
# Trac macros.
***/
//{{{
// Ensure that the TracFormatter Plugin is only installed once.
if(!version.extensions.TracFormatterPlugin) {
version.extensions.TracFormatterPlugin = {installed:true};
if(version.major < 2 || (version.major == 2 && version.minor < 1))
{alertAndThrow('TracFormatterPlugin requires TiddlyWiki 2.1 or later.');}
tracDebug = function(out,str)
{
createTiddlyText(out,str.replace(/\n/mg,'\\n').replace(/\r/mg,'RR'));
createTiddlyElement(out,'br');
};
config.trac = {};
config.trac.formatters = [
{
name: 'tracHeading',
match: '^={1,6} ',
termRegExp: /( ={1,6}.*?$\n?)/mg,
handler: function(w)
{
w.subWikifyTerm(createTiddlyElement(w.output,'h' + (w.matchLength-1)),this.termRegExp);
}
},
{
name: 'tracTable',
match: '^\\|\\|(?:[^\\n]*)\\|\\|$',
lookaheadRegExp: /^\|\|([^\n]*)\|\|$/mg,
rowTermRegExp: /(\|\|$\n?)/mg,
cellRegExp: /(?:\|\|([^\n]*)\|\|)|(\|\|$\n?)/mg,
cellTermRegExp: /((?:\x20*)\|\|)/mg,
handler: function(w)
{
var table = createTiddlyElement(w.output,'table');
var rowContainer = createTiddlyElement(table,'tbody');
var rowCount = 0;
w.nextMatch = w.matchStart;
this.lookaheadRegExp.lastIndex = w.nextMatch;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
while(lookaheadMatch && lookaheadMatch.index == w.nextMatch) {
this.rowHandler(w,createTiddlyElement(rowContainer,'tr',null,(rowCount&1)?'oddRow':'evenRow'));
rowCount++;
this.lookaheadRegExp.lastIndex = w.nextMatch;
lookaheadMatch = this.lookaheadRegExp.exec(w.source);
}
},//# end handler
rowHandler: function(w,e)
{
var col = 0;
var colSpanCount = 1;
var prevCell = null;
this.cellRegExp.lastIndex = w.nextMatch;
var cellMatch = this.cellRegExp.exec(w.source);
while(cellMatch && cellMatch.index == w.nextMatch) {
if(w.source.substr(w.nextMatch,4) == '||||') {
// Colspan
colSpanCount++;
w.nextMatch += 2;
} else if(cellMatch[2]) {
// End of row
if(colSpanCount > 1) {
prevCell.setAttribute('colspan',colSpanCount);
prevCell.setAttribute('colSpan',colSpanCount); // Needed for IE
}
w.nextMatch = this.cellRegExp.lastIndex;
break;
} else {
// Cell
w.nextMatch += 2; //skip over ||
var chr = w.source.substr(w.nextMatch,1);
var cell;
if(chr == '!') {
cell = createTiddlyElement(e,'th');
w.nextMatch++;
chr = w.source.substr(w.nextMatch,1);
} else {
cell = createTiddlyElement(e,'td');
}
var spaceLeft = false;
while(chr == ' ') {
spaceLeft = true;
w.nextMatch++;
chr = w.source.substr(w.nextMatch,1);
}
if(colSpanCount > 1) {
cell.setAttribute('colspan',colSpanCount);
cell.setAttribute('colSpan',colSpanCount); // Needed for IE
colSpanCount = 1;
}
w.subWikifyTerm(cell,this.cellTermRegExp);
if(w.matchText.substr(w.matchText.length-3,1) == ' ') {
// SpaceRight
cell.align = spaceLeft ? 'center' : 'left';
} else if(spaceLeft) {
cell.align = 'right';
}
prevCell = cell;
w.nextMatch -= 2;
}
col++;
this.cellRegExp.lastIndex = w.nextMatch;
cellMatch = this.cellRegExp.exec(w.source);
}
}//# end rowHandler
},
{
name: 'tracDefinitionList',
match: '^\\s+\\S+::\\s*\\n',
lookaheadRegExp: /^\s+\S+::\s*\n/mg,
l2RegExp: /^\s{2,}\S+/mg,
handler: function(w)
{
var li = createTiddlyElement(w.output,'dl');
w.nextMatch = w.matchStart;
this.lookaheadRegExp.lastIndex = w.nextMatch;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
while(lookaheadMatch && lookaheadMatch.index == w.nextMatch) {
w.subWikifyTerm(createTiddlyElement(li,'dt'),/(::\s*\n)/mg);
var dd = createTiddlyElement(li,'dd');
this.l2RegExp.lastIndex = w.nextMatch;
var l2Match = this.l2RegExp.exec(w.source);
while(l2Match && l2Match.index == w.nextMatch) {
while(w.source.substr(w.nextMatch,1) == ' ') {
w.nextMatch++;
}
w.subWikifyTerm(dd,/(\n)/mg);
l2Match = this.l2RegExp.exec(w.source);
if(l2Match) {
createTiddlyText(dd,' ');
}
}
this.lookaheadRegExp.lastIndex = w.nextMatch;
lookaheadMatch = this.lookaheadRegExp.exec(w.source);
}
}
},
{
name: 'tracList',
match: '^(?: )+(?:(?:\\* )|(?:1\\. )|(?:a\\. )|(?:i\\. ))',
lookaheadRegExp: /^(?: )+(?:(\* )|(1\. )|(a\. )|(i\. ))/mg,
termRegExp: /(\n)/mg,
handler: function(w)
{
var placeStack = [w.output];
var currLevel = 0, currType = null;
var listLevel, listType, itemType;
w.nextMatch = w.matchStart;
this.lookaheadRegExp.lastIndex = w.nextMatch;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
while(lookaheadMatch && lookaheadMatch.index == w.nextMatch) {
listType = 'ol';
itemType = 'li';
listLevel = (lookaheadMatch[0].length-3)/3;
var style = null;
if(lookaheadMatch[1]){
//*
listType = 'ul';
listLevel = (lookaheadMatch[0].length-2)/3;
} else if(lookaheadMatch[2]) {//1.
style = 'decimal';
} else if(lookaheadMatch[3]) {
//a.
style = 'lower-alpha';
} else if(lookaheadMatch[4]) {
//i.
style = 'lower-roman';
}
w.nextMatch += lookaheadMatch[0].length;
if(listLevel > currLevel) {
for(var i=currLevel; i<listLevel; i++)
{placeStack.push(createTiddlyElement(placeStack[placeStack.length-1],listType));}
} else if(listLevel < currLevel) {
for(i=currLevel; i>listLevel; i--)
{placeStack.pop();}
} else if(listLevel == currLevel && listType != currType) {
placeStack.pop();
placeStack.push(createTiddlyElement(placeStack[placeStack.length-1],listType));
}
currLevel = listLevel;
currType = listType;
var e = createTiddlyElement(placeStack[placeStack.length-1],itemType);
e.style['list-style-type'] = style;
w.subWikifyTerm(e,this.termRegExp);
this.lookaheadRegExp.lastIndex = w.nextMatch;
lookaheadMatch = this.lookaheadRegExp.exec(w.source);
}
}
},
{
name: 'tracQuoteByLine',
match: '^ ',
lookaheadRegExp: /^ /mg,
termRegExp: /(\n)/mg,
element: 'blockquote',
handler: config.formatterHelpers.createElementAndWikify
},
{
name: 'tracRule',
match: '^---+$\\n?',
handler: function(w)
{
createTiddlyElement(w.output,'hr');
}
},
{
name: 'tracHtml',
match: '^\\{\\{\\{\n#!html',
lookaheadRegExp: /^\{\{\{\n#!html\n((?:.|\n)*?)\}\}\}/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
createTiddlyElement(w.output,'span').innerHTML = lookaheadMatch[1];
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
},
{
name: 'tracMonospacedByLine',
match: '^\\{\\{\\{\\n',
lookaheadRegExp: /^\{\{\{\n((?:^[^\n]*\n)+?)(^\}\}\}$\n?)/mg,
element: 'pre',
handler: config.formatterHelpers.enclosedTextHelper
},
{
name: 'macro',
match: '<<',
lookaheadRegExp: /<<([^>\s]+)(?:\s*)((?:[^>]|(?:>(?!>)))*)>>/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart && lookaheadMatch[1]) {
w.nextMatch = this.lookaheadRegExp.lastIndex;
invokeMacro(w.output,lookaheadMatch[1],lookaheadMatch[2],w,w.tiddler);
}
}
},
{
name: 'tracExplicitLineBreak',
match: '\\[\\[BR\\]\\]',
handler: function(w)
{
createTiddlyElement(w.output,'br');
}
},
{
name: 'tracExplicitLink',
match: '\\[',
lookaheadRegExp: /\[([^\s\]]*?)(?:(?:\])|(?:\s(.*?))\])/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var link = lookaheadMatch[1];
var text = lookaheadMatch[2] ? lookaheadMatch[2] : link;
var e = config.formatterHelpers.isExternalLink(link) ? createExternalLink(w.output,link) : createTiddlyLink(w.output,link,false,null,w.isStatic);
createTiddlyText(e,text);
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
},
{
name: 'tracNotWikiLink',
match: '!' + config.textPrimitives.wikiLink,
handler: function(w)
{
w.outputText(w.output,w.matchStart+1,w.nextMatch);
}
},
{
name: 'tracWikiLink',
match: config.textPrimitives.wikiLink,
handler: function(w)
{
if(w.matchStart > 0) {
var preRegExp = new RegExp(config.textPrimitives.anyLetter,'mg');
preRegExp.lastIndex = w.matchStart-1;
var preMatch = preRegExp.exec(w.source);
if(preMatch.index == w.matchStart-1) {
w.outputText(w.output,w.matchStart,w.nextMatch);
return;
}
}
var output = w.output;
if(w.autoLinkWikiWords == true || store.isShadowTiddler(w.matchText)) {
output = createTiddlyLink(w.output,w.matchText,false,null,w.isStatic);
}
w.outputText(output,w.matchStart,w.nextMatch);
}
},
{
name: 'tracUrlLink',
match: config.textPrimitives.urlPattern,
handler: function(w)
{
w.outputText(createExternalLink(w.output,w.matchText),w.matchStart,w.nextMatch);
}
},
{
name: 'tracBold',
match: "'''",
termRegExp: /(''')/mg,
element: 'b',
handler: config.formatterHelpers.createElementAndWikify
},
{
name: 'characterFormat',
match: "''|__|\\^|,,|~~|`|\\{\\{\\{",
handler: function(w)
{
switch(w.matchText) {
case "''":
w.subWikifyTerm(createTiddlyElement(w.output,'i'),/('')/mg);
break;
case '__':
var e = createTiddlyElement(w.output,'span');
e.setAttribute('style','text-decoration:underline');
w.subWikifyTerm(e,/(__)/mg);
break;
case '^':
w.subWikifyTerm(createTiddlyElement(w.output,'sup'),/(\^)/mg);
break;
case ',,':
w.subWikifyTerm(createTiddlyElement(w.output,'sub'),/(,,)/mg);
break;
case '~~':
w.subWikifyTerm(createTiddlyElement(w.output,'del'),/(~~)/mg);
break;
case '`':
this.lookaheadRegExp = /`((?:.|\n)*?)`/mg;
this.element = 'code';
config.formatterHelpers.enclosedTextHelper.call(this,w);
break;
case '{{{':
this.lookaheadRegExp = /\{\{\{((?:.|\n)*?)\}\}\}/mg;
this.element = 'code';
config.formatterHelpers.enclosedTextHelper.call(this,w);
break;
}
}
},
{
name: 'tracParagraph',
match: '\\n{2,}',
handler: function(w)
{
createTiddlyElement(w.output,'p');
}
},
{
name: 'tracLineBreak',
match: '\\n',
handler: function(w)
{
createTiddlyElement(w.output,'br');
}
},
{
name: 'tracHtmlEntitiesEncoding',
match: '&#?[a-zA-Z0-9]{2,8};',
handler: function(w)
{
createTiddlyElement(w.output,'span').innerHTML = w.matchText;
}
}
];
config.parsers.tracFormatter = new Formatter(config.trac.formatters);
config.parsers.tracFormatter.format = 'trac';
config.parsers.tracFormatter.formatTag = 'TracFormat';
} // end of 'install only once'
//}}}
<!--{{{-->
<div class='toolbar' macro='toolbar encryptTiddler displayDecryptedTiddler decryptTiddler closeTiddler closeOthers +editTiddler > fields syncing permalink references jump'></div>
<div class='tagged' macro='tags'></div>
<div class='title' macro='view title'></div>
<div class='tagging' macro='tagging'></div>
<div class='viewer' macro='view text wikified'></div>
<div class='toolbar' macro='toolbar closeTiddler closeOthers +editTiddler'></div>
<!--}}}-->
/***
|''Name:''|WikispacesFormatterPlugin|
|''Description:''|Allows Tiddlers to use [[wikispaces|http://www.wikispaces.com/wikitext]] text formatting|
|''Description:''|Wikispaces Formatter|
|''Author:''|Martin Budden (mjbudden (at) gmail (dot) com)|
|''CodeRepository:''|http://svn.tiddlywiki.org/Trunk/contributors/MartinBudden/formatters/WikispacesFormatterPlugin.js |
|''Version:''|0.0.8|
|''Date:''|Nov 23, 2007|
|''Comments:''|Please make comments at http://groups.google.co.uk/group/TiddlyWikiDev |
|''License:''|[[Creative Commons Attribution-ShareAlike 2.5 License|http://creativecommons.org/licenses/by-sa/2.5/]] |
|''~CoreVersion:''|2.1.0|
***/
//{{{
// Ensure that the WikispacesFormatterPlugin is only installed once.
if(!version.extensions.WikispacesFormatterPlugin) {
version.extensions.WikispacesFormatterPlugin = {installed:true};
if(version.major < 2 || (version.major == 2 && version.minor < 1))
{alertAndThrow('WikispacesFormatterPlugin requires TiddlyWiki 2.1 or later.');}
wikispacesFormatter = {}; // 'namespace' for local functions
wikispacesDebug = function(out,str)
{
createTiddlyText(out,str.replace(/\n/mg,'\\n').replace(/\r/mg,'RR'));
createTiddlyElement(out,'br');
};
wikispacesFormatter.normalizedTitle = function(title)
{
title = title.trim();
return title.replace(/\s/g,'_');
};
wikispacesFormatter.baseUri = function(space,host)
{
if(!space)
space = 'www';
if(!host)
host = 'wikispaces.com';
return 'http://' + space + '.' + host;
};
wikispacesFormatter.processLink = function(link)
{
if(config.formatterHelpers.isExternalLink(link))
return link;
var space = null;
var pos = link.indexOf(':');
if(pos!=-1) {
space = link.substr(0,pos);
link = link.substring(pos+1);
}
return wikispacesFormatter.baseUri(space) + '/' + link.replace(/\s/g,'+');
};
wikispacesFormatter.setAttributesFromParams = function(e,p)
{
var re = /\s*(.*?)=(?:(?:"(.*?)")|(?:'(.*?)')|((?:\w|%|#)*))/mg;
var match = re.exec(p);
while(match) {
var s = match[1].unDash();
if(s == 'bgcolor') {
s = 'backgroundColor';
}
try {
if(match[2]) {
e.setAttribute(s,match[2]);
} else if(match[3]) {
e.setAttribute(s,match[3]);
} else {
e.setAttribute(s,match[4]);
}
}
catch(ex) {}
match = re.exec(p);
}
};
config.wikispacesFormatters = [
{
name: 'wikispacesHeading',
match: '^={1,3}(?!=)',
termRegExp: /(={0,3} *\n+)/mg,
handler: function(w)
{
w.subWikifyTerm(createTiddlyElement(w.output,'h'+w.matchLength),this.termRegExp);
}
},
{
name: 'wikispacesTable',
match: '^\\|\\|(?:(?:.|\n)*)\\|\\|$',
lookaheadRegExp: /^\|\|((?:.|\n)*)\|\|$/mg,
rowTermRegExp: /(\|\|$\n?)/mg,
cellRegExp: /(?:\|\|((?:.|\n)*)\|\|)/mg,
cellTermRegExp: /((?:\x20*)\|\|)/mg,
handler: function(w)
{
var table = createTiddlyElement(w.output,'table');
var prevColumns = [];
var rowCount = 0;
w.nextMatch = w.matchStart;
this.lookaheadRegExp.lastIndex = w.nextMatch;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
while(lookaheadMatch && lookaheadMatch.index == w.nextMatch) {
this.rowHandler(w,createTiddlyElement(table,'tr',null,(rowCount&1)?'oddRow':'evenRow'),prevColumns);
rowCount++;
this.lookaheadRegExp.lastIndex = w.nextMatch;
lookaheadMatch = this.lookaheadRegExp.exec(w.source);
}
},//# end handler
rowHandler: function(w,e,prevColumns)
{
var col = 0;
var colSpanCount = 1;
var prevCell = null;
this.cellRegExp.lastIndex = w.nextMatch;
var cellMatch = this.cellRegExp.exec(w.source);
while(cellMatch && cellMatch.index == w.nextMatch) {
if(w.source.substr(w.nextMatch,4) == '||||') {
// Colspan
colSpanCount++;
w.nextMatch += 2;
} else if(w.source.substr(w.nextMatch+2,1)=='^') {
// Rowspan
var last = prevColumns[col];
if(last) {
last.rowSpanCount++;
last.element.setAttribute("rowspan",last.rowSpanCount);
last.element.setAttribute("rowSpan",last.rowSpanCount); // Needed for IE
last.element.valign = "center";
}
var n = w.source.indexOf('||',w.nextMatch+2);
if(n!=-1)
w.nextMatch = n;
else
w.nextMatch += 3;
} else if(w.source.substr(w.nextMatch,3)=='||\n') {
// End of row
if(colSpanCount > 1) {
prevCell.setAttribute('colspan',colSpanCount);
prevCell.setAttribute('colSpan',colSpanCount); // Needed for IE
}
w.nextMatch += 3;
break;
} else {
// Cell
w.nextMatch += 2; //skip over ||
var chr = w.source.substr(w.nextMatch,1);
var cell;
if(chr == '~') {
cell = createTiddlyElement(e,'th');
w.nextMatch++;
} else {
cell = createTiddlyElement(e,'td');
if(chr == '>') {
cell.align = 'right';
w.nextMatch++;
} else if(chr == '=') {
cell.align = 'center';
w.nextMatch++;
} else {
cell.align = 'left';
}
}
prevCell = cell;
prevColumns[col] = {rowSpanCount:1,element:cell};
if(colSpanCount > 1) {
cell.setAttribute('colspan',colSpanCount);
cell.setAttribute('colSpan',colSpanCount); // Needed for IE
colSpanCount = 1;
}
w.subWikifyTerm(cell,this.cellTermRegExp);
prevCell = cell;
w.nextMatch -= 2;
}
col++;
if(w.source.substr(w.nextMatch,3)=='||\n') {
w.nextMatch += 3;
break;
}
if(w.nextMatch==w.source.length-2) {
// table ends at end of tiddler
w.nextMatch += 2;
break;
}
this.cellRegExp.lastIndex = w.nextMatch;
cellMatch = this.cellRegExp.exec(w.source);
col++;
}
}//# end rowHandler
},
{
name: 'wikispaceslist',
match: '^[\\*#]+ ',
lookaheadRegExp: /^([\*#])+ /mg,
termRegExp: /(\n)/mg,
handler: function(w)
{
var stack = [w.output];
var currLevel = 0, currType = null;
var listLevel, listType, itemType, baseType;
w.nextMatch = w.matchStart;
this.lookaheadRegExp.lastIndex = w.nextMatch;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
while(lookaheadMatch && lookaheadMatch.index == w.nextMatch) {
itemType = 'li';
listType = lookaheadMatch[1] == '*' ? 'ul' : 'ol';
if(!baseType)
baseType = listType;
listLevel = lookaheadMatch[0].length;
w.nextMatch += lookaheadMatch[0].length;
var t;
if(listLevel > currLevel) {
for(t=currLevel; t<listLevel; t++) {
var target = (currLevel == 0) ? stack[stack.length-1] : stack[stack.length-1].lastChild;
stack.push(createTiddlyElement(target,listType));
}
} else if(listType!=baseType && listLevel==1) {
w.nextMatch -= lookaheadMatch[0].length;
return;
} else if(listLevel < currLevel) {
for(t=currLevel; t>listLevel; t--)
stack.pop();
} else if(listLevel == currLevel && listType != currType) {
stack.pop();
stack.push(createTiddlyElement(stack[stack.length-1].lastChild,listType));
}
currLevel = listLevel;
currType = listType;
var e = createTiddlyElement(stack[stack.length-1],itemType);
w.subWikifyTerm(e,this.termRegExp);
this.lookaheadRegExp.lastIndex = w.nextMatch;
lookaheadMatch = this.lookaheadRegExp.exec(w.source);
}
}
},
{
name: 'wikispacesQuoteByLine',
match: '^>+',
lookaheadRegExp: /^>+/mg,
termRegExp: /(\n)/mg,
element: 'blockquote',
handler: function(w)
{
var stack = [w.output];
var currLevel = 0;
var newLevel = w.matchLength;
var t;
do {
if(newLevel > currLevel) {
for(t=currLevel; t<newLevel; t++)
stack.push(createTiddlyElement(stack[stack.length-1],this.element));
} else if(newLevel < currLevel) {
for(t=currLevel; t>newLevel; t--)
stack.pop();
}
currLevel = newLevel;
w.subWikifyTerm(stack[stack.length-1],this.termRegExp);
createTiddlyElement(stack[stack.length-1],'br');
this.lookaheadRegExp.lastIndex = w.nextMatch;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
var matched = lookaheadMatch && lookaheadMatch.index == w.nextMatch;
if(matched) {
newLevel = lookaheadMatch[0].length;
w.nextMatch += lookaheadMatch[0].length;
}
} while(matched);
}
},
{
name: 'wikispacesRule',
match: '^---+$\\n?',
handler: function(w)
{
createTiddlyElement(w.output,'hr');
}
},
{
name: 'macro',
match: '<<',
lookaheadRegExp: /<<([^>\s]+)(?:\s*)((?:[^>]|(?:>(?!>)))*)>>/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart && lookaheadMatch[1]) {
w.nextMatch = this.lookaheadRegExp.lastIndex;
invokeMacro(w.output,lookaheadMatch[1],lookaheadMatch[2],w,w.tiddler);
}
}
},
{
name: 'wikispacesImage',
match: '\\[\\[image:',
lookaheadRegExp: /\[\[image:(.*?)(?: +(.*?)=\"(.*?)")*\]\]/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var img = createTiddlyElement(w.output,'img');
img.src = 'images/' + lookaheadMatch[1];
img.title = lookaheadMatch[1];
img.alt = lookaheadMatch[1];
var i = 2;
var a = lookaheadMatch[i];
while(a) {
if(a=='width' || a=='height' || a=='align') {
if(lookaheadMatch[i+1]) {
img[a] = lookaheadMatch[i+1];
}
} else if(a=='link') {
var link = createTiddlyElement(w.output,'a');
link.href = wikispacesFormatter.processLink(lookaheadMatch[i+1]);
img = w.output.removeChild(img);
link.appendChild(img);
//} else if(a=='caption') {
}
i += 2;
a = lookaheadMatch[i];
}
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
},
{
name: 'wikispacesAnchor',
match: '\\[\\[#',
lookaheadRegExp: /\[\[#(.*?)(?:\|~?(.*?))?\]\]/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var a = createTiddlyElement(w.output,'a',null,null,lookaheadMatch[2]? lookaheadMatch[2]:null);
var t = w.tiddler ? wikispacesFormatter.normalizedTitle(w.tiddler.title) + '#' : '';
a.setAttribute('name',t+lookaheadMatch[1]);
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
},
{
name: 'wikispacesExplicitLink',
match: '\\[\\[',
lookaheadRegExp: /\[\[(.*?)(?:\|(.*?))?\]\]/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var link = lookaheadMatch[1];
var text = lookaheadMatch[2] ? lookaheadMatch[2] : link;
var e = link.indexOf(':')==-1 ?
createTiddlyLink(w.output,link,false,null,w.isStatic) :
createExternalLink(w.output,wikispacesFormatter.processLink(link));
createTiddlyText(e,text);
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
},
{
name: 'wikispacesUrlLink',
match: config.textPrimitives.urlPattern,
handler: function(w)
{
w.outputText(createExternalLink(w.output,w.matchText),w.matchStart,w.nextMatch);
}
},
{
name: 'wikispacesCharacterFormat',
match: '\\*\\*|//|__|\\{\\{|``',
handler: function(w)
{
switch(w.matchText) {
case '**':
w.subWikifyTerm(createTiddlyElement(w.output,'b'),/(\*\*|(?=\n\n))/mg);
break;
case '//':
w.subWikifyTerm(createTiddlyElement(w.output,'i'),/(\/\/|(?=\n\n))/mg);
break;
case '__':
var e = createTiddlyElement(w.output,"span");
e.setAttribute("style","text-decoration:underline");
w.subWikifyTerm(e,/(__|(?=\n\n))/mg);
break;
case '{{':
this.lookaheadRegExp = /\{\{((?:.|\n)*?)\}\}/mg;
this.element = 'code';
config.formatterHelpers.enclosedTextHelper.call(this,w);
break;
case '``':
var lookaheadRegExp = /``((?:.|\n)*?)``/mg;
lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
createTiddlyElement(w.output,'span',null,null,lookaheadMatch[1]);
w.nextMatch = lookaheadRegExp.lastIndex;
}
break;
}
}
},
/*{
name: 'wikispacesParagraph',
match: '\\n{2,}',
handler: function(w)
{
w.output = createTiddlyElement(w.output,'p');
}
},
*/
{
name: 'wikispacesSpan',
match: '<span[^>]*>',
lookaheadRegExp: /<span((?:\s+(?:.*?)=["']?(?:.*?)['"]?)*?)?\s*(\/)?>/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var e = createTiddlyElement(w.output,'span');
if(lookaheadMatch[1]) {
wikispacesFormatter.setAttributesFromParams(e,lookaheadMatch[1]);
}
if(lookaheadMatch[2]) {
w.nextMatch = this.lookaheadRegExp.lastIndex;
} else {
w.subWikify(e,'</span>');
}
}
}
},
{
name: 'wikispacesLineBreak',
match: '\\n|<br ?/?>',
handler: function(w)
{
createTiddlyElement(w.output,'br');
}
},
{
name: 'wikispacesComment',
match: '<!\\-\\-',
lookaheadRegExp: /<!\-\-((?:.|\n)*?)\-\-!>/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
},
{
name: 'wikispacesMailTo',
match: '[\\w\.]+@[\\w]+\.[\\w\.]+',
lookaheadRegExp: /([\w\.]+@[\w]+\.[\w\.]+)/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var text = lookaheadMatch[1];
createTiddlyText(createExternalLink(w.output,'mailto:'+text),text);
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
},
{
name: 'wikispacesHtmlEntitiesEncoding',
match: '&#?[a-zA-Z0-9]{2,8};',
handler: function(w)
{
createTiddlyElement(w.output,'span').innerHTML = w.matchText;
}
}
];
config.parsers.wikispacesFormatter = new Formatter(config.wikispacesFormatters);
config.parsers.wikispacesFormatter.format = 'wikispaces';
config.parsers.wikispacesFormatter.formatTag = 'wikispacesFormat';
} // end of 'install only once'
//}}}
/***
|''Name:''|ccTiddlyAdaptorPlugin|
|''Description:''|Adaptor for moving and converting data to and from ccTiddly wikis|
|''Author:''|Martin Budden (mjbudden (at) gmail (dot) com)|
|''Source:''|http://www.martinswiki.com/#ccTiddlyAdaptorPlugin|
|''CodeRepository:''|http://svn.tiddlywiki.org/Trunk/contributors/MartinBudden/adaptors/ccTiddlyAdaptorPlugin.js|
|''Version:''|0.5.2|
|''Date:''|Feb 25, 2007|
|''Comments:''|Please make comments at http://groups.google.co.uk/group/TiddlyWikiDev|
|''License:''|[[Creative Commons Attribution-ShareAlike 2.5 License|http://creativecommons.org/licenses/by-sa/2.5/]]|
|''~CoreVersion:''|2.2.0|
''For debug:''
|''Default ccTiddly username''|<<option txtccTiddlyUsername>>|
|''Default ccTiddly password''|<<option txtccTiddlyPassword>>|
***/
//{{{
if(!config.options.txtccTiddlyUsername)
{config.options.txtccTiddlyUsername = '';}
if(!config.options.txtccTiddlyPassword)
{config.options.txtccTiddlyPassword = '';}
//}}}
// Ensure that the plugin is only installed once.
if(!version.extensions.ccTiddlyAdaptorPlugin) {
version.extensions.ccTiddlyAdaptorPlugin = {installed:true};
function ccTiddlyAdaptor()
{
this.host = null;
this.workspace = null;
// for debug
this.username = config.options.txtccTiddlyUsername;
this.password = config.options.txtccTiddlyPassword;
return this;
}
ccTiddlyAdaptor.serverType = 'cctiddly';
ccTiddlyAdaptor.serverParsingErrorMessage = "Error parsing result from server";
ccTiddlyAdaptor.errorInFunctionMessage = "Error in function ccTiddlyAdaptor.%0";
ccTiddlyAdaptor.doHttpGET = function(uri,callback,params,headers,data,contentType,username,password)
{
return doHttp('GET',uri,data,contentType,username,password,callback,params,headers);
};
ccTiddlyAdaptor.doHttpPOST = function(uri,callback,params,headers,data,contentType,username,password)
{
return doHttp('POST',uri,data,contentType,username,password,callback,params,headers);
};
ccTiddlyAdaptor.prototype.setContext = function(context,userParams,callback)
{
if(!context) context = {};
context.userParams = userParams;
if(callback) context.callback = callback;
context.adaptor = this;
return context;
};
ccTiddlyAdaptor.fullHostName = function(host)
{
if(!host)
return '';
if(!host.match(/:\/\//))
host = 'http://' + host;
if(host.substr(-1) != '/')
host = host + '/';
return host;
};
ccTiddlyAdaptor.minHostName = function(host)
{
return host ? host.replace(/^http:\/\//,'').replace(/\/$/,'') : '';
};
ccTiddlyAdaptor.prototype.openHost = function(host,context,userParams,callback)
{
context = this.setContext(context,userParams,callback);
this.host = ccTiddlyAdaptor.fullHostName(host);
if(context.callback) {
context.status = true;
window.setTimeout(context.callback,0,context,userParams);
}
return true;
};
ccTiddlyAdaptor.prototype.openWorkspace = function(workspace,context,userParams,callback)
{
context = this.setContext(context,userParams,callback);
this.workspace = workspace;
if(context.callback) {
context.status = true;
window.setTimeout(context.callback,0,context,userParams);
}
return true;
};
ccTiddlyAdaptor.prototype.getWorkspaceList = function(context,userParams,callback)
{
context = this.setContext(context,userParams,callback);
var list = [];
list.push({title:"Main",name:"Main"});
context.workspaces = list;
if(context.callback) {
context.status = true;
window.setTimeout(context.callback,0,context,userParams);
}
return true;
};
ccTiddlyAdaptor.prototype.getTiddlerList = function(context,userParams,callback)
{
context = this.setContext(context,userParams,callback);
//var uriTemplate = '%0msghandle.php?action=content';
var uriTemplate = '%0msghandle.php?action=content&username=%1&password=%2';
var host = ccTiddlyAdaptor.fullHostName(this.host);
var uri = uriTemplate.format([host,this.workspace,this.username,this.password]);
var req = ccTiddlyAdaptor.doHttpGET(uri,ccTiddlyAdaptor.getTiddlerListCallback,context);
return typeof req == 'string' ? req : true;
};
ccTiddlyAdaptor.getTiddlerListCallback = function(status,context,responseText,uri,xhr)
{
displayMessage('getTiddlerListCallback status:'+status);
displayMessage('rt:'+responseText.substr(0,80));
context.status = false;
context.statusText = ccTiddlyAdaptor.errorInFunctionMessage.format(['getTiddlerListCallback']);
if(status) {
try {
list = [];
/*var titles = responseText.split('\n');
for(var i=0; i<titles.length; i++) {
var tiddler = new Tiddler(titles[i]);
list.push(tiddler);
}*/
if(list.length==0) {
list.push(new Tiddler('About')); //kludge until get support for listTiddlers in ccTiddly
}
context.tiddlers = list;
} catch (ex) {
context.statusText = exceptionText(ex,ccTiddlyAdaptor.serverParsingErrorMessage);
if(context.callback)
context.callback(context,context.userParams);
return;
}
context.status = true;
} else {
context.statusText = xhr.statusText;
}
if(context.callback)
context.callback(context,context.userParams);
};
ccTiddlyAdaptor.prototype.generateTiddlerInfo = function(tiddler)
{
var info = {};
var uriTemplate = '%0#%2';
var host = ccTiddlyAdaptor.fullHostName(this.host);
info.uri = uriTemplate.format([this.host,this.workspace,tiddler.title]);
return info;
};
ccTiddlyAdaptor.prototype.getTiddlerRevision = function(title,revision,context,userParams,callback)
{
context = this.setContext(context,userParams,callback);
context.revision = revision;
return this.getTiddler(title,null,context,userParams,callback);
};
ccTiddlyAdaptor.prototype.getTiddler = function(title,context,userParams,callback)
{
context = this.setContext(context,userParams,callback);
context.title = title;
//title = encodeURIComponent(title);
var host = ccTiddlyAdaptor.fullHostName(this.host);
context.tiddler = new Tiddler(title);
context.tiddler.fields['server.host'] = ccTiddlyAdaptor.minHostName(host);
context.tiddler.fields['server.type'] = ccTiddlyAdaptor.serverType;
if(revision) {
var uriTemplate = '%0msghandle.php?action=revisionDisplay&title=%1&revision=%2';
var uri = uriTemplate.format([host,title,revision]);
var req = ccTiddlyAdaptor.doHttpGET(uri,ccTiddlyAdaptor.getTiddlerCallback2,context);
} else {
// first get the revision list
uriTemplate = '%0msghandle.php?action=revisionList&title=%1';
uri = uriTemplate.format([host,title]);
req = ccTiddlyAdaptor.doHttpGET(uri,ccTiddlyAdaptor.getTiddlerCallback1,context);
}
return typeof req == 'string' ? req : true;
};
ccTiddlyAdaptor.getTiddlerCallback1 = function(status,context,responseText,xhr)
{
context.status = false;
context.statusText = ccTiddlyAdaptor.errorInFunctionMessage.format(['getTiddlerCallback']);
if(status) {
var revs = responseText.split('\n');
var parts = revs[0].split(' ');
var tiddlerRevision = parts[1];
// now get the latest revision
var uriTemplate = '%0msghandle.php?action=revisionDisplay&title=%1&revision=%2';
var host = ccTiddlyAdaptor.fullHostName(context.adaptor.host);
var uri = uriTemplate.format([host,context.tiddler.title,tiddlerRevision]);
var req = ccTiddlyAdaptor.doHttpGET(uri,ccTiddlyAdaptor.getTiddlerCallback2,context);
} else {
context.statusText = xhr.statusText;
if(context.callback)
context.callback(context,context.userParams);
}
};
ccTiddlyAdaptor.getTiddlerCallback2 = function(status,context,responseText,xhr)
{
context.status = false;
if(status) {
var x = responseText.split('\n');
try {
context.tiddler.text = x[2] ? x[2].unescapeLineBreaks().htmlDecode() : '';
context.tiddler.modifier = x[3];
if(x[4])
context.tiddler.created = Date.convertFromYYYYMMDDHHMM(x[4]);
if(x[5])
context.tiddler.modified = Date.convertFromYYYYMMDDHHMM(x[5]);
//context.tiddler.tags = x[6].join(' ');
} catch(ex) {
context.statusText = exceptionText(ex,ccTiddlyAdaptor.serverParsingErrorMessage);
if(context.callback)
context.callback(context);
return;
}
context.status = true;
} else {
context.statusText = xhr.statusText;
}
if(context.callback)
context.callback(context,context.userParams);
};
ccTiddlyAdaptor.prototype.getTiddlerRevisionList = function(title,context,userParams,callback)
// get a list of the revisions for a page
{
context = this.setContext(context,userParams,callback);
title = encodeURIComponent(title);
var uriTemplate = '%0handle.revisionlist.php?XXX&workspace=%1&title=%2';
var host = ccTiddlyAdaptor.fullHostName(this.host);
var uri = uriTemplate.format([host,workspace,title]);
context.tiddler = new Tiddler(title);
context.tiddler.fields['server.host'] = ccTiddlyAdaptor.minHostName(host);
context.tiddler.fields['server.type'] = ccTiddlyAdaptor.serverType;
var req = ccTiddlyAdaptor.doHttpGET(uri,ccTiddlyAdaptor.getTiddlerRevisionListCallback,context);
};
ccTiddlyAdaptor.getTiddlerRevisionListCallback = function(status,context,responseText,uri,xhr)
{
context.status = false;
if(status) {
list = [];
var r = responseText;
if(r != '-') {
var revs = r.split('\n');
var list = [];
for(var i=0; i<revs.length; i++) {
var parts = revs[i].split(' ');
if(parts.length>1) {
var tiddler = new Tiddler(context.tiddler.title);
tiddler.modified = Date.convertFromYYYYMMDDHHMM(parts[0]);
tiddler.fields['server.page.revision'] = String(parts[1]);
list.push(tiddler);
}
}
}
context.revisions = list;
context.status = true;
} else {
context.statusText = xhr.statusText;
}
if(context.callback)
context.callback(context,context.userParams);
};
ccTiddlyAdaptor.prototype.putTiddler = function(tiddler,context,userParams,callback)
{
context = this.setContext(context,userParams,callback);
context.title = tiddler.title;
var title = encodeURIComponent(tiddler.title);
var host = this && this.host ? this.host : ccTiddlyAdaptor.fullHostName(tiddler.fields['server.host']);
var uriTemplate = '%0handle/save.php?XXX&workspace=%1&title=%2';
var uri = uriTemplate.format([host,title]);
context.tiddler = tiddler;
context.tiddler.fields['server.host'] = ccTiddlyAdaptor.minHostName(host);
context.tiddler.fields['server.type'] = ccTiddlyAdaptor.serverType;
/* doHttp('POST'
,serverside.url + '/handle/save.php?' + serverside.queryString + '&workspace=' + serverside.workspace
,'tiddler=' + encodeURIComponent(store.getSaver().externalizeTiddler(store,tiddler))
+ '&otitle=' + encodeURIComponent(title.htmlDecode())
+ ((omodified!==null)?'&omodified=' + encodeURIComponent(omodified.convertToYYYYMMDDHHMM()):"")
+ ((ochangecount!==null)?'&ochangecount=' + encodeURIComponent(ochangecount):"")
,null, null, null
,serverside.fn.genericCallback
);
*/
var req = ccTiddlyAdaptor.doHttpPOST(uri,ccTiddlyAdaptor.putTiddlerCallback,tiddler.text,null,payload)
return typeof req == 'string' ? req : true;
};
ccTiddlyAdaptor.putTiddlerCallback = function(status,context,responseText,uri,xhr)
{
if(status) {
context.status = true;
} else {
context.status = false;
context.statusText = xhr.statusText;
}
if(context.callback)
context.callback(context,context.userParams);
};
ccTiddlyAdaptor.prototype.deleteTiddler = function(title,context,userParams,callback)
{
context = this.setContext(context,userParams,callback);
context.title = title;
var title = encodeURIComponent(tiddler.title);
var host = this && this.host ? this.host : ccTiddlyAdaptor.fullHostName(tiddler.fields['server.host']);
var uriTemplate = '%0handle/delete.php?XXX&workspace=%1&title=%2';
var uri = uriTemplate.format([host,workspace,title]);
var req = ccTiddlyAdaptor.doHttpPOST(uri,ccTiddlyAdaptor.deleteTiddlerCallback,title)
return typeof req == 'string' ? req : true;
};
ccTiddlyAdaptor.deleteTiddlerCallback = function(status,context,responseText,uri,xhr)
{
if(status) {
context.status = true;
} else {
context.status = false;
context.statusText = xhr.statusText;
}
if(context.callback)
context.callback(context,context.userParams);
};
ccTiddlyAdaptor.prototype.close = function() {return true;};
config.adaptors[ccTiddlyAdaptor.serverType] = ccTiddlyAdaptor;
} // end of 'install only once'
//}}}
/***
|''Name:''|settings|
|''Description:''|Set preferences|
|''~CoreVersion:''|2.1.0|
***/
/*{{{*/
if(config.backstageTasks.indexOf("sync")!=-1)
config.backstageTasks.splice(config.backstageTasks.indexOf("sync"),1);
if(config.backstageTasks.indexOf("importTask")!=-1)
config.backstageTasks.splice(config.backstageTasks.indexOf("importTask"),1);
//showBackstage = true;
config.views.editor.defaultText = '';
config.options.chkAnimate = false;
config.options.chkDisableWikiLinks = true;
config.options.txtMaxEditRows = 20;
/*}}}*/
== Headings
== Heading2
=== Heading3
==== Heading4
===== Heading5
==Heading2
===Heading3
====Heading4
=====Heading5
== Heading2 =
=== Heading3 =
==== Heading4 =====
===== Heading5 ==
== Bold and Italic
**bold**
//italic//
**//bolditalic//**
A normal sentence. **A bold sentence
that continues in bold over a line break.** And another normal sentence.
A normal sentence. **A bold sentence that is not terminated by star-star, but is instead is terminated by a paragraph break.
A normal sentence.
A normal sentence. //An italic sentence
that continues in italic over a line break.// And another normal sentence.
A normal sentence. //An italic sentence that is not terminated by slash-slash, but is instead is terminated by a paragraph break.
A normal sentence.
== Preformatted text
Normal text {{{preformatted text}}} Normal text.
{{{
A block
of preformatted text
}}}
== Links
[[explicitlink]]
[[link|explicitlinkTitle]]
http://www.wikicreole.org
[[http://www.wikicreole.org|Wiki Creole Site]]
== Misc
A horizontal rule follows
----
== Lists
* bulleted list
* bullet 2
** bullet level 2
*** bullet level 3
# numbered list
# item 2
## item 2.1
### item 2.1.1
#### item 2.1.1.1
##### item 2.1.1.1.1
# item 3
# item 4
'''bold'''
''italic''
<b>bold</b>
<sub>subscript</sub>
<sup>superscript</sup>
<u>underline</u>
<s>strikethrough</s>
<code>code</code>
'''bold''' ''italic'' <b>bold</b> <sub>subscript</sub> <sup>superscript</sup> <u>underline</u> <s>strikethrough</s> <code>code</code>
* You can even create mixed lists
*# and nest them
*#* like this
*#*; can I mix definition list as well?
*#*: yes
*#*; how?
*#*: it's easy as
*#*:* a
*#*:* b
*#*:* c
<blockquote>
a block to
quote
</blockquote>
=H1=
== H2==
some text
===H3===
====H4====
=====H5=====
======H6======
=======H7=======
----
[[BasicLink]]
[[BasicLink|PipedLink]]
[[0PeriodicTable]]
[[0PeriodicTable|PipedLink to PeriodicTable]]
^^ Markup
*bold* * notbold* *notbold *
_italic_
-strikethrough-
`monospace`
.pre
Block of text with no *special* punctuation
.pre
{{*this text is not bold*}}
^^ Headings
^ H1
^^H2
^^^ H3
^^^^ H4
^^^^^ H5
^^^^^^ H6
^^ Rule:
----
^^ Numbered list:
# item 1
## subitem 1
# item 2
^^ Bulleted list:
* item 1
** subitem 1
* item 2
^^ Indented text
> Indented
>> Indented twice
^^ Table
|aa | bb| cc |
|dd | ee| ff |
^^ Misc
trademark {tm}
^^ Images
Image attachment(.ico): {image: http://www.eu.socialtext.net/favicon.ico}
Image attachment(.gif): {image: http://www.eu.socialtext.net/static/images/socialtext-logo-30.gif}
External image(.ico): <http://www.eu.socialtext.net/favicon.ico>
External image(.gif): <http://www.eu.socialtext.net/static/images/socialtext-logo-30.gif>
External image(.gif): <http://www.eu.socialtext.net/exchange/index.cgi/new.gif>
^^ Links
Page Link: [Page Link]
Link text: "Link text" [Page Link]
External link: <http://www.socialtext.com>
Socialtext Home Page: "Socialtext Home Page"<http://www.socialtext.com>
Socialtext Email: "Socialtext Email"<mailto:info@socialtext.com>
URL link: http://www.socialtext.com/
----
^^ Not supported
proposal.pdf on this page {file: proposal.pdf} on this page
proposal.pdf on page name {file: [page name] proposal.pdf} on [page name]
Mail link: info@socialtext.com
Page Link to different-workspace: {link: different-workspace [Page link]} to different-workspace
Link to section of a page: {link: different-workspace [Page link] Section} to (optional) different-workspace
Page section {section: Name}
My Weblog weblog {weblog: My Weblog}
Meeting notes category {category: Meeting Notes}
Yahoo user (yahoouser) presence {ymsgr:yahoouser}
AOL user (aimuser) presence {aim:aimuser}
Table of contents {toc}
= Text Formatting =
= heading 1 =
== heading 2 ==
=== heading 3 ===
Bulleted List
* list
* list
Numbered List
# numbered
# numbered
Bold
**bold**
Italics
//italics//
Underline
__underline__
Monospaced Font
{{curly braces}}
Escaping
``escaping`` (surround in double backtick characters).
Indenting
> indent
>> double indent
= Tables =
||~ heading1 ||~ heading2 ||~ heading3 ||
|| table cell || table cell || table cell ||
||= centered ||> right || normal ||
|||| spans 2 columns || cell ||
|| col1 || col2 || col3 ||
||col1||col2||col3||
= Links and Images and Files =
Page Link
[[pagename|label]] or just [[pagename]]
Page Link in Another Space
[[space:pagename|label]] or just [[space:pagename]]
URL
http://some.url
Email
help@wikispaces.org
Labeled URL
[[http://some.url|label]]
Image
[[image:name.jpg]] (png, jpeg, and gif - learn more about image tags)
File
[[file:name.txt]] (any file type supported)
Anchor
[[#anchor]] see wikitext anchor for more details
== Link examples ==
[[foo]]
This will display the text "foo" on the page which will be a link to the page in this space also called "foo".
[[foo|bar]]
This will display the text "bar" on the page which will be a link to the page in this space called "foo".
[[hep:the]]
This will display the text "hep:the" on the page which will be a link to the page in the "hep" space called "the".
[[hep:the|bar]]
This will display the text "bar" on the page which will be a link to the page in the "hep" space called "the".