1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-07-13 15:32:51 +00:00

Refactored config.formatterHelpers

This commit is contained in:
Jeremy Ruston 2011-12-03 16:18:17 +00:00
parent 28cce8b269
commit e1f26eb07b

View File

@ -19,15 +19,11 @@ function Formatter(formatters)
this.formatterRegExp = new RegExp(pattern.join("|"),"mg");
}
config.formatterHelpers = {
createElementAndWikify: function(w)
{
Formatter.createElementAndWikify = function(w) {
w.subWikifyTerm(createTiddlyElement(w.output,this.element),this.termRegExp);
},
};
inlineCssHelper: function(w)
{
Formatter.inlineCssHelper = function(w) {
var styles = [];
config.textPrimitives.cssLookaheadRegExp.lastIndex = w.nextMatch;
var lookaheadMatch = config.textPrimitives.cssLookaheadRegExp.exec(w.source);
@ -50,10 +46,9 @@ config.formatterHelpers = {
lookaheadMatch = config.textPrimitives.cssLookaheadRegExp.exec(w.source);
}
return styles;
},
};
applyCssHelper: function(e,styles)
{
Formatter.applyCssHelper = function(e,styles) {
var t;
for(t=0; t< styles.length; t++) {
try {
@ -61,10 +56,9 @@ config.formatterHelpers = {
} catch (ex) {
}
}
},
};
enclosedTextHelper: function(w)
{
Formatter.enclosedTextHelper = function(w) {
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
@ -74,10 +68,9 @@ config.formatterHelpers = {
createTiddlyElement(w.output,this.element,null,null,text);
w.nextMatch = lookaheadMatch.index + lookaheadMatch[0].length;
}
},
};
isExternalLink: function(link)
{
Formatter.isExternalLink = function(link) {
if(store.tiddlerExists(link) || store.isShadowTiddler(link)) {
//# Definitely not an external link
return false;
@ -93,8 +86,6 @@ config.formatterHelpers = {
}
//# Otherwise assume it is not an external link
return false;
}
};
config.formatters = [
@ -185,7 +176,7 @@ config.formatters = [
} else {
// Cell
w.nextMatch++;
var styles = config.formatterHelpers.inlineCssHelper(w);
var styles = Formatter.inlineCssHelper(w);
var spaceLeft = false;
var chr = w.source.substr(w.nextMatch,1);
while(chr == " ") {
@ -207,7 +198,7 @@ config.formatters = [
cell.setAttribute("colSpan",colSpanCount); // Needed for IE
colSpanCount = 1;
}
config.formatterHelpers.applyCssHelper(cell,styles);
Formatter.applyCssHelper(cell,styles);
w.subWikifyTerm(cell,this.cellTermRegExp);
if(w.matchText.substr(w.matchText.length-2,1) == " ") // spaceRight
cell.align = spaceLeft ? "center" : "left";
@ -294,7 +285,7 @@ config.formatters = [
match: "^<<<\\n",
termRegExp: /(^<<<(\n|$))/mg,
element: "blockquote",
handler: config.formatterHelpers.createElementAndWikify
handler: Formatter.createElementAndWikify
},
{
@ -362,7 +353,7 @@ config.formatters = [
default:
break;
}
config.formatterHelpers.enclosedTextHelper.call(this,w);
Formatter.enclosedTextHelper.call(this,w);
}
},
@ -405,7 +396,7 @@ config.formatters = [
if(lookaheadMatch[3]) {
// Pretty bracketted link
var link = lookaheadMatch[3];
e = (!lookaheadMatch[2] && config.formatterHelpers.isExternalLink(link)) ?
e = (!lookaheadMatch[2] && Formatter.isExternalLink(link)) ?
createExternalLink(w.output,link) : createTiddlyLink(w.output,link,false,null,w.isStatic,w.tiddler);
} else {
// Simple bracketted link
@ -466,7 +457,7 @@ config.formatters = [
var e = w.output;
if(lookaheadMatch[5]) {
var link = lookaheadMatch[5];
e = config.formatterHelpers.isExternalLink(link) ? createExternalLink(w.output,link) : createTiddlyLink(w.output,link,false,null,w.isStatic,w.tiddler);
e = Formatter.isExternalLink(link) ? createExternalLink(w.output,link) : createTiddlyLink(w.output,link,false,null,w.isStatic,w.tiddler);
jQuery(e).addClass("imageLink");
}
var img = createTiddlyElement(e,"img");
@ -557,11 +548,11 @@ config.formatters = [
switch(w.matchText) {
case "@@":
var e = createTiddlyElement(w.output,"span");
var styles = config.formatterHelpers.inlineCssHelper(w);
var styles = Formatter.inlineCssHelper(w);
if(styles.length == 0)
e.className = "marked";
else
config.formatterHelpers.applyCssHelper(e,styles);
Formatter.applyCssHelper(e,styles);
w.subWikifyTerm(e,/(@@)/mg);
break;
case "{{":