| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
ve.dm.MWIncludesNode = function VeDmMWIncludesNode() { |
| 17 |
|
| 18 |
ve.dm.MWIncludesNode.super.apply( this, arguments ); |
| 19 |
}; |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
OO.inheritClass( ve.dm.MWIncludesNode, ve.dm.AlienInlineNode ); |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
ve.dm.MWIncludesNode.static.name = 'mwIncludes'; |
| 28 |
|
| 29 |
ve.dm.MWIncludesNode.static.matchRdfaTypes = [ |
| 30 |
/^mw:Includes\// |
| 31 |
]; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
ve.dm.MWIncludesNode.static.toDataElement = function ( domElements ) { |
| 39 |
const mwDataJSON = domElements[ 0 ].getAttribute( 'data-mw' ), |
| 40 |
type = domElements[ 0 ].getAttribute( 'typeof' ); |
| 41 |
|
| 42 |
const dataElement = { |
| 43 |
type: 'mwIncludes', |
| 44 |
attributes: { |
| 45 |
type: type |
| 46 |
} |
| 47 |
}; |
| 48 |
|
| 49 |
if ( mwDataJSON !== null ) { |
| 50 |
dataElement.attributes.mw = JSON.parse( mwDataJSON ); |
| 51 |
} |
| 52 |
|
| 53 |
if ( type === 'mw:Includes/IncludeOnly/End' ) { |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
return []; |
| 58 |
} |
| 59 |
|
| 60 |
return dataElement; |
| 61 |
}; |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
ve.dm.MWIncludesNode.static.toDomElements = function ( dataElement, doc, converter ) { |
| 67 |
const el = doc.createElement( 'meta' ); |
| 68 |
el.setAttribute( 'typeof', dataElement.attributes.type ); |
| 69 |
if ( dataElement.attributes.mw ) { |
| 70 |
el.setAttribute( 'data-mw', JSON.stringify( dataElement.attributes.mw ) ); |
| 71 |
} |
| 72 |
|
| 73 |
const els = [ el ]; |
| 74 |
if ( dataElement.attributes.type === 'mw:Includes/IncludeOnly' ) { |
| 75 |
|
| 76 |
ve.batchPush( els, ve.dm.MWIncludesNode.static.toDomElements( { |
| 77 |
type: 'mwIncludes', |
| 78 |
attributes: { |
| 79 |
type: 'mw:Includes/IncludeOnly/End' |
| 80 |
} |
| 81 |
}, doc, converter ) ); |
| 82 |
} |
| 83 |
|
| 84 |
return els; |
| 85 |
}; |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
ve.dm.MWIncludesNode.prototype.getWikitextTag = function () { |
| 90 |
const map = { |
| 91 |
'mw:Includes/NoInclude': '<noinclude>', |
| 92 |
'mw:Includes/NoInclude/End': '</noinclude>', |
| 93 |
'mw:Includes/OnlyInclude': '<onlyinclude>', |
| 94 |
'mw:Includes/OnlyInclude/End': '</onlyinclude>', |
| 95 |
'mw:Includes/IncludeOnly': '<includeonly>…</includeonly>' |
| 96 |
}; |
| 97 |
return map[ this.getAttribute( 'type' ) ]; |
| 98 |
}; |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
ve.dm.modelRegistry.register( ve.dm.MWIncludesNode ); |