1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-06-26 15:12:52 +00:00

Switched over to HTML.js

This commit is contained in:
Jeremy Ruston 2012-02-06 12:15:16 +00:00
parent 5406d00612
commit 4376e26d53
2 changed files with 16 additions and 16 deletions

View File

@ -33,6 +33,7 @@ HTML nodes look like this:
var WikiTextRules = require("./WikiTextRules.js"), var WikiTextRules = require("./WikiTextRules.js"),
WikiTextParseTree = require("./WikiTextParseTree.js").WikiTextParseTree, WikiTextParseTree = require("./WikiTextParseTree.js").WikiTextParseTree,
HTML = require("./HTML.js").HTML,
utils = require("./Utils.js"), utils = require("./Utils.js"),
util = require("util"); util = require("util");
@ -97,7 +98,7 @@ WikiTextParser.prototype.addDependencies = function(dependencies) {
WikiTextParser.prototype.outputText = function(place,startPos,endPos) { WikiTextParser.prototype.outputText = function(place,startPos,endPos) {
if(startPos < endPos) { if(startPos < endPos) {
place.push({type: "text", value: this.source.substring(startPos,endPos)}); place.push(HTML.text(this.source.substring(startPos,endPos)));
} }
}; };

View File

@ -8,6 +8,7 @@ title: js/WikiTextRules.js
"use strict"; "use strict";
var ArgParser = require("./ArgParser.js").ArgParser, var ArgParser = require("./ArgParser.js").ArgParser,
HTML = require("./HTML.js").HTML,
util = require("util"); util = require("util");
var textPrimitives = { var textPrimitives = {
@ -96,9 +97,7 @@ var enclosedTextHelper = function(w) {
var lookaheadMatch = this.lookaheadRegExp.exec(w.source); var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) { if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var text = lookaheadMatch[1]; var text = lookaheadMatch[1];
w.output.push({type: this.element, children: [ w.output.push(HTML.elem(this.element,null,[HTML.text(text)]));
{type: "text", value: text}
]});
w.nextMatch = lookaheadMatch.index + lookaheadMatch[0].length; w.nextMatch = lookaheadMatch.index + lookaheadMatch[0].length;
} }
}; };
@ -157,7 +156,7 @@ var rules = [
rowTypes: {"c":"caption", "h":"thead", "":"tbody", "f":"tfoot"}, rowTypes: {"c":"caption", "h":"thead", "":"tbody", "f":"tfoot"},
handler: function(w) handler: function(w)
{ {
var table = {type: "table", attributes: {"class": "twtable"}, children: []}; var table = HTML.elem("table",{"class": "twtable"},[]);
w.output.push(table); w.output.push(table);
var prevColumns = []; var prevColumns = [];
var currRowType = null; var currRowType = null;
@ -188,8 +187,8 @@ var rules = [
rowContainer.attributes.align = rowCount === 0 ? "top" : "bottom"; rowContainer.attributes.align = rowCount === 0 ? "top" : "bottom";
w.subWikifyTerm(rowContainer.children,this.rowTermRegExp); w.subWikifyTerm(rowContainer.children,this.rowTermRegExp);
} else { } else {
var theRow = {type: "tr", children: []}; var theRow = HTML.elem("tr",{},[]);
setAttr(theRow,"class",rowCount%2 ? "oddRow" : "evenRow"); theRow.attributes["class"] = rowCount%2 ? "oddRow" : "evenRow";
rowContainer.children.push(theRow); rowContainer.children.push(theRow);
this.rowHandler(w,theRow.children,prevColumns); this.rowHandler(w,theRow.children,prevColumns);
rowCount++; rowCount++;
@ -212,10 +211,10 @@ var rules = [
var last = prevColumns[col]; var last = prevColumns[col];
if(last) { if(last) {
last.rowSpanCount++; last.rowSpanCount++;
setAttr(last.element,"rowspan",last.rowSpanCount); last.element.attributes.rowspan = last.rowSpanCount;
setAttr(last.element,"valign","center"); last.element.attributes.valign = "center";
if(colSpanCount > 1) { if(colSpanCount > 1) {
setAttr(last.element,"colspan",colSpanCount); last.element.attributes.colspan = colSpanCount;
colSpanCount = 1; colSpanCount = 1;
} }
} }
@ -227,7 +226,7 @@ var rules = [
} else if(cellMatch[2]) { } else if(cellMatch[2]) {
// End of row // End of row
if(prevCell && colSpanCount > 1) { if(prevCell && colSpanCount > 1) {
setAttr(prevCell,"colspan",colSpanCount); prevCell.attributes.colspan = colSpanCount;
} }
w.nextMatch = this.cellRegExp.lastIndex; w.nextMatch = this.cellRegExp.lastIndex;
break; break;
@ -244,25 +243,25 @@ var rules = [
} }
var cell; var cell;
if(chr == "!") { if(chr == "!") {
cell = {type: "th", children: []}; cell = HTML.elem("th",{},[]);
e.push(cell); e.push(cell);
w.nextMatch++; w.nextMatch++;
} else { } else {
cell = {type: "td", children: []}; cell = HTML.elem("td",{},[]);
e.push(cell); e.push(cell);
} }
prevCell = cell; prevCell = cell;
prevColumns[col] = {rowSpanCount:1,element:cell}; prevColumns[col] = {rowSpanCount:1,element:cell};
if(colSpanCount > 1) { if(colSpanCount > 1) {
setAttr(cell,"colspan",colSpanCount); cell.attributes.colspan = colSpanCount;
colSpanCount = 1; colSpanCount = 1;
} }
applyCssHelper(cell,styles); applyCssHelper(cell,styles);
w.subWikifyTerm(cell.children,this.cellTermRegExp); w.subWikifyTerm(cell.children,this.cellTermRegExp);
if(w.matchText.substr(w.matchText.length-2,1) == " ") // spaceRight if(w.matchText.substr(w.matchText.length-2,1) == " ") // spaceRight
setAttr(cell,"align",spaceLeft ? "center" : "left"); cell.attributes.align = spaceLeft ? "center" : "left";
else if(spaceLeft) else if(spaceLeft)
setAttr(cell,"align","right"); cell.attributes.align = "right";
w.nextMatch--; w.nextMatch--;
} }
col++; col++;