1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-10-30 23:23:02 +00:00

Get rid of the tweakParseTreeNode() hack

It’s an embarrassing hangover from a refactoring of the parsing
mechanism last year.
This commit is contained in:
Jermolene
2014-05-14 08:51:08 +01:00
parent 92aa1f24be
commit c9c1b0fbb4
15 changed files with 39 additions and 69 deletions

View File

@@ -13,14 +13,12 @@ Parse tree utility functions.
"use strict";
exports.addAttributeToParseTreeNode = function(node,name,value) {
if(node.type === "element") {
node.attributes = node.attributes || {};
node.attributes[name] = {type: "string", value: value};
}
node.attributes = node.attributes || {};
node.attributes[name] = {type: "string", value: value};
};
exports.getAttributeValueFromParseTreeNode = function(node,name,defaultValue) {
if(node.type === "element" && node.attributes && node.attributes[name] && node.attributes[name].value !== undefined) {
if(node.attributes && node.attributes[name] && node.attributes[name].value !== undefined) {
return node.attributes[name].value;
}
return defaultValue;
@@ -28,29 +26,25 @@ exports.getAttributeValueFromParseTreeNode = function(node,name,defaultValue) {
exports.addClassToParseTreeNode = function(node,classString) {
var classes = [];
if(node.type === "element") {
node.attributes = node.attributes || {};
node.attributes["class"] = node.attributes["class"] || {type: "string", value: ""};
if(node.attributes["class"].type === "string") {
if(node.attributes["class"].value !== "") {
classes = node.attributes["class"].value.split(" ");
}
if(classString !== "") {
$tw.utils.pushTop(classes,classString.split(" "));
}
node.attributes["class"].value = classes.join(" ");
node.attributes = node.attributes || {};
node.attributes["class"] = node.attributes["class"] || {type: "string", value: ""};
if(node.attributes["class"].type === "string") {
if(node.attributes["class"].value !== "") {
classes = node.attributes["class"].value.split(" ");
}
if(classString !== "") {
$tw.utils.pushTop(classes,classString.split(" "));
}
node.attributes["class"].value = classes.join(" ");
}
};
exports.addStyleToParseTreeNode = function(node,name,value) {
if(node.type === "element") {
node.attributes = node.attributes || {};
node.attributes["style"] = node.attributes["style"] || {type: "string", value: ""};
if(node.attributes["style"].type === "string") {
node.attributes["style"].value += name + ":" + value + ";";
}
}
};
exports.findParseTreeNode = function(nodeArray,search) {