mirror of
				https://github.com/Jermolene/TiddlyWiki5
				synced 2025-10-29 14:47:40 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			50 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			50 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| /*\
 | |
| 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) {
 | |
| 	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(" ");
 | |
| 		}
 | |
| 	}
 | |
| };
 | |
| 
 | |
| 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 + ";";
 | |
| 		}
 | |
| 	}
 | |
| };
 | |
| 
 | |
| })();
 | 
