2012-12-15 11:38:59 +00:00
|
|
|
/*\
|
|
|
|
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) {
|
|
|
|
if(node.type === "element") {
|
|
|
|
node.attributes = node.attributes || {};
|
|
|
|
node.attributes[name] = {type: "string", value: value};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.addClassToParseTreeNode = function(node,classString) {
|
|
|
|
if(node.type === "element") {
|
|
|
|
node.attributes = node.attributes || {};
|
|
|
|
node.attributes["class"] = node.attributes["class"] || {type: "string", value: ""};
|
|
|
|
if(node.attributes["class"].type === "string") {
|
|
|
|
node.attributes["class"].value += " " + classString;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-12-20 09:21:58 +00:00
|
|
|
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 + ";";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-12-15 11:38:59 +00:00
|
|
|
})();
|