Index: trunk/extensions/ParserPlayground/modules/ext.parserPlayground.pegParser.js |
— | — | @@ -7,38 +7,38 @@ |
8 | 8 | * is 'MediaWiki:Gadget-ParserPlayground-PegParser.pegjs'. |
9 | 9 | */ |
10 | 10 | function PegParser(options) { |
11 | | - FakeParser.call(this, options); |
| 11 | + FakeParser.call(this, options); |
12 | 12 | } |
13 | 13 | |
14 | 14 | $.extend(PegParser.prototype, FakeParser.prototype); |
15 | 15 | |
16 | 16 | PegParser.prototype.parseToTree = function(text, callback) { |
17 | | - this.initField(function() { |
18 | | - var $src = $('#pegparser-source'); |
19 | | - if ($src.length) { |
20 | | - var parserSource = $src.val(); |
21 | | - } else { |
22 | | - var parserSource = ''; |
23 | | - } |
24 | | - var out, err; |
25 | | - try { |
26 | | - var parser = PEG.buildParser(parserSource); |
27 | | - out = parser.parse(text); |
28 | | - } catch (e) { |
29 | | - err = e; |
30 | | - } finally { |
31 | | - callback(out, err); |
32 | | - } |
33 | | - }); |
| 17 | + this.initField(function() { |
| 18 | + var $src = $('#pegparser-source'); |
| 19 | + if ($src.length) { |
| 20 | + var parserSource = $src.val(); |
| 21 | + } else { |
| 22 | + var parserSource = ''; |
| 23 | + } |
| 24 | + var out, err; |
| 25 | + try { |
| 26 | + var parser = PEG.buildParser(parserSource); |
| 27 | + out = parser.parse(text); |
| 28 | + } catch (e) { |
| 29 | + err = e; |
| 30 | + } finally { |
| 31 | + callback(out, err); |
| 32 | + } |
| 33 | + }); |
34 | 34 | } |
35 | 35 | |
36 | 36 | PegParser.prototype.initField = function(callback) { |
37 | | - var src = $('#pegparser-source'); |
38 | | - if (src.length) { |
39 | | - src.show(); |
40 | | - callback(); |
41 | | - } else { |
42 | | - var area = $('<textarea id="pegparser-source" rows=25></textarea>').insertBefore('#wpTextbox1'); |
| 37 | + var src = $('#pegparser-source'); |
| 38 | + if (src.length) { |
| 39 | + src.show(); |
| 40 | + callback(); |
| 41 | + } else { |
| 42 | + var area = $('<textarea id="pegparser-source" rows=25></textarea>').insertBefore('#wpTextbox1'); |
43 | 43 | if ( typeof parserPlaygroundPegPage !== 'undefined' ) { |
44 | 44 | $.get(wgScriptPath + '/api' + wgScriptExtension, { |
45 | 45 | format: 'json', |
— | — | @@ -60,5 +60,5 @@ |
61 | 61 | callback(); |
62 | 62 | }, 'text' ); |
63 | 63 | } |
64 | | - } |
| 64 | + } |
65 | 65 | }; |
Index: trunk/extensions/ParserPlayground/modules/ext.parserPlayground.css |
— | — | @@ -1,24 +1,24 @@ |
2 | 2 | #mw-parser-popup .parseNode, |
3 | 3 | #mw-parser-inspector .parseNode { |
4 | | - border: solid 1px transparent; |
| 4 | + border: solid 1px transparent; |
5 | 5 | } |
6 | 6 | #mw-parser-popup .parseNodeHighlight, |
7 | 7 | #mw-parser-inspector .parseNodeHighlight { |
8 | | - border: solid 1px blue; |
| 8 | + border: solid 1px blue; |
9 | 9 | } |
10 | 10 | |
11 | 11 | #mw-parser-popup .template { |
12 | | - background: #f8f8ff; |
| 12 | + background: #f8f8ff; |
13 | 13 | } |
14 | 14 | |
15 | 15 | #mw-parser-popup del, |
16 | 16 | #mw-parser-popup ins { |
17 | | - font-weight: bold; |
18 | | - color: red; |
| 17 | + font-weight: bold; |
| 18 | + color: red; |
19 | 19 | } |
20 | 20 | #mw-parser-popup del { |
21 | | - background: #FFFFAA; |
| 21 | + background: #FFFFAA; |
22 | 22 | } |
23 | 23 | #mw-parser-popup ins { |
24 | | - background: #CCFFCC; |
| 24 | + background: #CCFFCC; |
25 | 25 | } |
Index: trunk/extensions/ParserPlayground/modules/ext.parserPlayground.classicParser.js |
— | — | @@ -2,36 +2,36 @@ |
3 | 3 | var apiCache = {}; |
4 | 4 | |
5 | 5 | function callApi(params, callback) { |
6 | | - var api = wgScriptPath + '/api' + wgScriptExtension; |
7 | | - var key = JSON.stringify(params); |
8 | | - if (key in apiCallers && apiCallers[key]) { |
9 | | - apiCallers[key].push(callback); |
10 | | - } else if (key in apiCache) { |
11 | | - callback(apiCache[key] && apiCache[key]); |
12 | | - } else { |
13 | | - apiCallers[key] = [callback]; |
14 | | - $.ajax({ |
15 | | - url: api, |
16 | | - data: params, |
17 | | - type: 'POST', |
18 | | - dataType: 'json', |
19 | | - success: function(data, xhr) { |
20 | | - var callbacks = apiCallers[key]; |
21 | | - apiCallers[key] = null; |
22 | | - apiCache[key] = data; |
23 | | - $.each(callbacks, function(i, aCallback) { |
24 | | - aCallback(data); |
25 | | - }); |
26 | | - } |
27 | | - }); |
28 | | - } |
| 6 | + var api = wgScriptPath + '/api' + wgScriptExtension; |
| 7 | + var key = JSON.stringify(params); |
| 8 | + if (key in apiCallers && apiCallers[key]) { |
| 9 | + apiCallers[key].push(callback); |
| 10 | + } else if (key in apiCache) { |
| 11 | + callback(apiCache[key] && apiCache[key]); |
| 12 | + } else { |
| 13 | + apiCallers[key] = [callback]; |
| 14 | + $.ajax({ |
| 15 | + url: api, |
| 16 | + data: params, |
| 17 | + type: 'POST', |
| 18 | + dataType: 'json', |
| 19 | + success: function(data, xhr) { |
| 20 | + var callbacks = apiCallers[key]; |
| 21 | + apiCallers[key] = null; |
| 22 | + apiCache[key] = data; |
| 23 | + $.each(callbacks, function(i, aCallback) { |
| 24 | + aCallback(data); |
| 25 | + }); |
| 26 | + } |
| 27 | + }); |
| 28 | + } |
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
32 | 32 | * Stub wrapper for using MediaWiki's parser via API |
33 | 33 | */ |
34 | 34 | function MediaWikiParser(context) { |
35 | | - this.context = context; |
| 35 | + this.context = context; |
36 | 36 | } |
37 | 37 | |
38 | 38 | /** |
— | — | @@ -42,21 +42,21 @@ |
43 | 43 | * @param {function(tree, error)} callback |
44 | 44 | */ |
45 | 45 | MediaWikiParser.prototype.parseToTree = function(text, callback) { |
46 | | - callApi({ |
47 | | - action: 'expandtemplates', // not really what we want, but it'll do |
48 | | - title: wgPageName, |
49 | | - text: text, |
50 | | - generatexml: '1', |
51 | | - format: 'json' |
52 | | - }, function(data, xhr) { |
53 | | - if (typeof data.parsetree['*'] === 'string') { |
54 | | - var parser = new DOMParser(); |
55 | | - var dom = parser.parseFromString(data.parsetree['*'], 'text/xml'); |
56 | | - callback(dom.documentElement); |
57 | | - } else { |
58 | | - alert('Failed to parse!'); |
59 | | - } |
60 | | - }); |
| 46 | + callApi({ |
| 47 | + action: 'expandtemplates', // not really what we want, but it'll do |
| 48 | + title: wgPageName, |
| 49 | + text: text, |
| 50 | + generatexml: '1', |
| 51 | + format: 'json' |
| 52 | + }, function(data, xhr) { |
| 53 | + if (typeof data.parsetree['*'] === 'string') { |
| 54 | + var parser = new DOMParser(); |
| 55 | + var dom = parser.parseFromString(data.parsetree['*'], 'text/xml'); |
| 56 | + callback(dom.documentElement); |
| 57 | + } else { |
| 58 | + alert('Failed to parse!'); |
| 59 | + } |
| 60 | + }); |
61 | 61 | }; |
62 | 62 | |
63 | 63 | /** |
— | — | @@ -64,8 +64,8 @@ |
65 | 65 | * @param {function(tree, error)} callback |
66 | 66 | */ |
67 | 67 | MediaWikiParser.prototype.expandTree = function(tree, callback) { |
68 | | - // no-op! |
69 | | - callback(tree, null); |
| 68 | + // no-op! |
| 69 | + callback(tree, null); |
70 | 70 | }; |
71 | 71 | |
72 | 72 | /** |
— | — | @@ -84,27 +84,27 @@ |
85 | 85 | */ |
86 | 86 | MediaWikiParser.prototype.treeToHtml = function(tree, callback, inspectorMap) { |
87 | 87 | var self = this; |
88 | | - self.treeToSource(tree, function(src, err) { |
89 | | - if (err) { |
90 | | - return callback(src, err); |
91 | | - } |
92 | | - callApi({ |
93 | | - action: 'parse', |
94 | | - title: wgPageName, |
95 | | - text: src, |
96 | | - prop: 'text', |
97 | | - pst: 1, |
98 | | - format: 'json' |
99 | | - }, function(data, xhr) { |
100 | | - if (typeof data.parse.text['*'] === 'string') { |
101 | | - var html = data.parse.text['*']; |
102 | | - var parsed = $('<div>' + html + '</div>')[0]; |
103 | | - callback(parsed, null); |
104 | | - } else { |
105 | | - callback(null, 'Failed to parse!'); |
106 | | - } |
107 | | - }); |
108 | | - }); |
| 88 | + self.treeToSource(tree, function(src, err) { |
| 89 | + if (err) { |
| 90 | + return callback(src, err); |
| 91 | + } |
| 92 | + callApi({ |
| 93 | + action: 'parse', |
| 94 | + title: wgPageName, |
| 95 | + text: src, |
| 96 | + prop: 'text', |
| 97 | + pst: 1, |
| 98 | + format: 'json' |
| 99 | + }, function(data, xhr) { |
| 100 | + if (typeof data.parse.text['*'] === 'string') { |
| 101 | + var html = data.parse.text['*']; |
| 102 | + var parsed = $('<div>' + html + '</div>')[0]; |
| 103 | + callback(parsed, null); |
| 104 | + } else { |
| 105 | + callback(null, 'Failed to parse!'); |
| 106 | + } |
| 107 | + }); |
| 108 | + }); |
109 | 109 | }; |
110 | 110 | |
111 | 111 | |
— | — | @@ -118,74 +118,74 @@ |
119 | 119 | * @param {function(text, error)} callback |
120 | 120 | */ |
121 | 121 | MediaWikiParser.prototype.treeToSource = function(tree, callback) { |
122 | | - // I forget if this actually works, but let's pretend for now! |
123 | | - // looks like at least the heads of refs, and templates, need some more tweaking. but close :D |
124 | | - //var text = $(tree).text(); |
125 | | - //callback(text, null); |
| 122 | + // I forget if this actually works, but let's pretend for now! |
| 123 | + // looks like at least the heads of refs, and templates, need some more tweaking. but close :D |
| 124 | + //var text = $(tree).text(); |
| 125 | + //callback(text, null); |
126 | 126 | |
127 | | - var collapse, collapseList, collapseChildren; |
128 | | - collapseList = function(nodes, sep) { |
129 | | - sep = sep || ''; |
130 | | - var list = $.map(nodes, function(node, i) { |
131 | | - return collapse(node); |
132 | | - }); |
133 | | - return list.join(sep); |
134 | | - }; |
135 | | - collapseChildren = function(nodes, sep) { |
136 | | - sep = sep || ''; |
137 | | - if (nodes instanceof Node) { |
138 | | - nodes = [node]; |
139 | | - } |
140 | | - var list = $.map(nodes, function(node, i) { |
141 | | - return collapseList(node.childNodes); |
142 | | - }); |
143 | | - return list.join(sep); |
144 | | - }; |
145 | | - collapse = function(node) { |
146 | | - // Based loosely on PPFrame_DOM::expand() in RECOVER_ORIG mode |
147 | | - var name = node.nodeName || 'string'; |
148 | | - var out, list; |
149 | | - if (typeof node === 'string') { |
150 | | - out = node; |
151 | | - } else if (node.nodeType === Node.TEXT_NODE) { |
152 | | - out = node.textContent; |
153 | | - } else if (name === 'root') { |
154 | | - out = collapseList(node.childNodes); |
155 | | - } else if (name === 'template') { |
156 | | - out = '{{' + collapseChildren($(node).children('title,part'), '|') + '}}'; |
157 | | - } else if (name === 'tplarg') { |
158 | | - out = '{{{' + collapseChildren($(node).children('title,part'), '|') + '}}}'; |
159 | | - } else if (name === 'name') { // temp hack |
160 | | - out = collapseList(node.childNodes); |
161 | | - } else if (name === 'value') { // temp hack |
162 | | - out = collapseList(node.childNodes); |
163 | | - } else if (name === 'comment') { |
164 | | - // Recover the literal comment |
165 | | - out = collapseList(node.childNodes); |
166 | | - } else if (name === 'ignore') { |
167 | | - out = collapseList(node.childNodes); |
168 | | - } else if (name === 'ext') { |
169 | | - var close = $(node).children('close'); |
170 | | - out = '<' + |
171 | | - collapseChildren($(node).children('name,attr')) + |
172 | | - (close.length ? '>' : '/>')+ |
173 | | - collapseChildren($(node).children('inner')) + |
174 | | - collapseChildren(close); |
175 | | - } else if (name === 'h') { |
176 | | - out = $(node).text(); |
177 | | - } else { |
178 | | - console.log('unrecognized node during expansion', node); |
179 | | - out = ''; |
180 | | - } |
181 | | - //console.log(name, node, '->', out); |
182 | | - return out; |
183 | | - }; |
184 | | - try { |
185 | | - var err = null; |
186 | | - var src = collapse(tree); |
187 | | - } catch (e) { |
188 | | - err = e; |
189 | | - } finally { |
190 | | - callback(src, err); |
191 | | - } |
| 127 | + var collapse, collapseList, collapseChildren; |
| 128 | + collapseList = function(nodes, sep) { |
| 129 | + sep = sep || ''; |
| 130 | + var list = $.map(nodes, function(node, i) { |
| 131 | + return collapse(node); |
| 132 | + }); |
| 133 | + return list.join(sep); |
| 134 | + }; |
| 135 | + collapseChildren = function(nodes, sep) { |
| 136 | + sep = sep || ''; |
| 137 | + if (nodes instanceof Node) { |
| 138 | + nodes = [node]; |
| 139 | + } |
| 140 | + var list = $.map(nodes, function(node, i) { |
| 141 | + return collapseList(node.childNodes); |
| 142 | + }); |
| 143 | + return list.join(sep); |
| 144 | + }; |
| 145 | + collapse = function(node) { |
| 146 | + // Based loosely on PPFrame_DOM::expand() in RECOVER_ORIG mode |
| 147 | + var name = node.nodeName || 'string'; |
| 148 | + var out, list; |
| 149 | + if (typeof node === 'string') { |
| 150 | + out = node; |
| 151 | + } else if (node.nodeType === Node.TEXT_NODE) { |
| 152 | + out = node.textContent; |
| 153 | + } else if (name === 'root') { |
| 154 | + out = collapseList(node.childNodes); |
| 155 | + } else if (name === 'template') { |
| 156 | + out = '{{' + collapseChildren($(node).children('title,part'), '|') + '}}'; |
| 157 | + } else if (name === 'tplarg') { |
| 158 | + out = '{{{' + collapseChildren($(node).children('title,part'), '|') + '}}}'; |
| 159 | + } else if (name === 'name') { // temp hack |
| 160 | + out = collapseList(node.childNodes); |
| 161 | + } else if (name === 'value') { // temp hack |
| 162 | + out = collapseList(node.childNodes); |
| 163 | + } else if (name === 'comment') { |
| 164 | + // Recover the literal comment |
| 165 | + out = collapseList(node.childNodes); |
| 166 | + } else if (name === 'ignore') { |
| 167 | + out = collapseList(node.childNodes); |
| 168 | + } else if (name === 'ext') { |
| 169 | + var close = $(node).children('close'); |
| 170 | + out = '<' + |
| 171 | + collapseChildren($(node).children('name,attr')) + |
| 172 | + (close.length ? '>' : '/>')+ |
| 173 | + collapseChildren($(node).children('inner')) + |
| 174 | + collapseChildren(close); |
| 175 | + } else if (name === 'h') { |
| 176 | + out = $(node).text(); |
| 177 | + } else { |
| 178 | + console.log('unrecognized node during expansion', node); |
| 179 | + out = ''; |
| 180 | + } |
| 181 | + //console.log(name, node, '->', out); |
| 182 | + return out; |
| 183 | + }; |
| 184 | + try { |
| 185 | + var err = null; |
| 186 | + var src = collapse(tree); |
| 187 | + } catch (e) { |
| 188 | + err = e; |
| 189 | + } finally { |
| 190 | + callback(src, err); |
| 191 | + } |
192 | 192 | }; |
Index: trunk/extensions/ParserPlayground/modules/ext.parserPlayground.hashMap.js |
— | — | @@ -9,8 +9,8 @@ |
10 | 10 | * Used to map parse tree nodes to output nodes for the inspector mode. |
11 | 11 | */ |
12 | 12 | function HashMap() { |
13 | | - this.keyBuckets = {}; |
14 | | - this.valBuckets = {}; |
| 13 | + this.keyBuckets = {}; |
| 14 | + this.valBuckets = {}; |
15 | 15 | } |
16 | 16 | |
17 | 17 | /** |
— | — | @@ -18,17 +18,17 @@ |
19 | 19 | * @return {object} original object, or null if no match found. |
20 | 20 | */ |
21 | 21 | HashMap.prototype.get = function(keyObj) { |
22 | | - var key = this.hash(keyObj); |
23 | | - if (typeof this.keyBuckets[key] !== 'undefined') { |
24 | | - var keys = this.keyBuckets[key], |
25 | | - max = keys.length; |
26 | | - for (var i = 0; i < max; i++) { |
27 | | - if (keyObj === keys[i]) { |
28 | | - return this.valBuckets[key][i]; |
29 | | - } |
30 | | - } |
31 | | - } |
32 | | - return null; |
| 22 | + var key = this.hash(keyObj); |
| 23 | + if (typeof this.keyBuckets[key] !== 'undefined') { |
| 24 | + var keys = this.keyBuckets[key], |
| 25 | + max = keys.length; |
| 26 | + for (var i = 0; i < max; i++) { |
| 27 | + if (keyObj === keys[i]) { |
| 28 | + return this.valBuckets[key][i]; |
| 29 | + } |
| 30 | + } |
| 31 | + } |
| 32 | + return null; |
33 | 33 | }; |
34 | 34 | |
35 | 35 | /** |
— | — | @@ -36,18 +36,18 @@ |
37 | 37 | * @param {object} val |
38 | 38 | */ |
39 | 39 | HashMap.prototype.put = function(keyObj, val) { |
40 | | - var key = this.hash(keyObj); |
41 | | - if (typeof this.keyBuckets[key] === 'undefined') { |
42 | | - this.keyBuckets[key] = []; |
43 | | - this.valBuckets[key] = []; |
44 | | - } |
45 | | - this.keyBuckets[key].push(keyObj); |
46 | | - this.valBuckets[key].push(val); |
| 40 | + var key = this.hash(keyObj); |
| 41 | + if (typeof this.keyBuckets[key] === 'undefined') { |
| 42 | + this.keyBuckets[key] = []; |
| 43 | + this.valBuckets[key] = []; |
| 44 | + } |
| 45 | + this.keyBuckets[key].push(keyObj); |
| 46 | + this.valBuckets[key].push(val); |
47 | 47 | }; |
48 | 48 | |
49 | 49 | /** |
50 | 50 | * This will do for us for now. :) |
51 | 51 | */ |
52 | 52 | HashMap.prototype.hash = function(keyObj) { |
53 | | - return JSON.stringify(keyObj).substr(0, 40); |
| 53 | + return JSON.stringify(keyObj).substr(0, 40); |
54 | 54 | }; |
Index: trunk/extensions/ParserPlayground/modules/ext.parserPlayground.js |
— | — | @@ -23,33 +23,33 @@ |
24 | 24 | |
25 | 25 | var onResize = null; |
26 | 26 | $(window).resize(function() { |
27 | | - if (onResize) { |
28 | | - onResize(); |
29 | | - } |
| 27 | + if (onResize) { |
| 28 | + onResize(); |
| 29 | + } |
30 | 30 | }); |
31 | 31 | $('.mw-pp-node').live('click', function() { |
32 | | - var ul = $(this.parentNode).find('ul:first'); |
33 | | - if (ul.is(":hidden")) { |
34 | | - ul.slideDown(); |
35 | | - } else { |
36 | | - ul.slideUp(); |
37 | | - } |
| 32 | + var ul = $(this.parentNode).find('ul:first'); |
| 33 | + if (ul.is(":hidden")) { |
| 34 | + ul.slideDown(); |
| 35 | + } else { |
| 36 | + ul.slideUp(); |
| 37 | + } |
38 | 38 | }); |
39 | 39 | |
40 | 40 | var makeMagicBox = function(inside) { |
41 | | - $('#mw-parser-popup').remove(); |
42 | | - // line-height is needed to compensate for oddity in WikiEditor extension, which zeroes the line-height on a parent container |
43 | | - var box = $('#wpTextbox1'); |
44 | | - var target = $('<div id="mw-parser-popup" style="width: 100%; overflow-y: auto; background: white"><div class="editor" style="line-height: 1.5em; top: 0px; left: 0px; right: 0px; bottom: 0px; border: 1px solid gray">' + inside + '</div></div>').insertAfter(box); |
45 | | - $('#wpTextbox1').css('display', 'none'); |
| 41 | + $('#mw-parser-popup').remove(); |
| 42 | + // line-height is needed to compensate for oddity in WikiEditor extension, which zeroes the line-height on a parent container |
| 43 | + var box = $('#wpTextbox1'); |
| 44 | + var target = $('<div id="mw-parser-popup" style="width: 100%; overflow-y: auto; background: white"><div class="editor" style="line-height: 1.5em; top: 0px; left: 0px; right: 0px; bottom: 0px; border: 1px solid gray">' + inside + '</div></div>').insertAfter(box); |
| 45 | + $('#wpTextbox1').css('display', 'none'); |
46 | 46 | |
47 | | - onResize = function() { |
48 | | - //target.width(box.width()) |
49 | | - // .height(box.height()); |
50 | | - target.height(box.height()); |
51 | | - }; |
52 | | - onResize(); |
53 | | - return target; |
| 47 | + onResize = function() { |
| 48 | + //target.width(box.width()) |
| 49 | + // .height(box.height()); |
| 50 | + target.height(box.height()); |
| 51 | + }; |
| 52 | + onResize(); |
| 53 | + return target; |
54 | 54 | }; |
55 | 55 | |
56 | 56 | /** |
— | — | @@ -58,17 +58,17 @@ |
59 | 59 | * @return {jQuery} |
60 | 60 | */ |
61 | 61 | var makeInspectorColumns = function(dest) { |
62 | | - var h = $('#wpTextbox1').height(); // hack |
63 | | - var target = $( |
64 | | - '<table style="width: 100%; height: ' + h + 'px">' + |
65 | | - '<tr>' + |
66 | | - '<td width="50%"><div class="left" style="overflow:auto; ' + |
67 | | - 'height: ' + h + 'px"></div></td>' + |
68 | | - '<td width="50%"><div class="right" style="overflow:auto; ' + |
69 | | - 'height: ' + h + 'px"></div></td>' + |
70 | | - '</tr>' + |
71 | | - '</table>').appendTo(dest); |
72 | | - return target; |
| 62 | + var h = $('#wpTextbox1').height(); // hack |
| 63 | + var target = $( |
| 64 | + '<table style="width: 100%; height: ' + h + 'px">' + |
| 65 | + '<tr>' + |
| 66 | + '<td width="50%"><div class="left" style="overflow:auto; ' + |
| 67 | + 'height: ' + h + 'px"></div></td>' + |
| 68 | + '<td width="50%"><div class="right" style="overflow:auto; ' + |
| 69 | + 'height: ' + h + 'px"></div></td>' + |
| 70 | + '</tr>' + |
| 71 | + '</table>').appendTo(dest); |
| 72 | + return target; |
73 | 73 | }; |
74 | 74 | |
75 | 75 | /** |
— | — | @@ -79,27 +79,27 @@ |
80 | 80 | * @param {jQUery} right |
81 | 81 | */ |
82 | 82 | var setupInspector = function(left, right, leftMap, rightMap) { |
83 | | - var makeMagic = function(a, b, inspectorMap) { |
84 | | - var match = function(aNode, callback) { |
85 | | - var treeNode = $(aNode).data('parseNode'); |
86 | | - var bNode = treeNode && inspectorMap.get(treeNode); |
87 | | - callback(aNode, bNode); |
88 | | - }; |
89 | | - a.delegate('.parseNode', 'mouseenter', function(event) { |
| 83 | + var makeMagic = function(a, b, inspectorMap) { |
| 84 | + var match = function(aNode, callback) { |
| 85 | + var treeNode = $(aNode).data('parseNode'); |
| 86 | + var bNode = treeNode && inspectorMap.get(treeNode); |
| 87 | + callback(aNode, bNode); |
| 88 | + }; |
| 89 | + a.delegate('.parseNode', 'mouseenter', function(event) { |
90 | 90 | $('.parseNodeHighlight').removeClass('parseNodeHighlight'); |
91 | | - match(this, function(node, other) { |
92 | | - $(node).addClass('parseNodeHighlight'); |
93 | | - $(other).addClass('parseNodeHighlight'); |
94 | | - }); |
| 91 | + match(this, function(node, other) { |
| 92 | + $(node).addClass('parseNodeHighlight'); |
| 93 | + $(other).addClass('parseNodeHighlight'); |
| 94 | + }); |
95 | 95 | event.preventDefault(); |
96 | 96 | return false; |
97 | | - }).delegate('.parseNode', 'mouseleave', function(event) { |
| 97 | + }).delegate('.parseNode', 'mouseleave', function(event) { |
98 | 98 | $('.parseNodeHighlight').removeClass('parseNodeHighlight'); |
99 | 99 | event.preventDefault(); |
100 | 100 | return false; |
101 | | - }).delegate('.parseNode', 'click', function(event) { |
102 | | - match(this, function(node, other) { |
103 | | - if (other) { |
| 101 | + }).delegate('.parseNode', 'click', function(event) { |
| 102 | + match(this, function(node, other) { |
| 103 | + if (other) { |
104 | 104 | // try to scroll the other into view. how... feasible is this? :DD |
105 | 105 | var visibleStart = b.scrollTop(); |
106 | 106 | var visibleEnd = visibleStart + b.height(); |
— | — | @@ -112,12 +112,12 @@ |
113 | 113 | } |
114 | 114 | event.preventDefault(); |
115 | 115 | return false; |
116 | | - } |
117 | | - }); |
118 | | - }); |
119 | | - }; |
120 | | - makeMagic(left, right, rightMap); |
121 | | - makeMagic(right, left, leftMap); |
| 116 | + } |
| 117 | + }); |
| 118 | + }); |
| 119 | + }; |
| 120 | + makeMagic(left, right, rightMap); |
| 121 | + makeMagic(right, left, leftMap); |
122 | 122 | }; |
123 | 123 | |
124 | 124 | var addParserModes = function(modes, parserClass, className, detail) { |
— | — | @@ -134,11 +134,11 @@ |
135 | 135 | }; |
136 | 136 | |
137 | 137 | $(document).ready( function() { |
138 | | - /* Start trying to add items... */ |
139 | | - var editor = $('#wpTextbox1'); |
140 | | - if (editor.length > 0 && typeof $.fn.wikiEditor === 'function') { |
141 | | - //$('#wpTextbox1').bind('wikiEditor-toolbar-buildSection-main', function() { |
142 | | - var listItems = { |
| 138 | + /* Start trying to add items... */ |
| 139 | + var editor = $('#wpTextbox1'); |
| 140 | + if (editor.length > 0 && typeof $.fn.wikiEditor === 'function') { |
| 141 | + //$('#wpTextbox1').bind('wikiEditor-toolbar-buildSection-main', function() { |
| 142 | + var listItems = { |
143 | 143 | 'sourceView': { |
144 | 144 | 'label': 'Source', |
145 | 145 | 'action': { |
— | — | @@ -150,12 +150,12 @@ |
151 | 151 | } |
152 | 152 | } |
153 | 153 | } |
154 | | - }; |
155 | | - addParserModes(listItems, MediaWikiParser, 'MediaWikiParser'); |
156 | | - addParserModes(listItems, FakeParser, 'FakeParser'); |
157 | | - addParserModes(listItems, PegParser, 'PegParser', '<p>Peg-based parser plus FakeParser\'s output. <a href="http://pegjs.majda.cz/documentation">pegjs documentation</a>; edit and reselect to reparse with updated parser</p>'); |
| 154 | + }; |
| 155 | + addParserModes(listItems, MediaWikiParser, 'MediaWikiParser'); |
| 156 | + addParserModes(listItems, FakeParser, 'FakeParser'); |
| 157 | + addParserModes(listItems, PegParser, 'PegParser', '<p>Peg-based parser plus FakeParser\'s output. <a href="http://pegjs.majda.cz/documentation">pegjs documentation</a>; edit and reselect to reparse with updated parser</p>'); |
158 | 158 | |
159 | | - window.setTimeout(function() { |
| 159 | + window.setTimeout(function() { |
160 | 160 | var context = editor.data('wikiEditor-context'); |
161 | 161 | context.parserPlayground = { |
162 | 162 | parser: new FakeParser(), |
— | — | @@ -166,7 +166,7 @@ |
167 | 167 | if (context.$parserContainer) { |
168 | 168 | context.parserPlayground.fn.hide(); |
169 | 169 | } |
170 | | - var $target = makeMagicBox(''); |
| 170 | + var $target = makeMagicBox(''); |
171 | 171 | $('#mw-parser-inspector').remove(); |
172 | 172 | var $inspector = $('<div id="mw-parser-inspector" style="position: relative; width: 100%; overflow-y: auto; height: 200px"></div>'); |
173 | 173 | $inspector.insertAfter($target); |
— | — | @@ -177,12 +177,12 @@ |
178 | 178 | context.$parserContainer = $target; |
179 | 179 | context.$parserInspector = $inspector; |
180 | 180 | |
181 | | - var src = $('#wpTextbox1').val(); |
182 | | - var $dest = $target.find('div'); |
| 181 | + var src = $('#wpTextbox1').val(); |
| 182 | + var $dest = $target.find('div'); |
183 | 183 | |
184 | 184 | var parser = context.parserPlayground.parser; |
185 | 185 | var treeMap = context.parserPlayground.treeMap = new HashMap(), |
186 | | - renderMap = new HashMap(); |
| 186 | + renderMap = new HashMap(); |
187 | 187 | parser.parseToTree(src, function(tree, err) { |
188 | 188 | context.parserPlayground.tree = tree; |
189 | 189 | if (context.parserPlayground.useInspector) { |
— | — | @@ -193,12 +193,12 @@ |
194 | 194 | parser.treeToHtml(tree, function(node, err) { |
195 | 195 | $dest.append(node); |
196 | 196 | context.parserPlayground.fn.setupEditor($target); |
197 | | - setupInspector($target, $inspector, renderMap, treeMap); |
| 197 | + setupInspector($target, $inspector, renderMap, treeMap); |
198 | 198 | }, renderMap); |
199 | 199 | }); |
200 | 200 | }, |
201 | 201 | hide: function() { |
202 | | - $('#pegparser-source').hide(); // it'll reshow; others won't need it |
| 202 | + $('#pegparser-source').hide(); // it'll reshow; others won't need it |
203 | 203 | context.$iframe = undefined; |
204 | 204 | context.$parserContainer.remove(); |
205 | 205 | context.$parserContainer = undefined; |
— | — | @@ -273,10 +273,10 @@ |
274 | 274 | } |
275 | 275 | } |
276 | 276 | } ); |
277 | | - }, 500 ); |
278 | | - } else { |
279 | | - mw.log('No wiki editor'); |
280 | | - } |
| 277 | + }, 500 ); |
| 278 | + } else { |
| 279 | + mw.log('No wiki editor'); |
| 280 | + } |
281 | 281 | }); |
282 | 282 | |
283 | 283 | })(jQuery); |
Index: trunk/extensions/ParserPlayground/modules/ext.parserPlayground.fakeParser.js |
— | — | @@ -2,8 +2,8 @@ |
3 | 3 | * @param {ParserContext} context |
4 | 4 | */ |
5 | 5 | function FakeParser(context) { |
6 | | - // whee |
7 | | - this.context = context || {}; |
| 6 | + // whee |
| 7 | + this.context = context || {}; |
8 | 8 | } |
9 | 9 | |
10 | 10 | /** |
— | — | @@ -11,115 +11,115 @@ |
12 | 12 | * @param {function(tree, error)} callback |
13 | 13 | */ |
14 | 14 | FakeParser.prototype.parseToTree = function(text, callback) { |
15 | | - // quick and crappy :D |
16 | | - var lines = text.split("\n"); |
| 15 | + // quick and crappy :D |
| 16 | + var lines = text.split("\n"); |
17 | 17 | var blocks = []; |
18 | | - var matches; |
19 | | - /** |
20 | | - * Subparse of inline links within a paragraph etc. |
21 | | - * @param {string} line |
22 | | - * @return {object[]} list of content subblocks |
23 | | - */ |
24 | | - var linksParse = function(line) { |
25 | | - var bits = line.split('[['), |
26 | | - parts = []; |
27 | | - if (bits[0] != '') { |
28 | | - parts.push({ |
29 | | - type: 'text', |
30 | | - text: bits[0] |
31 | | - }); |
32 | | - } |
33 | | - for (var i = 1; i < bits.length; i++) { |
34 | | - var bit = bits[i]; |
35 | | - var bracketPos = bit.indexOf(']]'); |
36 | | - if (bracketPos === -1) { |
37 | | - // not a link oh noooooo |
38 | | - parts.push({ |
39 | | - type: 'text', |
40 | | - text: '[[' + bit |
41 | | - }); |
42 | | - } else { |
43 | | - var link = bit.substr(0, bracketPos); |
44 | | - var tail = bit.substr(bracketPos + 2); |
45 | | - var linkbits = link.split('|'); |
46 | | - if (linkbits.length == 1) { |
47 | | - parts.push({ |
48 | | - type: 'link', |
49 | | - target: link |
50 | | - }); |
51 | | - } else { |
52 | | - parts.push({ |
53 | | - type: 'link', |
54 | | - target: linkbits[0], |
55 | | - text: linkbits.slice(1).join('|') // @fixme multiples for images etc |
56 | | - }); |
57 | | - } |
58 | | - if (tail !== '') { |
59 | | - parts.push({ |
60 | | - type: 'text', |
61 | | - text: tail |
62 | | - }); |
63 | | - } |
64 | | - } |
65 | | - } |
66 | | - return parts; |
67 | | - }; |
68 | | - /** |
69 | | - * Subparse of all inline stuff within a paragraph etc. |
70 | | - * @param {string} line |
71 | | - * @return {object[]} list of content subblocks |
72 | | - */ |
73 | | - var inlineParse = function(line) { |
74 | | - var parts = []; |
75 | | - var bits = line.split('<ref'); |
76 | | - var re = /^([^>]*)>(.*)<\/ref\s*>(.*)/; |
77 | | - var re2 = /^([^>]*)\/>(.*)/; |
78 | | - if (bits[0] != '') { |
79 | | - // text before... |
80 | | - $.merge(parts, linksParse(bits[0])); |
81 | | - } |
82 | | - $.each(bits.slice(1), function(i, bit) { |
83 | | - var matches; |
84 | | - var after; |
85 | | - if ((matches = re.exec(bit)) != null) { |
86 | | - var params = matches[1], text = matches[2]; |
87 | | - after = matches[3]; |
88 | | - parts.push({ |
89 | | - type: 'ext', |
90 | | - name: 'ref', |
91 | | - params: params, |
92 | | - content: (text == '') ? [] : linksParse(text) |
93 | | - }); |
94 | | - } else if ((matches = re2.exec(bit)) != null) { |
95 | | - var params = matches[1]; |
96 | | - after = matches[2]; |
97 | | - parts.push({ |
98 | | - type: 'ext', |
99 | | - name: 'ref', |
100 | | - params: params |
101 | | - }); |
102 | | - } else { |
103 | | - after = '<ref' + bit; |
104 | | - } |
105 | | - if (after != '') { |
106 | | - $.merge(parts, linksParse(after)); |
107 | | - } |
108 | | - }); |
109 | | - return parts; |
110 | | - }; |
| 18 | + var matches; |
| 19 | + /** |
| 20 | + * Subparse of inline links within a paragraph etc. |
| 21 | + * @param {string} line |
| 22 | + * @return {object[]} list of content subblocks |
| 23 | + */ |
| 24 | + var linksParse = function(line) { |
| 25 | + var bits = line.split('[['), |
| 26 | + parts = []; |
| 27 | + if (bits[0] != '') { |
| 28 | + parts.push({ |
| 29 | + type: 'text', |
| 30 | + text: bits[0] |
| 31 | + }); |
| 32 | + } |
| 33 | + for (var i = 1; i < bits.length; i++) { |
| 34 | + var bit = bits[i]; |
| 35 | + var bracketPos = bit.indexOf(']]'); |
| 36 | + if (bracketPos === -1) { |
| 37 | + // not a link oh noooooo |
| 38 | + parts.push({ |
| 39 | + type: 'text', |
| 40 | + text: '[[' + bit |
| 41 | + }); |
| 42 | + } else { |
| 43 | + var link = bit.substr(0, bracketPos); |
| 44 | + var tail = bit.substr(bracketPos + 2); |
| 45 | + var linkbits = link.split('|'); |
| 46 | + if (linkbits.length == 1) { |
| 47 | + parts.push({ |
| 48 | + type: 'link', |
| 49 | + target: link |
| 50 | + }); |
| 51 | + } else { |
| 52 | + parts.push({ |
| 53 | + type: 'link', |
| 54 | + target: linkbits[0], |
| 55 | + text: linkbits.slice(1).join('|') // @fixme multiples for images etc |
| 56 | + }); |
| 57 | + } |
| 58 | + if (tail !== '') { |
| 59 | + parts.push({ |
| 60 | + type: 'text', |
| 61 | + text: tail |
| 62 | + }); |
| 63 | + } |
| 64 | + } |
| 65 | + } |
| 66 | + return parts; |
| 67 | + }; |
| 68 | + /** |
| 69 | + * Subparse of all inline stuff within a paragraph etc. |
| 70 | + * @param {string} line |
| 71 | + * @return {object[]} list of content subblocks |
| 72 | + */ |
| 73 | + var inlineParse = function(line) { |
| 74 | + var parts = []; |
| 75 | + var bits = line.split('<ref'); |
| 76 | + var re = /^([^>]*)>(.*)<\/ref\s*>(.*)/; |
| 77 | + var re2 = /^([^>]*)\/>(.*)/; |
| 78 | + if (bits[0] != '') { |
| 79 | + // text before... |
| 80 | + $.merge(parts, linksParse(bits[0])); |
| 81 | + } |
| 82 | + $.each(bits.slice(1), function(i, bit) { |
| 83 | + var matches; |
| 84 | + var after; |
| 85 | + if ((matches = re.exec(bit)) != null) { |
| 86 | + var params = matches[1], text = matches[2]; |
| 87 | + after = matches[3]; |
| 88 | + parts.push({ |
| 89 | + type: 'ext', |
| 90 | + name: 'ref', |
| 91 | + params: params, |
| 92 | + content: (text == '') ? [] : linksParse(text) |
| 93 | + }); |
| 94 | + } else if ((matches = re2.exec(bit)) != null) { |
| 95 | + var params = matches[1]; |
| 96 | + after = matches[2]; |
| 97 | + parts.push({ |
| 98 | + type: 'ext', |
| 99 | + name: 'ref', |
| 100 | + params: params |
| 101 | + }); |
| 102 | + } else { |
| 103 | + after = '<ref' + bit; |
| 104 | + } |
| 105 | + if (after != '') { |
| 106 | + $.merge(parts, linksParse(after)); |
| 107 | + } |
| 108 | + }); |
| 109 | + return parts; |
| 110 | + }; |
111 | 111 | $.each(lines, function(i, line) { |
112 | 112 | if (line == '') { |
113 | 113 | blocks.push({ |
114 | 114 | type: 'break' |
115 | 115 | }); |
116 | 116 | } else if (matches = /^(={1,6})(.*)\1$/.exec(line)) { |
117 | | - blocks.push({ |
118 | | - type: 'h', |
119 | | - level: matches[1].length, |
120 | | - text: matches[2] |
121 | | - }); |
| 117 | + blocks.push({ |
| 118 | + type: 'h', |
| 119 | + level: matches[1].length, |
| 120 | + text: matches[2] |
| 121 | + }); |
122 | 122 | } else { |
123 | | - var parts = inlineParse(line); |
| 123 | + var parts = inlineParse(line); |
124 | 124 | blocks.push({ |
125 | 125 | type: 'para', |
126 | 126 | content: parts |
— | — | @@ -149,7 +149,7 @@ |
150 | 150 | */ |
151 | 151 | FakeParser.prototype.treeToHtml = function(tree, callback, inspectorMap) { |
152 | 152 | var self = this; |
153 | | - var subParseArray = function(listOfTrees, node) { |
| 153 | + var subParseArray = function(listOfTrees, node) { |
154 | 154 | $.each(listOfTrees, function(i, subtree) { |
155 | 155 | self.treeToHtml(subtree, function(subnode, err) { |
156 | 156 | if (subnode) { |
— | — | @@ -157,129 +157,129 @@ |
158 | 158 | } |
159 | 159 | }, inspectorMap); |
160 | 160 | }); |
161 | | - }; |
| 161 | + }; |
162 | 162 | var node; |
163 | 163 | switch (tree.type) { |
164 | 164 | case 'page': |
165 | 165 | // A sequence of block-level elements... |
166 | 166 | var page = $('<div class="parseNode"></div>'); |
167 | | - subParseArray(tree.content, page); |
168 | | - if (self.context.refs) { |
169 | | - // We're at the end; drop all the remaining refs! |
170 | | - subParseArray([{ |
171 | | - type: 'ext', |
172 | | - name: 'references' |
173 | | - }], page); |
174 | | - } |
175 | | - node = page[0]; |
| 167 | + subParseArray(tree.content, page); |
| 168 | + if (self.context.refs) { |
| 169 | + // We're at the end; drop all the remaining refs! |
| 170 | + subParseArray([{ |
| 171 | + type: 'ext', |
| 172 | + name: 'references' |
| 173 | + }], page); |
| 174 | + } |
| 175 | + node = page[0]; |
176 | 176 | break; |
177 | 177 | case 'para': |
178 | 178 | // A single-line paragraph. |
179 | 179 | var para = $('<p class="parseNode"></p>'); |
180 | | - subParseArray(tree.content, para); |
181 | | - node = para[0]; |
| 180 | + subParseArray(tree.content, para); |
| 181 | + node = para[0]; |
182 | 182 | break; |
183 | 183 | case 'break': |
184 | 184 | // Just a stub in the parse tree. |
185 | 185 | break; |
186 | | - case 'text': |
187 | | - // hack hack |
188 | | - node = document.createTextNode(tree.text); |
189 | | - break; |
190 | | - case 'link': |
191 | | - var link = $('<a class="parseNode"></a>'); |
192 | | - link.text(tree.text || tree.target); |
193 | | - link.attr('href', '/wiki/' + tree.target); // hack |
194 | | - node = link[0]; |
195 | | - break; |
196 | | - case 'extlink': |
197 | | - var link = $('<a class="parseNode"></a>'); |
198 | | - link.text(tree.text || tree.target); // fixme? #d links, freelinks etc |
199 | | - link.attr('href', tree.target); // hack: validate etc |
200 | | - node = link[0]; |
201 | | - break; |
202 | | - case 'h': |
203 | | - var h = $('<h' + tree.level + ' class="parseNode"></h' + tree.level + '>').text(tree.text); |
204 | | - node = h[0]; |
205 | | - break; |
206 | | - case 'i': |
207 | | - var h = $('<i class="parseNode"></i>').text(tree.text); // hack -- use contents[] |
208 | | - node = h[0]; |
209 | | - break; |
210 | | - case 'template': |
211 | | - var t = $('<span class="parseNode template"></span>').text('{{' + tree.target); |
212 | | - if ('params' in tree) { |
213 | | - $.each(tree.params, function(i, param) { |
214 | | - var str = param.contents; |
215 | | - if ('name' in param) { |
216 | | - str = param.name + '=' + str; |
217 | | - } |
218 | | - var p = $('<span></span>').text('|' + str); |
219 | | - t.append(p); |
220 | | - }); |
221 | | - } |
222 | | - t.append('}}'); |
223 | | - node = t[0]; |
224 | | - break; |
225 | | - case 'ext': |
226 | | - if (tree.name == 'ref') { |
227 | | - // Save the reference for later! |
228 | | - // @fixme names etc? |
229 | | - if (self.context.refs === undefined) { |
230 | | - self.context.refs = []; |
231 | | - } |
232 | | - self.context.refs.push(tree); |
233 | | - var refNum = self.context.refs.length; |
234 | | - var ref = $('<span class="ref parseNode">[</span>'); |
235 | | - $('<a></a>') |
236 | | - .text(refNum + '') |
237 | | - .attr('src', '#ref-' + refNum) |
238 | | - .appendTo(ref); |
239 | | - ref.append(']'); |
240 | | - node = ref[0]; |
241 | | - } else if (tree.name == 'references') { |
242 | | - // Force inline expansion of references with a given group |
243 | | - // @fixme support multiple groups etc |
244 | | - var references = $('<ol class="references parseNode"></ol>'); |
245 | | - var oldRefs = self.context.refs; |
246 | | - self.context.refs = []; |
247 | | - $.each(oldRefs, function(i, subtree) { |
248 | | - var ref = $('<li class="ref parseNode" id="ref-' + i + '"></li>'); |
249 | | - if ('content' in subtree) { |
250 | | - subParseArray(subtree.content, ref); |
251 | | - } |
252 | | - references.append(ref); |
253 | | - }); |
254 | | - node = references[0]; |
255 | | - } else if (tree.name == 'cite') { |
256 | | - // Kinda like a ref but inline. |
257 | | - // @fixme validate and output the tag parameters |
258 | | - var cite = $('<span class="cite parseNode"></span>'); |
259 | | - if ('content' in tree) { |
260 | | - subParseArray(tree.content, cite); |
261 | | - } |
262 | | - node = cite[0]; |
263 | | - } else { |
264 | | - // @fixme unrecognized exts should output as text + rendered contents? |
265 | | - callback(null, 'Unrecognized extension in parse tree'); |
266 | | - return; |
267 | | - } |
268 | | - break; |
| 186 | + case 'text': |
| 187 | + // hack hack |
| 188 | + node = document.createTextNode(tree.text); |
| 189 | + break; |
| 190 | + case 'link': |
| 191 | + var link = $('<a class="parseNode"></a>'); |
| 192 | + link.text(tree.text || tree.target); |
| 193 | + link.attr('href', '/wiki/' + tree.target); // hack |
| 194 | + node = link[0]; |
| 195 | + break; |
| 196 | + case 'extlink': |
| 197 | + var link = $('<a class="parseNode"></a>'); |
| 198 | + link.text(tree.text || tree.target); // fixme? #d links, freelinks etc |
| 199 | + link.attr('href', tree.target); // hack: validate etc |
| 200 | + node = link[0]; |
| 201 | + break; |
| 202 | + case 'h': |
| 203 | + var h = $('<h' + tree.level + ' class="parseNode"></h' + tree.level + '>').text(tree.text); |
| 204 | + node = h[0]; |
| 205 | + break; |
| 206 | + case 'i': |
| 207 | + var h = $('<i class="parseNode"></i>').text(tree.text); // hack -- use contents[] |
| 208 | + node = h[0]; |
| 209 | + break; |
| 210 | + case 'template': |
| 211 | + var t = $('<span class="parseNode template"></span>').text('{{' + tree.target); |
| 212 | + if ('params' in tree) { |
| 213 | + $.each(tree.params, function(i, param) { |
| 214 | + var str = param.contents; |
| 215 | + if ('name' in param) { |
| 216 | + str = param.name + '=' + str; |
| 217 | + } |
| 218 | + var p = $('<span></span>').text('|' + str); |
| 219 | + t.append(p); |
| 220 | + }); |
| 221 | + } |
| 222 | + t.append('}}'); |
| 223 | + node = t[0]; |
| 224 | + break; |
| 225 | + case 'ext': |
| 226 | + if (tree.name == 'ref') { |
| 227 | + // Save the reference for later! |
| 228 | + // @fixme names etc? |
| 229 | + if (self.context.refs === undefined) { |
| 230 | + self.context.refs = []; |
| 231 | + } |
| 232 | + self.context.refs.push(tree); |
| 233 | + var refNum = self.context.refs.length; |
| 234 | + var ref = $('<span class="ref parseNode">[</span>'); |
| 235 | + $('<a></a>') |
| 236 | + .text(refNum + '') |
| 237 | + .attr('src', '#ref-' + refNum) |
| 238 | + .appendTo(ref); |
| 239 | + ref.append(']'); |
| 240 | + node = ref[0]; |
| 241 | + } else if (tree.name == 'references') { |
| 242 | + // Force inline expansion of references with a given group |
| 243 | + // @fixme support multiple groups etc |
| 244 | + var references = $('<ol class="references parseNode"></ol>'); |
| 245 | + var oldRefs = self.context.refs; |
| 246 | + self.context.refs = []; |
| 247 | + $.each(oldRefs, function(i, subtree) { |
| 248 | + var ref = $('<li class="ref parseNode" id="ref-' + i + '"></li>'); |
| 249 | + if ('content' in subtree) { |
| 250 | + subParseArray(subtree.content, ref); |
| 251 | + } |
| 252 | + references.append(ref); |
| 253 | + }); |
| 254 | + node = references[0]; |
| 255 | + } else if (tree.name == 'cite') { |
| 256 | + // Kinda like a ref but inline. |
| 257 | + // @fixme validate and output the tag parameters |
| 258 | + var cite = $('<span class="cite parseNode"></span>'); |
| 259 | + if ('content' in tree) { |
| 260 | + subParseArray(tree.content, cite); |
| 261 | + } |
| 262 | + node = cite[0]; |
| 263 | + } else { |
| 264 | + // @fixme unrecognized exts should output as text + rendered contents? |
| 265 | + callback(null, 'Unrecognized extension in parse tree'); |
| 266 | + return; |
| 267 | + } |
| 268 | + break; |
269 | 269 | default: |
270 | 270 | callback(null, 'Unrecognized parse tree node'); |
271 | | - return; |
| 271 | + return; |
272 | 272 | } |
273 | | - if (node) { |
274 | | - if (node.nodeType == 1) { |
275 | | - $(node).data('parseNode', tree); // assign the node for the tree inspector |
276 | | - if (inspectorMap) { |
277 | | - inspectorMap.put(tree, node); // store for reverse lookup |
278 | | - } |
279 | | - } |
| 273 | + if (node) { |
| 274 | + if (node.nodeType == 1) { |
| 275 | + $(node).data('parseNode', tree); // assign the node for the tree inspector |
| 276 | + if (inspectorMap) { |
| 277 | + inspectorMap.put(tree, node); // store for reverse lookup |
| 278 | + } |
| 279 | + } |
280 | 280 | callback(node); |
281 | | - } else { |
282 | | - callback(null); // hmmmm |
283 | | - } |
| 281 | + } else { |
| 282 | + callback(null); // hmmmm |
| 283 | + } |
284 | 284 | }; |
285 | 285 | |
286 | 286 | /** |
— | — | @@ -292,90 +292,90 @@ |
293 | 293 | * @param {function(text, error)} callback |
294 | 294 | */ |
295 | 295 | FakeParser.prototype.treeToSource = function(tree, callback) { |
296 | | - var self = this; |
297 | | - var subParseArray = function(listOfTrees) { |
298 | | - var str = ''; |
| 296 | + var self = this; |
| 297 | + var subParseArray = function(listOfTrees) { |
| 298 | + var str = ''; |
299 | 299 | $.each(listOfTrees, function(i, subtree) { |
300 | 300 | self.treeToSource(subtree, function(substr, err) { |
301 | 301 | if (substr) { |
302 | | - str += substr; |
| 302 | + str += substr; |
303 | 303 | } |
304 | 304 | }); |
305 | 305 | }); |
306 | | - return str; |
307 | | - }; |
| 306 | + return str; |
| 307 | + }; |
308 | 308 | var src; |
309 | 309 | switch (tree.type) { |
310 | 310 | case 'page': |
311 | | - src = subParseArray(tree.content); |
| 311 | + src = subParseArray(tree.content); |
312 | 312 | break; |
313 | 313 | case 'para': |
314 | 314 | // A single-line paragraph. |
315 | | - src = subParseArray(tree.content) + '\n'; |
| 315 | + src = subParseArray(tree.content) + '\n'; |
316 | 316 | break; |
317 | 317 | case 'break': |
318 | | - src = '\n'; |
| 318 | + src = '\n'; |
319 | 319 | break; |
320 | | - case 'text': |
321 | | - // In the real world, there might be escaping. |
322 | | - src = tree.text; |
323 | | - break; |
324 | | - case 'link': |
325 | | - src = '[['; |
326 | | - src += tree.target; |
327 | | - if (tree.text) { |
328 | | - src += '|'; |
329 | | - src += tree.text; |
330 | | - } |
331 | | - src += ']]'; |
332 | | - break; |
333 | | - case 'h': |
334 | | - stub = ''; |
335 | | - for (var i = 0; i < tree.level; i++) { |
336 | | - stub += '='; |
337 | | - } |
338 | | - src = stub + tree.text + stub + '\n'; |
339 | | - break; |
340 | | - case 'ext': |
341 | | - src = '<' + tree.name; |
342 | | - if (tree.params) { |
343 | | - src += ' ' + tree.params; |
344 | | - } |
345 | | - if ('content' in tree) { |
346 | | - src += '>'; |
347 | | - src += subParseArray(tree.content); |
348 | | - src += '</' + tree.name + '>'; |
349 | | - } else { |
350 | | - src += '/>'; |
351 | | - } |
352 | | - break; |
353 | | - case 'template': |
354 | | - src = '{{' + tree.target; |
355 | | - if (tree.params) { |
356 | | - for (var i = 0; i < tree.params.length; i++) { |
357 | | - var param = tree.params[i]; |
358 | | - src += '|'; |
359 | | - if ('name' in param) { |
360 | | - src += param.name + '='; |
361 | | - } |
362 | | - src += param.contents; |
363 | | - } |
364 | | - } |
365 | | - src += '}}'; |
366 | | - break; |
367 | | - case 'i': |
368 | | - src = "''" + tree.text + "''"; |
369 | | - break; |
370 | | - case 'extlink': |
371 | | - src = '[' + tree.target + ' ' + tree.text + ']'; |
372 | | - break; |
| 320 | + case 'text': |
| 321 | + // In the real world, there might be escaping. |
| 322 | + src = tree.text; |
| 323 | + break; |
| 324 | + case 'link': |
| 325 | + src = '[['; |
| 326 | + src += tree.target; |
| 327 | + if (tree.text) { |
| 328 | + src += '|'; |
| 329 | + src += tree.text; |
| 330 | + } |
| 331 | + src += ']]'; |
| 332 | + break; |
| 333 | + case 'h': |
| 334 | + stub = ''; |
| 335 | + for (var i = 0; i < tree.level; i++) { |
| 336 | + stub += '='; |
| 337 | + } |
| 338 | + src = stub + tree.text + stub + '\n'; |
| 339 | + break; |
| 340 | + case 'ext': |
| 341 | + src = '<' + tree.name; |
| 342 | + if (tree.params) { |
| 343 | + src += ' ' + tree.params; |
| 344 | + } |
| 345 | + if ('content' in tree) { |
| 346 | + src += '>'; |
| 347 | + src += subParseArray(tree.content); |
| 348 | + src += '</' + tree.name + '>'; |
| 349 | + } else { |
| 350 | + src += '/>'; |
| 351 | + } |
| 352 | + break; |
| 353 | + case 'template': |
| 354 | + src = '{{' + tree.target; |
| 355 | + if (tree.params) { |
| 356 | + for (var i = 0; i < tree.params.length; i++) { |
| 357 | + var param = tree.params[i]; |
| 358 | + src += '|'; |
| 359 | + if ('name' in param) { |
| 360 | + src += param.name + '='; |
| 361 | + } |
| 362 | + src += param.contents; |
| 363 | + } |
| 364 | + } |
| 365 | + src += '}}'; |
| 366 | + break; |
| 367 | + case 'i': |
| 368 | + src = "''" + tree.text + "''"; |
| 369 | + break; |
| 370 | + case 'extlink': |
| 371 | + src = '[' + tree.target + ' ' + tree.text + ']'; |
| 372 | + break; |
373 | 373 | default: |
374 | 374 | callback(null, 'Unrecognized parse tree node'); |
375 | | - return; |
| 375 | + return; |
376 | 376 | } |
377 | | - if (src) { |
378 | | - callback(src); |
379 | | - } else { |
380 | | - callback(null); // hmmmm |
381 | | - } |
| 377 | + if (src) { |
| 378 | + callback(src); |
| 379 | + } else { |
| 380 | + callback(null); // hmmmm |
| 381 | + } |
382 | 382 | }; |