• R/O
  • SSH
  • HTTPS

whitespacejs: Commit


Commit MetaInfo

Revision1 (tree)
Time2011-12-28 11:10:34
Authorthejs

Log Message

(empty log message)

Change Summary

Incremental Difference

--- whitespacejs/trunk/src/core.js (nonexistent)
+++ whitespacejs/trunk/src/core.js (revision 1)
@@ -0,0 +1,114 @@
1+/**
2+ * @package thejs.whitespace
3+ * @class
4+ * @name Whitespace
5+ */
6+(function(G){
7+
8+ G["Whitespace"] = function()
9+ {
10+ return prot.parse.apply(prot, arguments);
11+ };
12+
13+ var D = document;
14+
15+ var __TABLE__ = {
16+ "/*{{[[EOL]]}}*/" : G["__EOL__"],
17+ "/*{{[[TAB]]}}*/" : "\t"
18+ };
19+
20+ /** @lends Whitespace */
21+ var prot = {
22+
23+ /**
24+ * ホワイトスペースノードを実体化したDOMツリーを返す.
25+ *
26+ * @constructs
27+ * @param {String} text
28+ * @param {Object} [table]
29+ * @return DOM
30+ */
31+ parse : function(text, table)
32+ {
33+ if (typeof table == "object") {
34+ for (var key in table) {
35+ __TABLE__[key] = table[key];
36+ }
37+ }
38+ return this.__parse(text);
39+ },
40+
41+ /**
42+ * テキストをデコードして返す.
43+ *
44+ * @param {String} text
45+ * @return {String}
46+ */
47+ __decode : function(text)
48+ {
49+ var LIST = __TABLE__;
50+ for (var k in LIST) {
51+ var v = LIST[k];
52+ text = text.
53+ split(k).join(v);
54+ }
55+ return text;
56+ },
57+
58+ /**
59+ * テキストをエンコードして返す.
60+ *
61+ * @param {String} text
62+ * @return {String}
63+ */
64+ __encode : function(text)
65+ {
66+ var LIST = __TABLE__;
67+ for (var k in LIST) {
68+ var v = LIST[k];
69+ text = text.
70+ split(v).join(k);
71+ }
72+ return text;
73+ },
74+
75+ /**
76+ * ホワイトスペースノードを実体化したDOMツリーを返す.
77+ *
78+ * @param {String} str
79+ * @return DOM
80+ */
81+ __parse : function(str)
82+ {
83+ var node, list, w;
84+ var self = this;
85+ node = D.createElement("div");
86+ node.innerHTML = " ";
87+ str+=G["__EOL__"];
88+ if (!(w = node.childNodes[0])) {
89+ str = this.__encode(str);
90+ }
91+ node.innerHTML = str;
92+ list = node.childNodes;
93+ if (!w) (function(cs){
94+ for(var i=0; i<cs.length; i++){
95+ var v, c = cs[i];
96+ switch(c.nodeType){
97+ case 1 :
98+ arguments.callee(c.attributes);
99+ arguments.callee(c.childNodes);
100+ break;
101+ default :
102+ try {
103+ if ((v = self.__decode(c.nodeValue))
104+ != c.nodeValue) {
105+ c.nodeValue = v;
106+ }
107+ }catch(e){}
108+ }
109+ }
110+ })(list);
111+ return list;
112+ }
113+ };
114+})(window);
\ No newline at end of file
--- whitespacejs/trunk/whitespace.js (nonexistent)
+++ whitespacejs/trunk/whitespace.js (revision 1)
@@ -0,0 +1,13 @@
1+/*!
2+ * Whitespacejs v0.8 HTML Parser
3+ * http://thejs.org/#!whitespace
4+ *
5+ * Copyright (c) 2012 Sadaaki Yamasaki <thejs@users.sourceforge.jp>
6+ * Licensed under the MIT License.
7+ */
8+
9+/**
10+ * @fileOverview package thejs.whitespace
11+ * @requires src/core.js
12+ * @requires eol.js (http://thejs.org/#!eol)
13+ */
\ No newline at end of file
--- whitespacejs/branches/whitespacejs-0.8.x/src/core.js (nonexistent)
+++ whitespacejs/branches/whitespacejs-0.8.x/src/core.js (revision 1)
@@ -0,0 +1,114 @@
1+/**
2+ * @package thejs.whitespace
3+ * @class
4+ * @name Whitespace
5+ */
6+(function(G){
7+
8+ G["Whitespace"] = function()
9+ {
10+ return prot.parse.apply(prot, arguments);
11+ };
12+
13+ var D = document;
14+
15+ var __TABLE__ = {
16+ "/*{{[[EOL]]}}*/" : G["__EOL__"],
17+ "/*{{[[TAB]]}}*/" : "\t"
18+ };
19+
20+ /** @lends Whitespace */
21+ var prot = {
22+
23+ /**
24+ * ホワイトスペースノードを実体化したDOMツリーを返す.
25+ *
26+ * @constructs
27+ * @param {String} text
28+ * @param {Object} [table]
29+ * @return DOM
30+ */
31+ parse : function(text, table)
32+ {
33+ if (typeof table == "object") {
34+ for (var key in table) {
35+ __TABLE__[key] = table[key];
36+ }
37+ }
38+ return this.__parse(text);
39+ },
40+
41+ /**
42+ * テキストをデコードして返す.
43+ *
44+ * @param {String} text
45+ * @return {String}
46+ */
47+ __decode : function(text)
48+ {
49+ var LIST = __TABLE__;
50+ for (var k in LIST) {
51+ var v = LIST[k];
52+ text = text.
53+ split(k).join(v);
54+ }
55+ return text;
56+ },
57+
58+ /**
59+ * テキストをエンコードして返す.
60+ *
61+ * @param {String} text
62+ * @return {String}
63+ */
64+ __encode : function(text)
65+ {
66+ var LIST = __TABLE__;
67+ for (var k in LIST) {
68+ var v = LIST[k];
69+ text = text.
70+ split(v).join(k);
71+ }
72+ return text;
73+ },
74+
75+ /**
76+ * ホワイトスペースノードを実体化したDOMツリーを返す.
77+ *
78+ * @param {String} str
79+ * @return DOM
80+ */
81+ __parse : function(str)
82+ {
83+ var node, list, w;
84+ var self = this;
85+ node = D.createElement("div");
86+ node.innerHTML = " ";
87+ str+=G["__EOL__"];
88+ if (!(w = node.childNodes[0])) {
89+ str = this.__encode(str);
90+ }
91+ node.innerHTML = str;
92+ list = node.childNodes;
93+ if (!w) (function(cs){
94+ for(var i=0; i<cs.length; i++){
95+ var v, c = cs[i];
96+ switch(c.nodeType){
97+ case 1 :
98+ arguments.callee(c.attributes);
99+ arguments.callee(c.childNodes);
100+ break;
101+ default :
102+ try {
103+ if ((v = self.__decode(c.nodeValue))
104+ != c.nodeValue) {
105+ c.nodeValue = v;
106+ }
107+ }catch(e){}
108+ }
109+ }
110+ })(list);
111+ return list;
112+ }
113+ };
114+})(window);
\ No newline at end of file
--- whitespacejs/branches/whitespacejs-0.8.x/whitespace.js (nonexistent)
+++ whitespacejs/branches/whitespacejs-0.8.x/whitespace.js (revision 1)
@@ -0,0 +1,13 @@
1+/*!
2+ * Whitespacejs v0.8 HTML Parser
3+ * http://thejs.org/#!whitespace
4+ *
5+ * Copyright (c) 2012 Sadaaki Yamasaki <thejs@users.sourceforge.jp>
6+ * Licensed under the MIT License.
7+ */
8+
9+/**
10+ * @fileOverview package thejs.whitespace
11+ * @requires src/core.js
12+ * @requires eol.js (http://thejs.org/#!eol)
13+ */
\ No newline at end of file
Show on old repository browser