| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
ve.dm.SourceConverter = function VeDmSourceConverter() { |
| 8 |
}; |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
ve.dm.SourceConverter.prototype.getModelFromSourceText = function ( sourceText, options ) { |
| 22 |
const data = this.getDataFromSourceText( sourceText ); |
| 23 |
|
| 24 |
options = options || {}; |
| 25 |
|
| 26 |
|
| 27 |
data.push( { type: 'internalList' }, { type: '/internalList' } ); |
| 28 |
|
| 29 |
return new ve.dm.Document( data, undefined, undefined, undefined, undefined, options.lang, options.dir, undefined, true ); |
| 30 |
}; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
ve.dm.SourceConverter.prototype.getDataFromSourceText = function ( sourceText, inline ) { |
| 40 |
const lines = sourceText.split( /\r\n|\r|\n/ ), |
| 41 |
content = []; |
| 42 |
|
| 43 |
for ( let i = 0, l = lines.length; i < l; i++ ) { |
| 44 |
|
| 45 |
if ( !( inline && i === 0 ) ) { |
| 46 |
content.push( { type: 'paragraph' } ); |
| 47 |
} |
| 48 |
ve.batchPush( content, lines[ i ].split( '' ) ); |
| 49 |
|
| 50 |
if ( !( inline && i === l - 1 ) ) { |
| 51 |
content.push( { type: '/paragraph' } ); |
| 52 |
} |
| 53 |
} |
| 54 |
return content; |
| 55 |
}; |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
ve.dm.SourceConverter.prototype.getSourceTextFromModel = function ( model ) { |
| 64 |
return this.getSourceTextFromDataRange( model.data.data ); |
| 65 |
}; |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
ve.dm.SourceConverter.prototype.getSourceTextFromDataRange = function ( data, range ) { |
| 75 |
let text = ''; |
| 76 |
|
| 77 |
range = range || new ve.Range( 0, data.length ); |
| 78 |
|
| 79 |
for ( let i = range.start; i < range.end; i++ ) { |
| 80 |
|
| 81 |
if ( !data[ i ].type ) { |
| 82 |
text += data[ i ]; |
| 83 |
} else if ( data[ i ].type === '/paragraph' && |
| 84 |
( !data[ i + 1 ] || data[ i + 1 ].type === 'paragraph' ) |
| 85 |
) { |
| 86 |
|
| 87 |
text += '\n'; |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
return text; |
| 92 |
}; |
| 93 |
|
| 94 |
ve.dm.sourceConverter = new ve.dm.SourceConverter(); |