| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
ve.ce.TextNode = function VeCeTextNode() { |
| 17 |
|
| 18 |
ve.ce.TextNode.super.apply( this, arguments ); |
| 19 |
|
| 20 |
this.$element = $( [] ); |
| 21 |
}; |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
OO.inheritClass( ve.ce.TextNode, ve.ce.LeafNode ); |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
ve.ce.TextNode.static.name = 'text'; |
| 30 |
|
| 31 |
ve.ce.TextNode.static.splitOnEnter = true; |
| 32 |
|
| 33 |
|
| 34 |
ve.ce.TextNode.static.whitespaceHtmlCharacters = ve.visibleWhitespaceCharacters; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
ve.ce.TextNode.prototype.getAnnotatedHtml = function () { |
| 44 |
const data = this.model.getDocument().getDataFromNode( this.model ), |
| 45 |
whitespaceHtmlChars = ve.visibleWhitespaceCharacters, |
| 46 |
significantWhitespace = this.getModel().getParent().hasSignificantWhitespace(); |
| 47 |
|
| 48 |
function setChar( chr, index ) { |
| 49 |
if ( Array.isArray( data[ index ] ) ) { |
| 50 |
|
| 51 |
data[ index ] = data[ index ].slice( 0 ); |
| 52 |
data[ index ][ 0 ] = chr; |
| 53 |
} else { |
| 54 |
data[ index ] = chr; |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
function getChar( index ) { |
| 59 |
if ( Array.isArray( data[ index ] ) ) { |
| 60 |
return data[ index ][ 0 ]; |
| 61 |
} else { |
| 62 |
return data[ index ]; |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
if ( !significantWhitespace ) { |
| 67 |
for ( let i = 0; i < data.length; i++ ) { |
| 68 |
const char = getChar( i ); |
| 69 |
|
| 70 |
if ( Object.prototype.hasOwnProperty.call( whitespaceHtmlChars, char ) ) { |
| 71 |
setChar( whitespaceHtmlChars[ char ], i ); |
| 72 |
} |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
return data; |
| 77 |
}; |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
ve.ce.nodeFactory.register( ve.ce.TextNode ); |