All pastes #658200 Raw Edit

tabletest of mine

public javascript v1 · immutable
#658200 ·published 2007-08-15 13:06 UTC
rendered paste body
config.formatters = [{	name: "table",	match: "^\\|(?:[^\\n]*)\\|(?:[fhck]?)$",	lookaheadRegExp: /^\|([^\n]*)\|([fhck]?)$/mg,	rowTermRegExp: /(\|(?:[fhck]?)$\n?)/mg,	cellRegExp: /(?:\|([^\n\|]*)\|)|(\|[fhck]?$\n?)/mg,	cellTermRegExp: /((?:\x20*)\|)/mg,	rowTypes: {"c":"caption", "h":"thead", "":"tbody", "f":"tfoot"},	handler: function(w)	{		var table = createTiddlyElement(w.output,"table",null,"twtable");		var prevColumns = [];		var currRowType = null;		var rowContainer;		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 nextRowType = lookaheadMatch[2];			if(nextRowType == "k") {				table.className = lookaheadMatch[1];				w.nextMatch += lookaheadMatch[0].length+1;			} else {				if(nextRowType != currRowType) {					rowContainer = createTiddlyElement(table,this.rowTypes[nextRowType]);					currRowType = nextRowType;				}				if(currRowType == "c") {					// Caption					w.nextMatch++;					if(rowContainer != table.firstChild)						table.insertBefore(rowContainer,table.firstChild);					rowContainer.setAttribute("align",rowCount == 0?"top":"bottom");					w.subWikifyTerm(rowContainer,this.rowTermRegExp);				} else {					this.rowHandler(w,createTiddlyElement(rowContainer,"tr",null,(rowCount&1)?"oddRow":"evenRow"),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 styles = config.formatterHelpers.inlineCssHelper(w);				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;				if(chr == "!") {					cell = createTiddlyElement(e,"th");					w.nextMatch++;				} else {					cell = createTiddlyElement(e,"td",null,"cell");				//	cell.onmouseover = function() {this.addClass = "active";};				//	cell.onmouseout = function() {this.removeClass = "active";};				}				prevCell = cell;				prevColumns[col] = {rowSpanCount:1,element:cell};				if(colSpanCount > 1) {					cell.setAttribute("colspan",colSpanCount);					cell.setAttribute("colSpan",colSpanCount); // Needed for IE					colSpanCount = 1;				}				config.formatterHelpers.applyCssHelper(cell,styles);				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);		}	}},