/*\ title: $:/core/modules/utils/parsetree.js type: application/javascript module-type: utils Parse tree utility functions. \*/ (function(){ /*jslint node: true, browser: true */ /*global $tw: false */ "use strict"; exports.addAttributeToParseTreeNode = function(node,name,value) { var attribute = {name: name, type: "string", value: value}; node.attributes = node.attributes || {}; node.attributes[name] = attribute; if(node.orderedAttributes) { node.orderedAttributes.push(attribute); } }; exports.getAttributeValueFromParseTreeNode = function(node,name,defaultValue) { if(node.attributes && node.attributes[name] && node.attributes[name].value !== undefined) { return node.attributes[name].value; } return defaultValue; }; exports.addClassToParseTreeNode = function(node,classString) { var classes = [], attribute; node.attributes = node.attributes || {}; attribute = node.attributes["class"]; if(!attribute) { // If the class attribute does not exist, we must create it first. attribute = {name: "class", type: "string", value: ""}; node.attributes["class"] = attribute; if(node.orderedAttributes) { // If there are orderedAttributes, we've got to add them there too. node.orderedAttributes.push(attribute); } } if(attribute.type === "string") { if(attribute.value !== "") { classes = attribute.value.split(" "); } if(classString !== "") { $tw.utils.pushTop(classes,classString.split(" ")); } attribute.value = classes.join(" "); } }; exports.addStyleToParseTreeNode = function(node,name,value) { var attribute; node.attributes = node.attributes || {}; attribute = node.attributes.style; if(!attribute) { attribute = {name: "style", type: "string", value: ""}; node.attributes.style = attribute; if(node.orderedAttributes) { // If there are orderedAttributes, we've got to add them there too. node.orderedAttributes.push(attribute); } } if(attribute.type === "string") { attribute.value += name + ":" + value + ";"; } }; exports.findParseTreeNode = function(nodeArray,search) { for(var t=0; t