- From: Shane McCarron via cvs-syncmail <cvsmail@w3.org>
- Date: Wed, 24 Feb 2010 15:45:39 +0000
- To: public-dap-commits@w3.org
Update of /sources/public/2009/dap/ReSpec.js/js In directory hutz:/tmp/cvs-serv14556/js Modified Files: respec.js Log Message: Added support for data-transform attribute. Fixed pre.example handling so it uses innerHTML instead of TextContent. Index: respec.js =================================================================== RCS file: /sources/public/2009/dap/ReSpec.js/js/respec.js,v retrieving revision 1.90 retrieving revision 1.91 diff -u -d -r1.90 -r1.91 --- respec.js 22 Feb 2010 23:15:36 -0000 1.90 +++ respec.js 24 Feb 2010 15:45:37 -0000 1.91 @@ -161,6 +161,10 @@ } this.makeTemplate(); + // This is done REALLY early in case the transform ends up + // needing to include something + this.doTransforms() ; + // This is done early so that if other data gets embedded it will be // processed this.includeFiles(); @@ -330,6 +334,29 @@ this._insertCSS(css, false); }, + doTransforms: function() { + var divs = document.querySelectorAll("[data-transform]"); + for (var i = 0; i < divs.length; i++) { + var div = divs[i]; + var content = div.innerHTML ; + var flist = div.getAttribute('data-transform'); + if (flist) { + var methods = flist.split(/\s+/) ; + for (var j = 0; j < methods.length; j++) { + var call = 'content = ' + methods[j] + '(this,content)' ; + try { + eval(call) ; + } catch (e) { + warning('call to ' + call + ' failed with ' + e) ; + } + } + } + if (content) { + div.innerHTML = content ; + } + } + }, + includeFiles: function() { var divs = document.querySelectorAll("[data-include]"); for (var i = 0; i < divs.length; i++) { @@ -578,7 +605,7 @@ var exes = document.querySelectorAll("pre.example"); for (var i = 0; i < exes.length; i++) { var ex = exes[i]; - var lines = ex.textContent.split("\n"); + var lines = ex.innerHTML.split("\n"); while (lines.length && /^\s*$/.test(lines[0])) lines.shift(); while (/^\s*$/.test(lines[lines.length - 1])) lines.pop(); var matches = /^(\s+)/.exec(lines[0]); @@ -588,7 +615,7 @@ lines[j] = lines[j].replace(rep, ""); } } - ex.textContent = lines.join("\n"); + ex.innerHTML = lines.join("\n"); } // highlight sh_highlightDocument(this.base + "js/lang/", ".min.js");
Received on Wednesday, 24 February 2010 15:45:41 UTC