mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-12-02 14:29:55 +00:00
Update table.js
This commit is contained in:
parent
43f3f8b5ed
commit
856cb42039
@ -186,9 +186,6 @@ exports.parse = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
exports.serialize = function(tree, serialize) {
|
exports.serialize = function(tree, serialize) {
|
||||||
// tree: { type: 'element', tag: 'table', children: [{ type: 'element', tag: 'thead', children: [{ type: 'element', tag: 'tr', children: [{ type: 'element', tag: 'th', children: [{ type: 'text', text: 'Alpha' }] }, { type: 'element', tag: 'th', children: [{ type: 'text', text: 'Beta' }] }, { type: 'element', tag: 'th', children: [{ type: 'text', text: 'Gamma' }] }, { type: 'element', tag: 'th', children: [{ type: 'text', text: 'Delta' }] }] }] }, { type: 'element', tag: 'tbody', children: [{ type: 'element', tag: 'tr', children: [{ type: 'element', tag: 'th', children: [{ type: 'text', text: 'One' }] }, { type: 'element', tag: 'td', children: [] }, { type: 'element', tag: 'td', children: [] }, { type: 'element', tag: 'td', children: [] }, { type: 'element', tag: 'td', children: [] }] }, { type: 'element', tag: 'tr', children: [{ type: 'element', tag: 'th', children: [{ type: 'text', text: 'Two' }] }, { type: 'element', tag: 'td', children: [] }, { type: 'element', tag: 'td', children: [] }, { type: 'element', tag: 'td', children: [] }, { type: 'element', tag: 'td', children: [] }] }, { type: 'element', tag: 'tr', children: [{ type: 'element', tag: 'th', children: [{ type: 'text', text: 'Three' }] }, { type: 'element', tag: 'td', children: [] }, { type: 'element', tag: 'td', children: [] }, { type: 'element', tag: 'td', children: [] }, { type: 'element', tag: 'td', children: [] }] }] }] }
|
|
||||||
// serialize: function that accepts array of nodes or a node and returns a string
|
|
||||||
// Initialize the serialized string
|
|
||||||
var serialized = "";
|
var serialized = "";
|
||||||
// Iterate over the table rows
|
// Iterate over the table rows
|
||||||
for(var i = 0; i < tree.children.length; i++) {
|
for(var i = 0; i < tree.children.length; i++) {
|
||||||
@ -201,10 +198,14 @@ exports.serialize = function(tree, serialize) {
|
|||||||
// Iterate over the cells in the row
|
// Iterate over the cells in the row
|
||||||
for(var k = 0; k < row.children.length; k++) {
|
for(var k = 0; k < row.children.length; k++) {
|
||||||
var cell = row.children[k];
|
var cell = row.children[k];
|
||||||
|
// if is th, append additional `!`
|
||||||
|
if(cell.tag === "th") {
|
||||||
|
serialized += "!";
|
||||||
|
}
|
||||||
// Serialize the cell content
|
// Serialize the cell content
|
||||||
serialized += serialize(cell.children);
|
serialized += serialize(cell.children);
|
||||||
// End the cell
|
// End the cell with a tailing space
|
||||||
serialized += "|";
|
serialized += " |";
|
||||||
}
|
}
|
||||||
// End the row
|
// End the row
|
||||||
serialized += "\n";
|
serialized += "\n";
|
||||||
|
Loading…
Reference in New Issue
Block a user