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