mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-29 00:30:44 +00:00
e148234c29
Moved annotation rendering from ce.Textnode into the new ce.ContentBranchNode class. This allows us to render annotations that span across multiple nodes. * Add ce.ContentBranchNode, inheriting ce.BranchNode * Make ce.{Paragraph,Heading,Preformatted}Node inherit ce.ContentBranchNode * Made ce.ContentBranchNode render its child nodes with anntations, using .getAnnotatedHtml() on the child nodes * Put a default implementation for .getAnnotatedHtml() in ce.LeafNode * Override this in ce.TextNode to do escaping and whitespace handling * Removed rendering code from ce.TextNode (this.$ is now unused there) * Removed ce.TextNode.onUpdate() and ce.BranchNode.clean(), now unneeded * Have ce.BranchNode propagate update events from children, so ce.ContentBranchNode can rerender when its children change * Update tests, add test case for escaping of &<>'" Change-Id: I4600e984b287c6ff9267f4281d2f09bab9e1ad95
153 lines
4.3 KiB
JavaScript
153 lines
4.3 KiB
JavaScript
/**
|
|
* VisualEditor content editable TextNode tests.
|
|
*
|
|
* @copyright 2011-2012 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
QUnit.module( 've.ce.TextNode' );
|
|
|
|
/* Tests */
|
|
|
|
QUnit.test( 'getAnnotatedHtml', function ( assert ) {
|
|
var i, len, cases;
|
|
|
|
cases = [
|
|
{
|
|
'data': [
|
|
{ 'type': 'paragraph' },
|
|
'a',
|
|
'b',
|
|
'c',
|
|
{ 'type': '/paragraph' }
|
|
],
|
|
'html': [ 'a', 'b', 'c' ]
|
|
},
|
|
{
|
|
'data': [
|
|
{ 'type': 'paragraph' },
|
|
['a', [ { 'type': 'textStyle/bold' } ]],
|
|
['b', [ { 'type': 'textStyle/bold' } ]],
|
|
['c', [ { 'type': 'textStyle/bold' } ]],
|
|
{ 'type': '/paragraph' }
|
|
],
|
|
'html': [
|
|
['a', [ { 'type': 'textStyle/bold' } ]],
|
|
['b', [ { 'type': 'textStyle/bold' } ]],
|
|
['c', [ { 'type': 'textStyle/bold' } ]]
|
|
]
|
|
},
|
|
{
|
|
'data': [
|
|
{ 'type': 'paragraph' },
|
|
['a', [ { 'type': 'textStyle/bold' } ]],
|
|
'b',
|
|
['c', [ { 'type': 'textStyle/italic' } ]],
|
|
{ 'type': '/paragraph' }
|
|
],
|
|
'html': [
|
|
['a', [ { 'type': 'textStyle/bold' } ]],
|
|
'b',
|
|
['c', [ { 'type': 'textStyle/italic' } ]]
|
|
]
|
|
},
|
|
{
|
|
// [ ]
|
|
'data': [{ 'type': 'paragraph' },{ 'type': '/paragraph' }],
|
|
'html': []
|
|
},
|
|
{
|
|
// [ ]
|
|
'data': [{ 'type': 'paragraph' },' ',{ 'type': '/paragraph' }],
|
|
'html': [ ' ' ]
|
|
},
|
|
{
|
|
// [ ][ ]
|
|
'data': [{ 'type': 'paragraph' },' ', ' ',{ 'type': '/paragraph' }],
|
|
'html': [ ' ', ' ' ]
|
|
},
|
|
{
|
|
// [ ][ ][ ]
|
|
'data': [{ 'type': 'paragraph' },' ', ' ', ' ',{ 'type': '/paragraph' }],
|
|
'html': [ ' ', ' ', ' ' ]
|
|
},
|
|
{
|
|
// [ ][ ][ ][ ]
|
|
'data': [{ 'type': 'paragraph' },' ', ' ', ' ', ' ',{ 'type': '/paragraph' }],
|
|
'html': [ ' ', ' ', ' ', ' ' ]
|
|
},
|
|
{
|
|
// [ ][ ][ ][ ][ ]
|
|
'data': [{ 'type': 'paragraph' },' ', ' ', ' ', ' ', ' ',{ 'type': '/paragraph' }],
|
|
'html': [ ' ', ' ', ' ', ' ', ' ' ]
|
|
},
|
|
{
|
|
// [ ][ ][ ][ ][ ][ ]
|
|
'data': [{ 'type': 'paragraph' },' ', ' ', ' ', ' ', ' ', ' ',{ 'type': '/paragraph' }],
|
|
'html': [ ' ', ' ', ' ', ' ', ' ', ' ' ]
|
|
},
|
|
{
|
|
// [ ][A][ ][ ][ ][ ]
|
|
'data': [{ 'type': 'paragraph' },' ', 'A', ' ', ' ', ' ', ' ',{ 'type': '/paragraph' }],
|
|
'html': [ ' ', 'A', ' ', ' ', ' ', ' ' ]
|
|
},
|
|
{
|
|
// [ ][ ][A][ ][ ][ ]
|
|
'data': [{ 'type': 'paragraph' },' ', ' ', 'A', ' ', ' ', ' ',{ 'type': '/paragraph' }],
|
|
'html': [ ' ', ' ', 'A', ' ', ' ', ' ' ]
|
|
},
|
|
{
|
|
// [ ][ ][ ][A][ ][ ]
|
|
'data': [{ 'type': 'paragraph' },' ', ' ', ' ', 'A', ' ', ' ',{ 'type': '/paragraph' }],
|
|
'html': [ ' ', ' ', ' ', 'A', ' ', ' ' ]
|
|
},
|
|
{
|
|
// [ ][ ][ ][ ][A][ ]
|
|
'data': [{ 'type': 'paragraph' },' ', ' ', ' ', ' ', 'A', ' ',{ 'type': '/paragraph' }],
|
|
'html': [ ' ', ' ', ' ', ' ', 'A', ' ' ]
|
|
},
|
|
{
|
|
// [ ][ ][ ][ ][ ][A]
|
|
'data': [{ 'type': 'paragraph' },' ', ' ', ' ', ' ', ' ', 'A',{ 'type': '/paragraph' }],
|
|
'html': [ ' ', ' ', ' ', ' ', ' ', 'A' ]
|
|
},
|
|
{
|
|
'data': [{ 'type': 'paragraph' }, '\n', 'A', '\n', 'B', '\n', { 'type': '/paragraph' }],
|
|
'html': [ '↵', 'A', '↵', 'B', '↵' ]
|
|
},
|
|
{
|
|
'data': [{ 'type': 'paragraph' }, '\t', 'A', '\t', 'B', '\t', { 'type': '/paragraph' }],
|
|
'html': [ '➞', 'A', '➞', 'B', '➞' ]
|
|
},
|
|
{
|
|
'data': [{ 'type': 'preformatted' }, '\n', 'A', '\n', 'B', '\n', { 'type': '/preformatted' }],
|
|
'html': [ '\n', 'A', '\n', 'B', '\n' ]
|
|
},
|
|
{
|
|
'data': [{ 'type': 'preformatted' }, '\t', 'A', '\t', 'B', '\t', { 'type': '/preformatted' }],
|
|
'html': [ '\t', 'A', '\t', 'B', '\t' ]
|
|
},
|
|
{
|
|
// [ ][ ][ ][A][ ][ ]
|
|
'data': [{ 'type': 'preformatted' },' ', ' ', ' ', 'A', ' ', ' ',{ 'type': '/preformatted' }],
|
|
'html': [ ' ', ' ', ' ', 'A', ' ', ' ' ]
|
|
},
|
|
{
|
|
'data': [{ 'type': 'paragraph' }, '&', '<', '>', '\'', '"', { 'type': '/paragraph' }],
|
|
'html': [ '&', '<', '>', ''', '"' ]
|
|
}
|
|
];
|
|
QUnit.expect( cases.length );
|
|
for ( i = 0, len = cases.length; i < len; i++ ) {
|
|
ve.dm.example.preprocessAnnotations( cases[i].data );
|
|
ve.dm.example.preprocessAnnotations( cases[i].html );
|
|
assert.deepEqual(
|
|
( new ve.ce.TextNode(
|
|
( new ve.dm.Document( cases[i].data ) )
|
|
.documentNode.getChildren()[0].getChildren()[0] )
|
|
).getAnnotatedHtml(),
|
|
cases[i].html
|
|
);
|
|
}
|
|
} );
|