Index: trunk/extensions/VisualEditor/modules/parser/pegParser.pegjs.txt |
— | — | @@ -84,7 +84,39 @@ |
85 | 85 | } |
86 | 86 | } |
87 | 87 | return bTypes; |
88 | | - } |
| 88 | + }; |
| 89 | + |
| 90 | + var extractInline = function ( node ) { |
| 91 | + return { text: extractText(node) |
| 92 | + } |
| 93 | + }; |
| 94 | + |
| 95 | + |
| 96 | + var extractText = function ( node ) { |
| 97 | + dp("extract: " + print_r(node)); |
| 98 | + if (typeof node === 'string') { |
| 99 | + return node; |
| 100 | + } else if ($.isArray(node)) { |
| 101 | + var texts = []; |
| 102 | + for (var i = 0, length = node.length; i < length; i++) { |
| 103 | + texts.push(extractText(node[i])); |
| 104 | + } |
| 105 | + return texts.join(''); |
| 106 | + } else if ( 'text' in node ) { |
| 107 | + return extractText(node.text); |
| 108 | + } else if ( 'content' in node ) { |
| 109 | + return extractText(node.content); |
| 110 | + } else if ( 'children' in node ) { |
| 111 | + var texts = []; |
| 112 | + for (var i = 0, length = node.children.length; i < length; i++) { |
| 113 | + texts.push(extractText(node.children[i])); |
| 114 | + } |
| 115 | + return texts.join(''); |
| 116 | + } else { |
| 117 | + console.log("extract failed!" + print_r(node)); |
| 118 | + throw ("extract failed: " + print_r(node)); |
| 119 | + } |
| 120 | + }; |
89 | 121 | } |
90 | 122 | |
91 | 123 | start |
— | — | @@ -116,8 +148,12 @@ |
117 | 149 | |
118 | 150 | |
119 | 151 | // Start of line |
120 | | -sol = (newline / & { return pos === 0; } { return true; }) (comment newline?)? |
| 152 | +sol = (newline / & { return pos === 0; } { return true; }) |
| 153 | + cn:(comment n:newline? { return n })? { |
| 154 | + return cn; |
| 155 | + } |
121 | 156 | |
| 157 | + |
122 | 158 | newline |
123 | 159 | = '\n' / '\r\n' |
124 | 160 | |
— | — | @@ -146,7 +182,7 @@ |
147 | 183 | return { |
148 | 184 | type: 'heading', |
149 | 185 | attributes: {level: 1}, |
150 | | - text: c |
| 186 | + content: extractInline(c) |
151 | 187 | } |
152 | 188 | } |
153 | 189 | / { clearFlag('h'); clearFlag('h1'); return null } |
— | — | @@ -161,7 +197,7 @@ |
162 | 198 | return { |
163 | 199 | type: 'heading', |
164 | 200 | attributes: {level: 2}, |
165 | | - content: c |
| 201 | + content: extractInline(c) |
166 | 202 | } |
167 | 203 | } |
168 | 204 | / { clearFlag('h'); clearFlag('h2'); return null } |
— | — | @@ -176,7 +212,7 @@ |
177 | 213 | return { |
178 | 214 | type: 'heading', |
179 | 215 | attributes: {level: 3}, |
180 | | - content: c |
| 216 | + content: extractInline(c) |
181 | 217 | } |
182 | 218 | } |
183 | 219 | / { clearFlag('h'); clearFlag('h3'); return null } |
— | — | @@ -191,7 +227,7 @@ |
192 | 228 | return { |
193 | 229 | type: 'heading', |
194 | 230 | attributes: {level: 4}, |
195 | | - content: c |
| 231 | + content: extractInline(c) |
196 | 232 | } |
197 | 233 | } |
198 | 234 | / { clearFlag('h'); clearFlag('h4'); return null } |
— | — | @@ -205,7 +241,7 @@ |
206 | 242 | return { |
207 | 243 | type: 'heading', |
208 | 244 | attributes: {level: 5}, |
209 | | - content: c |
| 245 | + content: extractInline(c) |
210 | 246 | } |
211 | 247 | } |
212 | 248 | / { clearFlag('h'); clearFlag('h5'); return null } |
— | — | @@ -219,7 +255,7 @@ |
220 | 256 | return { |
221 | 257 | type: 'heading', |
222 | 258 | attributes: {level: 6}, |
223 | | - content: c |
| 259 | + content: extractInline(c) |
224 | 260 | } |
225 | 261 | } |
226 | 262 | / { clearFlag('h'); clearFlag('h6'); return null } |
— | — | @@ -237,10 +273,10 @@ |
238 | 274 | = (sol br)? para_lines |
239 | 275 | |
240 | 276 | para_lines |
241 | | - = sol c:inlineline cs:(!block_lines para_lines)* { |
| 277 | + = s:sol c:inlineline cs:(!block_lines para_lines)* { |
242 | 278 | return { |
243 | 279 | type: 'paragraph', |
244 | | - content: c[0] // XXX Hack alarm! |
| 280 | + content: extractInline([s].concat([c]).concat(cs)) |
245 | 281 | } |
246 | 282 | } |
247 | 283 | |
— | — | @@ -250,7 +286,7 @@ |
251 | 287 | = l:pre_indent_line+ { |
252 | 288 | return { |
253 | 289 | type: 'pre', |
254 | | - children: l |
| 290 | + content: extractInline(l) |
255 | 291 | } |
256 | 292 | } |
257 | 293 | pre_indent_line = sol space l:inlineline { return l } |
— | — | @@ -305,7 +341,7 @@ |
306 | 342 | = c:(text / !inline_breaks (inline_element / [^\n]))+ { |
307 | 343 | var out = []; |
308 | 344 | var text = ''; |
309 | | - dp("inlineline: " + print_r(c)); |
| 345 | + //dp("inlineline: " + print_r(c)); |
310 | 346 | for (var i = 0; i < c.length; i++) { |
311 | 347 | if (typeof c[i] == 'string') { |
312 | 348 | text += c[i]; |
— | — | @@ -458,7 +494,7 @@ |
459 | 495 | clearFlag('bold'); |
460 | 496 | return { |
461 | 497 | type: 'b', |
462 | | - text: c, |
| 498 | + content: {text: c} |
463 | 499 | } |
464 | 500 | } |
465 | 501 | / bold_marker { clearFlag('bold'); return null } |
— | — | @@ -476,7 +512,7 @@ |
477 | 513 | dp('ileave:' + pos); |
478 | 514 | return { |
479 | 515 | type: 'i', |
480 | | - text: c |
| 516 | + content: {text: c} |
481 | 517 | } |
482 | 518 | } |
483 | 519 | / italic_marker { clearFlag('italic'); return null } |
— | — | @@ -623,7 +659,7 @@ |
624 | 660 | attributes: { |
625 | 661 | styles: bulletsToTypes(bullets) |
626 | 662 | }, |
627 | | - content: c[0] |
| 663 | + content: extractInline(c) |
628 | 664 | }; |
629 | 665 | } |
630 | 666 | |
— | — | @@ -642,12 +678,12 @@ |
643 | 679 | { |
644 | 680 | type: 'listItem', |
645 | 681 | attributes: {styles: bulletsToTypes(bullets)}, |
646 | | - content: {text: c.join('')} |
| 682 | + content: extractInline(c) |
647 | 683 | }, { |
648 | 684 | type: 'listItem', |
649 | 685 | attributes: {styles: bulletsToTypes( |
650 | 686 | bullets.slice(0, bullets.length - 1) + ':')}, |
651 | | - content: {text: d.join('')} |
| 687 | + content: extractInline(d) |
652 | 688 | } |
653 | 689 | ] |
654 | 690 | } |
Index: trunk/extensions/VisualEditor/modules/es/serializers/es.HtmlSerializer.js |
— | — | @@ -62,7 +62,7 @@ |
63 | 63 | |
64 | 64 | es.HtmlSerializer.prototype.pre = function( node ) { |
65 | 65 | return es.Html.makeTag( |
66 | | - 'pre', {}, this.document( node, true ) |
| 66 | + 'pre', {}, this.content( node.content, true ) |
67 | 67 | ); |
68 | 68 | }; |
69 | 69 | |