W3C home > Mailing lists > Public > public-dap-commits@w3.org > December 2009

2009/dap/ReSpec.js/js respec.js,1.59,1.60

From: Robin Berjon via cvs-syncmail <cvsmail@w3.org>
Date: Thu, 03 Dec 2009 12:36:58 +0000
To: public-dap-commits@w3.org
Message-Id: <E1NGAva-0005vK-0m@lionel-hutz.w3.org>
Update of /sources/public/2009/dap/ReSpec.js/js
In directory hutz:/tmp/cvs-serv22728/js

Modified Files:
	respec.js 
Log Message:
trim leading space in examples

Index: respec.js
===================================================================
RCS file: /sources/public/2009/dap/ReSpec.js/js/respec.js,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -d -r1.59 -r1.60
--- respec.js	3 Dec 2009 12:21:52 -0000	1.59
+++ respec.js	3 Dec 2009 12:36:55 -0000	1.60
@@ -463,6 +463,23 @@
     },
 
     examples:    function () {
+        // reindent
+        var exes = document.querySelectorAll("pre.example");
+        for (var i = 0; i < exes.length; i++) {
+            var ex = exes[i];
+            var lines = ex.textContent.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]);
+            if (matches) {
+                var rep = new RegExp("^" + matches[1]);
+                for (var j = 0; j < lines.length; j++) {
+                    lines[j] = lines[j].replace(rep, "");
+                }
+            }
+            ex.textContent = lines.join("\n");
+        }
+        // highlight
         sh_highlightDocument(this.base + "js/lang/", ".min.js");
     },
 
Received on Thursday, 3 December 2009 12:37:06 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Thursday, 3 December 2009 12:37:07 GMT