dojox.dtl.html.getTemplate
dojo.require("dojox.dtl.html");
defined in dojox/dtl/html.js
Usage
function (text) (view source)
if(typeof this._commentable == "undefined"){ // Check to see if the browser can handle comments this._commentable = false; var div = document.createElement("div"); div.innerHTML = "<!--Test comment handling, and long comments, using comments whenever possible.-->"; if(div.childNodes.length && div.childNodes[0].nodeType == 8 && div.childNodes[0].data == "comment"){ this._commentable = true; } } if(!this._commentable){ // Strip comments text = text.replace(/<!--({({|%).*?(%|})})-->/g|>, "$1"); } var match; var pairs = [ [true, "select", "option"], [dojo.isSafari, "tr", "th"], [dojo.isSafari, "tr", "td"], [dojo.isSafari, "thead", "tr", "th"], [dojo.isSafari, "tbody", "tr", "td"] ]; // Some tags can't contain text. So we wrap the text in tags that they can have. for(var i = 0, pair; pair = pairs[i]; i++){ if(!pair[0]){ continue; } if(text.indexOf("<" + pair[1]) != -1){ var selectRe = new RegExp("<" + pair[1] + "[\\s\\S]*?>([\\s\\S]+?)</" + pair[1] + ">", "ig"); while(match = selectRe.exec(text)){ // Do it like this to make sure we don't double-wrap var found = false; var tokens = dojox.string.tokenize(match[1], new RegExp("(<" + pair[2] + "[\\s\\S]*?>[\\s\\S]*?</" + pair[2] + ">)", "ig"), function(child){ found = true; return {data: child}; }); if(found){ var replace = []; for(var j = 0; j < tokens.length; j++) { if(dojo.isObject(tokens[j])){ replace.push(tokens[j].data); }else{ var close = pair[pair.length - 1]; var k, replacement = ""; for(k = 2; k < pair.length - 1; k++){ replacement += "<" + pair[k] + ">"; } replacement += "<" + close + ' iscomment="true">' + dojo.trim(tokens[j]) + "</" + close + ">"; for(k = 2; k < pair.length - 1; k++){ replacement += "</" + pair[k] + ">"; } replace.push(replacement); } } text = text.replace(match[1], replace.join("")); } } } } var re = /\b([a-zA-Z]+)=['"]/g; while(match = re.exec(text)){ this._attributes[match[1].toLowerCase()] = true; } var div = document.createElement("div"); div.innerHTML = text; var output = {nodes: []}; while(div.childNodes.length){ output.nodes.push(div.removeChild(div.childNodes[0])) } return output;
parameter | type | description |
---|---|---|
text |