Debian Codegraph @

extensions/VisualEditor/lib/ve/tests/dm/ve.dm.example.js

raw symbols SCIP
1 /*!
2 * VisualEditor DataModel example data sets.
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 /**
8 * @class
9 * @singleton
10 * @ignore
11 */
12 ve.dm.example = {};
13
14 /* Methods */
15
16 ve.dm.example.singleLine = function ( strings, ...values ) {
17 // Concatenate
18 let output = '';
19 for ( let i = 0; i < values.length; i++ ) {
20 output += strings[ i ] + values[ i ];
21 }
22 output += strings[ values.length ];
23
24 // Remove line-leading indentation (but not spaces)
25 return output.replace( /\n\t+/g, '' ).trim();
26 };
27
28 /**
29 * Convert arrays of shorthand annotations in a data fragment to AnnotationSets with real
30 * annotation objects, and wraps the result in a ve.dm.ElementLinearData object.
31 *
32 * Shorthand notation for annotations is:
33 * [ 'a', [ { type: 'link', attributes: { href: '…' } ] ]
34 *
35 * The actual storage format has an instance of ve.dm.LinkAnnotation instead of the plain object,
36 * and an instance of ve.dm.AnnotationSet instead of the array.
37 *
38 * @param {Array} data Linear model data
39 * @param {ve.dm.HashValueStore} [store] Hash-value store to use, creates one if undefined
40 * @return {ve.dm.ElementLinearData} Linear data store
41 * @throws {Error} Example data passed to preprocessAnnotations by reference
42 */
43 ve.dm.example.preprocessAnnotations = function ( data, store ) {
44 let i;
45
46 // Sanity check to make sure ve.dm.example data has not been passed in
47 // by reference. Always use ve#copy.
48 for ( i in ve.dm.example ) {
49 if ( data === ve.dm.example[ i ] ) {
50 throw new Error( 'Example data passed to preprocessAnnotations by reference' );
51 }
52 }
53
54 function preprocessOriginalDomElements( el ) {
55 const originalDomElements = el.originalDomElements;
56 if ( originalDomElements ) {
57 el.originalDomElementsHash = store.hash( originalDomElements, originalDomElements.map( ve.getNodeHtml ).join( '' ) );
58 delete el.originalDomElements;
59 }
60 }
61
62 store = store || new ve.dm.HashValueStore();
63 for ( i = 0; i < data.length; i++ ) {
64 const key = data[ i ].annotations ? 'annotations' : 1;
65 // Check for shorthand annotation objects in array
66 if ( Array.isArray( data[ i ][ key ] ) && data[ i ][ key ][ 0 ].type ) {
67 data[ i ][ key ].forEach( preprocessOriginalDomElements );
68 data[ i ][ key ] = ve.dm.example.createAnnotationSet( store, data[ i ][ key ] ).getHashes();
69 }
70 preprocessOriginalDomElements( data[ i ] );
71 }
72 return new ve.dm.ElementLinearData( store, data );
73 };
74
75 /**
76 * Convert real data back to shorthand notation. See #preprocessAnnotations.
77 *
78 * Any annotation that has originalDomElements will be shallow-cloned and have
79 * originalDomElements removed.
80 *
81 * @param {Array} data Linear model data. Will be modified.
82 * @param {ve.dm.HashValueStore} store Hash-value store to resolve annotations in
83 * @param {boolean} [preserveDomElements] Preserve original DOM elements
84 * @return {Array} The given `data` parameter.
85 */
86 ve.dm.example.postprocessAnnotations = function ( data, store, preserveDomElements ) {
87 for ( let i = 0; i < data.length; i++ ) {
88 const key = data[ i ].annotations ? 'annotations' : 1;
89 if ( Array.isArray( data[ i ][ key ] ) ) {
90 data[ i ] = ve.extendObject( Array.isArray( data[ i ] ) ? [] : {}, data[ i ] );
91 data[ i ][ key ] = new ve.dm.AnnotationSet( store, data[ i ][ key ] ).get();
92 for ( let j = 0; j < data[ i ][ key ].length; j++ ) {
93 data[ i ][ key ][ j ] = data[ i ][ key ][ j ].element;
94 if ( !preserveDomElements && data[ i ][ key ][ j ].originalDomElementsHash !== undefined ) {
95 // Make a shallow clone and remove originalDomElements from it
96 data[ i ][ key ][ j ] = ve.extendObject( {}, data[ i ][ key ][ j ] );
97 delete data[ i ][ key ][ j ].originalDomElementsHash;
98 }
99 }
100 }
101 }
102 return data;
103 };
104
105 /**
106 * Create an annotation object from shorthand notation.
107 *
108 * @param {Object} annotation Plain object with type and attributes properties
109 * @param {ve.dm.HashValueStore} [store] Hash value store
110 * @return {ve.dm.Annotation} Instance of the right ve.dm.Annotation subclass
111 */
112 ve.dm.example.createAnnotation = function ( annotation, store ) {
113 return ve.dm.annotationFactory.createFromElement( annotation, store );
114 };
115
116 /**
117 * Create an AnnotationSet from an array of shorthand annotations.
118 *
119 * This calls ve.dm.example.createAnnotation() for each element and puts the result in an
120 * AnnotationSet.
121 *
122 * @param {ve.dm.HashValueStore} store Hash-value store
123 * @param {Object[]} annotations Array of annotations in shorthand format
124 * @return {ve.dm.AnnotationSet}
125 */
126 ve.dm.example.createAnnotationSet = function ( store, annotations ) {
127 for ( let i = 0; i < annotations.length; i++ ) {
128 annotations[ i ] = ve.dm.example.createAnnotation( annotations[ i ], store );
129 }
130 return new ve.dm.AnnotationSet( store, store.hashAll( annotations ) );
131 };
132
133 /* Some common annotations in shorthand format */
134 ve.dm.example.bold = { type: 'textStyle/bold', attributes: { nodeName: 'b' } };
135 ve.dm.example.italic = { type: 'textStyle/italic', attributes: { nodeName: 'i' } };
136 ve.dm.example.underline = { type: 'textStyle/underline', attributes: { nodeName: 'u' } };
137 ve.dm.example.span = { type: 'textStyle/span', attributes: { nodeName: 'span' } };
138 ve.dm.example.big = { type: 'textStyle/big', attributes: { nodeName: 'big' } };
139 ve.dm.example.code = { type: 'textStyle/code', attributes: { nodeName: 'code' } };
140 ve.dm.example.tt = { type: 'textStyle/code', attributes: { nodeName: 'tt' } };
141 ve.dm.example.strong = { type: 'textStyle/bold', attributes: { nodeName: 'strong' } };
142 ve.dm.example.link = function ( href ) {
143 return { type: 'link', attributes: { href: href } };
144 };
145 ve.dm.example.language = function ( lang, dir, nodeName ) {
146 return { type: 'meta/language', attributes: { nodeName: nodeName || 'span', lang: lang, dir: dir } };
147 };
148 ve.dm.example.boldWithStyle = ve.extendObject( {}, ve.dm.example.bold, { originalDomElements: $.parseHTML( '<b style="color:red;" />' ) } );
149
150 ve.dm.example.annHash = function ( tagName ) {
151 const ann = ve.copy( {
152 b: ve.dm.example.bold,
153 i: ve.dm.example.italic,
154 u: ve.dm.example.underline
155 }[ tagName ] );
156
157 ann.originalDomElementsHash = ve.dm.HashValueStore.prototype.hashOfValue( null, '<' + tagName + '></' + tagName + '>' );
158 return ve.dm.HashValueStore.prototype.hashOfValue( ann );
159 };
160
161 // hash = store.hashOfValue( ve.dm.example.bold )
162 ve.dm.example.boldHash = 'h49981eab0f8056ff';
163 ve.dm.example.italicHash = 'hefd27ef3bf2041dd';
164 ve.dm.example.underlineHash = 'hf214c680fbc361da';
165 ve.dm.example.strongHash = 'ha5aaf526d1c3af54';
166
167 ve.dm.example.inlineSlug = '<span class="ve-ce-branchNode-slug ve-ce-branchNode-inlineSlug"></span>';
168 ve.dm.example.blockSlug = '<div class="ve-ce-branchNode-slug ve-ce-branchNode-blockSlug"></div>';
169
170 ve.dm.example.ceParagraph = '<p class="ve-ce-branchNode ve-ce-contentBranchNode ve-ce-paragraphNode">';
171 ve.dm.example.ceWrapperParagraph = '<p class="ve-ce-branchNode ve-ce-contentBranchNode ve-ce-paragraphNode ve-ce-generated-wrapper">';
172
173 ve.dm.example.textStyleClasses = 've-ce-annotation ve-ce-textStyleAnnotation';
174
175 ve.dm.example.commentNodePreview = function ( text ) {
176 return '<span class="ve-ce-leafNode ve-ce-focusableNode ve-ce-commentNode ve-ce-focusableNode-invisible" contenteditable="false" title="' + text + '">' +
177 ( new OO.ui.ButtonWidget( {
178 // Copied from ve.ce.FocusableNode#createInvisibleIcon
179 classes: [ 've-ce-focusableNode-invisibleIcon' ],
180 framed: false,
181 tabIndex: null,
182 icon: ve.ce.CommentNode.static.iconWhenInvisible
183 } ).setLabel( text ) ).$element[ 0 ].outerHTML +
184 '</span>';
185 };
186
187 /**
188 * Creates a document from example data.
189 *
190 * Defaults to ve.dm.example.data if no name is supplied.
191 *
192 * @param {string} [name='data'] Named element of ve.dm.example
193 * @param {ve.dm.HashValueStore} [store] A specific hash-value store to use, optionally.
194 * @param {string} [base=ve.dm.example.baseUri] Base URL to use for the document
195 * @return {ve.dm.Document}
196 * @throws {Error} Example data not found
197 */
198 ve.dm.example.createExampleDocument = function ( name, store, base ) {
199 return ve.dm.example.createExampleDocumentFromObject( name, store, ve.dm.example, base );
200 };
201
202 /**
203 * Helper function for ve.dm.createExampleDocument.
204 *
205 * @param {string} [name='data'] Named element of ve.dm.example
206 * @param {ve.dm.HashValueStore} [store] A specific hash-value store to use, optionally.
207 * @param {Object} object Collection of test documents, keyed by name
208 * @param {string} [base=ve.dm.example.baseUri] Base URL to use for the document
209 * @return {ve.dm.Document}
210 * @throws {Error} Example data not found
211 */
212 ve.dm.example.createExampleDocumentFromObject = function ( name, store, object, base ) {
213 name = name || 'data';
214 if ( object[ name ] === undefined ) {
215 throw new Error( 'Example data \'' + name + '\' not found' );
216 }
217 return ve.dm.example.createExampleDocumentFromData( object[ name ], store, base );
218 };
219
220 ve.dm.example.createExampleDocumentFromData = function ( data, store, base ) {
221 store = store || new ve.dm.HashValueStore();
222 base = base || ve.dm.example.baseUri;
223 const doc = new ve.dm.Document(
224 ve.dm.example.preprocessAnnotations( ve.copy( data ), store )
225 );
226 // HACK internalList isn't populated when creating a document from data
227 if ( data.internalItems ) {
228 for ( let i = 0; i < data.internalItems.length; i++ ) {
229 doc.internalList.queueItemHtml(
230 data.internalItems[ i ].group,
231 data.internalItems[ i ].key,
232 data.internalItems[ i ].body
233 );
234 }
235 }
236 if ( data.internalListNextUniqueNumber ) {
237 doc.setStorage( 'internallist-counter', data.internalListNextUniqueNumber );
238 }
239 doc.buildNodeTree();
240 ve.fixBase( doc.getHtmlDocument(), doc.getHtmlDocument(), base );
241 return doc;
242 };
243
244 /**
245 * Looks up a value in a node tree.
246 *
247 * @param {ve.Node} root Root node to lookup from
248 * @param {...number} [indexes] Index path
249 * @return {ve.Node} Node at given path
250 */
251 ve.dm.example.lookupNode = function ( root, ...indexes ) {
252 let node = root;
253 indexes.forEach( ( index ) => {
254 node = node.children[ index ];
255 } );
256 return node;
257 };
258
259 ve.dm.example.imgSrc = 'https://upload.wikimedia.org/wikipedia/commons/b/b3/Wikipedia-logo-v2-en.svg';
260
261 ve.dm.example.baseUri = 'http://example.org';
262
263 ve.dm.example.image = {
264 html: '<img src="' + ve.dm.example.imgSrc + '" alt="Example" width="100" height="50">',
265 data: {
266 type: 'inlineImage',
267 attributes: {
268 src: ve.dm.example.imgSrc,
269 alt: 'Example',
270 width: 100,
271 height: 50
272 }
273 }
274 };
275
276 ve.dm.example.blockImage = {
277 html: ve.dm.example.singleLine`
278 <figure class="ve-align-right"><img src="${ ve.dm.example.imgSrc }" alt="Example" width="100" height="50">
279 <figcaption>foo <b style="color:red;">red</b></figcaption>
280 </figure>
281 `,
282 data: [
283 {
284 type: 'blockImage',
285 attributes: {
286 src: ve.dm.example.imgSrc,
287 alt: 'Example',
288 width: 100,
289 height: 50,
290 originalClasses: 've-align-right',
291 unrecognizedClasses: [],
292 align: 'right'
293 }
294 },
295 { type: 'imageCaption' },
296 { type: 'paragraph', internal: { generated: 'wrapper' } },
297 ...'foo ',
298 [ 'r', [ ve.dm.example.boldWithStyle ] ],
299 [ 'e', [ ve.dm.example.boldWithStyle ] ],
300 [ 'd', [ ve.dm.example.boldWithStyle ] ],
301 { type: '/paragraph' },
302 { type: '/imageCaption' },
303 { type: '/blockImage' }
304 ],
305 ceHtml: ve.dm.example.singleLine`
306 <figure class="ve-ce-branchNode ve-ce-focusableNode ve-ce-imageNode ve-ce-blockImageNode" contenteditable="false">
307 <img src="${ ve.dm.example.imgSrc }" alt="Example" style="width: 100px; height: 50px;">
308 <figcaption class="ve-ce-branchNode ve-ce-activeNode" contenteditable="true" spellcheck="true">
309 ${ ve.dm.example.ceWrapperParagraph }
310 foo
311 <b style="color:red;" class="${ ve.dm.example.textStyleClasses } ve-ce-boldAnnotation">red</b>
312 </p>
313 </figcaption>
314 </figure>
315 `
316 };
317
318 /**
319 * Serialized HTML.
320 *
321 * This is what the parser will emit.
322 * TODO remove some of the <p>s here to test automatic wrapping
323 */
324 ve.dm.example.html = ve.dm.example.singleLine`
325 <h1>a<b>b</b><i>c</i></h1>
326 <table>
327 ${ /* Implicit <tbody> */'' }
328 <tr>
329 <td>
330 <p>d</p>
331 <ul>
332 <li>
333 <p>e</p>
334 <ul>
335 <li>
336 <p>f</p>
337 </li>
338 </ul>
339 </li>
340 </ul>
341 <ol>
342 <li>
343 <p>g</p>
344 </li>
345 </ol>
346 </td>
347 </tr>
348 </table>
349 <pre>h${ ve.dm.example.image.html }i</pre>
350 <dl>
351 <dt>
352 <p>j</p>
353 </dt>
354 <dd>
355 <p>k</p>
356 </dd>
357 </dl>
358 <p>l</p>
359 <p>m</p>
360 `;
361
362 /**
363 * The offset path of the result of getNodeAndOffset for each offset
364 *
365 * @see ve.getOffsetPath
366 */
367 ve.dm.example.offsetPaths = [
368 [ 0, 0, 0 ],
369 [ 0, 0, 0 ],
370 [ 0, 0, 1 ],
371 [ 0, 1, 0, 1 ],
372 [ 0, 2, 0, 1 ],
373 [ 0, 2, 0, 1 ],
374 [ 0, 2, 0, 1 ],
375 [ 0, 2, 0, 1 ],
376 [ 0, 2, 0, 1 ],
377 [ 0, 2, 0, 1 ],
378 // 10
379 [ 1, 0, 0, 0, 0, 0, 0 ],
380 [ 1, 0, 0, 0, 0, 0, 1 ],
381 [ 1, 0, 0, 0, 0, 0, 1 ],
382 [ 1, 0, 0, 0, 0, 0, 1 ],
383 [ 1, 0, 0, 0, 0, 0, 1 ],
384 [ 1, 0, 0, 0, 1, 0, 0, 0, 0 ],
385 [ 1, 0, 0, 0, 1, 0, 0, 0, 1 ],
386 [ 1, 0, 0, 0, 1, 0, 0, 0, 1 ],
387 [ 1, 0, 0, 0, 1, 0, 0, 0, 1 ],
388 [ 1, 0, 0, 0, 1, 0, 0, 0, 1 ],
389 // 20
390 [ 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0 ],
391 [ 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1 ],
392 [ 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1 ],
393 [ 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1 ],
394 [ 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1 ],
395 [ 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1 ],
396 [ 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1 ],
397 [ 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1 ],
398 [ 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1 ],
399 [ 1, 0, 0, 0, 2, 0, 0, 0, 0 ],
400 // 30
401 [ 1, 0, 0, 0, 2, 0, 0, 0, 1 ],
402 [ 1, 0, 0, 0, 2, 0, 0, 0, 1 ],
403 [ 1, 0, 0, 0, 2, 0, 0, 0, 1 ],
404 [ 1, 0, 0, 0, 2, 0, 0, 0, 1 ],
405 [ 1, 0, 0, 0, 2, 0, 0, 0, 1 ],
406 [ 1, 0, 0, 0, 2, 0, 0, 0, 1 ],
407 [ 1, 0, 0, 0, 2, 0, 0, 0, 1 ],
408 [ 1, 0, 0, 0, 2, 0, 0, 0, 1 ],
409 [ 2, 0, 0 ],
410 [ 2, 0, 1 ],
411 // 40
412 null,
413 [ 2, 2, 0 ],
414 [ 2, 2, 1 ],
415 [ 2, 2, 1 ],
416 [ 2, 2, 1 ],
417 [ 2, 2, 1 ],
418 [ 3, 0, 0, 0, 0 ],
419 [ 3, 0, 0, 0, 1 ],
420 [ 3, 0, 0, 0, 1 ],
421 [ 3, 0, 0, 0, 1 ],
422 // 50
423 [ 3, 0, 0, 0, 1 ],
424 [ 3, 1, 0, 0, 0 ],
425 [ 3, 1, 0, 0, 1 ],
426 [ 3, 1, 0, 0, 1 ],
427 [ 3, 1, 0, 0, 1 ],
428 [ 3, 1, 0, 0, 1 ],
429 [ 4, 0, 0 ],
430 [ 4, 0, 1 ],
431 [ 4, 0, 1 ],
432 [ 5, 0, 0 ],
433 // 60
434 [ 5, 0, 1 ]
435 ];
436
437 /*
438 * Linear data.
439 *
440 * This is what we convert serialized HTML from the parser into so we can work with it more easily.
441 *
442 * There are three types of components in content data:
443 *
444 * {string} Plain text character
445 *
446 * {Array} Annotated character
447 * 0: {string} Character
448 * 1: {Object} List of references to immutable annotation objects, keyed by JSON
449 * serializations of their values (hashes)
450 *
451 * {Object} Opening or closing structural element
452 * type: {string} Symbolic node type name, if closing element first character will be "/"
453 * [attributes]: {Object} List of symbolic attribute name and literal value pairs
454 */
455 ve.dm.example.data = [
456 // 0 - Beginning of heading
457 { type: 'heading', attributes: { level: 1 } },
458 // 1 - Plain "a"
459 'a',
460 // 2 - Bold "b"
461 [ 'b', [ ve.dm.example.bold ] ],
462 // 3 - Italic "c"
463 [ 'c', [ ve.dm.example.italic ] ],
464 // 4 - End of heading
465 { type: '/heading' },
466 // 5 - Beginning of table
467 { type: 'table' },
468 // 6 - Beginning of body
469 { type: 'tableSection', attributes: { style: 'body' } },
470 // 7 - Beginning of row
471 { type: 'tableRow' },
472 // 8 - Beginning of cell
473 { type: 'tableCell', attributes: { style: 'data' } },
474 // 9 - Beginning of paragraph
475 { type: 'paragraph' },
476 // 10 - Plain "d"
477 'd',
478 // 11 - End of paragraph
479 { type: '/paragraph' },
480 // 12 - Beginning of bullet list
481 { type: 'list', attributes: { style: 'bullet' } },
482 // 13 - Beginning of list item
483 { type: 'listItem' },
484 // 14 - Beginning of paragraph
485 { type: 'paragraph' },
486 // 15 - Plain "e"
487 'e',
488 // 16 - End of paragraph
489 { type: '/paragraph' },
490 // 17 - Beginning of nested bullet list
491 { type: 'list', attributes: { style: 'bullet' } },
492 // 18 - Beginning of nested bullet list item
493 { type: 'listItem' },
494 // 19 - Beginning of paragraph
495 { type: 'paragraph' },
496 // 20 - Plain "f"
497 'f',
498 // 21 - End of paragraph
499 { type: '/paragraph' },
500 // 22 - End of nested bullet list item
501 { type: '/listItem' },
502 // 23 - End of nested bullet list
503 { type: '/list' },
504 // 24 - End of bullet list item
505 { type: '/listItem' },
506 // 25 - End of bullet list
507 { type: '/list' },
508 // 26 - Beginning of numbered list
509 { type: 'list', attributes: { style: 'number' } },
510 // 27 - Beginning of numbered list item
511 { type: 'listItem' },
512 // 28 - Beginning of paragraph
513 { type: 'paragraph' },
514 // 29 - Plain "g"
515 'g',
516 // 30 - End of paragraph
517 { type: '/paragraph' },
518 // 31 - End of item
519 { type: '/listItem' },
520 // 32 - End of list
521 { type: '/list' },
522 // 33 - End of cell
523 { type: '/tableCell' },
524 // 34 - End of row
525 { type: '/tableRow' },
526 // 35 - End of body
527 { type: '/tableSection' },
528 // 36 - End of table
529 { type: '/table' },
530 // 37 - Beginning of preformatted
531 { type: 'preformatted' },
532 // 38 - Plain "h"
533 'h',
534 // 39 - Beginning of inline image
535 ve.dm.example.image.data,
536 // 40 - End of inline image
537 { type: '/inlineImage' },
538 // 41 - Plain "i"
539 'i',
540 // 42 - End of preformatted
541 { type: '/preformatted' },
542 // 43 - Beginning of definition list
543 { type: 'definitionList' },
544 // 44 - Beginning of definition list term item
545 { type: 'definitionListItem', attributes: { style: 'term' } },
546 // 45 - Beginning of paragraph
547 { type: 'paragraph' },
548 // 46 - Plain "j"
549 'j',
550 // 47 - End of paragraph
551 { type: '/paragraph' },
552 // 48 - End of definition list term item
553 { type: '/definitionListItem' },
554 // 49 - Beginning of definition list definition item
555 { type: 'definitionListItem', attributes: { style: 'definition' } },
556 // 50 - Beginning of paragraph
557 { type: 'paragraph' },
558 // 51 - Plain "k"
559 'k',
560 // 52 - End of paragraph
561 { type: '/paragraph' },
562 // 53 - End of definition list definition item
563 { type: '/definitionListItem' },
564 // 54 - End of definition list
565 { type: '/definitionList' },
566 // 55 - Beginning of paragraph
567 { type: 'paragraph' },
568 // 56 - Plain "l"
569 'l',
570 // 57 - End of paragraph
571 { type: '/paragraph' },
572 // 58 - Beginning of paragraph
573 { type: 'paragraph' },
574 // 59 - Plain "m"
575 'm',
576 // 60 - End of paragraph
577 { type: '/paragraph' },
578 // 61 - Beginning of internalList
579 { type: 'internalList' },
580 // 62 - End of internalList
581 { type: '/internalList' }
582 // 63 - End of document
583 ];
584
585 ve.dm.example.alienData = [
586 // 0
587 { type: 'alienBlock', originalDomElements: $.parseHTML( '<foobar />' ) },
588 { type: '/alienBlock' },
589 // 2
590 { type: 'paragraph' },
591 'a',
592 // 4
593 { type: 'alienInline', originalDomElements: $.parseHTML( '<foobar />' ) },
594 { type: '/alienInline' },
595 // 6
596 'b',
597 { type: '/paragraph' },
598 // 8
599 { type: 'alienBlock', originalDomElements: $.parseHTML( '<foobar />' ) },
600 { type: '/alienBlock' },
601 // 10
602 { type: 'internalList' },
603 { type: '/internalList' }
604 ];
605
606 ve.dm.example.alienWithEmptyData = [
607 // 0
608 { type: 'paragraph' },
609 { type: '/paragraph' },
610 // 2
611 { type: 'paragraph' },
612 'a',
613 // 4
614 { type: 'alienInline', originalDomElements: $.parseHTML( '<foobar />' ) },
615 { type: '/alienInline' },
616 // 6
617 { type: '/paragraph' },
618 // 7
619 { type: 'internalList' },
620 { type: '/internalList' }
621 ];
622
623 ve.dm.example.internalData = [
624 // 0
625 { type: 'paragraph' },
626 ...'Foo',
627 { type: '/paragraph' },
628 // 5
629 { type: 'internalList' },
630 // 6
631 { type: 'internalItem' },
632 // 7
633 { type: 'paragraph', internal: { generated: 'wrapper' } },
634 ...'Bar',
635 { type: '/paragraph' },
636 // 12
637 { type: '/internalItem' },
638 // 13
639 { type: 'internalItem' },
640 // 14
641 { type: 'paragraph', internal: { generated: 'wrapper' } },
642 ...'Baz',
643 { type: '/paragraph' },
644 // 19
645 { type: '/internalItem' },
646 // 20
647 { type: '/internalList' },
648 // 21
649 { type: 'paragraph' },
650 ...'Quux',
651 { type: '/paragraph' }
652 // 27
653 ];
654
655 ve.dm.example.internalData.internalItems = [
656 { group: 'test', key: 'bar', body: 'Bar' },
657 { group: 'test', key: 'baz', body: 'Baz' }
658 ];
659
660 ve.dm.example.withMeta = [
661 // 0
662 {
663 type: 'alienMeta',
664 originalDomElements: $.parseHTML( '<!-- No content conversion -->' )
665 },
666 { type: '/alienMeta' },
667 {
668 type: 'alienMeta',
669 originalDomElements: $.parseHTML( '<meta property="foo" />' )
670 },
671 { type: '/alienMeta' },
672 { type: 'paragraph' },
673 // 5
674 ...'Foo',
675 { type: '/paragraph' },
676 {
677 type: 'alienMeta',
678 originalDomElements: $.parseHTML( '<link rel="bar" href="baz" />' )
679 },
680 // 10
681 { type: '/alienMeta' },
682 { type: 'paragraph' },
683 ...'Bar',
684 // 15
685 { type: '/paragraph' },
686 {
687 type: 'alienMeta',
688 originalDomElements: $.parseHTML( '<meta property="foo" content="bar" />' )
689 },
690 { type: '/alienMeta' },
691 { type: 'paragraph' },
692 // 19
693 ...'Baz',
694 { type: '/paragraph' },
695 {
696 type: 'removableAlienMeta',
697 originalDomElements: $.parseHTML( '<b></b>' )
698 },
699 { type: '/removableAlienMeta' },
700 // 25
701 {
702 type: 'alienMeta',
703 originalDomElements: $.parseHTML( '<meta property="bar" content="baz" />' )
704 },
705 { type: '/alienMeta' },
706 {
707 type: 'alienMeta',
708 originalDomElements: $.parseHTML( '<!--barbaz-->' )
709 },
710 { type: '/alienMeta' },
711 {
712 type: 'alienMeta',
713 originalDomElements: $.parseHTML( '<link rel="foofoo" href="barbar" />' )
714 },
715 // 30
716 { type: '/alienMeta' },
717 {
718 type: 'alienMeta',
719 originalDomElements: $.parseHTML( '<meta typeof=bazquux" data-foo="foobar" />' )
720 },
721 { type: '/alienMeta' },
722 { type: 'internalList' },
723 { type: '/internalList' }
724 ];
725
726 ve.dm.example.listWithMeta = [
727 // 0 - Beginning of list
728 {
729 type: 'alienMeta',
730 originalDomElements: $.parseHTML( '<meta property="one" />' )
731 },
732 { type: '/alienMeta' },
733 { type: 'list' },
734 // 1 - Beginning of first list item
735 {
736 type: 'alienMeta',
737 originalDomElements: $.parseHTML( '<meta property="two" />' )
738 },
739 { type: '/alienMeta' },
740 { type: 'listItem', attributes: { styles: [ 'bullet' ] } },
741 // 2 - Beginning of paragraph
742 {
743 type: 'alienMeta',
744 originalDomElements: $.parseHTML( '<meta property="three" />' )
745 },
746 { type: '/alienMeta' },
747 { type: 'paragraph' },
748 // 3 - Plain "a"
749 {
750 type: 'alienMeta',
751 originalDomElements: $.parseHTML( '<meta property="four" />' )
752 },
753 { type: '/alienMeta' },
754 'a',
755 // 4 - End of paragraph
756 {
757 type: 'alienMeta',
758 originalDomElements: $.parseHTML( '<meta property="five" />' )
759 },
760 { type: '/alienMeta' },
761 { type: '/paragraph' },
762 // 5 - End of first list item
763 {
764 type: 'alienMeta',
765 originalDomElements: $.parseHTML( '<meta property="six" />' )
766 },
767 { type: '/alienMeta' },
768 { type: '/listItem' },
769 // 6 - Beginning of second list item
770 {
771 type: 'alienMeta',
772 originalDomElements: $.parseHTML( '<meta property="seven" />' )
773 },
774 { type: '/alienMeta' },
775 { type: 'listItem', attributes: { styles: [ 'bullet' ] } },
776 // 7 - Beginning of paragraph
777 {
778 type: 'alienMeta',
779 originalDomElements: $.parseHTML( '<meta property="eight" />' )
780 },
781 { type: '/alienMeta' },
782 { type: 'paragraph' },
783 // 8 - Plain "b"
784 {
785 type: 'alienMeta',
786 originalDomElements: $.parseHTML( '<meta property="nine" />' )
787 },
788 { type: '/alienMeta' },
789 'b',
790 // 9 - End of paragraph
791 {
792 type: 'alienMeta',
793 originalDomElements: $.parseHTML( '<meta property="ten" />' )
794 },
795 { type: '/alienMeta' },
796 { type: '/paragraph' },
797 // 10 - End of second list item
798 {
799 type: 'alienMeta',
800 originalDomElements: $.parseHTML( '<meta property="eleven" />' )
801 },
802 { type: '/alienMeta' },
803 { type: '/listItem' },
804 // 11 - End of list
805 {
806 type: 'alienMeta',
807 originalDomElements: $.parseHTML( '<meta property="twelve" />' )
808 },
809 { type: '/alienMeta' },
810 { type: '/list' },
811 // 12 - Trailing metadata
812 {
813 type: 'alienMeta',
814 originalDomElements: $.parseHTML( '<meta property="thirteen" />' )
815 },
816 { type: '/alienMeta' },
817 { type: 'internalList' },
818 { type: '/internalList' }
819 ];
820
821 ve.dm.example.mergedCellsHtml = ve.dm.example.singleLine`
822 <table>
823 <tr>
824 <td>1</td><td>2</td><td>3</td><td rowspan="3">4</td><td>5</td><td>6</td>
825 </tr>
826 <tr>
827 <td>7</td><td colspan="2">8</td><td rowspan="4">9</td><td>10</td>
828 </tr>
829 <tr>
830 <td>11</td><td>12</td><td>13</td><td>14</td>
831 </tr>
832 <tr>
833 <td>15</td><td rowspan="3" colspan="3">16</td><td>17</td>
834 </tr>
835 <tr>
836 <td>18</td><td>19</td>
837 </tr>
838 <tr>
839 <td>20</td><td colspan="2">21</td>
840 </tr>
841 <tr>
842 <td>22</td><td>23</td><td>24</td><td>25</td><td>26</td><td>27</td>
843 </tr>
844 </table>
845 `;
846
847 ve.dm.example.mergedCells = [
848 { type: 'table' },
849 { type: 'tableSection', attributes: { style: 'body' } },
850 { type: 'tableRow' },
851 { type: 'tableCell', attributes: { style: 'data' } },
852 { type: 'paragraph', internal: { generated: 'wrapper' } },
853 '1',
854 { type: '/paragraph' },
855 { type: '/tableCell' },
856 { type: 'tableCell', attributes: { style: 'data' } },
857 { type: 'paragraph', internal: { generated: 'wrapper' } },
858 '2',
859 { type: '/paragraph' },
860 { type: '/tableCell' },
861 { type: 'tableCell', attributes: { style: 'data' } },
862 { type: 'paragraph', internal: { generated: 'wrapper' } },
863 '3',
864 { type: '/paragraph' },
865 { type: '/tableCell' },
866 {
867 type: 'tableCell',
868 attributes: {
869 style: 'data',
870 originalRowspan: '3',
871 rowspan: 3
872 }
873 },
874 { type: 'paragraph', internal: { generated: 'wrapper' } },
875 '4',
876 { type: '/paragraph' },
877 { type: '/tableCell' },
878 { type: 'tableCell', attributes: { style: 'data' } },
879 { type: 'paragraph', internal: { generated: 'wrapper' } },
880 '5',
881 { type: '/paragraph' },
882 { type: '/tableCell' },
883 { type: 'tableCell', attributes: { style: 'data' } },
884 { type: 'paragraph', internal: { generated: 'wrapper' } },
885 '6',
886 { type: '/paragraph' },
887 { type: '/tableCell' },
888 { type: '/tableRow' },
889 { type: 'tableRow' },
890 { type: 'tableCell', attributes: { style: 'data' } },
891 { type: 'paragraph', internal: { generated: 'wrapper' } },
892 '7',
893 { type: '/paragraph' },
894 { type: '/tableCell' },
895 {
896 type: 'tableCell',
897 attributes: {
898 style: 'data',
899 colspan: 2,
900 originalColspan: '2'
901 }
902 },
903 { type: 'paragraph', internal: { generated: 'wrapper' } },
904 '8',
905 { type: '/paragraph' },
906 { type: '/tableCell' },
907 {
908 type: 'tableCell',
909 attributes: {
910 style: 'data',
911 originalRowspan: '4',
912 rowspan: 4
913 }
914 },
915 { type: 'paragraph', internal: { generated: 'wrapper' } },
916 '9',
917 { type: '/paragraph' },
918 { type: '/tableCell' },
919 { type: 'tableCell', attributes: { style: 'data' } },
920 { type: 'paragraph', internal: { generated: 'wrapper' } },
921 ...'10',
922 { type: '/paragraph' },
923 { type: '/tableCell' },
924 { type: '/tableRow' },
925 { type: 'tableRow' },
926 { type: 'tableCell', attributes: { style: 'data' } },
927 { type: 'paragraph', internal: { generated: 'wrapper' } },
928 ...'11',
929 { type: '/paragraph' },
930 { type: '/tableCell' },
931 { type: 'tableCell', attributes: { style: 'data' } },
932 { type: 'paragraph', internal: { generated: 'wrapper' } },
933 ...'12',
934 { type: '/paragraph' },
935 { type: '/tableCell' },
936 { type: 'tableCell', attributes: { style: 'data' } },
937 { type: 'paragraph', internal: { generated: 'wrapper' } },
938 ...'13',
939 { type: '/paragraph' },
940 { type: '/tableCell' },
941 { type: 'tableCell', attributes: { style: 'data' } },
942 { type: 'paragraph', internal: { generated: 'wrapper' } },
943 ...'14',
944 { type: '/paragraph' },
945 { type: '/tableCell' },
946 { type: '/tableRow' },
947 { type: 'tableRow' },
948 { type: 'tableCell', attributes: { style: 'data' } },
949 { type: 'paragraph', internal: { generated: 'wrapper' } },
950 ...'15',
951 { type: '/paragraph' },
952 { type: '/tableCell' },
953 {
954 type: 'tableCell',
955 attributes: {
956 style: 'data',
957 colspan: 3,
958 originalColspan: '3',
959 originalRowspan: '3',
960 rowspan: 3
961 }
962 },
963 { type: 'paragraph', internal: { generated: 'wrapper' } },
964 ...'16',
965 { type: '/paragraph' },
966 { type: '/tableCell' },
967 { type: 'tableCell', attributes: { style: 'data' } },
968 { type: 'paragraph', internal: { generated: 'wrapper' } },
969 ...'17',
970 { type: '/paragraph' },
971 { type: '/tableCell' },
972 { type: '/tableRow' },
973 { type: 'tableRow' },
974 { type: 'tableCell', attributes: { style: 'data' } },
975 { type: 'paragraph', internal: { generated: 'wrapper' } },
976 ...'18',
977 { type: '/paragraph' },
978 { type: '/tableCell' },
979 { type: 'tableCell', attributes: { style: 'data' } },
980 { type: 'paragraph', internal: { generated: 'wrapper' } },
981 ...'19',
982 { type: '/paragraph' },
983 { type: '/tableCell' },
984 { type: '/tableRow' },
985 { type: 'tableRow' },
986 { type: 'tableCell', attributes: { style: 'data' } },
987 { type: 'paragraph', internal: { generated: 'wrapper' } },
988 ...'20',
989 { type: '/paragraph' },
990 { type: '/tableCell' },
991 {
992 type: 'tableCell',
993 attributes: {
994 style: 'data',
995 colspan: 2,
996 originalColspan: '2'
997 }
998 },
999 { type: 'paragraph', internal: { generated: 'wrapper' } },
1000 ...'21',
1001 { type: '/paragraph' },
1002 { type: '/tableCell' },
1003 { type: '/tableRow' },
1004 { type: 'tableRow' },
1005 { type: 'tableCell', attributes: { style: 'data' } },
1006 { type: 'paragraph', internal: { generated: 'wrapper' } },
1007 ...'22',
1008 { type: '/paragraph' },
1009 { type: '/tableCell' },
1010 { type: 'tableCell', attributes: { style: 'data' } },
1011 { type: 'paragraph', internal: { generated: 'wrapper' } },
1012 ...'23',
1013 { type: '/paragraph' },
1014 { type: '/tableCell' },
1015 { type: 'tableCell', attributes: { style: 'data' } },
1016 { type: 'paragraph', internal: { generated: 'wrapper' } },
1017 ...'24',
1018 { type: '/paragraph' },
1019 { type: '/tableCell' },
1020 { type: 'tableCell', attributes: { style: 'data' } },
1021 { type: 'paragraph', internal: { generated: 'wrapper' } },
1022 ...'25',
1023 { type: '/paragraph' },
1024 { type: '/tableCell' },
1025 { type: 'tableCell', attributes: { style: 'data' } },
1026 { type: 'paragraph', internal: { generated: 'wrapper' } },
1027 ...'26',
1028 { type: '/paragraph' },
1029 { type: '/tableCell' },
1030 { type: 'tableCell', attributes: { style: 'data' } },
1031 { type: 'paragraph', internal: { generated: 'wrapper' } },
1032 ...'27',
1033 { type: '/paragraph' },
1034 { type: '/tableCell' },
1035 { type: '/tableRow' },
1036 { type: '/tableSection' },
1037 { type: '/table' },
1038 { type: 'internalList' },
1039 { type: '/internalList' }
1040 ];
1041
1042 ve.dm.example.complexTableHtml = ve.dm.example.singleLine`
1043 <table>
1044 <caption>Foo</caption>
1045 <thead><tr><th rowspan="">Bar</th></tr></thead>
1046 <tfoot><tr><td colspan="2">Baz</td></tr></tfoot>
1047 <tbody><tr><td rowspan="02">Quux</td><td colspan="2 garbage">Whee</td></tr></tbody>
1048 </table>
1049 `;
1050
1051 ve.dm.example.complexTable = [
1052 { type: 'table' },
1053 { type: 'tableCaption' },
1054 { type: 'paragraph', internal: { generated: 'wrapper' } },
1055 ...'Foo',
1056 { type: '/paragraph' },
1057 { type: '/tableCaption' },
1058 { type: 'tableSection', attributes: { style: 'header' } },
1059 { type: 'tableRow' },
1060 {
1061 type: 'tableCell',
1062 attributes: {
1063 style: 'header',
1064 originalRowspan: ''
1065 }
1066 },
1067 { type: 'paragraph', internal: { generated: 'wrapper' } },
1068 ...'Bar',
1069 { type: '/paragraph' },
1070 { type: '/tableCell' },
1071 { type: '/tableRow' },
1072 { type: '/tableSection' },
1073 { type: 'tableSection', attributes: { style: 'footer' } },
1074 { type: 'tableRow' },
1075 {
1076 type: 'tableCell',
1077 attributes: {
1078 style: 'data',
1079 colspan: 2,
1080 originalColspan: '2'
1081 }
1082 },
1083 { type: 'paragraph', internal: { generated: 'wrapper' } },
1084 ...'Baz',
1085 { type: '/paragraph' },
1086 { type: '/tableCell' },
1087 { type: '/tableRow' },
1088 { type: '/tableSection' },
1089 { type: 'tableSection', attributes: { style: 'body' } },
1090 { type: 'tableRow' },
1091 {
1092 type: 'tableCell',
1093 attributes: {
1094 style: 'data',
1095 rowspan: 2,
1096 originalRowspan: '02'
1097 }
1098 },
1099 { type: 'paragraph', internal: { generated: 'wrapper' } },
1100 ...'Quux',
1101 { type: '/paragraph' },
1102 { type: '/tableCell' },
1103 {
1104 type: 'tableCell',
1105 attributes: {
1106 style: 'data',
1107 originalColspan: '2 garbage'
1108 }
1109 },
1110 { type: 'paragraph', internal: { generated: 'wrapper' } },
1111 ...'Whee',
1112 { type: '/paragraph' },
1113 { type: '/tableCell' },
1114 { type: '/tableRow' },
1115 { type: '/tableSection' },
1116 { type: '/table' },
1117 { type: 'internalList' },
1118 { type: '/internalList' }
1119 ];
1120
1121 ve.dm.example.inlineAtEdges = [
1122 // 0
1123 { type: 'paragraph' },
1124 // 1
1125 ve.dm.example.image.data,
1126 // 2
1127 { type: '/inlineImage' },
1128 // 3
1129 ...'Foo',
1130 // 6
1131 { type: 'alienInline', originalDomElements: $.parseHTML( '<foobar />' ) },
1132 // 7
1133 { type: '/alienInline' },
1134 // 8
1135 { type: '/paragraph' },
1136 // 9
1137 { type: 'internalList' },
1138 { type: '/internalList' }
1139 ];
1140
1141 ve.dm.example.annotatedTableHtml = ve.dm.example.singleLine`
1142 <table>
1143 <tr><td><b>Foo</b></td><td><strong>Bar</strong></td><td><i>Baz</i></td></tr>
1144 <tr><td><b><i>Quux</i></b></td><td><strong>Whee</strong></td><td><u>Yay</u></td></tr>
1145 </table>
1146 `;
1147
1148 ve.dm.example.annotatedTable = [
1149 { type: 'table' },
1150 {
1151 type: 'tableSection',
1152 attributes: { style: 'body' }
1153 },
1154 { type: 'tableRow' },
1155 {
1156 type: 'tableCell',
1157 attributes: { style: 'data' }
1158 },
1159 {
1160 type: 'paragraph',
1161 internal: { generated: 'wrapper' }
1162 },
1163 [ 'F', [ ve.dm.example.bold ] ],
1164 [ 'o', [ ve.dm.example.bold ] ],
1165 [ 'o', [ ve.dm.example.bold ] ],
1166 { type: '/paragraph' },
1167 { type: '/tableCell' },
1168 {
1169 type: 'tableCell',
1170 attributes: { style: 'data' }
1171 },
1172 {
1173 type: 'paragraph',
1174 internal: { generated: 'wrapper' }
1175 },
1176 [ 'B', [ ve.dm.example.strong ] ],
1177 [ 'a', [ ve.dm.example.strong ] ],
1178 [ 'r', [ ve.dm.example.strong ] ],
1179 { type: '/paragraph' },
1180 { type: '/tableCell' },
1181 {
1182 type: 'tableCell',
1183 attributes: { style: 'data' }
1184 },
1185 {
1186 type: 'paragraph',
1187 internal: { generated: 'wrapper' }
1188 },
1189 [ 'B', [ ve.dm.example.italic ] ],
1190 [ 'a', [ ve.dm.example.italic ] ],
1191 [ 'z', [ ve.dm.example.italic ] ],
1192 { type: '/paragraph' },
1193 { type: '/tableCell' },
1194 { type: '/tableRow' },
1195 { type: 'tableRow' },
1196 {
1197 type: 'tableCell',
1198 attributes: { style: 'data' }
1199 },
1200 {
1201 type: 'paragraph',
1202 internal: { generated: 'wrapper' }
1203 },
1204 [ 'Q', [ ve.dm.example.bold, ve.dm.example.italic ] ],
1205 [ 'u', [ ve.dm.example.bold, ve.dm.example.italic ] ],
1206 [ 'u', [ ve.dm.example.bold, ve.dm.example.italic ] ],
1207 [ 'x', [ ve.dm.example.bold, ve.dm.example.italic ] ],
1208 { type: '/paragraph' },
1209 { type: '/tableCell' },
1210 {
1211 type: 'tableCell',
1212 attributes: { style: 'data' }
1213 },
1214 {
1215 type: 'paragraph',
1216 internal: { generated: 'wrapper' }
1217 },
1218 [ 'W', [ ve.dm.example.strong ] ],
1219 [ 'h', [ ve.dm.example.strong ] ],
1220 [ 'e', [ ve.dm.example.strong ] ],
1221 [ 'e', [ ve.dm.example.strong ] ],
1222 { type: '/paragraph' },
1223 { type: '/tableCell' },
1224 {
1225 type: 'tableCell',
1226 attributes: { style: 'data' }
1227 },
1228 {
1229 type: 'paragraph',
1230 internal: { generated: 'wrapper' }
1231 },
1232 [ 'Y', [ ve.dm.example.underline ] ],
1233 [ 'a', [ ve.dm.example.underline ] ],
1234 [ 'y', [ ve.dm.example.underline ] ],
1235 { type: '/paragraph' },
1236 { type: '/tableCell' },
1237 { type: '/tableRow' },
1238 { type: '/tableSection' },
1239 { type: '/table' },
1240 { type: 'internalList' },
1241 { type: '/internalList' }
1242 ];
1243
1244 ve.dm.example.figcaptionHtml = ve.dm.example.singleLine`
1245 <p>a</p>
1246 <figure>
1247 ${ ve.dm.example.image.html }
1248 <figcaption><p>b</p></figcaption>
1249 </figure>
1250 <p>c</p>
1251 `;
1252
1253 ve.dm.example.figcaption = [
1254 // 0 - Beginning of paragraph
1255 { type: 'paragraph' },
1256 // 1 - Plain "a"
1257 'a',
1258 // 2 - End of paragraph
1259 { type: '/paragraph' },
1260 // 3 - Beginning of figure
1261 { type: 'blockImage', attributes: ve.dm.example.image.data.attributes },
1262 // 4 - Beginning of figure caption
1263 { type: 'imageCaption' },
1264 // 5 - Beginning of paragraph
1265 { type: 'paragraph' },
1266 // 6 - Plain "b"
1267 'b',
1268 // 7 - End of paragraph
1269 { type: '/paragraph' },
1270 // 8 - End of figure caption
1271 { type: '/imageCaption' },
1272 // 9 - End of figure
1273 { type: '/blockImage' },
1274 // 10 - Beginning of paragraph
1275 { type: 'paragraph' },
1276 // 11 - Plain "c"
1277 'c',
1278 // 12 - End of paragraph
1279 { type: '/paragraph' },
1280 // 13 - Beginning of internalList
1281 { type: 'internalList' },
1282 // 14 - End of internalList
1283 { type: '/internalList' }
1284 // 15 - End of document
1285 ];
1286
1287 ve.dm.example.emptyBranch = [
1288 { type: 'table' },
1289 { type: '/table' },
1290 { type: 'internalList' },
1291 { type: '/internalList' }
1292 ];
1293
1294 /**
1295 * Sample content data index.
1296 *
1297 * This is part of what a ve.dm.DocumentFragment generates when given linear data.
1298 *
1299 * (21) branch nodes
1300 * (01) document node
1301 * (01) heading node
1302 * (01) table node
1303 * (01) tableRow node
1304 * (01) tableCell node
1305 * (06) paragraph nodes
1306 * (03) list nodes
1307 * (03) listItem nodes
1308 * (01) preformatted node
1309 * (01) definitionList node
1310 * (02) definitionListItem nodes
1311 * (10) leaf nodes
1312 * (09) text nodes
1313 * (01) image node
1314 */
1315 ve.dm.example.tree = new ve.dm.DocumentNode( [
1316 // Heading with "abc"
1317 new ve.dm.HeadingNode( ve.dm.example.data[ 0 ], [ new ve.dm.TextNode( 3 ) ] ),
1318 new ve.dm.TableNode( ve.dm.example.data[ 5 ], [
1319 new ve.dm.TableSectionNode( ve.dm.example.data[ 6 ], [
1320 new ve.dm.TableRowNode( ve.dm.example.data[ 7 ], [
1321 new ve.dm.TableCellNode( ve.dm.example.data[ 8 ], [
1322 // Paragraph with "d"
1323 new ve.dm.ParagraphNode( ve.dm.example.data[ 9 ], [ new ve.dm.TextNode( 1 ) ] ),
1324 new ve.dm.ListNode( ve.dm.example.data[ 12 ], [
1325 // 1st level bullet list item with "e"
1326 new ve.dm.ListItemNode( ve.dm.example.data[ 13 ], [
1327 new ve.dm.ParagraphNode(
1328 ve.dm.example.data[ 14 ],
1329 [ new ve.dm.TextNode( 1 ) ]
1330 ),
1331 new ve.dm.ListNode( ve.dm.example.data[ 17 ], [
1332 // 2nd level bullet list item with "f"
1333 new ve.dm.ListItemNode( ve.dm.example.data[ 18 ], [
1334 new ve.dm.ParagraphNode(
1335 ve.dm.example.data[ 19 ],
1336 [ new ve.dm.TextNode( 1 ) ]
1337 )
1338 ] )
1339 ] )
1340 ] )
1341 ] ),
1342 new ve.dm.ListNode( ve.dm.example.data[ 26 ], [
1343 // Numbered list item with "g"
1344 new ve.dm.ListItemNode( ve.dm.example.data[ 27 ], [
1345 new ve.dm.ParagraphNode(
1346 ve.dm.example.data[ 28 ],
1347 [ new ve.dm.TextNode( 1 ) ]
1348 )
1349 ] )
1350 ] )
1351 ] )
1352 ] )
1353 ] )
1354 ] ),
1355 // Preformatted with "h[example.png]i"
1356 new ve.dm.PreformattedNode( ve.dm.example.data[ 37 ], [
1357 new ve.dm.TextNode( 1 ),
1358 new ve.dm.InlineImageNode( ve.dm.example.data[ 39 ] ),
1359 new ve.dm.TextNode( 1 )
1360 ] ),
1361 new ve.dm.DefinitionListNode( ve.dm.example.data[ 43 ], [
1362 // Definition list term item with "j"
1363 new ve.dm.DefinitionListItemNode( ve.dm.example.data[ 44 ], [
1364 new ve.dm.ParagraphNode( ve.dm.example.data[ 45 ], [ new ve.dm.TextNode( 1 ) ] )
1365 ] ),
1366 // Definition list definition item with "k"
1367 new ve.dm.DefinitionListItemNode( ve.dm.example.data[ 49 ], [
1368 new ve.dm.ParagraphNode( ve.dm.example.data[ 50 ], [ new ve.dm.TextNode( 1 ) ] )
1369 ] )
1370 ] ),
1371 new ve.dm.ParagraphNode( ve.dm.example.data[ 55 ], [ new ve.dm.TextNode( 1 ) ] ),
1372 new ve.dm.ParagraphNode( ve.dm.example.data[ 58 ], [ new ve.dm.TextNode( 1 ) ] ),
1373 new ve.dm.InternalListNode( ve.dm.example.data[ 61 ] )
1374 ] );
1375
1376 ve.dm.example.domToDataCases = {
1377 'paragraph with plain text': {
1378 body: '<p>abc</p>',
1379 data: [
1380 { type: 'paragraph' },
1381 ...'abc',
1382 { type: '/paragraph' },
1383 { type: 'internalList' },
1384 { type: '/internalList' }
1385 ]
1386 },
1387 'annotated text with bold, italic, underline formatting': {
1388 body: '<p><b>a</b><i>b</i><u>c</u></p>',
1389 data: [
1390 { type: 'paragraph' },
1391 [ 'a', [ ve.dm.example.bold ] ],
1392 [ 'b', [ ve.dm.example.italic ] ],
1393 [ 'c', [ ve.dm.example.underline ] ],
1394 { type: '/paragraph' },
1395 { type: 'internalList' },
1396 { type: '/internalList' }
1397 ],
1398 ceHtml: ve.dm.example.singleLine`
1399 ${ ve.dm.example.ceParagraph }
1400 <b class="${ ve.dm.example.textStyleClasses } ve-ce-boldAnnotation">a</b>
1401 <i class="${ ve.dm.example.textStyleClasses } ve-ce-italicAnnotation">b</i>
1402 <u class="${ ve.dm.example.textStyleClasses } ve-ce-underlineAnnotation">c</u>
1403 </p>
1404 `
1405 },
1406 'annotation from data': {
1407 data: [
1408 { type: 'paragraph' },
1409 // Annotation without nodeName
1410 [ 'a', [ { type: 'textStyle/bold' } ] ],
1411 { type: '/paragraph' },
1412 { type: 'internalList' },
1413 { type: '/internalList' }
1414 ],
1415 fromDataBody: '<p><b>a</b></p>'
1416 },
1417 'equivalent annotations': {
1418 body: '<p><code>a</code>b<tt>c</tt>d<code>e</code><tt>f</tt></p>',
1419 data: [
1420 { type: 'paragraph' },
1421 [ 'a', [ ve.dm.example.code ] ],
1422 'b',
1423 [ 'c', [ ve.dm.example.tt ] ],
1424 'd',
1425 [ 'e', [ ve.dm.example.code ] ],
1426 [ 'f', [ ve.dm.example.tt ] ],
1427 { type: '/paragraph' },
1428 { type: 'internalList' },
1429 { type: '/internalList' }
1430 ],
1431 fromDataBody: '<p><code>a</code>b<tt>c</tt>d<code>ef</code></p>'
1432 },
1433 'additive annotations': {
1434 body: '<p><big>a<big>b</big>c</big><b>d<b>e</b>f</b></p>',
1435 data: [
1436 { type: 'paragraph' },
1437 [ 'a', [ ve.dm.example.big ] ],
1438 [ 'b', [ ve.dm.example.big, ve.dm.example.big ] ],
1439 [ 'c', [ ve.dm.example.big ] ],
1440 [ 'd', [ ve.dm.example.bold ] ],
1441 [ 'e', [ ve.dm.example.bold, ve.dm.example.bold ] ],
1442 [ 'f', [ ve.dm.example.bold ] ],
1443 { type: '/paragraph' },
1444 { type: 'internalList' },
1445 { type: '/internalList' }
1446 ]
1447 },
1448 'additive annotations overlapping other annotations': {
1449 body: '<p><i><big>a<big><b>b</b></big><b>c</b></big></i></p>',
1450 data: [
1451 { type: 'paragraph' },
1452 [ 'a', [ ve.dm.example.italic, ve.dm.example.big ] ],
1453 [ 'b', [ ve.dm.example.italic, ve.dm.example.big, ve.dm.example.big, ve.dm.example.bold ] ],
1454 [ 'c', [ ve.dm.example.italic, ve.dm.example.big, ve.dm.example.bold ] ],
1455 { type: '/paragraph' },
1456 { type: 'internalList' },
1457 { type: '/internalList' }
1458 ]
1459 },
1460 'annotations normalised on import': {
1461 body: '<p><em>Foo</em><strong>bar</strong></p>',
1462 fromClipboard: true,
1463 data: [
1464 { type: 'paragraph' },
1465 [ 'F', [ ve.dm.example.italic ] ],
1466 [ 'o', [ ve.dm.example.italic ] ],
1467 [ 'o', [ ve.dm.example.italic ] ],
1468 [ 'b', [ ve.dm.example.bold ] ],
1469 [ 'a', [ ve.dm.example.bold ] ],
1470 [ 'r', [ ve.dm.example.bold ] ],
1471 { type: '/paragraph' },
1472 { type: 'internalList' },
1473 { type: '/internalList' }
1474 ],
1475 normalizedBody: '<p><i>Foo</i><b>bar</b></p>'
1476 },
1477 'annotation merging': {
1478 body: '<p><b>abc</b>X<b>def</b><i>ghi</i></p>',
1479 data: [
1480 { type: 'paragraph' },
1481 [ 'a', [ ve.dm.example.bold ] ],
1482 [ 'b', [ ve.dm.example.bold ] ],
1483 [ 'c', [ ve.dm.example.bold ] ],
1484 'X',
1485 [ 'd', [ ve.dm.example.bold ] ],
1486 [ 'e', [ ve.dm.example.bold ] ],
1487 [ 'f', [ ve.dm.example.bold ] ],
1488 [ 'g', [ ve.dm.example.italic ] ],
1489 [ 'h', [ ve.dm.example.italic ] ],
1490 [ 'i', [ ve.dm.example.italic ] ],
1491 { type: '/paragraph' },
1492 { type: 'internalList' },
1493 { type: '/internalList' }
1494 ],
1495 modify: function ( doc ) {
1496 doc.commit( ve.dm.TransactionBuilder.static.newFromRemoval(
1497 doc,
1498 new ve.Range( 4, 5 )
1499 ) );
1500 },
1501 normalizedBody: '<p><b>abcdef</b><i>ghi</i></p>',
1502 fromDataBody: '<p><b>abcdef</b><i>ghi</i></p>'
1503 },
1504 'language annotation': {
1505 body: ve.dm.example.singleLine`
1506 <p>
1507 <span lang="en">ten</span>
1508 <span lang="fr" dir="ltr">dix</span>
1509 <bdo lang="cy" dir="ltr">deg</bdo>
1510 <span dir="rtl">12</span>
1511 <span dir="RtL">34</span>
1512 </p>
1513 `,
1514 data: [
1515 { type: 'paragraph' },
1516 [ 't', [ ve.dm.example.language( 'en', null ) ] ],
1517 [ 'e', [ ve.dm.example.language( 'en', null ) ] ],
1518 [ 'n', [ ve.dm.example.language( 'en', null ) ] ],
1519 [ 'd', [ ve.dm.example.language( 'fr', 'ltr' ) ] ],
1520 [ 'i', [ ve.dm.example.language( 'fr', 'ltr' ) ] ],
1521 [ 'x', [ ve.dm.example.language( 'fr', 'ltr' ) ] ],
1522 [ 'd', [ ve.dm.example.language( 'cy', 'ltr', 'bdo' ) ] ],
1523 [ 'e', [ ve.dm.example.language( 'cy', 'ltr', 'bdo' ) ] ],
1524 [ 'g', [ ve.dm.example.language( 'cy', 'ltr', 'bdo' ) ] ],
1525 [ '1', [ ve.dm.example.language( null, 'rtl' ) ] ],
1526 [ '2', [ ve.dm.example.language( null, 'rtl' ) ] ],
1527 [ '3', [ ve.dm.example.language( null, 'RtL' ) ] ],
1528 [ '4', [ ve.dm.example.language( null, 'RtL' ) ] ],
1529 { type: '/paragraph' },
1530 { type: 'internalList' },
1531 { type: '/internalList' }
1532 ],
1533 ceHtml: ve.dm.example.singleLine`
1534 ${ ve.dm.example.ceParagraph }
1535 <span class="${ ve.dm.example.textStyleClasses } ve-ce-languageAnnotation ve-ce-bidi-isolate" lang="en" title="visualeditor-languageannotation-description,langname-en">ten</span>
1536 <span class="${ ve.dm.example.textStyleClasses } ve-ce-languageAnnotation ve-ce-bidi-isolate" lang="fr" dir="ltr" title="visualeditor-languageannotation-description,langname-fr">dix</span>
1537 <bdo class="${ ve.dm.example.textStyleClasses } ve-ce-languageAnnotation ve-ce-bidi-isolate" lang="cy" dir="ltr" title="visualeditor-languageannotation-description,langname-cy">deg</bdo>
1538 <span class="${ ve.dm.example.textStyleClasses } ve-ce-languageAnnotation ve-ce-bidi-isolate" dir="rtl" title="visualeditor-languageannotation-description-with-dir,langname-,RTL">12</span>
1539 <span class="${ ve.dm.example.textStyleClasses } ve-ce-languageAnnotation ve-ce-bidi-isolate" dir="RtL" title="visualeditor-languageannotation-description-with-dir,langname-,RTL">34</span>
1540 </p>
1541 `
1542 },
1543 'datetime annotation': {
1544 body:
1545 ve.dm.example.singleLine`
1546 <p>
1547 <time>a</time>
1548 <time datetime="2001-05-15T19:00">b</time>
1549 </p>
1550 `,
1551 data: [
1552 { type: 'paragraph' },
1553 [ 'a', [ { type: 'textStyle/datetime', attributes: { nodeName: 'time', datetime: null } } ] ],
1554 [ 'b', [ { type: 'textStyle/datetime', attributes: { nodeName: 'time', datetime: '2001-05-15T19:00' } } ] ],
1555 { type: '/paragraph' },
1556 { type: 'internalList' },
1557 { type: '/internalList' }
1558 ],
1559 ceHtml: ve.dm.example.singleLine`
1560 ${ ve.dm.example.ceParagraph }
1561 <time class="${ ve.dm.example.textStyleClasses } ve-ce-datetimeAnnotation">a</time>
1562 <time class="${ ve.dm.example.textStyleClasses } ve-ce-datetimeAnnotation">b</time>
1563 </p>
1564 `
1565 },
1566 'comment annotation': {
1567 body: ve.dm.example.singleLine`
1568 <p>
1569 <span rel="ve:CommentAnnotation" data-text="Test">a</span>
1570 </p>
1571 `,
1572 data: [
1573 { type: 'paragraph' },
1574 [ 'a', [ { type: 'commentAnnotation', attributes: { text: 'Test' } } ] ],
1575 { type: '/paragraph' },
1576 { type: 'internalList' },
1577 { type: '/internalList' }
1578 ],
1579 ceHtml: ve.dm.example.singleLine`
1580 ${ ve.dm.example.ceParagraph }
1581 <span class="ve-ce-annotation ve-ce-commentAnnotation">a</span>
1582 </p>
1583 `,
1584 normalizedBody: '<p>a</p>',
1585 clipboardBody: ve.dm.example.singleLine`
1586 <p>
1587 <span rel="ve:CommentAnnotation" data-text="Test">a</span>
1588 </p>
1589 `,
1590 previewBody: '<p>a</p>'
1591 },
1592 'other textStyle annotations': {
1593 body: ve.dm.example.singleLine`
1594 <p>
1595 <abbr>a</abbr>
1596 <var>b</var>
1597 <kbd>c</kbd>
1598 <q>d</q>
1599 <samp>e</samp>
1600 <dfn>f</dfn>
1601 <mark>g</mark>
1602 <font>h</font>
1603 <bdi>i</bdi>
1604 </p>
1605 `,
1606 data: [
1607 { type: 'paragraph' },
1608 [ 'a', [ { type: 'textStyle/abbreviation', attributes: { nodeName: 'abbr' } } ] ],
1609 [ 'b', [ { type: 'textStyle/variable', attributes: { nodeName: 'var' } } ] ],
1610 [ 'c', [ { type: 'textStyle/userInput', attributes: { nodeName: 'kbd' } } ] ],
1611 [ 'd', [ { type: 'textStyle/quotation', attributes: { nodeName: 'q' } } ] ],
1612 [ 'e', [ { type: 'textStyle/codeSample', attributes: { nodeName: 'samp' } } ] ],
1613 [ 'f', [ { type: 'textStyle/definition', attributes: { nodeName: 'dfn' } } ] ],
1614 [ 'g', [ { type: 'textStyle/highlight', attributes: { nodeName: 'mark' } } ] ],
1615 [ 'h', [ { type: 'textStyle/font', attributes: { nodeName: 'font' } } ] ],
1616 [ 'i', [ { type: 'textStyle/bidi', attributes: { nodeName: 'bdi' } } ] ],
1617 { type: '/paragraph' },
1618 { type: 'internalList' },
1619 { type: '/internalList' }
1620 ],
1621 ceHtml: ve.dm.example.singleLine`
1622 ${ ve.dm.example.ceParagraph }
1623 <abbr class="${ ve.dm.example.textStyleClasses } ve-ce-abbreviationAnnotation">a</abbr>
1624 <var class="${ ve.dm.example.textStyleClasses } ve-ce-variableAnnotation">b</var>
1625 <kbd class="${ ve.dm.example.textStyleClasses } ve-ce-userInputAnnotation">c</kbd>
1626 <q class="${ ve.dm.example.textStyleClasses } ve-ce-quotationAnnotation">d</q>
1627 <samp class="${ ve.dm.example.textStyleClasses } ve-ce-codeSampleAnnotation">e</samp>
1628 <dfn class="${ ve.dm.example.textStyleClasses } ve-ce-definitionAnnotation">f</dfn>
1629 <mark class="${ ve.dm.example.textStyleClasses } ve-ce-highlightAnnotation">g</mark>
1630 <font class="${ ve.dm.example.textStyleClasses } ve-ce-fontAnnotation">h</font>
1631 <bdi class="${ ve.dm.example.textStyleClasses } ve-ce-bidiAnnotation">i</bdi>
1632 </p>
1633 `
1634 },
1635 'check list': {
1636 body: ve.dm.example.singleLine`
1637 <ul rel="ve:checkList">
1638 <li rel="ve:checkList" data-checked="checked"><p>foo</p></li>
1639 <li rel="ve:checkList">bar</li>
1640 </ul>
1641 `,
1642 data: [
1643 { type: 'checkList' },
1644 { type: 'checkListItem', attributes: { checked: true } },
1645 { type: 'paragraph' },
1646 ...'foo',
1647 { type: '/paragraph' },
1648 { type: '/checkListItem' },
1649 { type: 'checkListItem', attributes: { checked: false } },
1650 { type: 'paragraph', internal: { generated: 'wrapper' } },
1651 ...'bar',
1652 { type: '/paragraph' },
1653 { type: '/checkListItem' },
1654 { type: '/checkList' },
1655 { type: 'internalList' },
1656 { type: '/internalList' }
1657 ],
1658 ceHtml: ve.dm.example.singleLine`
1659 ${ ve.dm.example.blockSlug }
1660 <ul class="ve-ce-branchNode ve-ce-checkListNode">
1661 <li class="ve-ce-branchNode ve-ce-checkListItemNode ve-ce-checkListItemNode-checked">
1662 ${ ve.dm.example.ceParagraph }foo</p>
1663 </li>
1664 <li class="ve-ce-branchNode ve-ce-checkListItemNode">
1665 ${ ve.dm.example.ceWrapperParagraph }bar</p>
1666 </li>
1667 </ul>
1668 `,
1669 normalizedBody: ve.dm.example.singleLine`
1670 <ul rel="ve:checkList">
1671 <li rel="ve:checkList" data-checked="checked"><p>☑ foo</p></li>
1672 <li rel="ve:checkList">☐ bar</li>
1673 </ul>
1674 `,
1675 clipboardBody: ve.dm.example.singleLine`
1676 <ul rel="ve:checkList">
1677 <li rel="ve:checkList" data-checked="checked" style="list-style: none;"><p><span data-ve-ignore="true">☑</span> foo</p></li>
1678 <li rel="ve:checkList" style="list-style: none;"><span data-ve-ignore="true">☐</span> bar</li>
1679 </ul>
1680 `
1681 },
1682 'strip leading whitespace in non-whitespace preserving nodes': {
1683 // T53462/T142132
1684 data: [
1685 { type: 'paragraph' },
1686 ...' foo',
1687 { type: '/paragraph' },
1688 { type: 'paragraph' },
1689 ...' \t \tbar',
1690 { type: '/paragraph' },
1691 { type: 'heading', attributes: { level: 2 } },
1692 ...' baz',
1693 { type: '/heading' },
1694 { type: 'preformatted' },
1695 ...' \tquux',
1696 { type: '/preformatted' },
1697 { type: 'internalList' },
1698 { type: '/internalList' }
1699 ],
1700 normalizedBody: '<p>foo</p><p>bar</p><h2>baz</h2><pre> \tquux</pre>',
1701 clipboardBody: '<p> foo</p><p> \t \tbar</p><h2> baz</h2><pre> \tquux</pre>',
1702 previewBody: '<p> foo</p><p> ➞ ➞bar</p><h2> baz</h2><pre> \tquux</pre>'
1703 },
1704 image: {
1705 body: ve.dm.example.image.html,
1706 data: [
1707 { type: 'paragraph', internal: { generated: 'wrapper' } },
1708 ve.dm.example.image.data,
1709 { type: '/inlineImage' },
1710 { type: '/paragraph' },
1711 { type: 'internalList' },
1712 { type: '/internalList' }
1713 ],
1714 ceHtml: ve.dm.example.singleLine`
1715 ${ ve.dm.example.ceWrapperParagraph }
1716 ${ ve.dm.example.inlineSlug }
1717 <img class="ve-ce-leafNode ve-ce-focusableNode ve-ce-imageNode ve-ce-inlineImageNode" contenteditable="false" alt="Example"
1718 src="${ ve.dm.example.imgSrc }" style="width: 100px; height: 50px;">
1719 ${ ve.dm.example.inlineSlug }
1720 </p>
1721 `
1722 },
1723 'block images': {
1724 body: ve.dm.example.blockImage.html + ve.dm.example.blockImage.html,
1725 data: [
1726 ...ve.dm.example.blockImage.data,
1727 ...ve.dm.example.blockImage.data,
1728 { type: 'internalList' },
1729 { type: '/internalList' }
1730 ],
1731 ceHtml: ve.dm.example.blockSlug +
1732 ve.dm.example.blockImage.ceHtml +
1733 // No block slug between two floated images
1734 ve.dm.example.blockImage.ceHtml +
1735 ve.dm.example.blockSlug
1736 },
1737 'block image modified': {
1738 body: ve.dm.example.blockImage.html,
1739 data: [
1740 ...ve.dm.example.blockImage.data,
1741 { type: 'internalList' },
1742 { type: '/internalList' }
1743 ],
1744 modify: function ( doc ) {
1745 doc.commit( ve.dm.TransactionBuilder.static.newFromAnnotation(
1746 doc,
1747 new ve.Range( 3, 6 ),
1748 'set',
1749 ve.dm.example.createAnnotation( ve.dm.example.bold, doc.getStore() )
1750 ) );
1751 },
1752 normalizedBody: ve.dm.example.singleLine`
1753 <figure class="ve-align-right"><img src="${ ve.dm.example.imgSrc }" width="100" height="50" alt="Example">
1754 <figcaption>
1755 <b>foo</b> <b style="color:red;">red</b>
1756 </figcaption>
1757 </figure>
1758 `
1759 },
1760 'block image with no caption': {
1761 body: '<figure><img></figure>',
1762 data: [
1763 {
1764 type: 'blockImage',
1765 attributes: {
1766 width: null,
1767 height: null,
1768 src: null,
1769 alt: null
1770 }
1771 },
1772 { type: 'imageCaption' },
1773 { type: '/imageCaption' },
1774 { type: '/blockImage' },
1775 { type: 'internalList' },
1776 { type: '/internalList' }
1777 ]
1778 },
1779 'paragraph with alienInline inside': {
1780 body: '<p>a<foobar class="foo">b</foobar>c</p>',
1781 data: [
1782 { type: 'paragraph' },
1783 'a',
1784 {
1785 type: 'alienInline',
1786 originalDomElements: $.parseHTML( '<foobar class="foo">b</foobar>' )
1787 },
1788 { type: '/alienInline' },
1789 'c',
1790 { type: '/paragraph' },
1791 { type: 'internalList' },
1792 { type: '/internalList' }
1793 ]
1794 },
1795 'paragraphs with an alienBlock between them': {
1796 body: '<p>abc</p><div rel="ve:Alien">abc</div><p>def</p>',
1797 data: [
1798 { type: 'paragraph' },
1799 ...'abc',
1800 { type: '/paragraph' },
1801 { type: 'alienBlock', originalDomElements: $.parseHTML( '<div rel="ve:Alien">abc</div>' ) },
1802 { type: '/alienBlock' },
1803 { type: 'paragraph' },
1804 ...'def',
1805 { type: '/paragraph' },
1806 { type: 'internalList' },
1807 { type: '/internalList' }
1808 ]
1809 },
1810 'annotated inline nodes': {
1811 body: ve.dm.example.singleLine`
1812 <p>
1813 a
1814 <b>
1815 <foobar class="foo">b</foobar>
1816 <i>
1817 <foobar class="bar">c</foobar>
1818 </i>
1819 </b>
1820 <i><br/>d</i>
1821 e
1822 </p>
1823 `,
1824 data: [
1825 { type: 'paragraph' },
1826 'a',
1827 {
1828 type: 'alienInline',
1829 originalDomElements: $.parseHTML( '<foobar class="foo">b</foobar>' ),
1830 annotations: [ ve.dm.example.bold ]
1831 },
1832 { type: '/alienInline' },
1833 {
1834 type: 'alienInline',
1835 originalDomElements: $.parseHTML( '<foobar class="bar">c</foobar>' ),
1836 annotations: [ ve.dm.example.bold, ve.dm.example.italic ]
1837 },
1838 { type: '/alienInline' },
1839 {
1840 type: 'break',
1841 annotations: [ ve.dm.example.italic ]
1842 },
1843 { type: '/break' },
1844 [ 'd', [ ve.dm.example.italic ] ],
1845 'e',
1846 { type: '/paragraph' },
1847 { type: 'internalList' },
1848 { type: '/internalList' }
1849 ]
1850 },
1851 'annotated comments': {
1852 body: '<p><b><!--foo-->bar<!--baz--></b></p>',
1853 data: [
1854 { type: 'paragraph' },
1855 {
1856 type: 'comment',
1857 annotations: [ ve.dm.example.bold ],
1858 attributes: {
1859 text: 'foo'
1860 }
1861 },
1862 { type: '/comment' },
1863 [ 'b', [ ve.dm.example.bold ] ],
1864 [ 'a', [ ve.dm.example.bold ] ],
1865 [ 'r', [ ve.dm.example.bold ] ],
1866 {
1867 type: 'comment',
1868 annotations: [ ve.dm.example.bold ],
1869 attributes: {
1870 text: 'baz'
1871 }
1872 },
1873 { type: '/comment' },
1874 { type: '/paragraph' },
1875 { type: 'internalList' },
1876 { type: '/internalList' }
1877 ],
1878 clipboardBody: ve.dm.example.singleLine`
1879 <p>
1880 <b>
1881 <span rel="ve:Comment" data-ve-comment="foo">&nbsp;</span>
1882 bar
1883 <span rel="ve:Comment" data-ve-comment="baz">&nbsp;</span>
1884 </b>
1885 </p>
1886 `,
1887 previewBody: ve.dm.example.singleLine`
1888 <p>
1889 <b>
1890 ${ ve.dm.example.commentNodePreview( 'foo' ) }
1891 bar
1892 ${ ve.dm.example.commentNodePreview( 'baz' ) }
1893 </b>
1894 </p>
1895 `,
1896 ceHtml: ve.dm.example.singleLine`
1897 ${ ve.dm.example.ceParagraph }
1898 <b class="${ ve.dm.example.textStyleClasses } ve-ce-boldAnnotation">
1899 ${ ve.dm.example.inlineSlug }
1900 <span class="ve-ce-leafNode ve-ce-focusableNode ve-ce-commentNode" contenteditable="false"></span>
1901 bar
1902 <span class="ve-ce-leafNode ve-ce-focusableNode ve-ce-commentNode" contenteditable="false"></span>
1903 </b>
1904 ${ ve.dm.example.inlineSlug }
1905 </p>
1906 `
1907 },
1908 'annotated metadata': {
1909 body: '<p><b><meta />bar<meta /></b></p>',
1910 data: [
1911 { type: 'paragraph' },
1912 {
1913 type: 'alienMeta',
1914 annotations: [ ve.dm.example.bold ],
1915 originalDomElements: $.parseHTML( '<meta />' )
1916 },
1917 { type: '/alienMeta' },
1918 [ 'b', [ ve.dm.example.bold ] ],
1919 [ 'a', [ ve.dm.example.bold ] ],
1920 [ 'r', [ ve.dm.example.bold ] ],
1921 {
1922 type: 'alienMeta',
1923 annotations: [ ve.dm.example.bold ],
1924 originalDomElements: $.parseHTML( '<meta />' )
1925 },
1926 { type: '/alienMeta' },
1927 { type: '/paragraph' },
1928 { type: 'internalList' },
1929 { type: '/internalList' }
1930 ],
1931 realData: [
1932 { type: 'paragraph' },
1933 [ 'b', [ ve.dm.example.bold ] ],
1934 [ 'a', [ ve.dm.example.bold ] ],
1935 [ 'r', [ ve.dm.example.bold ] ],
1936 { type: '/paragraph' },
1937 {
1938 type: 'alienMeta',
1939 annotations: [ ve.dm.example.bold ],
1940 originalDomElements: $.parseHTML( '<meta />' )
1941 },
1942 { type: '/alienMeta' },
1943 {
1944 type: 'alienMeta',
1945 annotations: [ ve.dm.example.bold ],
1946 originalDomElements: $.parseHTML( '<meta />' )
1947 },
1948 { type: '/alienMeta' },
1949 { type: 'internalList' },
1950 { type: '/internalList' }
1951 ]
1952 },
1953 'annotated metadata in a wrapper': {
1954 body: '<b><meta />bar<meta />quux<meta /></b>',
1955 data: [
1956 { type: 'paragraph', internal: { generated: 'wrapper' } },
1957 {
1958 type: 'alienMeta',
1959 annotations: [ ve.dm.example.bold ],
1960 originalDomElements: $.parseHTML( '<meta />' )
1961 },
1962 { type: '/alienMeta' },
1963 [ 'b', [ ve.dm.example.bold ] ],
1964 [ 'a', [ ve.dm.example.bold ] ],
1965 [ 'r', [ ve.dm.example.bold ] ],
1966 {
1967 type: 'alienMeta',
1968 annotations: [ ve.dm.example.bold ],
1969 originalDomElements: $.parseHTML( '<meta />' )
1970 },
1971 { type: '/alienMeta' },
1972 [ 'q', [ ve.dm.example.bold ] ],
1973 [ 'u', [ ve.dm.example.bold ] ],
1974 [ 'u', [ ve.dm.example.bold ] ],
1975 [ 'x', [ ve.dm.example.bold ] ],
1976 {
1977 type: 'alienMeta',
1978 annotations: [ ve.dm.example.bold ],
1979 originalDomElements: $.parseHTML( '<meta />' )
1980 },
1981 { type: '/alienMeta' },
1982 { type: '/paragraph' },
1983 { type: 'internalList' },
1984 { type: '/internalList' }
1985 ],
1986 realData: [
1987 { type: 'paragraph', internal: { generated: 'wrapper' } },
1988 [ 'b', [ ve.dm.example.bold ] ],
1989 [ 'a', [ ve.dm.example.bold ] ],
1990 [ 'r', [ ve.dm.example.bold ] ],
1991 [ 'q', [ ve.dm.example.bold ] ],
1992 [ 'u', [ ve.dm.example.bold ] ],
1993 [ 'u', [ ve.dm.example.bold ] ],
1994 [ 'x', [ ve.dm.example.bold ] ],
1995 { type: '/paragraph' },
1996 {
1997 type: 'alienMeta',
1998 annotations: [ ve.dm.example.bold ],
1999 originalDomElements: $.parseHTML( '<meta />' )
2000 },
2001 { type: '/alienMeta' },
2002 {
2003 type: 'alienMeta',
2004 annotations: [ ve.dm.example.bold ],
2005 originalDomElements: $.parseHTML( '<meta />' )
2006 },
2007 { type: '/alienMeta' },
2008 {
2009 type: 'alienMeta',
2010 annotations: [ ve.dm.example.bold ],
2011 originalDomElements: $.parseHTML( '<meta />' )
2012 },
2013 { type: '/alienMeta' },
2014 { type: 'internalList' },
2015 { type: '/internalList' }
2016 ]
2017 },
2018 'annotated element metadata in a wrapper with content': {
2019 body: '<b><link />foo<link /></b>',
2020 data: [
2021 { type: 'paragraph', internal: { generated: 'wrapper' } },
2022 {
2023 type: 'alienMeta',
2024 annotations: [ ve.dm.example.bold ],
2025 originalDomElements: $.parseHTML( '<link />' )
2026 },
2027 { type: '/alienMeta' },
2028 [ 'f', [ ve.dm.example.bold ] ],
2029 [ 'o', [ ve.dm.example.bold ] ],
2030 [ 'o', [ ve.dm.example.bold ] ],
2031 {
2032 type: 'alienMeta',
2033 annotations: [ ve.dm.example.bold ],
2034 originalDomElements: $.parseHTML( '<link />' )
2035 },
2036 { type: '/alienMeta' },
2037 { type: '/paragraph' },
2038 { type: 'internalList' },
2039 { type: '/internalList' }
2040 ],
2041 realData: [
2042 { type: 'paragraph', internal: { generated: 'wrapper' } },
2043 [ 'f', [ ve.dm.example.bold ] ],
2044 [ 'o', [ ve.dm.example.bold ] ],
2045 [ 'o', [ ve.dm.example.bold ] ],
2046 { type: '/paragraph' },
2047 {
2048 type: 'alienMeta',
2049 annotations: [ ve.dm.example.bold ],
2050 originalDomElements: $.parseHTML( '<link />' )
2051 },
2052 { type: '/alienMeta' },
2053 {
2054 type: 'alienMeta',
2055 annotations: [ ve.dm.example.bold ],
2056 originalDomElements: $.parseHTML( '<link />' )
2057 },
2058 { type: '/alienMeta' },
2059 { type: 'internalList' },
2060 { type: '/internalList' }
2061 ]
2062 },
2063 'metadata in a wrapper followed by annotated text': {
2064 body: 'Foo<meta /><b>Baz</b>',
2065 data: [
2066 { type: 'paragraph', internal: { generated: 'wrapper' } },
2067 ...'Foo',
2068 {
2069 type: 'alienMeta',
2070 originalDomElements: $.parseHTML( '<meta />' )
2071 },
2072 { type: '/alienMeta' },
2073 [ 'B', [ ve.dm.example.bold ] ],
2074 [ 'a', [ ve.dm.example.bold ] ],
2075 [ 'z', [ ve.dm.example.bold ] ],
2076 { type: '/paragraph' },
2077 { type: 'internalList' },
2078 { type: '/internalList' }
2079 ],
2080 realData: [
2081 { type: 'paragraph', internal: { generated: 'wrapper' } },
2082 ...'Foo',
2083 [ 'B', [ ve.dm.example.bold ] ],
2084 [ 'a', [ ve.dm.example.bold ] ],
2085 [ 'z', [ ve.dm.example.bold ] ],
2086 { type: '/paragraph' },
2087 {
2088 type: 'alienMeta',
2089 originalDomElements: $.parseHTML( '<meta />' )
2090 },
2091 { type: '/alienMeta' },
2092 { type: 'internalList' },
2093 { type: '/internalList' }
2094 ]
2095 },
2096 'wrapping of bare content': {
2097 body: 'abc',
2098 data: [
2099 { type: 'paragraph', internal: { generated: 'wrapper' } },
2100 ...'abc',
2101 { type: '/paragraph' },
2102 { type: 'internalList' },
2103 { type: '/internalList' }
2104 ]
2105 },
2106 'wrapping of bare content with inline node': {
2107 body: '1<br/>2',
2108 data: [
2109 { type: 'paragraph', internal: { generated: 'wrapper' } },
2110 '1',
2111 { type: 'break' },
2112 { type: '/break' },
2113 '2',
2114 { type: '/paragraph' },
2115 { type: 'internalList' },
2116 { type: '/internalList' }
2117 ]
2118 },
2119 'wrapping of bare content starting with inline node': {
2120 body: ve.dm.example.image.html + '12',
2121 data: [
2122 { type: 'paragraph', internal: { generated: 'wrapper' } },
2123 ve.dm.example.image.data,
2124 { type: '/inlineImage' },
2125 ...'12',
2126 { type: '/paragraph' },
2127 { type: 'internalList' },
2128 { type: '/internalList' }
2129 ]
2130 },
2131 'wrapping of bare content with inline alien': {
2132 body: '1<foobar class="bar">baz</foobar>2',
2133 data: [
2134 { type: 'paragraph', internal: { generated: 'wrapper' } },
2135 '1',
2136 {
2137 type: 'alienInline',
2138 originalDomElements: $.parseHTML( '<foobar class="bar">baz</foobar>' )
2139 },
2140 { type: '/alienInline' },
2141 '2',
2142 { type: '/paragraph' },
2143 { type: 'internalList' },
2144 { type: '/internalList' }
2145 ]
2146 },
2147 'wrapping of bare content with block alien': {
2148 body: '1<div rel="ve:Alien" class="bar">baz</div>2',
2149 data: [
2150 { type: 'paragraph', internal: { generated: 'wrapper' } },
2151 '1',
2152 { type: '/paragraph' },
2153 {
2154 type: 'alienBlock',
2155 originalDomElements: $.parseHTML( '<div rel="ve:Alien" class="bar">baz</div>' )
2156 },
2157 { type: '/alienBlock' },
2158 { type: 'paragraph', internal: { generated: 'wrapper' } },
2159 '2',
2160 { type: '/paragraph' },
2161 { type: 'internalList' },
2162 { type: '/internalList' }
2163 ]
2164 },
2165 'wrapping of bare content starting with inline alien': {
2166 body: '<foobar class="bar">Foo</foobar>Bar',
2167 data: [
2168 { type: 'paragraph', internal: { generated: 'wrapper' } },
2169 {
2170 type: 'alienInline',
2171 originalDomElements: $.parseHTML( '<foobar class="bar">Foo</foobar>' )
2172 },
2173 { type: '/alienInline' },
2174 ...'Bar',
2175 { type: '/paragraph' },
2176 { type: 'internalList' },
2177 { type: '/internalList' }
2178 ]
2179 },
2180 'wrapping of bare content ending with inline alien': {
2181 body: 'Foo<foobar class="bar">Bar</foobar>',
2182 data: [
2183 { type: 'paragraph', internal: { generated: 'wrapper' } },
2184 ...'Foo',
2185 {
2186 type: 'alienInline',
2187 originalDomElements: $.parseHTML( '<foobar class="bar">Bar</foobar>' )
2188 },
2189 { type: '/alienInline' },
2190 { type: '/paragraph' },
2191 { type: 'internalList' },
2192 { type: '/internalList' }
2193 ]
2194 },
2195 'wrapping of bare content with about group': {
2196 body: '1<foobar about="#vet1">foo</foobar><foobar about="#vet1">bar</foobar>2',
2197 data: [
2198 { type: 'paragraph', internal: { generated: 'wrapper' } },
2199 '1',
2200 {
2201 type: 'alienInline',
2202 originalDomElements: $.parseHTML( '<foobar about="#vet1">foo</foobar><foobar about="#vet1">bar</foobar>' )
2203 },
2204 { type: '/alienInline' },
2205 '2',
2206 { type: '/paragraph' },
2207 { type: 'internalList' },
2208 { type: '/internalList' }
2209 ]
2210 },
2211 'wrapping of bare content between structural nodes': {
2212 body: '<table></table>abc<table></table>',
2213 data: [
2214 { type: 'table' },
2215 { type: '/table' },
2216 { type: 'paragraph', internal: { generated: 'wrapper' } },
2217 ...'abc',
2218 { type: '/paragraph' },
2219 { type: 'table' },
2220 { type: '/table' },
2221 { type: 'internalList' },
2222 { type: '/internalList' }
2223 ]
2224 },
2225 'wrapping of bare content between paragraphs': {
2226 body: '<p>abc</p>def<p></p>',
2227 data: [
2228 { type: 'paragraph' },
2229 ...'abc',
2230 { type: '/paragraph' },
2231 { type: 'paragraph', internal: { generated: 'wrapper' } },
2232 ...'def',
2233 { type: '/paragraph' },
2234 { type: 'paragraph' },
2235 { type: '/paragraph' },
2236 { type: 'internalList' },
2237 { type: '/internalList' }
2238 ]
2239 },
2240 'wrapping prevents empty list items': {
2241 body: '<ul><li></li></ul>',
2242 data: [
2243 { type: 'list', attributes: { style: 'bullet' } },
2244 { type: 'listItem' },
2245 { type: 'paragraph', internal: { generated: 'wrapper' } },
2246 { type: '/paragraph' },
2247 { type: '/listItem' },
2248 { type: '/list' },
2249 { type: 'internalList' },
2250 { type: '/internalList' }
2251 ],
2252 // Inserting content doesn't result in a real <p> node
2253 modify: function ( doc ) {
2254 doc.commit( ve.dm.TransactionBuilder.static.newFromInsertion(
2255 doc,
2256 3,
2257 'Foo'
2258 ) );
2259 },
2260 normalizedBody: '<ul><li>Foo</li></ul>',
2261 fromDataBody: '<ul><li>Foo</li></ul>'
2262 },
2263 'empty document': {
2264 body: '',
2265 data: [
2266 { type: 'paragraph', internal: { generated: 'empty' } },
2267 { type: '/paragraph' },
2268 { type: 'internalList' },
2269 { type: '/internalList' }
2270 ]
2271 },
2272 'empty document with meta': {
2273 body: '<meta />',
2274 data: [
2275 {
2276 type: 'alienMeta',
2277 originalDomElements: $.parseHTML( '<meta />' )
2278 },
2279 { type: '/alienMeta' },
2280 { type: 'paragraph', internal: { generated: 'empty' } },
2281 { type: '/paragraph' },
2282 { type: 'internalList' },
2283 { type: '/internalList' }
2284 ]
2285 },
2286 'empty document with comment': {
2287 body: '<!-- comment -->',
2288 data: [
2289 { type: 'paragraph', internal: { generated: 'wrapper' } },
2290 {
2291 type: 'comment',
2292 attributes: {
2293 text: ' comment '
2294 }
2295 },
2296 { type: '/comment' },
2297 { type: '/paragraph' },
2298 { type: 'internalList' },
2299 { type: '/internalList' }
2300 ],
2301 clipboardBody: '<span rel="ve:Comment" data-ve-comment=" comment ">&nbsp;</span>',
2302 previewBody: ve.dm.example.commentNodePreview( ' comment ' )
2303 },
2304 'empty document with content added by the editor': {
2305 data: [
2306 { type: 'paragraph', internal: { generated: 'empty' } },
2307 ...'Foo',
2308 { type: '/paragraph' },
2309 { type: 'internalList' },
2310 { type: '/internalList' }
2311 ],
2312 normalizedBody: '<p>Foo</p>'
2313 },
2314 'empty list item with content added by the editor': {
2315 data: [
2316 { type: 'list', attributes: { style: 'bullet' } },
2317 { type: 'listItem' },
2318 { type: 'paragraph', internal: { generated: 'empty' } },
2319 ...'Foo',
2320 { type: '/paragraph' },
2321 { type: '/listItem' },
2322 { type: '/list' },
2323 { type: 'internalList' },
2324 { type: '/internalList' }
2325 ],
2326 normalizedBody: '<ul><li><p>Foo</p></li></ul>'
2327 },
2328 'slug paragraph added between two nodes that had whitespace': {
2329 data: [
2330 { type: 'table', internal: { whitespace: [ undefined, undefined, undefined, '\n' ] } },
2331 { type: '/table' },
2332 { type: 'paragraph', internal: { generated: 'slug' } },
2333 { type: '/paragraph' },
2334 { type: 'table', internal: { whitespace: [ '\n' ] } },
2335 { type: '/table' },
2336 { type: 'internalList' },
2337 { type: '/internalList' }
2338 ],
2339 normalizedBody: '<table></table>\n<table></table>'
2340 },
2341 'example document': {
2342 body: ve.dm.example.html,
2343 data: ve.dm.example.data
2344 },
2345 'example document (figure/figcaption)': {
2346 body: ve.dm.example.figcaptionHtml,
2347 data: ve.dm.example.figcaption
2348 },
2349 'empty annotation': {
2350 body: '<p>Foo<span id="anchorTarget"></span>Bar</p>',
2351 data: [
2352 { type: 'paragraph' },
2353 ...'Foo',
2354 {
2355 type: 'removableAlienMeta',
2356 originalDomElements: $.parseHTML( '<span id="anchorTarget"></span>' )
2357 },
2358 { type: '/removableAlienMeta' },
2359 ...'Bar',
2360 { type: '/paragraph' },
2361 { type: 'internalList' },
2362 { type: '/internalList' }
2363 ],
2364 realData: [
2365 { type: 'paragraph' },
2366 ...'Foo',
2367 ...'Bar',
2368 { type: '/paragraph' },
2369 {
2370 type: 'removableAlienMeta',
2371 originalDomElements: $.parseHTML( '<span id="anchorTarget"></span>' )
2372 },
2373 { type: '/removableAlienMeta' },
2374 { type: 'internalList' },
2375 { type: '/internalList' }
2376 ]
2377 },
2378 'empty annotation in wrapper paragraph': {
2379 body: 'Foo<span id="anchorTarget"></span>Bar',
2380 data: [
2381 { type: 'paragraph', internal: { generated: 'wrapper' } },
2382 ...'Foo',
2383 {
2384 type: 'removableAlienMeta',
2385 originalDomElements: $.parseHTML( '<span id="anchorTarget"></span>' )
2386 },
2387 { type: '/removableAlienMeta' },
2388 ...'Bar',
2389 { type: '/paragraph' },
2390 { type: 'internalList' },
2391 { type: '/internalList' }
2392 ],
2393 realData: [
2394 { type: 'paragraph', internal: { generated: 'wrapper' } },
2395 ...'Foo',
2396 ...'Bar',
2397 { type: '/paragraph' },
2398 {
2399 type: 'removableAlienMeta',
2400 originalDomElements: $.parseHTML( '<span id="anchorTarget"></span>' )
2401 },
2402 { type: '/removableAlienMeta' },
2403 { type: 'internalList' },
2404 { type: '/internalList' }
2405 ]
2406 },
2407 'annotation next to wrapper paragraph': {
2408 data: [
2409 { type: 'table' },
2410 { type: 'tableSection', attributes: { style: 'body' } },
2411 { type: 'tableRow' },
2412 { type: 'tableCell', attributes: { style: 'data' } },
2413 { type: 'paragraph', internal: { generated: 'wrapper' } },
2414 [ 'F', [ ve.dm.example.link( 'Foo' ) ] ],
2415 [ 'o', [ ve.dm.example.link( 'Foo' ) ] ],
2416 [ 'o', [ ve.dm.example.link( 'Foo' ) ] ],
2417 { type: '/paragraph' },
2418 { type: 'paragraph', internal: { generated: 'wrapper' } },
2419 ...'Bar',
2420 { type: '/paragraph' },
2421 { type: '/tableCell' },
2422 { type: '/tableRow' },
2423 { type: '/tableSection' },
2424 { type: '/table' },
2425 { type: 'internalList' },
2426 { type: '/internalList' }
2427 ],
2428 fromDataBody: '<table><tr><td><a href="Foo">Foo</a><p>Bar</p></td></tr></table>'
2429 },
2430 'nested empty annotation': {
2431 body: '<p>Foo<i><b><u></u></b></i>Bar</p>',
2432 data: [
2433 { type: 'paragraph' },
2434 ...'Foo',
2435 {
2436 type: 'removableAlienMeta',
2437 originalDomElements: $.parseHTML( '<i><b><u></u></b></i>' )
2438 },
2439 { type: '/removableAlienMeta' },
2440 ...'Bar',
2441 { type: '/paragraph' },
2442 { type: 'internalList' },
2443 { type: '/internalList' }
2444 ],
2445 realData: [
2446 { type: 'paragraph' },
2447 ...'Foo',
2448 ...'Bar',
2449 { type: '/paragraph' },
2450 {
2451 type: 'removableAlienMeta',
2452 originalDomElements: $.parseHTML( '<i><b><u></u></b></i>' )
2453 },
2454 { type: '/removableAlienMeta' },
2455 { type: 'internalList' },
2456 { type: '/internalList' }
2457 ]
2458 },
2459 'empty annotation inside nonempty annotation': {
2460 body: '<p><i>Foo<b></b></i></p>',
2461 data: [
2462 { type: 'paragraph' },
2463 [ 'F', [ ve.dm.example.italic ] ],
2464 [ 'o', [ ve.dm.example.italic ] ],
2465 [ 'o', [ ve.dm.example.italic ] ],
2466 {
2467 type: 'removableAlienMeta',
2468 originalDomElements: $.parseHTML( '<b></b>' ),
2469 annotations: [ ve.dm.example.italic ]
2470 },
2471 { type: '/removableAlienMeta' },
2472 { type: '/paragraph' },
2473 { type: 'internalList' },
2474 { type: '/internalList' }
2475 ],
2476 realData: [
2477 { type: 'paragraph' },
2478 [ 'F', [ ve.dm.example.italic ] ],
2479 [ 'o', [ ve.dm.example.italic ] ],
2480 [ 'o', [ ve.dm.example.italic ] ],
2481 { type: '/paragraph' },
2482 {
2483 type: 'removableAlienMeta',
2484 originalDomElements: $.parseHTML( '<b></b>' ),
2485 annotations: [ ve.dm.example.italic ]
2486 },
2487 { type: '/removableAlienMeta' },
2488 { type: 'internalList' },
2489 { type: '/internalList' }
2490 ]
2491 },
2492 'empty annotation with comment': {
2493 body: '<p>Foo<b><!-- Bar --></b>Baz</p>',
2494 data: [
2495 { type: 'paragraph' },
2496 ...'Foo',
2497 {
2498 type: 'comment',
2499 annotations: [ ve.dm.example.bold ],
2500 attributes: {
2501 text: ' Bar '
2502 }
2503 },
2504 { type: '/comment' },
2505 ...'Baz',
2506 { type: '/paragraph' },
2507 { type: 'internalList' },
2508 { type: '/internalList' }
2509 ],
2510 clipboardBody: '<p>Foo<b><span rel="ve:Comment" data-ve-comment=" Bar ">&nbsp;</span></b>Baz</p>',
2511 previewBody: '<p>Foo<b>' + ve.dm.example.commentNodePreview( ' Bar ' ) + '</b>Baz</p>'
2512 },
2513 'empty annotation with metadata': {
2514 body: '<p>Foo<b><meta /></b>Baz</p>',
2515 data: [
2516 { type: 'paragraph' },
2517 ...'Foo',
2518 {
2519 type: 'alienMeta',
2520 originalDomElements: $.parseHTML( '<b><meta /></b>' )
2521 },
2522 { type: '/alienMeta' },
2523 ...'Baz',
2524 { type: '/paragraph' },
2525 { type: 'internalList' },
2526 { type: '/internalList' }
2527 ],
2528 realData: [
2529 { type: 'paragraph' },
2530 ...'Foo',
2531 ...'Baz',
2532 { type: '/paragraph' },
2533 {
2534 type: 'alienMeta',
2535 originalDomElements: $.parseHTML( '<b><meta /></b>' )
2536 },
2537 { type: '/alienMeta' },
2538 { type: 'internalList' },
2539 { type: '/internalList' }
2540 ]
2541 },
2542 'adjacent identical annotations': {
2543 body: ve.dm.example.singleLine`
2544 <p>
2545 <b>Foo</b>
2546 <b>bar</b>
2547 <strong>baz</strong>
2548 </p>
2549 <p>
2550 <a href="quux">Foo</a>
2551 <a href="quux">bar</a>
2552 <a href="whee">baz</a>
2553 </p>
2554 `,
2555 normalizedBody: ve.dm.example.singleLine`
2556 <p>
2557 <b>Foobar</b>
2558 <strong>baz</strong>
2559 </p>
2560 <p>
2561 <a href="quux">Foobar</a>
2562 <a href="whee">baz</a>
2563 </p>
2564 `,
2565 data: [
2566 { type: 'paragraph' },
2567 [ 'F', [ ve.dm.example.bold ] ],
2568 [ 'o', [ ve.dm.example.bold ] ],
2569 [ 'o', [ ve.dm.example.bold ] ],
2570 [ 'b', [ ve.dm.example.bold ] ],
2571 [ 'a', [ ve.dm.example.bold ] ],
2572 [ 'r', [ ve.dm.example.bold ] ],
2573 [ 'b', [ ve.dm.example.strong ] ],
2574 [ 'a', [ ve.dm.example.strong ] ],
2575 [ 'z', [ ve.dm.example.strong ] ],
2576 { type: '/paragraph' },
2577 { type: 'paragraph' },
2578 [ 'F', [ ve.dm.example.link( 'quux' ) ] ],
2579 [ 'o', [ ve.dm.example.link( 'quux' ) ] ],
2580 [ 'o', [ ve.dm.example.link( 'quux' ) ] ],
2581 [ 'b', [ ve.dm.example.link( 'quux' ) ] ],
2582 [ 'a', [ ve.dm.example.link( 'quux' ) ] ],
2583 [ 'r', [ ve.dm.example.link( 'quux' ) ] ],
2584 [ 'b', [ ve.dm.example.link( 'whee' ) ] ],
2585 [ 'a', [ ve.dm.example.link( 'whee' ) ] ],
2586 [ 'z', [ ve.dm.example.link( 'whee' ) ] ],
2587 { type: '/paragraph' },
2588 { type: 'internalList' },
2589 { type: '/internalList' }
2590 ],
2591 fromDataBody: ve.dm.example.singleLine`
2592 <p>
2593 <b>Foobarbaz</b>
2594 </p>
2595 <p>
2596 <a href="quux">Foobar</a>
2597 <a href="whee">baz</a>
2598 </p>
2599 `
2600 },
2601 'adjacent identical annotations with identical content': {
2602 body: '<p><b>x</b><b>x</b></p>',
2603 normalizedBody: '<p><b>xx</b></p>',
2604 data: [
2605 { type: 'paragraph' },
2606 [ 'x', [ ve.dm.example.bold ] ],
2607 [ 'x', [ ve.dm.example.bold ] ],
2608 { type: '/paragraph' },
2609 { type: 'internalList' },
2610 { type: '/internalList' }
2611 ],
2612 fromDataBody: '<p><b>xx</b></p>'
2613 },
2614 'plain href-less anchors (e.g. on paste) are converted to spans': {
2615 body: '<a name="foo">ab</a>',
2616 data: [
2617 {
2618 type: 'paragraph',
2619 internal: {
2620 generated: 'wrapper'
2621 }
2622 },
2623 [
2624 'a',
2625 [ {
2626 type: 'textStyle/span',
2627 attributes: { nodeName: 'a' }
2628 } ]
2629 ],
2630 [
2631 'b',
2632 [ {
2633 type: 'textStyle/span',
2634 attributes: { nodeName: 'a' }
2635 } ]
2636 ],
2637 {
2638 type: '/paragraph'
2639 },
2640 {
2641 type: 'internalList'
2642 },
2643 {
2644 type: '/internalList'
2645 }
2646 ],
2647 fromDataBody: '<a>ab</a>'
2648 },
2649 'list item with space followed by link': {
2650 body: '<ul><li><p> <a href="Foobar">bar</a></p></li></ul>',
2651 base: 'http://example.com/Foo',
2652 data: [
2653 { type: 'list', attributes: { style: 'bullet' } },
2654 { type: 'listItem' },
2655 { type: 'paragraph', internal: { whitespace: [ undefined, ' ' ] } },
2656 [ 'b', [ ve.dm.example.link( 'Foobar' ) ] ],
2657 [ 'a', [ ve.dm.example.link( 'Foobar' ) ] ],
2658 [ 'r', [ ve.dm.example.link( 'Foobar' ) ] ],
2659 { type: '/paragraph' },
2660 { type: '/listItem' },
2661 { type: '/list' },
2662 { type: 'internalList' },
2663 { type: '/internalList' }
2664 ]
2665 },
2666 'whitespace between unwrapped inline nodes': {
2667 body: '<foobar>c</foobar> <foobar>d</foobar>\n<foobar>e</foobar>',
2668 data: [
2669 {
2670 type: 'paragraph',
2671 internal: {
2672 generated: 'wrapper'
2673 }
2674 },
2675 {
2676 type: 'alienInline',
2677 originalDomElements: $.parseHTML( '<foobar>c</foobar>' )
2678 },
2679 { type: '/alienInline' },
2680 ' ',
2681 {
2682 type: 'alienInline',
2683 originalDomElements: $.parseHTML( '<foobar>d</foobar>' )
2684 },
2685 { type: '/alienInline' },
2686 '\n',
2687 {
2688 type: 'alienInline',
2689 originalDomElements: $.parseHTML( '<foobar>e</foobar>' )
2690 },
2691 { type: '/alienInline' },
2692 { type: '/paragraph' },
2693 { type: 'internalList' },
2694 { type: '/internalList' }
2695 ]
2696 },
2697 'whitespace preservation in headings': {
2698 body: '<h2>Foo</h2><h2> Bar</h2><h2>Baz </h2><h2> Quux </h2>',
2699 data: [
2700 { type: 'heading', attributes: { level: 2 } },
2701 ...'Foo',
2702 { type: '/heading' },
2703 {
2704 type: 'heading',
2705 attributes: { level: 2 },
2706 internal: { whitespace: [ undefined, ' ' ] }
2707 },
2708 ...'Bar',
2709 { type: '/heading' },
2710 {
2711 type: 'heading',
2712 attributes: { level: 2 },
2713 internal: { whitespace: [ undefined, undefined, ' ' ] }
2714 },
2715 ...'Baz',
2716 { type: '/heading' },
2717 {
2718 type: 'heading',
2719 attributes: { level: 2 },
2720 internal: { whitespace: [ undefined, ' ', ' ' ] }
2721 },
2722 ...'Quux',
2723 { type: '/heading' },
2724 { type: 'internalList' },
2725 { type: '/internalList' }
2726 ]
2727 },
2728 'whitespace preservation in list items': {
2729 body: '<ul><li>Foo</li><li> Bar</li><li>Baz </li><li> Quux </li></ul>',
2730 data: [
2731 { type: 'list', attributes: { style: 'bullet' } },
2732 { type: 'listItem' },
2733 { type: 'paragraph', internal: { generated: 'wrapper' } },
2734 ...'Foo',
2735 { type: '/paragraph' },
2736 { type: '/listItem' },
2737 { type: 'listItem', internal: { whitespace: [ undefined, ' ' ] } },
2738 { type: 'paragraph', internal: { whitespace: [ ' ' ], generated: 'wrapper' } },
2739 ...'Bar',
2740 { type: '/paragraph' },
2741 { type: '/listItem' },
2742 { type: 'listItem', internal: { whitespace: [ undefined, undefined, ' ' ] } },
2743 { type: 'paragraph', internal: { whitespace: [ undefined, undefined, undefined, ' ' ], generated: 'wrapper' } },
2744 ...'Baz',
2745 { type: '/paragraph' },
2746 { type: '/listItem' },
2747 { type: 'listItem', internal: { whitespace: [ undefined, ' ', ' ' ] } },
2748 {
2749 type: 'paragraph',
2750 internal: { whitespace: [ ' ', undefined, undefined, ' ' ], generated: 'wrapper' }
2751 },
2752 ...'Quux',
2753 { type: '/paragraph' },
2754 { type: '/listItem' },
2755 { type: '/list' },
2756 { type: 'internalList' },
2757 { type: '/internalList' }
2758 ]
2759 },
2760 'whitespace preservation with annotations': {
2761 body: '<p> <i> Foo </i> </p>',
2762 data: [
2763 {
2764 type: 'paragraph',
2765 internal: { whitespace: [ undefined, ' ', ' ' ] }
2766 },
2767 [ ' ', [ ve.dm.example.italic ] ],
2768 [ ' ', [ ve.dm.example.italic ] ],
2769 [ 'F', [ ve.dm.example.italic ] ],
2770 [ 'o', [ ve.dm.example.italic ] ],
2771 [ 'o', [ ve.dm.example.italic ] ],
2772 [ ' ', [ ve.dm.example.italic ] ],
2773 [ ' ', [ ve.dm.example.italic ] ],
2774 [ ' ', [ ve.dm.example.italic ] ],
2775 { type: '/paragraph' },
2776 { type: 'internalList' },
2777 { type: '/internalList' }
2778 ],
2779 fromDataBody: '<p> <i>Foo</i> </p>'
2780 },
2781 'outer whitespace preservation in a list with bare text and a wrapper paragraph': {
2782 body: '\n<ul>\n\n<li>\n\n\nBa re\n\n\n\n</li>\n\n\n\n\n<li>\t<p>\t\tP\t\t\t</p>\t\t\t\t</li>\t\n</ul>\t\n\t\n',
2783 data: [
2784 { type: 'list', attributes: { style: 'bullet' }, internal: { whitespace: [ '\n', '\n\n', '\t\n', '\t\n\t\n' ] } },
2785 { type: 'listItem', internal: { whitespace: [ '\n\n', '\n\n\n', '\n\n\n\n', '\n\n\n\n\n' ] } },
2786 { type: 'paragraph', internal: { generated: 'wrapper', whitespace: [ '\n\n\n', undefined, undefined, '\n\n\n\n' ] } },
2787 ...'Ba re',
2788 { type: '/paragraph' },
2789 { type: '/listItem' },
2790 { type: 'listItem', internal: { whitespace: [ '\n\n\n\n\n', '\t', '\t\t\t\t', '\t\n' ] } },
2791 { type: 'paragraph', internal: { whitespace: [ '\t', '\t\t', '\t\t\t', '\t\t\t\t' ] } },
2792 'P',
2793 { type: '/paragraph' },
2794 { type: '/listItem' },
2795 { type: '/list' },
2796 { type: 'internalList' },
2797 { type: '/internalList' }
2798 ],
2799 innerWhitespace: [ '\n', '\t\n\t\n' ]
2800 },
2801 'outer whitespace preservation in a list with bare text and a sublist': {
2802 body: '<ul>\n<li>\n\nBa re\n\n\n<ul>\n\n\n\n<li> <p> P </p> </li>\t</ul>\t\t</li>\t\t\t</ul>',
2803 data: [
2804 { type: 'list', attributes: { style: 'bullet' }, internal: { whitespace: [ undefined, '\n', '\t\t\t' ] } },
2805 { type: 'listItem', internal: { whitespace: [ '\n', '\n\n', '\t\t', '\t\t\t' ] } },
2806 { type: 'paragraph', internal: { generated: 'wrapper', whitespace: [ '\n\n', undefined, undefined, '\n\n\n' ] } },
2807 ...'Ba re',
2808 { type: '/paragraph' },
2809 { type: 'list', attributes: { style: 'bullet' }, internal: { whitespace: [ '\n\n\n', '\n\n\n\n', '\t', '\t\t' ] } },
2810 { type: 'listItem', internal: { whitespace: [ '\n\n\n\n', ' ', ' ', '\t' ] } },
2811 { type: 'paragraph', internal: { whitespace: [ ' ', ' ', ' ', ' ' ] } },
2812 'P',
2813 { type: '/paragraph' },
2814 { type: '/listItem' },
2815 { type: '/list' },
2816 { type: '/listItem' },
2817 { type: '/list' },
2818 { type: 'internalList' },
2819 { type: '/internalList' }
2820 ]
2821 },
2822 'whitespace preservation leaves non-edge content whitespace alone': {
2823 body: '<p> A B <b> C\t</b>\t\tD\t\t\t</p>\nE\n\nF\n\n\n<b>\n\n\n\nG </b> H ',
2824 data: [
2825 { type: 'paragraph', internal: { whitespace: [ undefined, ' ', '\t\t\t', '\n' ] } },
2826 ...'A B ',
2827 [ ' ', [ ve.dm.example.bold ] ],
2828 [ ' ', [ ve.dm.example.bold ] ],
2829 [ ' ', [ ve.dm.example.bold ] ],
2830 [ ' ', [ ve.dm.example.bold ] ],
2831 [ 'C', [ ve.dm.example.bold ] ],
2832 [ '\t', [ ve.dm.example.bold ] ],
2833 ...'\t\tD',
2834 { type: '/paragraph' },
2835 { type: 'paragraph', internal: { generated: 'wrapper', whitespace: [ '\n', undefined, undefined, ' ' ] } },
2836 ...'E\n\nF\n\n\n',
2837 [ '\n', [ ve.dm.example.bold ] ],
2838 [ '\n', [ ve.dm.example.bold ] ],
2839 [ '\n', [ ve.dm.example.bold ] ],
2840 [ '\n', [ ve.dm.example.bold ] ],
2841 [ 'G', [ ve.dm.example.bold ] ],
2842 [ ' ', [ ve.dm.example.bold ] ],
2843 ...' H',
2844 { type: '/paragraph' },
2845 { type: 'internalList' },
2846 { type: '/internalList' }
2847 ],
2848 innerWhitespace: [ undefined, ' ' ],
2849 fromDataBody: '<p> A B <b>C</b>\t\t\tD\t\t\t</p>\nE\n\nF\n\n\n\n\n\n\n<b>G</b> H '
2850 },
2851 'whitespace preservation with non-edge content whitespace with nested annotations': {
2852 body: '<p> A B <b> C\t<i>\t\tD\t\t\t</i>\t\t\t\tE\n</b>\n\nF\n\n\n</p>',
2853 data: [
2854 { type: 'paragraph', internal: { whitespace: [ undefined, ' ', '\n\n\n' ] } },
2855 ...'A B ',
2856 [ ' ', [ ve.dm.example.bold ] ],
2857 [ ' ', [ ve.dm.example.bold ] ],
2858 [ ' ', [ ve.dm.example.bold ] ],
2859 [ ' ', [ ve.dm.example.bold ] ],
2860 [ 'C', [ ve.dm.example.bold ] ],
2861 [ '\t', [ ve.dm.example.bold ] ],
2862 [ '\t', [ ve.dm.example.bold, ve.dm.example.italic ] ],
2863 [ '\t', [ ve.dm.example.bold, ve.dm.example.italic ] ],
2864 [ 'D', [ ve.dm.example.bold, ve.dm.example.italic ] ],
2865 [ '\t', [ ve.dm.example.bold, ve.dm.example.italic ] ],
2866 [ '\t', [ ve.dm.example.bold, ve.dm.example.italic ] ],
2867 [ '\t', [ ve.dm.example.bold, ve.dm.example.italic ] ],
2868 [ '\t', [ ve.dm.example.bold ] ],
2869 [ '\t', [ ve.dm.example.bold ] ],
2870 [ '\t', [ ve.dm.example.bold ] ],
2871 [ '\t', [ ve.dm.example.bold ] ],
2872 [ 'E', [ ve.dm.example.bold ] ],
2873 [ '\n', [ ve.dm.example.bold ] ],
2874 ...'\n\nF',
2875 { type: '/paragraph' },
2876 { type: 'internalList' },
2877 { type: '/internalList' }
2878 ],
2879 fromDataBody: '<p> A B <b>C\t\t\t<i>D</i>\t\t\t\t\t\t\tE</b>\n\n\nF\n\n\n</p>'
2880 },
2881 'whitespace preservation with tightly nested annotations': {
2882 body: '<p> A B <b><i>\t\tC\t\t\t</i></b>\n\nD\n\n\n</p>',
2883 data: [
2884 { type: 'paragraph', internal: { whitespace: [ undefined, ' ', '\n\n\n' ] } },
2885 ...'A B ',
2886 [ '\t', [ ve.dm.example.bold, ve.dm.example.italic ] ],
2887 [ '\t', [ ve.dm.example.bold, ve.dm.example.italic ] ],
2888 [ 'C', [ ve.dm.example.bold, ve.dm.example.italic ] ],
2889 [ '\t', [ ve.dm.example.bold, ve.dm.example.italic ] ],
2890 [ '\t', [ ve.dm.example.bold, ve.dm.example.italic ] ],
2891 [ '\t', [ ve.dm.example.bold, ve.dm.example.italic ] ],
2892 ...'\n\nD',
2893 { type: '/paragraph' },
2894 { type: 'internalList' },
2895 { type: '/internalList' }
2896 ],
2897 fromDataBody: '<p> A B \t\t<b><i>C</i></b>\t\t\t\n\nD\n\n\n</p>'
2898 },
2899 'whitespace preservation with nested annotations with whitespace on the left side': {
2900 body: '<p> A B <b>\n\t<i>\t\tC\t\t\t</i></b>\n\nD\n\n\n</p>',
2901 data: [
2902 { type: 'paragraph', internal: { whitespace: [ undefined, ' ', '\n\n\n' ] } },
2903 ...'A B ',
2904 [ '\n', [ ve.dm.example.bold ] ],
2905 [ '\t', [ ve.dm.example.bold ] ],
2906 [ '\t', [ ve.dm.example.bold, ve.dm.example.italic ] ],
2907 [ '\t', [ ve.dm.example.bold, ve.dm.example.italic ] ],
2908 [ 'C', [ ve.dm.example.bold, ve.dm.example.italic ] ],
2909 [ '\t', [ ve.dm.example.bold, ve.dm.example.italic ] ],
2910 [ '\t', [ ve.dm.example.bold, ve.dm.example.italic ] ],
2911 [ '\t', [ ve.dm.example.bold, ve.dm.example.italic ] ],
2912 ...'\n\nD',
2913 { type: '/paragraph' },
2914 { type: 'internalList' },
2915 { type: '/internalList' }
2916 ],
2917 fromDataBody: '<p> A B \n\t\t\t<b><i>C</i></b>\t\t\t\n\nD\n\n\n</p>'
2918 },
2919 'whitespace preservation with nested annotations with whitespace on the right side': {
2920 body: '<p> A B <b><i>\t\tC\t\t\t</i>\n\t</b>\n\nD\n\n\n</p>',
2921 data: [
2922 { type: 'paragraph', internal: { whitespace: [ undefined, ' ', '\n\n\n' ] } },
2923 ...'A B ',
2924 [ '\t', [ ve.dm.example.bold, ve.dm.example.italic ] ],
2925 [ '\t', [ ve.dm.example.bold, ve.dm.example.italic ] ],
2926 [ 'C', [ ve.dm.example.bold, ve.dm.example.italic ] ],
2927 [ '\t', [ ve.dm.example.bold, ve.dm.example.italic ] ],
2928 [ '\t', [ ve.dm.example.bold, ve.dm.example.italic ] ],
2929 [ '\t', [ ve.dm.example.bold, ve.dm.example.italic ] ],
2930 [ '\n', [ ve.dm.example.bold ] ],
2931 [ '\t', [ ve.dm.example.bold ] ],
2932 ...'\n\nD',
2933 { type: '/paragraph' },
2934 { type: 'internalList' },
2935 { type: '/internalList' }
2936 ],
2937 fromDataBody: '<p> A B \t\t<b><i>C</i></b>\t\t\t\n\t\n\nD\n\n\n</p>'
2938 },
2939 'whitespace preservation with aliens': {
2940 body: ' <div rel="ve:Alien"> <br> </div> <p>\tFoo\t\t<foobar>\t\t\tBar\t\t\t\t</foobar>\nBaz\n\n<foobar>\n\n\nQuux\n\n\n\n</foobar> \tWhee \n</p>\t\n<div rel="ve:Alien">\n\tYay \t </div> \n ',
2941 data: [
2942 {
2943 type: 'alienBlock',
2944 originalDomElements: $.parseHTML( '<div rel="ve:Alien"> <br> </div>' ),
2945 internal: {
2946 whitespace: [ ' ', undefined, undefined, ' ' ]
2947 }
2948 },
2949 { type: '/alienBlock' },
2950 { type: 'paragraph', internal: { whitespace: [ ' ', '\t', ' \n', '\t\n' ] } },
2951 ...'Foo\t\t',
2952 { type: 'alienInline', originalDomElements: $.parseHTML( '<foobar>\t\t\tBar\t\t\t\t</foobar>' ) },
2953 { type: '/alienInline' },
2954 ...'\nBaz\n\n',
2955 {
2956 type: 'alienInline',
2957 originalDomElements: $.parseHTML( '<foobar>\n\n\nQuux\n\n\n\n</foobar>' )
2958 },
2959 { type: '/alienInline' },
2960 ...' \tWhee',
2961 { type: '/paragraph' },
2962 {
2963 type: 'alienBlock',
2964 originalDomElements: $.parseHTML( '<div rel="ve:Alien">\n\tYay \t </div>' ),
2965 internal: {
2966 whitespace: [ '\t\n', undefined, undefined, ' \n ' ]
2967 }
2968 },
2969 { type: '/alienBlock' },
2970 { type: 'internalList' },
2971 { type: '/internalList' }
2972 ],
2973 innerWhitespace: [ ' ', ' \n ' ]
2974 },
2975 'whitespace preservation not triggered inside <pre>': {
2976 body: '\n<pre>\n\n\nFoo\n\n\nBar\n\n\n\n</pre>\n\n\n\n\n',
2977 data: [
2978 { type: 'preformatted', internal: { whitespace: [ '\n', undefined, undefined, '\n\n\n\n\n' ] } },
2979 ...'\n\nFoo\n\n\nBar\n\n\n\n',
2980 { type: '/preformatted' },
2981 { type: 'internalList' },
2982 { type: '/internalList' }
2983 ],
2984 innerWhitespace: [ '\n', '\n\n\n\n\n' ]
2985 },
2986 'whitespace preservation in table cell starting with text and ending with annotation': {
2987 body: '<table><tbody><tr><td>Foo <b>Bar</b></td></tr></tbody></table>',
2988 data: [
2989 { type: 'table' },
2990 { type: 'tableSection', attributes: { style: 'body' } },
2991 { type: 'tableRow' },
2992 { type: 'tableCell', attributes: { style: 'data' } },
2993 { type: 'paragraph', internal: { generated: 'wrapper' } },
2994 ...'Foo ',
2995 [ 'B', [ ve.dm.example.bold ] ],
2996 [ 'a', [ ve.dm.example.bold ] ],
2997 [ 'r', [ ve.dm.example.bold ] ],
2998 { type: '/paragraph' },
2999 { type: '/tableCell' },
3000 { type: '/tableRow' },
3001 { type: '/tableSection' },
3002 { type: '/table' },
3003 { type: 'internalList' },
3004 { type: '/internalList' }
3005 ]
3006 },
3007 'whitespace preservation with wrapped text and metas': {
3008 body: '<meta /> <meta />\nFoo',
3009 data: [
3010 {
3011 type: 'alienMeta',
3012 internal: {
3013 whitespace: [
3014 undefined,
3015 undefined,
3016 undefined,
3017 ' '
3018 ]
3019 },
3020 originalDomElements: $.parseHTML( '<meta />' )
3021 },
3022 { type: '/alienMeta' },
3023 {
3024 type: 'alienMeta',
3025 internal: {
3026 whitespace: [
3027 ' ',
3028 undefined,
3029 undefined,
3030 '\n'
3031 ]
3032 },
3033 originalDomElements: $.parseHTML( '<meta />' )
3034 },
3035 { type: '/alienMeta' },
3036 {
3037 type: 'paragraph',
3038 internal: {
3039 whitespace: [
3040 '\n'
3041 ],
3042 generated: 'wrapper'
3043 }
3044 },
3045 ...'Foo',
3046 { type: '/paragraph' },
3047 { type: 'internalList' },
3048 { type: '/internalList' }
3049 ]
3050 },
3051 'whitespace preservation with wrapped text and comments': {
3052 body: '<!-- Foo --> <!-- Bar -->\nFoo',
3053 data: [
3054 {
3055 type: 'paragraph',
3056 internal: {
3057 generated: 'wrapper'
3058 }
3059 },
3060 {
3061 type: 'comment',
3062 attributes: {
3063 text: ' Foo '
3064 }
3065 },
3066 { type: '/comment' },
3067 ' ',
3068 {
3069 type: 'comment',
3070 attributes: {
3071 text: ' Bar '
3072 }
3073 },
3074 { type: '/comment' },
3075 ...'\nFoo',
3076 { type: '/paragraph' },
3077 { type: 'internalList' },
3078 { type: '/internalList' }
3079 ],
3080 clipboardBody: '<span rel="ve:Comment" data-ve-comment=" Foo ">&nbsp;</span> <span rel="ve:Comment" data-ve-comment=" Bar ">&nbsp;</span>\nFoo',
3081 previewBody: ve.dm.example.commentNodePreview( ' Foo ' ) + ' ' + ve.dm.example.commentNodePreview( ' Bar ' ) + '↵Foo'
3082 },
3083 'whitespace preservation with comments at end of wrapper paragraph': {
3084 body: '<ul><li> bar<!-- baz -->quux </li></ul>',
3085 data: [
3086 { type: 'list', attributes: { style: 'bullet' } },
3087 {
3088 type: 'listItem',
3089 internal: {
3090 whitespace: [
3091 undefined,
3092 ' ',
3093 ' '
3094 ]
3095 }
3096 },
3097 {
3098 type: 'paragraph',
3099 internal: {
3100 generated: 'wrapper',
3101 whitespace: [
3102 ' ',
3103 undefined,
3104 undefined,
3105 ' '
3106 ]
3107 }
3108 },
3109 ...'bar',
3110 {
3111 type: 'comment',
3112 attributes: {
3113 text: ' baz '
3114 }
3115 },
3116 { type: '/comment' },
3117 ...'quux',
3118 { type: '/paragraph' },
3119 { type: '/listItem' },
3120 { type: '/list' },
3121 { type: 'internalList' },
3122 { type: '/internalList' }
3123 ],
3124 clipboardBody: '<ul><li> bar<span rel="ve:Comment" data-ve-comment=" baz ">&nbsp;</span>quux </li></ul>',
3125 previewBody: '<ul><li> bar' + ve.dm.example.commentNodePreview( ' baz ' ) + 'quux </li></ul>'
3126 },
3127 'whitespace preservation with metadata and space at end of wrapper paragraph': {
3128 body: '<ul><li> bar<meta />quux </li></ul>',
3129 data: [
3130 { type: 'list', attributes: { style: 'bullet' } },
3131 {
3132 type: 'listItem',
3133 internal: {
3134 whitespace: [
3135 undefined,
3136 ' ',
3137 ' '
3138 ]
3139 }
3140 },
3141 {
3142 type: 'paragraph',
3143 internal: {
3144 generated: 'wrapper',
3145 whitespace: [
3146 ' ',
3147 undefined,
3148 undefined,
3149 ' '
3150 ]
3151 }
3152 },
3153 ...'bar',
3154 {
3155 type: 'alienMeta',
3156 originalDomElements: $.parseHTML( '<meta />' )
3157 },
3158 { type: '/alienMeta' },
3159 ...'quux',
3160 { type: '/paragraph' },
3161 { type: '/listItem' },
3162 { type: '/list' },
3163 { type: 'internalList' },
3164 { type: '/internalList' }
3165 ],
3166 realData: [
3167 { type: 'list', attributes: { style: 'bullet' } },
3168 {
3169 type: 'listItem',
3170 internal: {
3171 whitespace: [
3172 undefined,
3173 ' ',
3174 ' '
3175 ]
3176 }
3177 },
3178 {
3179 type: 'paragraph',
3180 internal: {
3181 generated: 'wrapper',
3182 whitespace: [
3183 ' ',
3184 undefined,
3185 undefined,
3186 ' '
3187 ]
3188 }
3189 },
3190 ...'bar',
3191 ...'quux',
3192 { type: '/paragraph' },
3193 {
3194 type: 'alienMeta',
3195 originalDomElements: $.parseHTML( '<meta />' )
3196 },
3197 { type: '/alienMeta' },
3198 { type: '/listItem' },
3199 { type: '/list' },
3200 { type: 'internalList' },
3201 { type: '/internalList' }
3202 ]
3203 },
3204 'whitespace preservation with meta at end of wrapper paragraph': {
3205 body: '<ul><li> bar<meta /> </li></ul>',
3206 data: [
3207 { type: 'list', attributes: { style: 'bullet' } },
3208 {
3209 type: 'listItem',
3210 internal: {
3211 whitespace: [
3212 undefined,
3213 ' ',
3214 ' '
3215 ]
3216 }
3217 },
3218 {
3219 type: 'paragraph',
3220 internal: {
3221 generated: 'wrapper',
3222 whitespace: [
3223 ' '
3224 ]
3225 }
3226 },
3227 ...'bar',
3228 { type: '/paragraph' },
3229 {
3230 type: 'alienMeta',
3231 originalDomElements: $.parseHTML( '<meta />' ),
3232 internal: {
3233 whitespace: [
3234 undefined,
3235 undefined,
3236 undefined,
3237 ' '
3238 ]
3239 }
3240 },
3241 { type: '/alienMeta' },
3242 { type: '/listItem' },
3243 { type: '/list' },
3244 { type: 'internalList' },
3245 { type: '/internalList' }
3246 ],
3247 realData: [
3248 { type: 'list', attributes: { style: 'bullet' } },
3249 {
3250 type: 'listItem',
3251 internal: {
3252 whitespace: [
3253 undefined,
3254 ' ',
3255 ' '
3256 ]
3257 }
3258 },
3259 {
3260 type: 'paragraph',
3261 internal: {
3262 generated: 'wrapper',
3263 whitespace: [
3264 ' '
3265 ]
3266 }
3267 },
3268 ...'bar',
3269 { type: '/paragraph' },
3270 { type: '/listItem' },
3271 // FIXME! <alienMeta></alienMeta> should be before </listItem>. T189826
3272 {
3273 type: 'alienMeta',
3274 originalDomElements: $.parseHTML( '<meta />' ),
3275 internal: {
3276 whitespace: [
3277 undefined,
3278 undefined,
3279 undefined,
3280 ' '
3281 ]
3282 }
3283 },
3284 { type: '/alienMeta' },
3285 { type: '/list' },
3286 { type: 'internalList' },
3287 { type: '/internalList' }
3288 ]
3289 },
3290 'whitespace preservation with multiple metas at end of wrapper paragraph': {
3291 body: '<ul><li> foo <meta /> <meta /> </li></ul>',
3292 data: [
3293 { type: 'list', attributes: { style: 'bullet' } },
3294 {
3295 type: 'listItem',
3296 internal: {
3297 whitespace: [
3298 undefined,
3299 ' ',
3300 ' '
3301 ]
3302 }
3303 },
3304 {
3305 type: 'paragraph',
3306 internal: {
3307 generated: 'wrapper',
3308 whitespace: [
3309 ' ',
3310 undefined,
3311 undefined,
3312 ' '
3313 ]
3314 }
3315 },
3316 ...'foo',
3317 { type: '/paragraph' },
3318 {
3319 type: 'alienMeta',
3320 originalDomElements: $.parseHTML( '<meta />' ),
3321 internal: {
3322 whitespace: [
3323 ' ',
3324 undefined,
3325 undefined,
3326 ' '
3327 ]
3328 }
3329 },
3330 { type: '/alienMeta' },
3331 {
3332 type: 'alienMeta',
3333 originalDomElements: $.parseHTML( '<meta />' ),
3334 internal: {
3335 whitespace: [
3336 ' ',
3337 undefined,
3338 undefined,
3339 ' '
3340 ]
3341 }
3342 },
3343 { type: '/alienMeta' },
3344 { type: '/listItem' },
3345 { type: '/list' },
3346 { type: 'internalList' },
3347 { type: '/internalList' }
3348 ],
3349 realData: [
3350 { type: 'list', attributes: { style: 'bullet' } },
3351 {
3352 type: 'listItem',
3353 internal: {
3354 whitespace: [
3355 undefined,
3356 ' ',
3357 ' '
3358 ]
3359 }
3360 },
3361 {
3362 type: 'paragraph',
3363 internal: {
3364 generated: 'wrapper',
3365 whitespace: [
3366 ' ',
3367 undefined,
3368 undefined,
3369 ' '
3370 ]
3371 }
3372 },
3373 ...'foo',
3374 { type: '/paragraph' },
3375 { type: '/listItem' },
3376 // FIXME! <alienMeta></alienMeta> should be before </listItem>. T189826
3377 {
3378 type: 'alienMeta',
3379 originalDomElements: $.parseHTML( '<meta />' ),
3380 internal: {
3381 whitespace: [
3382 ' ',
3383 undefined,
3384 undefined,
3385 ' '
3386 ]
3387 }
3388 },
3389 { type: '/alienMeta' },
3390 {
3391 type: 'alienMeta',
3392 originalDomElements: $.parseHTML( '<meta />' ),
3393 internal: {
3394 whitespace: [
3395 ' ',
3396 undefined,
3397 undefined,
3398 ' '
3399 ]
3400 }
3401 },
3402 { type: '/alienMeta' },
3403 { type: '/list' },
3404 { type: 'internalList' },
3405 { type: '/internalList' }
3406 ]
3407 },
3408 'whitespace preservation with comment at start or end of element': {
3409 body: '<p> <!-- foo -->bar<!-- baz --> </p>',
3410 data: [
3411 {
3412 type: 'paragraph',
3413 internal: {
3414 whitespace: [
3415 undefined,
3416 ' ',
3417 ' '
3418 ]
3419 }
3420 },
3421 {
3422 type: 'comment',
3423 attributes: {
3424 text: ' foo '
3425 }
3426 },
3427 { type: '/comment' },
3428 ...'bar',
3429 {
3430 type: 'comment',
3431 attributes: {
3432 text: ' baz '
3433 }
3434 },
3435 { type: '/comment' },
3436 { type: '/paragraph' },
3437 { type: 'internalList' },
3438 { type: '/internalList' }
3439 ],
3440 clipboardBody: '<p> <span rel="ve:Comment" data-ve-comment=" foo ">&nbsp;</span>bar<span rel="ve:Comment" data-ve-comment=" baz ">&nbsp;</span> </p>',
3441 previewBody: '<p> ' + ve.dm.example.commentNodePreview( ' foo ' ) + 'bar' + ve.dm.example.commentNodePreview( ' baz ' ) + ' </p>'
3442 },
3443 'non-breaking spaces not treated as whitespace': {
3444 body: '<p> &nbsp;&nbsp;foo&nbsp;\t</p>',
3445 data: [
3446 { type: 'paragraph', internal: { whitespace: [ undefined, ' ', '\t' ] } },
3447 ...'\u00a0\u00a0foo\u00a0',
3448 { type: '/paragraph' },
3449 { type: 'internalList' },
3450 { type: '/internalList' }
3451 ]
3452 },
3453 'whitespace surrounding metadata in a wrapper': {
3454 body: '<b>Foo</b> <meta />\n<i>Bar</i>',
3455 data: [
3456 { type: 'paragraph', internal: { generated: 'wrapper' } },
3457 [ 'F', [ ve.dm.example.bold ] ],
3458 [ 'o', [ ve.dm.example.bold ] ],
3459 [ 'o', [ ve.dm.example.bold ] ],
3460 ' ',
3461 {
3462 type: 'alienMeta',
3463 originalDomElements: $.parseHTML( '<meta />' )
3464 },
3465 { type: '/alienMeta' },
3466 '\n',
3467 [ 'B', [ ve.dm.example.italic ] ],
3468 [ 'a', [ ve.dm.example.italic ] ],
3469 [ 'r', [ ve.dm.example.italic ] ],
3470 { type: '/paragraph' },
3471 { type: 'internalList' },
3472 { type: '/internalList' }
3473 ]
3474 },
3475 'whitespace surrounding metadata in a wrapper followed by inline node': {
3476 body: '<b>Foo</b> <meta />\n<span rel="ve:Alien"></span>',
3477 data: [
3478 { type: 'paragraph', internal: { generated: 'wrapper' } },
3479 [ 'F', [ ve.dm.example.bold ] ],
3480 [ 'o', [ ve.dm.example.bold ] ],
3481 [ 'o', [ ve.dm.example.bold ] ],
3482 ' ',
3483 {
3484 type: 'alienMeta',
3485 originalDomElements: $.parseHTML( '<meta />' )
3486 },
3487 { type: '/alienMeta' },
3488 '\n',
3489 {
3490 type: 'alienInline',
3491 originalDomElements: $.parseHTML( '<span rel="ve:Alien"></span>' )
3492 },
3493 { type: '/alienInline' },
3494 { type: '/paragraph' },
3495 { type: 'internalList' },
3496 { type: '/internalList' }
3497 ]
3498 },
3499 'whitespace preservation in empty branch node': {
3500 body: '<table>\n\n</table>',
3501 data: [
3502 { type: 'table', internal: { whitespace: [ undefined, '\n\n' ] } },
3503 { type: '/table' },
3504 { type: 'internalList' },
3505 { type: '/internalList' }
3506 ]
3507 },
3508 'whitespace preservation in empty list item': {
3509 body: '<ul><li>\n\t</li></ul>',
3510 data: [
3511 { type: 'list', attributes: { style: 'bullet' } },
3512 { type: 'listItem', internal: { whitespace: [ undefined, '\n\t' ] } },
3513 { type: 'paragraph', internal: { generated: 'wrapper', whitespace: [ '\n\t' ] } },
3514 { type: '/paragraph' },
3515 { type: '/listItem' },
3516 { type: '/list' },
3517 { type: 'internalList' },
3518 { type: '/internalList' }
3519 ]
3520 },
3521 'whitespace preservation in body with only plain text': {
3522 body: ' Hello\n\t',
3523 data: [
3524 { type: 'paragraph', internal: { generated: 'wrapper', whitespace: [ ' ', undefined, undefined, '\n\t' ] } },
3525 ...'Hello',
3526 { type: '/paragraph' },
3527 { type: 'internalList' },
3528 { type: '/internalList' }
3529 ],
3530 innerWhitespace: [ ' ', '\n\t' ]
3531 },
3532 'whitespace preservation in empty body': {
3533 body: '\n\t',
3534 data: [
3535 { type: 'paragraph', internal: { generated: 'empty', whitespace: [ '\n\t' ] } },
3536 { type: '/paragraph' },
3537 { type: 'internalList' },
3538 { type: '/internalList' }
3539 ],
3540 innerWhitespace: [ '\n\t', undefined ]
3541 },
3542 'mismatching whitespace data is ignored': {
3543 data: [
3544 { type: 'list', attributes: { style: 'bullet' }, internal: { whitespace: [ ' ', ' ', ' ', ' ' ] } },
3545 { type: 'listItem', internal: { whitespace: [ ' ', ' ', ' ', ' ' ] } },
3546 { type: 'paragraph', internal: { whitespace: [ ' ', '\t', '\n', ' ' ] } },
3547 'A',
3548 { type: '/paragraph' },
3549 { type: 'paragraph', internal: { whitespace: [ ' ' ] } },
3550 'B',
3551 { type: '/paragraph' },
3552 { type: '/listItem' },
3553 { type: 'listItem', internal: { whitespace: [ undefined, ' ', '\n' ] } },
3554 { type: 'paragraph', internal: { generated: 'empty' } },
3555 { type: '/paragraph' },
3556 { type: '/listItem' },
3557 { type: '/list' },
3558 { type: 'internalList' },
3559 { type: '/internalList' }
3560 ],
3561 innerWhitespace: [ '\t', '\n' ],
3562 normalizedBody: '<ul><li><p>\tA\n</p> <p>B</p></li><li></li></ul>'
3563 },
3564 'whitespace is trimmed from the edges of annotations when serializing': {
3565 body: '<p>A <b> B <i> C\t</i> </b><u>\nD\t</u></p>',
3566 data: [
3567 { type: 'paragraph' },
3568 ...'A ',
3569 [ ' ', [ ve.dm.example.bold ] ],
3570 [ 'B', [ ve.dm.example.bold ] ],
3571 [ ' ', [ ve.dm.example.bold ] ],
3572 [ ' ', [ ve.dm.example.bold, ve.dm.example.italic ] ],
3573 [ 'C', [ ve.dm.example.bold, ve.dm.example.italic ] ],
3574 [ '\t', [ ve.dm.example.bold, ve.dm.example.italic ] ],
3575 [ ' ', [ ve.dm.example.bold ] ],
3576 [ '\n', [ ve.dm.example.underline ] ],
3577 [ 'D', [ ve.dm.example.underline ] ],
3578 [ '\t', [ ve.dm.example.underline ] ],
3579 { type: '/paragraph' },
3580 { type: 'internalList' },
3581 { type: '/internalList' }
3582 ],
3583 fromDataBody: '<p>A <b>B <i>C</i></b>\t \n<u>D</u>\t</p>'
3584 },
3585 'annotation whitespace trimming does not create empty annotations': {
3586 body: '<p>A<b> </b> <b>B</b></p>',
3587 data: [
3588 { type: 'paragraph' },
3589 'A',
3590 [ ' ', [ ve.dm.example.bold ] ],
3591 ' ',
3592 [ 'B', [ ve.dm.example.bold ] ],
3593 { type: '/paragraph' },
3594 { type: 'internalList' },
3595 { type: '/internalList' }
3596 ],
3597 fromDataBody: '<p>A <b>B</b></p>'
3598 },
3599 'order of nested annotations is preserved': {
3600 body: '<p><b><u><i>Foo</i></u></b></p>',
3601 data: [
3602 { type: 'paragraph' },
3603 [
3604 'F',
3605 [
3606 ve.dm.example.bold,
3607 ve.dm.example.underline,
3608 ve.dm.example.italic
3609 ]
3610 ],
3611 [
3612 'o',
3613 [
3614 ve.dm.example.bold,
3615 ve.dm.example.underline,
3616 ve.dm.example.italic
3617
3618 ]
3619 ],
3620 [
3621 'o',
3622 [
3623 ve.dm.example.bold,
3624 ve.dm.example.underline,
3625 ve.dm.example.italic
3626
3627 ]
3628 ],
3629 { type: '/paragraph' },
3630 { type: 'internalList' },
3631 { type: '/internalList' }
3632 ]
3633 },
3634 'nested annotations are closed and reopened in the correct order': {
3635 body: '<p><a href="Foo">F<b>o<i>o</i></b><i>b</i></a><i>a<b>r</b>b<u>a</u>z</i></p>',
3636 base: 'http://example.com/Bar/Baz',
3637 data: [
3638 { type: 'paragraph' },
3639 [ 'F', [ ve.dm.example.link( 'Foo' ) ] ],
3640 [ 'o', [ ve.dm.example.link( 'Foo' ), ve.dm.example.bold ] ],
3641 [ 'o', [ ve.dm.example.link( 'Foo' ), ve.dm.example.bold, ve.dm.example.italic ] ],
3642 [ 'b', [ ve.dm.example.link( 'Foo' ), ve.dm.example.italic ] ],
3643 [ 'a', [ ve.dm.example.italic ] ],
3644 [ 'r', [ ve.dm.example.italic, ve.dm.example.bold ] ],
3645 [ 'b', [ ve.dm.example.italic ] ],
3646 [ 'a', [ ve.dm.example.italic, ve.dm.example.underline ] ],
3647 [ 'z', [ ve.dm.example.italic ] ],
3648 { type: '/paragraph' },
3649 { type: 'internalList' },
3650 { type: '/internalList' }
3651 ]
3652 },
3653 'about grouping': {
3654 body: ve.dm.example.singleLine`
3655 <div rel="ve:Alien" about="#vet1">Foo</div>
3656 <div rel="ve:Alien" about="#vet1">Bar</div>
3657 <div rel="ve:Alien" about="#vet2">Baz</div>
3658 <foobar about="#vet2">Quux</foobar>
3659 <p>Whee</p>
3660 <foobar about="#vet2">Yay</foobar>
3661 <div rel="ve:Alien" about="#vet2">Blah</div>
3662 <foobar about="#vet3">Meh</foobar>
3663 `,
3664 data: [
3665 {
3666 type: 'alienBlock',
3667 originalDomElements: $.parseHTML( ve.dm.example.singleLine`
3668 <div rel="ve:Alien" about="#vet1">Foo</div>
3669 <div rel="ve:Alien" about="#vet1">Bar</div>
3670 ` )
3671 },
3672 { type: '/alienBlock' },
3673 {
3674 type: 'alienBlock',
3675 originalDomElements: $.parseHTML( ve.dm.example.singleLine`
3676 <div rel="ve:Alien" about="#vet2">Baz</div>
3677 <foobar about="#vet2">Quux</foobar>
3678 ` )
3679 },
3680 { type: '/alienBlock' },
3681 { type: 'paragraph' },
3682 ...'Whee',
3683 { type: '/paragraph' },
3684 {
3685 type: 'alienBlock',
3686 originalDomElements: $.parseHTML( ve.dm.example.singleLine`
3687 <foobar about="#vet2">Yay</foobar>
3688 <div rel="ve:Alien" about="#vet2">Blah</div>
3689 ` )
3690 },
3691 { type: '/alienBlock' },
3692 { type: 'paragraph', internal: { generated: 'wrapper' } },
3693 {
3694 type: 'alienInline',
3695 originalDomElements: $.parseHTML( '<foobar about="#vet3">Meh</foobar>' )
3696 },
3697 { type: '/alienInline' },
3698 { type: '/paragraph' },
3699 { type: 'internalList' },
3700 { type: '/internalList' }
3701 ]
3702 },
3703 'about group separated by whitespace is split': {
3704 body: '<div rel="ve:Alien" about="#vet1">Foo</div>\t<div rel="ve:Alien" about="#vet1">Bar</div>',
3705 data: [
3706 {
3707 type: 'alienBlock',
3708 originalDomElements: $.parseHTML( '<div rel="ve:Alien" about="#vet1">Foo</div>' ),
3709 internal: {
3710 whitespace: [ undefined, undefined, undefined, '\t' ]
3711 }
3712 },
3713 { type: '/alienBlock' },
3714 {
3715 type: 'alienBlock',
3716 originalDomElements: $.parseHTML( '<div rel="ve:Alien" about="#vet1">Bar</div>' ),
3717 internal: {
3718 whitespace: [ '\t' ]
3719 }
3720 },
3721 { type: '/alienBlock' },
3722 { type: 'internalList' },
3723 { type: '/internalList' }
3724 ]
3725 },
3726 'about group separated by text is split': {
3727 body: '<p><span rel="ve:Alien" about="#vet1">Foo</span>X<span rel="ve:Alien" about="#vet1">Bar</span></p>',
3728 data: [
3729 { type: 'paragraph' },
3730 {
3731 type: 'alienInline',
3732 originalDomElements: $.parseHTML( '<span rel="ve:Alien" about="#vet1">Foo</span>' )
3733 },
3734 { type: '/alienInline' },
3735 'X',
3736 {
3737 type: 'alienInline',
3738 originalDomElements: $.parseHTML( '<span rel="ve:Alien" about="#vet1">Bar</span>' )
3739 },
3740 { type: '/alienInline' },
3741 { type: '/paragraph' },
3742 { type: 'internalList' },
3743 { type: '/internalList' }
3744 ]
3745 },
3746 'whitespace preservation with an about group': {
3747 body: ' <div rel="ve:Alien" about="#vet1">\tFoo\t\t</div>' +
3748 '<div rel="ve:Alien" about="#vet1"> Bar </div> ',
3749 data: [
3750 {
3751 type: 'alienBlock',
3752 originalDomElements: $.parseHTML( '<div rel="ve:Alien" about="#vet1">\tFoo\t\t</div>' +
3753 '<div rel="ve:Alien" about="#vet1"> Bar </div>' ),
3754 internal: {
3755 whitespace: [ ' ', undefined, undefined, ' ' ]
3756 }
3757 },
3758 { type: '/alienBlock' },
3759 { type: 'internalList' },
3760 { type: '/internalList' }
3761 ],
3762 innerWhitespace: [ ' ', ' ' ]
3763 },
3764 'block node inside annotation node is alienated': {
3765 body: '<span>\n<p>Bar</p></span>',
3766 data: [
3767 { type: 'paragraph', internal: { generated: 'wrapper' } },
3768 [ '\n', [ ve.dm.example.span ] ],
3769 {
3770 type: 'alienInline',
3771 originalDomElements: $.parseHTML( '<p>Bar</p>' ),
3772 annotations: [ ve.dm.example.span ]
3773 },
3774 { type: '/alienInline' },
3775 { type: '/paragraph' },
3776 { type: 'internalList' },
3777 { type: '/internalList' }
3778 ],
3779 fromDataBody: '\n<span><p>Bar</p></span>'
3780 },
3781 'block node inside annotation node surrounded by tables': {
3782 body: '<table></table><span>\n<p>Bar</p></span><table></table>',
3783 data: [
3784 { type: 'table' },
3785 { type: '/table' },
3786 { type: 'paragraph', internal: { generated: 'wrapper' } },
3787 [ '\n', [ ve.dm.example.span ] ],
3788 {
3789 type: 'alienInline',
3790 originalDomElements: $.parseHTML( '<p>Bar</p>' ),
3791 annotations: [ ve.dm.example.span ]
3792 },
3793 { type: '/alienInline' },
3794 { type: '/paragraph' },
3795 { type: 'table' },
3796 { type: '/table' },
3797 { type: 'internalList' },
3798 { type: '/internalList' }
3799 ],
3800 fromDataBody: '<table></table>\n<span><p>Bar</p></span><table></table>'
3801 },
3802 'block node inside annotation node is alienated and continues wrapping': {
3803 body: 'Foo<span>\n<p>Bar</p></span>Baz',
3804 data: [
3805 { type: 'paragraph', internal: { generated: 'wrapper' } },
3806 ...'Foo',
3807 [ '\n', [ ve.dm.example.span ] ],
3808 {
3809 type: 'alienInline',
3810 originalDomElements: $.parseHTML( '<p>Bar</p>' ),
3811 annotations: [ ve.dm.example.span ]
3812 },
3813 { type: '/alienInline' },
3814 ...'Baz',
3815 { type: '/paragraph' },
3816 { type: 'internalList' },
3817 { type: '/internalList' }
3818 ],
3819 fromDataBody: 'Foo\n<span><p>Bar</p></span>Baz'
3820 },
3821 'list item wrapped in annotation is alienated': {
3822 body: '<ul><li>Foo</li><s><li>Bar</li></s><li>Baz</li></ul>',
3823 data: [
3824 { type: 'list', attributes: { style: 'bullet' } },
3825 { type: 'listItem' },
3826 { type: 'paragraph', internal: { generated: 'wrapper' } },
3827 ...'Foo',
3828 { type: '/paragraph' },
3829 { type: '/listItem' },
3830 {
3831 type: 'alienBlock',
3832 originalDomElements: $.parseHTML( '<s><li>Bar</li></s>' )
3833 },
3834 { type: '/alienBlock' },
3835 { type: 'listItem' },
3836 { type: 'paragraph', internal: { generated: 'wrapper' } },
3837 ...'Baz',
3838 { type: '/paragraph' },
3839 { type: '/listItem' },
3840 { type: '/list' },
3841 { type: 'internalList' },
3842 { type: '/internalList' }
3843 ]
3844 },
3845 'whitespace before meta node in wrapping mode': {
3846 body: '<table><tbody><tr><td>Foo\n<meta content="bar" /></td></tr></tbody></table>',
3847 data: [
3848 { type: 'table' },
3849 { type: 'tableSection', attributes: { style: 'body' } },
3850 { type: 'tableRow' },
3851 {
3852 type: 'tableCell',
3853 attributes: { style: 'data' },
3854 internal: { whitespace: [ undefined, undefined, '\n' ] }
3855 },
3856 {
3857 type: 'paragraph',
3858 internal: {
3859 generated: 'wrapper',
3860 whitespace: [ undefined, undefined, undefined, '\n' ]
3861 }
3862 },
3863 ...'Foo',
3864 { type: '/paragraph' },
3865 {
3866 type: 'alienMeta',
3867 internal: { whitespace: [ '\n' ] },
3868 originalDomElements: $.parseHTML( '<meta content="bar" />' )
3869 },
3870 { type: '/alienMeta' },
3871 { type: '/tableCell' },
3872 { type: '/tableRow' },
3873 { type: '/tableSection' },
3874 { type: '/table' },
3875 { type: 'internalList' },
3876 { type: '/internalList' }
3877 ],
3878 realData: [
3879 { type: 'table' },
3880 { type: 'tableSection', attributes: { style: 'body' } },
3881 { type: 'tableRow' },
3882 {
3883 type: 'tableCell',
3884 attributes: { style: 'data' },
3885 internal: { whitespace: [ undefined, undefined, '\n' ] }
3886 },
3887 {
3888 type: 'paragraph',
3889 internal: {
3890 generated: 'wrapper',
3891 whitespace: [ undefined, undefined, undefined, '\n' ]
3892 }
3893 },
3894 ...'Foo',
3895 { type: '/paragraph' },
3896 { type: '/tableCell' },
3897 // FIXME! <alienMeta></alienMeta> should be before </tableCell>. T189826
3898 {
3899 type: 'alienMeta',
3900 internal: { whitespace: [ '\n' ] },
3901 originalDomElements: $.parseHTML( '<meta content="bar" />' )
3902 },
3903 { type: '/alienMeta' },
3904 { type: '/tableRow' },
3905 { type: '/tableSection' },
3906 { type: '/table' },
3907 { type: 'internalList' },
3908 { type: '/internalList' }
3909 ]
3910 },
3911 'table with merged cells': {
3912 body: ve.dm.example.mergedCellsHtml,
3913 data: ve.dm.example.mergedCells
3914 },
3915 'table with caption, head, foot and body': {
3916 body: ve.dm.example.complexTableHtml,
3917 data: ve.dm.example.complexTable
3918 },
3919 'div set to RTL with paragraph inside': {
3920 body: '<div style="direction: rtl;"><p>a<b>b</b>c<i>d</i>e</p></div>',
3921 data: [
3922 { type: 'div' },
3923 { type: 'paragraph' },
3924 'a',
3925 [ 'b', [ ve.dm.example.bold ] ],
3926 'c',
3927 [ 'd', [ ve.dm.example.italic ] ],
3928 'e',
3929 { type: '/paragraph' },
3930 { type: '/div' },
3931 { type: 'internalList' },
3932 { type: '/internalList' }
3933 ],
3934 fromDataBody: '<div><p>a<b>b</b>c<i>d</i>e</p></div>'
3935 },
3936 'comment escaping': {
3937 body: '<p><!--&#x2D;Foo&#x2D;bar&#x2D;&#x2D;&#x3E;b&#x26;r&#x2D;--></p>',
3938 ignoreXmlWarnings: true,
3939 data: [
3940 { type: 'paragraph' },
3941 { type: 'comment', attributes: { text: '-Foo-bar-->b&r-' } },
3942 { type: '/comment' },
3943 { type: '/paragraph' },
3944 { type: 'internalList' },
3945 { type: '/internalList' }
3946 ],
3947 clipboardBody: '<p><span rel="ve:Comment" data-ve-comment="-Foo-bar-->b&amp;r-">&nbsp;</span></p>',
3948 previewBody: '<p>' + ve.dm.example.commentNodePreview( '-Foo-bar-->b&r-' ) + '</p>'
3949 },
3950 'comment escaping is normalized': {
3951 body: '<p><!--&gt;Foo-bar--&gt;b&amp;r---></p>',
3952 ignoreXmlWarnings: true,
3953 data: [
3954 { type: 'paragraph' },
3955 { type: 'comment', attributes: { text: '>Foo-bar-->b&r-' } },
3956 { type: '/comment' },
3957 { type: '/paragraph' },
3958 { type: 'internalList' },
3959 { type: '/internalList' }
3960 ],
3961 normalizedBody: '<p><!--&#x3E;Foo&#x2D;bar&#x2D;&#x2D;&#x3E;b&#x26;r&#x2D;--></p>',
3962 clipboardBody: '<p><span rel="ve:Comment" data-ve-comment=">Foo-bar-->b&amp;r-">&nbsp;</span></p>',
3963 previewBody: '<p>' + ve.dm.example.commentNodePreview( '>Foo-bar-->b&r-' ) + '</p>'
3964 },
3965 'comment as a child of node that can not handle comments (list)': {
3966 body: '<ul><li>foo</li><!--bar--></ul>',
3967 data: [
3968 { type: 'list', attributes: { style: 'bullet' } },
3969 { type: 'listItem' },
3970 { type: 'paragraph', internal: { generated: 'wrapper' } },
3971 ...'foo',
3972 { type: '/paragraph' },
3973 { type: '/listItem' },
3974 { type: 'commentMeta', attributes: { text: 'bar' } },
3975 { type: '/commentMeta' },
3976 { type: '/list' },
3977 { type: 'internalList' },
3978 { type: '/internalList' }
3979 ],
3980 realData: [
3981 { type: 'list', attributes: { style: 'bullet' } },
3982 { type: 'listItem' },
3983 { type: 'paragraph', internal: { generated: 'wrapper' } },
3984 ...'foo',
3985 { type: '/paragraph' },
3986 { type: '/listItem' },
3987 // FIXME! 'commentMeta' should not be a child of 'list'. T189543
3988 { type: 'commentMeta', attributes: { text: 'bar' } },
3989 { type: '/commentMeta' },
3990 { type: '/list' },
3991 { type: 'internalList' },
3992 { type: '/internalList' }
3993 ]
3994 },
3995 'comment as a child of node that can not handle comments (table row)': {
3996 body: '<table><tbody><tr><td>foo</td><!--bar--></tr></tbody></table>',
3997 data: [
3998 { type: 'table' },
3999 { type: 'tableSection', attributes: { style: 'body' } },
4000 { type: 'tableRow' },
4001 { type: 'tableCell', attributes: { style: 'data' } },
4002 { type: 'paragraph', internal: { generated: 'wrapper' } },
4003 ...'foo',
4004 { type: '/paragraph' },
4005 { type: '/tableCell' },
4006 { type: 'commentMeta', attributes: { text: 'bar' } },
4007 { type: '/commentMeta' },
4008 { type: '/tableRow' },
4009 { type: '/tableSection' },
4010 { type: '/table' },
4011 { type: 'internalList' },
4012 { type: '/internalList' }
4013 ],
4014 realData: [
4015 { type: 'table' },
4016 { type: 'tableSection', attributes: { style: 'body' } },
4017 { type: 'tableRow' },
4018 { type: 'tableCell', attributes: { style: 'data' } },
4019 { type: 'paragraph', internal: { generated: 'wrapper' } },
4020 ...'foo',
4021 { type: '/paragraph' },
4022 { type: '/tableCell' },
4023 // FIXME! 'commentMeta' should not be a child of 'tableRow'. T189543
4024 { type: 'commentMeta', attributes: { text: 'bar' } },
4025 { type: '/commentMeta' },
4026 { type: '/tableRow' },
4027 { type: '/tableSection' },
4028 { type: '/table' },
4029 { type: 'internalList' },
4030 { type: '/internalList' }
4031 ]
4032 },
4033 'article and sections': {
4034 body: '<article><header>Foo</header><section>Bar</section><footer>Baz</footer></article>',
4035 data: [
4036 { type: 'article' },
4037 { type: 'section', attributes: { style: 'header' } },
4038 { type: 'paragraph', internal: { generated: 'wrapper' } },
4039 ...'Foo',
4040 { type: '/paragraph' },
4041 { type: '/section' },
4042 { type: 'section', attributes: { style: 'section' } },
4043 { type: 'paragraph', internal: { generated: 'wrapper' } },
4044 ...'Bar',
4045 { type: '/paragraph' },
4046 { type: '/section' },
4047 { type: 'section', attributes: { style: 'footer' } },
4048 { type: 'paragraph', internal: { generated: 'wrapper' } },
4049 ...'Baz',
4050 { type: '/paragraph' },
4051 { type: '/section' },
4052 { type: '/article' },
4053 { type: 'internalList' },
4054 { type: '/internalList' }
4055 ],
4056 ceHtml: ve.dm.example.singleLine`
4057 <article class="ve-ce-branchNode ve-ce-articleNode" contenteditable="false">
4058 <header class="ve-ce-branchNode ve-ce-activeNode ve-ce-sectionNode" contenteditable="true" spellcheck="true">
4059 ${ ve.dm.example.ceWrapperParagraph }Foo</p>
4060 </header>
4061 <section class="ve-ce-branchNode ve-ce-activeNode ve-ce-sectionNode" contenteditable="true" spellcheck="true">
4062 ${ ve.dm.example.ceWrapperParagraph }Bar</p>
4063 </section>
4064 <footer class="ve-ce-branchNode ve-ce-activeNode ve-ce-sectionNode" contenteditable="true" spellcheck="true">
4065 ${ ve.dm.example.ceWrapperParagraph }Baz</p>
4066 </footer>
4067 </article>
4068 `
4069 },
4070 'other block nodes': {
4071 body: '<center>Foo</center><hr><blockquote>Bar</blockquote>',
4072 data: [
4073 { type: 'center' },
4074 { type: 'paragraph', internal: { generated: 'wrapper' } },
4075 ...'Foo',
4076 { type: '/paragraph' },
4077 { type: '/center' },
4078 { type: 'horizontalRule' },
4079 { type: '/horizontalRule' },
4080 { type: 'blockquote' },
4081 { type: 'paragraph', internal: { generated: 'wrapper' } },
4082 ...'Bar',
4083 { type: '/paragraph' },
4084 { type: '/blockquote' },
4085 { type: 'internalList' },
4086 { type: '/internalList' }
4087 ],
4088 ceHtml: ve.dm.example.singleLine`
4089 ${ ve.dm.example.blockSlug }
4090 <center class="ve-ce-branchNode">
4091 ${ ve.dm.example.ceWrapperParagraph }Foo</p>
4092 </center>
4093 ${ ve.dm.example.blockSlug }
4094 <div class="ve-ce-focusableNode ve-ce-horizontalRuleNode" contenteditable="false">
4095 <hr class="ve-ce-leafNode">
4096 </div>
4097 ${ ve.dm.example.blockSlug }
4098 <blockquote class="ve-ce-branchNode">
4099 ${ ve.dm.example.ceWrapperParagraph }Bar</p>
4100 </blockquote>
4101 ${ ve.dm.example.blockSlug }
4102 `
4103 },
4104 'alien table cells': {
4105 body: ve.dm.example.singleLine`
4106 <table>
4107 <tr>
4108 <td>A</td><td>B</td><td>C</td><td rel="ve:Alien" rowspan="2">Alien with rowspan</td>
4109 </tr>
4110 <tr>
4111 <td>E</td><td rel="ve:Alien">Alien 1</td><td rel="ve:Alien">Alien 2</td>
4112 </tr>
4113 <tr rel="ve:Alien">
4114 <td>Table</td><td>row</td><td>is an</td><td>alien</td>
4115 </tr>
4116 <tr>
4117 <td rel="ve:Alien" colspan="4">Row-spanning alien cell</td>
4118 </tr>
4119 <tr>
4120 <td>M</td><td colspan="2" rel="ve:Alien">Alien with colspan</td><td>P</td>
4121 </tr>
4122 <tr>
4123 <td>Q</td><td rel="ve:Alien" about="#group1">About-grouped</td><td rel="ve:Alien" about="#group1">alien cells</td><td>T</td>
4124 </tr>
4125 </table>
4126 `,
4127 data: [
4128 { type: 'table' },
4129 { type: 'tableSection', attributes: { style: 'body' } },
4130 { type: 'tableRow' },
4131 { type: 'tableCell', attributes: { style: 'data' } },
4132 { type: 'paragraph', internal: { generated: 'wrapper' } },
4133 'A',
4134 { type: '/paragraph' },
4135 { type: '/tableCell' },
4136 { type: 'tableCell', attributes: { style: 'data' } },
4137 { type: 'paragraph', internal: { generated: 'wrapper' } },
4138 'B',
4139 { type: '/paragraph' },
4140 { type: '/tableCell' },
4141 { type: 'tableCell', attributes: { style: 'data' } },
4142 { type: 'paragraph', internal: { generated: 'wrapper' } },
4143 'C',
4144 { type: '/paragraph' },
4145 { type: '/tableCell' },
4146 {
4147 type: 'alienTableCell',
4148 attributes: { rowspan: 2 },
4149 originalDomElements: $.parseHTML( '<td rel="ve:Alien" rowspan="2">Alien with rowspan</td>' ) },
4150 { type: '/alienTableCell' },
4151 { type: '/tableRow' },
4152 { type: 'tableRow' },
4153 { type: 'tableCell', attributes: { style: 'data' } },
4154 { type: 'paragraph', internal: { generated: 'wrapper' } },
4155 'E',
4156 { type: '/paragraph' },
4157 { type: '/tableCell' },
4158 {
4159 type: 'alienTableCell',
4160 originalDomElements: $.parseHTML( '<td rel="ve:Alien">Alien 1</td>' )
4161 },
4162 { type: '/alienTableCell' },
4163 {
4164 type: 'alienTableCell',
4165 originalDomElements: $.parseHTML( '<td rel="ve:Alien">Alien 2</td>' )
4166 },
4167 { type: '/alienTableCell' },
4168 { type: '/tableRow' },
4169 { type: 'alienBlock', originalDomElements: $.parseHTML( '<tr rel="ve:Alien"><td>Table</td><td>row</td><td>is an</td><td>alien</td></tr>' ) },
4170 { type: '/alienBlock' },
4171 { type: 'tableRow' },
4172 {
4173 type: 'alienTableCell',
4174 attributes: { colspan: 4 },
4175 originalDomElements: $.parseHTML( '<td rel="ve:Alien" colspan="4">Row-spanning alien cell</td>' )
4176 },
4177 { type: '/alienTableCell' },
4178 { type: '/tableRow' },
4179 { type: 'tableRow' },
4180 { type: 'tableCell', attributes: { style: 'data' } },
4181 { type: 'paragraph', internal: { generated: 'wrapper' } },
4182 'M',
4183 { type: '/paragraph' },
4184 { type: '/tableCell' },
4185 {
4186 type: 'alienTableCell',
4187 attributes: { colspan: 2 },
4188 originalDomElements: $.parseHTML( '<td colspan="2" rel="ve:Alien">Alien with colspan</td>' )
4189 },
4190 { type: '/alienTableCell' },
4191 { type: 'tableCell', attributes: { style: 'data' } },
4192 { type: 'paragraph', internal: { generated: 'wrapper' } },
4193 'P',
4194 { type: '/paragraph' },
4195 { type: '/tableCell' },
4196 { type: '/tableRow' },
4197 { type: 'tableRow' },
4198 { type: 'tableCell', attributes: { style: 'data' } },
4199 { type: 'paragraph', internal: { generated: 'wrapper' } },
4200 'Q',
4201 { type: '/paragraph' },
4202 { type: '/tableCell' },
4203 {
4204 type: 'alienTableCell',
4205 attributes: { colspan: 2 },
4206 originalDomElements: $.parseHTML( '<td rel="ve:Alien" about="#group1">About-grouped</td><td rel="ve:Alien" about="#group1">alien cells</td>' )
4207 },
4208 { type: '/alienTableCell' },
4209 { type: 'tableCell', attributes: { style: 'data' } },
4210 { type: 'paragraph', internal: { generated: 'wrapper' } },
4211 'T',
4212 { type: '/paragraph' },
4213 { type: '/tableCell' },
4214 { type: '/tableRow' },
4215 { type: '/tableSection' },
4216 { type: '/table' },
4217 { type: 'internalList' },
4218 { type: '/internalList' }
4219 ]
4220 }
4221 };
4222
4223 ve.dm.example.isolationHtml = ve.dm.example.singleLine`
4224 <ul>
4225 <li>Item 1</li>
4226 <li>Item 2</li>
4227 <li>Item 3</li>
4228 </ul>
4229 Paragraph
4230 <ul>
4231 <li>Item 4</li>
4232 <li>Item 5</li>
4233 <li>Item 6</li>
4234 </ul>
4235 <table><tbody>
4236 <tr>
4237 <td>Cell 1</td><td>Cell 2</td><td>Cell 3</td></tr><tr><td>Cell 4</td>
4238 </tr>
4239 </tbody></table>
4240 Not allowed by dm:
4241 <ul>
4242 <li><h1>Title in list</h1></li>
4243 <li><pre>Preformatted in list</pre></li>
4244 </ul>
4245 <ul>
4246 <li>
4247 <ol>
4248 <li>Nested 1</li>
4249 <li>Nested 2</li>
4250 <li>Nested 3</li>
4251 </ol>
4252 </li>
4253 </ul>
4254 <ul>
4255 <li>
4256 <p>P1</p>
4257 <p>P2</p>
4258 <p>P3</p>
4259 </li>
4260 </ul>
4261 `;
4262
4263 ve.dm.example.isolationData = [
4264 // 0
4265 { type: 'list', attributes: { style: 'bullet' } },
4266 { type: 'listItem' },
4267 { type: 'paragraph', internal: { generated: 'wrapper' } },
4268 ...'Item 1',
4269 { type: '/paragraph' },
4270 // 10
4271 { type: '/listItem' },
4272 { type: 'listItem' },
4273 { type: 'paragraph', internal: { generated: 'wrapper' } },
4274 ...'Item 2',
4275 { type: '/paragraph' },
4276 // 20
4277 { type: '/listItem' },
4278 { type: 'listItem' },
4279 { type: 'paragraph', internal: { generated: 'wrapper' } },
4280 ...'Item 3',
4281 { type: '/paragraph' },
4282 // 30
4283 { type: '/listItem' },
4284 { type: '/list' },
4285 { type: 'paragraph', internal: { generated: 'wrapper' } },
4286 ...'Paragraph',
4287 // 42
4288 { type: '/paragraph' },
4289 { type: 'list', attributes: { style: 'bullet' } },
4290 { type: 'listItem' },
4291 { type: 'paragraph', internal: { generated: 'wrapper' } },
4292 ...'Item 4',
4293 // 52
4294 { type: '/paragraph' },
4295 { type: '/listItem' },
4296 { type: 'listItem' },
4297 { type: 'paragraph', internal: { generated: 'wrapper' } },
4298 ...'Item 5',
4299 // 62
4300 { type: '/paragraph' },
4301 { type: '/listItem' },
4302 { type: 'listItem' },
4303 { type: 'paragraph', internal: { generated: 'wrapper' } },
4304 ...'Item 6',
4305 // 72
4306 { type: '/paragraph' },
4307 { type: '/listItem' },
4308 { type: '/list' },
4309 { type: 'table' },
4310 { type: 'tableSection', attributes: { style: 'body' } },
4311 { type: 'tableRow' },
4312 { type: 'tableCell', attributes: { style: 'data' } },
4313 { type: 'paragraph', internal: { generated: 'wrapper' } },
4314 // 80
4315 ...'Cell 1',
4316 { type: '/paragraph' },
4317 { type: '/tableCell' },
4318 { type: 'tableCell', attributes: { style: 'data' } },
4319 { type: 'paragraph', internal: { generated: 'wrapper' } },
4320 // 90
4321 ...'Cell 2',
4322 { type: '/paragraph' },
4323 { type: '/tableCell' },
4324 { type: 'tableCell', attributes: { style: 'data' } },
4325 { type: 'paragraph', internal: { generated: 'wrapper' } },
4326 // 100
4327 ...'Cell 3',
4328 { type: '/paragraph' },
4329 { type: '/tableCell' },
4330 { type: '/tableRow' },
4331 { type: 'tableRow' },
4332 // 110
4333 { type: 'tableCell', attributes: { style: 'data' } },
4334 { type: 'paragraph', internal: { generated: 'wrapper' } },
4335 ...'Cell 4',
4336 { type: '/paragraph' },
4337 { type: '/tableCell' },
4338 // 120
4339 { type: '/tableRow' },
4340 { type: '/tableSection' },
4341 { type: '/table' },
4342 { type: 'paragraph', internal: { generated: 'wrapper' } },
4343 // 124
4344 ...'Not allowed by dm:',
4345 // 142
4346 { type: '/paragraph' },
4347 { type: 'list', attributes: { style: 'bullet' } },
4348 { type: 'listItem' },
4349 { type: 'heading', attributes: { level: 1 } },
4350 // 146
4351 ...'Title in list',
4352 { type: '/heading' },
4353 // 160
4354 { type: '/listItem' },
4355 { type: 'listItem' },
4356 { type: 'preformatted' },
4357 // 163
4358 ...'Preformatted in list',
4359 // 183
4360 { type: '/preformatted' },
4361 { type: '/listItem' },
4362 { type: '/list' },
4363 { type: 'list', attributes: { style: 'bullet' } },
4364 { type: 'listItem' },
4365 { type: 'list', attributes: { style: 'number' } },
4366 { type: 'listItem' },
4367 // 190
4368 { type: 'paragraph', internal: { generated: 'wrapper' } },
4369 ...'Nested 1',
4370 { type: '/paragraph' },
4371 // 200
4372 { type: '/listItem' },
4373 { type: 'listItem' },
4374 { type: 'paragraph', internal: { generated: 'wrapper' } },
4375 ...'Nested 2',
4376 // 211
4377 { type: '/paragraph' },
4378 { type: '/listItem' },
4379 { type: 'listItem' },
4380 { type: 'paragraph', internal: { generated: 'wrapper' } },
4381 ...'Nested 3',
4382 // 223
4383 { type: '/paragraph' },
4384 { type: '/listItem' },
4385 { type: '/list' },
4386 { type: '/listItem' },
4387 { type: '/list' },
4388 { type: 'list', attributes: { style: 'bullet' } },
4389 { type: 'listItem' },
4390 // 230
4391 { type: 'paragraph' },
4392 ...'P1',
4393 { type: '/paragraph' },
4394 { type: 'paragraph' },
4395 ...'P2',
4396 { type: '/paragraph' },
4397 { type: 'paragraph' },
4398 ...'P3',
4399 // 241
4400 { type: '/paragraph' },
4401 { type: '/listItem' },
4402 { type: '/list' },
4403 { type: 'internalList' },
4404 { type: '/internalList' }
4405 // 246
4406 ];
4407
4408 ve.dm.example.RDFaDoc = ve.dm.converter.getModelFromDom( ve.createDocumentFromHtml( ve.dm.example.singleLine`
4409 <p content="b" datatype="c" resource="f" rev="g"
4410 ${ /* Non-RDFa attribute */'' }
4411 class="i">
4412 Foo
4413 </p>
4414 ` ) );
4415
4416 ve.dm.example.UnboldableNode = function () {
4417 // Parent constructor
4418 ve.dm.example.UnboldableNode.super.apply( this, arguments );
4419 };
4420 OO.inheritClass( ve.dm.example.UnboldableNode, ve.dm.LeafNode );
4421 ve.dm.example.UnboldableNode.static.name = 'exampleUnboldable';
4422 ve.dm.example.UnboldableNode.static.isContent = true;
4423 ve.dm.example.UnboldableNode.static.disallowedAnnotationTypes = [ 'textStyle/bold' ];
4424 ve.dm.example.UnboldableNode.static.matchTagNames = [];
4425 ve.dm.modelRegistry.register( ve.dm.example.UnboldableNode );
4426
4427 ve.dm.example.IgnoreChildrenNode = function () {
4428 // Parent constructor
4429 ve.dm.example.IgnoreChildrenNode.super.apply( this, arguments );
4430 };
4431 OO.inheritClass( ve.dm.example.IgnoreChildrenNode, ve.dm.BranchNode );
4432 ve.dm.example.IgnoreChildrenNode.static.name = 'exampleIgnoreChildren';
4433 ve.dm.example.IgnoreChildrenNode.static.ignoreChildren = true;
4434 ve.dm.example.IgnoreChildrenNode.static.matchTagNames = [];
4435 ve.dm.modelRegistry.register( ve.dm.example.IgnoreChildrenNode );
4436
4437 ve.dm.example.annotationData = [
4438 { type: 'paragraph' },
4439 ...'Foo',
4440 { type: 'exampleUnboldable' },
4441 // 5
4442 { type: '/exampleUnboldable' },
4443 ...'Bar',
4444 { type: '/paragraph' },
4445 // 10
4446 { type: 'exampleIgnoreChildren' },
4447 { type: 'paragraph' },
4448 'B',
4449 { type: '/paragraph' },
4450 { type: 'exampleIgnoreChildren' },
4451 // 15
4452 { type: 'paragraph' },
4453 'a',
4454 { type: '/paragraph' },
4455 { type: '/exampleIgnoreChildren' },
4456 { type: 'paragraph' },
4457 // 20
4458 'r',
4459 { type: '/paragraph' },
4460 { type: '/exampleIgnoreChildren' },
4461 { type: 'paragraph' },
4462 // 24
4463 ...'Baz',
4464 { type: '/paragraph' },
4465 { type: 'internalList' },
4466 { type: '/internalList' }
4467 // 30
4468 ];
4469
4470 ve.dm.example.selectNodesCases = [
4471 {
4472 range: new ve.Range( 1 ),
4473 mode: 'branches',
4474 expected: [
4475 // heading
4476 {
4477 node: [ 0 ],
4478 range: new ve.Range( 1 ),
4479 index: 0,
4480 nodeRange: new ve.Range( 1, 4 ),
4481 nodeOuterRange: new ve.Range( 0, 5 ),
4482 parentOuterRange: new ve.Range( 0, 63 )
4483 }
4484 ]
4485 },
4486 {
4487 range: new ve.Range( 10 ),
4488 mode: 'branches',
4489 expected: [
4490 // table/tableSection/tableRow/tableCell/paragraph
4491 {
4492 node: [ 1, 0, 0, 0, 0 ],
4493 range: new ve.Range( 10 ),
4494 index: 0,
4495 nodeRange: new ve.Range( 10, 11 ),
4496 nodeOuterRange: new ve.Range( 9, 12 ),
4497 parentOuterRange: new ve.Range( 8, 34 )
4498 }
4499 ]
4500 },
4501 {
4502 range: new ve.Range( 20 ),
4503 mode: 'branches',
4504 expected: [
4505 // table/tableSection/tableRow/tableCell/list/listItem/list/listItem/paragraph
4506 {
4507 node: [ 1, 0, 0, 0, 1, 0, 1, 0, 0 ],
4508 range: new ve.Range( 20 ),
4509 index: 0,
4510 nodeRange: new ve.Range( 20, 21 ),
4511 nodeOuterRange: new ve.Range( 19, 22 ),
4512 parentOuterRange: new ve.Range( 18, 23 )
4513 }
4514 ]
4515 },
4516 {
4517 range: new ve.Range( 1, 20 ),
4518 mode: 'branches',
4519 expected: [
4520 // heading
4521 {
4522 node: [ 0 ],
4523 range: new ve.Range( 1, 4 ),
4524 index: 0,
4525 nodeRange: new ve.Range( 1, 4 ),
4526 nodeOuterRange: new ve.Range( 0, 5 ),
4527 parentOuterRange: new ve.Range( 0, 63 )
4528 },
4529
4530 // table/tableSection/tableRow/tableCell/paragraph
4531 {
4532 node: [ 1, 0, 0, 0, 0 ],
4533 index: 0,
4534 nodeRange: new ve.Range( 10, 11 ),
4535 nodeOuterRange: new ve.Range( 9, 12 ),
4536 parentOuterRange: new ve.Range( 8, 34 )
4537 },
4538
4539 // table/tableSection/tableRow/tableCell/list/listItem/paragraph
4540 {
4541 node: [ 1, 0, 0, 0, 1, 0, 0 ],
4542 index: 0,
4543 nodeRange: new ve.Range( 15, 16 ),
4544 nodeOuterRange: new ve.Range( 14, 17 ),
4545 parentOuterRange: new ve.Range( 13, 25 )
4546 },
4547
4548 // table/tableSection/tableRow/tableCell/list/listItem/list/listItem/paragraph
4549 {
4550 node: [ 1, 0, 0, 0, 1, 0, 1, 0, 0 ],
4551 range: new ve.Range( 20 ),
4552 index: 0,
4553 nodeRange: new ve.Range( 20, 21 ),
4554 nodeOuterRange: new ve.Range( 19, 22 ),
4555 parentOuterRange: new ve.Range( 18, 23 )
4556 }
4557 ]
4558 },
4559 {
4560 range: new ve.Range( 1 ),
4561 mode: 'branches',
4562 expected: [
4563 // heading
4564 {
4565 node: [ 0 ],
4566 range: new ve.Range( 1 ),
4567 index: 0,
4568 nodeRange: new ve.Range( 1, 4 ),
4569 nodeOuterRange: new ve.Range( 0, 5 ),
4570 parentOuterRange: new ve.Range( 0, 63 )
4571 }
4572 ]
4573 },
4574 {
4575 range: new ve.Range( 0, 3 ),
4576 mode: 'leaves',
4577 expected: [
4578 // heading/text
4579 {
4580 node: [ 0, 0 ],
4581 range: new ve.Range( 1, 3 ),
4582 index: 0,
4583 nodeRange: new ve.Range( 1, 4 ),
4584 nodeOuterRange: new ve.Range( 1, 4 ),
4585 parentOuterRange: new ve.Range( 0, 5 )
4586 }
4587 ],
4588 msg: 'partial leaf results have ranges with global offsets'
4589 },
4590 {
4591 range: new ve.Range( 0, 11 ),
4592 mode: 'leaves',
4593 expected: [
4594 // heading/text
4595 {
4596 node: [ 0, 0 ],
4597 index: 0,
4598 nodeRange: new ve.Range( 1, 4 ),
4599 nodeOuterRange: new ve.Range( 1, 4 ),
4600 parentOuterRange: new ve.Range( 0, 5 )
4601 },
4602 // table/tableSection/tableRow/tableCell/paragraph/text
4603 {
4604 node: [ 1, 0, 0, 0, 0, 0 ],
4605 index: 0,
4606 nodeRange: new ve.Range( 10, 11 ),
4607 nodeOuterRange: new ve.Range( 10, 11 ),
4608 parentOuterRange: new ve.Range( 9, 12 )
4609 }
4610 ],
4611 msg: 'leaf nodes do not have ranges, leaf nodes from different levels'
4612 },
4613 {
4614 range: new ve.Range( 29, 43 ),
4615 mode: 'leaves',
4616 expected: [
4617 // table/tableSection/tableRow/tableCell/list/listItem/paragraph/text
4618 {
4619 node: [ 1, 0, 0, 0, 2, 0, 0, 0 ],
4620 index: 0,
4621 nodeRange: new ve.Range( 29, 30 ),
4622 nodeOuterRange: new ve.Range( 29, 30 ),
4623 parentOuterRange: new ve.Range( 28, 31 )
4624 },
4625 // preformatted/text
4626 {
4627 node: [ 2, 0 ],
4628 index: 0,
4629 nodeRange: new ve.Range( 38, 39 ),
4630 nodeOuterRange: new ve.Range( 38, 39 ),
4631 parentOuterRange: new ve.Range( 37, 43 )
4632 },
4633 // preformatted/image
4634 {
4635 node: [ 2, 1 ],
4636 index: 1,
4637 nodeRange: new ve.Range( 40 ),
4638 nodeOuterRange: new ve.Range( 39, 41 ),
4639 parentOuterRange: new ve.Range( 37, 43 )
4640 },
4641 // preformatted/text
4642 {
4643 node: [ 2, 2 ],
4644 index: 2,
4645 nodeRange: new ve.Range( 41, 42 ),
4646 nodeOuterRange: new ve.Range( 41, 42 ),
4647 parentOuterRange: new ve.Range( 37, 43 )
4648 }
4649 ],
4650 msg: 'leaf nodes that are not text nodes'
4651 },
4652 {
4653 range: new ve.Range( 2, 16 ),
4654 mode: 'siblings',
4655 expected: [
4656 // heading
4657 {
4658 node: [ 0 ],
4659 range: new ve.Range( 2, 4 ),
4660 index: 0,
4661 nodeRange: new ve.Range( 1, 4 ),
4662 nodeOuterRange: new ve.Range( 0, 5 ),
4663 parentOuterRange: new ve.Range( 0, 63 )
4664 },
4665 // table
4666 {
4667 node: [ 1 ],
4668 range: new ve.Range( 6, 16 ),
4669 index: 1,
4670 nodeRange: new ve.Range( 6, 36 ),
4671 nodeOuterRange: new ve.Range( 5, 37 ),
4672 parentOuterRange: new ve.Range( 0, 63 )
4673 }
4674 ],
4675 msg: 'siblings at the document level'
4676 },
4677 {
4678 range: new ve.Range( 2, 51 ),
4679 mode: 'siblings',
4680 expected: [
4681 // heading
4682 {
4683 node: [ 0 ],
4684 range: new ve.Range( 2, 4 ),
4685 index: 0,
4686 nodeRange: new ve.Range( 1, 4 ),
4687 nodeOuterRange: new ve.Range( 0, 5 ),
4688 parentOuterRange: new ve.Range( 0, 63 )
4689 },
4690 // table
4691 {
4692 node: [ 1 ],
4693 index: 1,
4694 nodeRange: new ve.Range( 6, 36 ),
4695 nodeOuterRange: new ve.Range( 5, 37 ),
4696 parentOuterRange: new ve.Range( 0, 63 )
4697 },
4698 // preformatted
4699 {
4700 node: [ 2 ],
4701 index: 2,
4702 nodeRange: new ve.Range( 38, 42 ),
4703 nodeOuterRange: new ve.Range( 37, 43 ),
4704 parentOuterRange: new ve.Range( 0, 63 )
4705 },
4706 // definitionList
4707 {
4708 node: [ 3 ],
4709 range: new ve.Range( 44, 51 ),
4710 index: 3,
4711 nodeRange: new ve.Range( 44, 54 ),
4712 nodeOuterRange: new ve.Range( 43, 55 ),
4713 parentOuterRange: new ve.Range( 0, 63 )
4714 }
4715 ],
4716 msg: 'more than 2 siblings at the document level'
4717 },
4718 {
4719 range: new ve.Range( 1 ),
4720 mode: 'leaves',
4721 expected: [
4722 // heading/text
4723 {
4724 node: [ 0, 0 ],
4725 range: new ve.Range( 1 ),
4726 index: 0,
4727 nodeRange: new ve.Range( 1, 4 ),
4728 nodeOuterRange: new ve.Range( 1, 4 ),
4729 parentOuterRange: new ve.Range( 0, 5 )
4730 }
4731 ],
4732 msg: 'zero-length range at the start of a text node returns text node rather than parent'
4733 },
4734 {
4735 range: new ve.Range( 4 ),
4736 mode: 'leaves',
4737 expected: [
4738 // heading/text
4739 {
4740 node: [ 0, 0 ],
4741 range: new ve.Range( 4 ),
4742 index: 0,
4743 nodeRange: new ve.Range( 1, 4 ),
4744 nodeOuterRange: new ve.Range( 1, 4 ),
4745 parentOuterRange: new ve.Range( 0, 5 )
4746 }
4747 ],
4748 msg: 'zero-length range at the end of a text node returns text node rather than parent'
4749 },
4750 {
4751 range: new ve.Range( 2, 3 ),
4752 mode: 'leaves',
4753 expected: [
4754 // heading/text
4755 {
4756 node: [ 0, 0 ],
4757 range: new ve.Range( 2, 3 ),
4758 index: 0,
4759 nodeRange: new ve.Range( 1, 4 ),
4760 nodeOuterRange: new ve.Range( 1, 4 ),
4761 parentOuterRange: new ve.Range( 0, 5 )
4762 }
4763 ],
4764 msg: 'range entirely within one leaf node'
4765 },
4766 {
4767 range: new ve.Range( 5 ),
4768 mode: 'leaves',
4769 expected: [
4770 // document
4771 {
4772 node: [],
4773 range: new ve.Range( 5 ),
4774 // No 'index' because documentNode has no parent
4775 indexInNode: 1,
4776 nodeRange: new ve.Range( 0, 63 ),
4777 nodeOuterRange: new ve.Range( 0, 63 )
4778 }
4779 ],
4780 msg: 'zero-length range between two children of the document'
4781 },
4782 {
4783 range: new ve.Range( 0 ),
4784 mode: 'leaves',
4785 expected: [
4786 // document
4787 {
4788 node: [],
4789 range: new ve.Range( 0 ),
4790 // No 'index' because documentNode has no parent
4791 indexInNode: 0,
4792 nodeRange: new ve.Range( 0, 63 ),
4793 nodeOuterRange: new ve.Range( 0, 63 )
4794 }
4795 ],
4796 msg: 'zero-length range at the start of the document'
4797 },
4798 {
4799 range: new ve.Range( 32, 39 ),
4800 mode: 'leaves',
4801 expected: [
4802 // table/tableSection/tableRow/tableCell/list
4803 {
4804 node: [ 1, 0, 0, 0, 2 ],
4805 range: new ve.Range( 32 ),
4806 index: 2,
4807 indexInNode: 1,
4808 nodeRange: new ve.Range( 27, 32 ),
4809 nodeOuterRange: new ve.Range( 26, 33 )
4810 },
4811 // preformatted/text
4812 {
4813 node: [ 2, 0 ],
4814 // No 'range' because the text node is covered completely
4815 index: 0,
4816 nodeRange: new ve.Range( 38, 39 ),
4817 nodeOuterRange: new ve.Range( 38, 39 ),
4818 parentOuterRange: new ve.Range( 37, 43 )
4819 }
4820 ],
4821 msg: 'range with 5 closings and a text node'
4822 },
4823 {
4824 range: new ve.Range( 2, 57 ),
4825 mode: 'covered',
4826 expected: [
4827 // heading/text
4828 {
4829 node: [ 0, 0 ],
4830 range: new ve.Range( 2, 4 ),
4831 index: 0,
4832 nodeRange: new ve.Range( 1, 4 ),
4833 nodeOuterRange: new ve.Range( 1, 4 ),
4834 parentOuterRange: new ve.Range( 0, 5 )
4835 },
4836 // table
4837 {
4838 node: [ 1 ],
4839 // no 'range' because the table is covered completely
4840 index: 1,
4841 nodeRange: new ve.Range( 6, 36 ),
4842 nodeOuterRange: new ve.Range( 5, 37 ),
4843 parentOuterRange: new ve.Range( 0, 63 )
4844 },
4845 // preformatted
4846 {
4847 node: [ 2 ],
4848 // No 'range' because the node is covered completely
4849 index: 2,
4850 nodeRange: new ve.Range( 38, 42 ),
4851 nodeOuterRange: new ve.Range( 37, 43 ),
4852 parentOuterRange: new ve.Range( 0, 63 )
4853 },
4854 // definitionList
4855 {
4856 node: [ 3 ],
4857 // No 'range' because the node is covered completely
4858 index: 3,
4859 nodeRange: new ve.Range( 44, 54 ),
4860 nodeOuterRange: new ve.Range( 43, 55 ),
4861 parentOuterRange: new ve.Range( 0, 63 )
4862 },
4863 // paragraph/text
4864 {
4865 node: [ 4, 0 ],
4866 // No 'range' because the text node is covered completely
4867 index: 0,
4868 nodeRange: new ve.Range( 56, 57 ),
4869 nodeOuterRange: new ve.Range( 56, 57 ),
4870 parentOuterRange: new ve.Range( 55, 58 )
4871 }
4872 ],
4873 msg: 'range from the first heading into the second-to-last paragraph, in covered mode'
4874 },
4875 {
4876 range: new ve.Range( 14 ),
4877 mode: 'siblings',
4878 expected: [
4879 // table/tableSection/tableRow/tableCell/list/listItem
4880 {
4881 node: [ 1, 0, 0, 0, 1, 0 ],
4882 range: new ve.Range( 14 ),
4883 index: 0,
4884 indexInNode: 0,
4885 nodeRange: new ve.Range( 14, 24 ),
4886 nodeOuterRange: new ve.Range( 13, 25 )
4887 }
4888 ],
4889 msg: 'zero-length range at the beginning of a listItem, in siblings mode'
4890 },
4891 {
4892 range: new ve.Range( 25, 27 ),
4893 mode: 'covered',
4894 expected: [
4895 // table/tableSection/tableRow/tableCell/list
4896 {
4897 node: [ 1, 0, 0, 0, 1 ],
4898 range: new ve.Range( 25 ),
4899 index: 1,
4900 indexInNode: 1,
4901 nodeRange: new ve.Range( 13, 25 ),
4902 nodeOuterRange: new ve.Range( 12, 26 )
4903 },
4904 // table/tableSection/tableRow/tableCell/list
4905 {
4906 node: [ 1, 0, 0, 0, 2 ],
4907 range: new ve.Range( 27 ),
4908 index: 2,
4909 indexInNode: 0,
4910 nodeRange: new ve.Range( 27, 32 ),
4911 nodeOuterRange: new ve.Range( 26, 33 )
4912 }
4913 ],
4914 msg: 'range covering a list closing and a list opening'
4915 },
4916 {
4917 range: new ve.Range( 39 ),
4918 mode: 'leaves',
4919 expected: [
4920 // preformatted/text
4921 {
4922 node: [ 2, 0 ],
4923 range: new ve.Range( 39 ),
4924 index: 0,
4925 nodeRange: new ve.Range( 38, 39 ),
4926 nodeOuterRange: new ve.Range( 38, 39 ),
4927 parentOuterRange: new ve.Range( 37, 43 )
4928 }
4929 ],
4930 msg: 'zero-length range in text node before inline node'
4931 },
4932 {
4933 range: new ve.Range( 41 ),
4934 mode: 'leaves',
4935 expected: [
4936 // preformatted/text
4937 {
4938 node: [ 2, 2 ],
4939 range: new ve.Range( 41 ),
4940 index: 2,
4941 nodeRange: new ve.Range( 41, 42 ),
4942 nodeOuterRange: new ve.Range( 41, 42 ),
4943 parentOuterRange: new ve.Range( 37, 43 )
4944 }
4945 ],
4946 msg: 'zero-length range in text node after inline node'
4947 },
4948 {
4949 doc: 'emptyBranch',
4950 range: new ve.Range( 1 ),
4951 mode: 'leaves',
4952 expected: [
4953 // table
4954 {
4955 node: [ 0 ],
4956 range: new ve.Range( 1 ),
4957 index: 0,
4958 indexInNode: 0,
4959 nodeRange: new ve.Range( 1 ),
4960 nodeOuterRange: new ve.Range( 0, 2 ),
4961 parentOuterRange: new ve.Range( 0, 4 )
4962 }
4963 ],
4964 msg: 'zero-length range in empty branch node'
4965 },
4966 {
4967 doc: 'internalData',
4968 range: new ve.Range( 6, 13 ),
4969 mode: 'leaves',
4970 expected: [
4971 // internal item
4972 {
4973 node: [ 1, 0 ],
4974 index: 0,
4975 nodeRange: new ve.Range( 7, 12 ),
4976 nodeOuterRange: new ve.Range( 6, 13 ),
4977 parentOuterRange: new ve.Range( 5, 21 )
4978 }
4979 ],
4980 msg: 'range covering ignoreChildren node doesn\'t descend'
4981 }
4982 ];