1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
|
/*!
* VisualEditor Wikitext command registry
*
* @copyright See AUTHORS.txt
*/
/**
* Command registry.
*
* @class
* @extends ve.ui.CommandRegistry
* @constructor
* @param {ve.ui.CommandRegistry} fallbackRegistry Fallback registry
*/
ve.ui.MWWikitextCommandRegistry = function VeUiMwWikitextCommandRegistry( fallbackRegistry ) {
// Parent constructor
ve.ui.MWWikitextCommandRegistry.super.apply( this, arguments );
this.fallbackRegistry = fallbackRegistry;
};
/* Inheritance */
OO.inheritClass( ve.ui.MWWikitextCommandRegistry, ve.ui.CommandRegistry );
/* Methods */
/**
* Get data for a given symbolic name.
*
* See https://doc.wikimedia.org/oojs/master/OO.Registry.html
*
* @param {string} name Symbolic name
* @return {any|undefined} Data associated with symbolic name
*/
ve.ui.MWWikitextCommandRegistry.prototype.lookup = function ( name ) {
// Parent method
const data = ve.ui.MWWikitextCommandRegistry.super.prototype.lookup.call( this, name );
if ( data !== undefined ) {
return data;
}
// Fall through to original command registry if not overridden.
return this.fallbackRegistry.lookup( name );
};
/**
* @inheritdoc
*/
ve.ui.MWWikitextCommandRegistry.prototype.getNames = function () {
return OO.simpleArrayUnion(
// Parent method
ve.ui.MWWikitextCommandRegistry.super.prototype.getNames.call( this ),
this.fallbackRegistry.getNames()
);
};
/* Initialization */
ve.ui.wikitextCommandRegistry = new ve.ui.MWWikitextCommandRegistry( ve.ui.commandRegistry );
/* Registrations */
ve.ui.wikitextCommandRegistry.register(
new ve.ui.Command(
'bold', 'mwWikitext', 'toggleWrapSelection',
{ args: [ '\'\'\'', '\'\'\'', OO.ui.deferMsg( 'visualeditor-annotationbutton-bold-tooltip' ) ], supportedSelections: [ 'linear' ] }
)
);
ve.ui.wikitextCommandRegistry.register(
new ve.ui.Command(
'italic', 'mwWikitext', 'toggleWrapSelection',
{
args: [
'\'\'', '\'\'',
OO.ui.deferMsg( 'visualeditor-annotationbutton-italic-tooltip' ),
/* expandOffsetsCallback */
function ( textBefore, textAfter ) {
let matches, lengthBefore, lengthAfter;
if ( ( matches = textBefore.match( /('+)$/ ) ) ) {
lengthBefore = -matches[ 1 ].length;
}
if ( ( matches = textAfter.match( /^('+)/ ) ) ) {
lengthAfter = matches[ 1 ].length;
}
return lengthBefore || lengthAfter ? [ lengthBefore, lengthAfter ] : null;
},
/* unwrapOffsetsCallback */
function ( text ) {
/* Text is only italic if there are 2 or 5+ apostrophes */
const matches = /^(''([^'].*|.*[^'])''|'{5,}([^'].*|.*[^'])'{5,})$/.test( text );
return matches ? [ 2, 2 ] : null;
}
],
supportedSelections: [ 'linear' ] }
)
);
ve.ui.wikitextCommandRegistry.register(
new ve.ui.Command(
'code', 'mwWikitext', 'toggleWrapSelection',
{ args: [ '<code>', '</code>', OO.ui.deferMsg( 'visualeditor-annotationbutton-code-tooltip' ) ], supportedSelections: [ 'linear' ] }
)
);
ve.ui.wikitextCommandRegistry.register(
new ve.ui.Command(
'strikethrough', 'mwWikitext', 'toggleWrapSelection',
{ args: [ '<s>', '</s>', OO.ui.deferMsg( 'visualeditor-annotationbutton-strikethrough-tooltip' ) ], supportedSelections: [ 'linear' ] }
)
);
ve.ui.wikitextCommandRegistry.register(
new ve.ui.Command(
'underline', 'mwWikitext', 'toggleWrapSelection',
{ args: [ '<u>', '</u>', OO.ui.deferMsg( 'visualeditor-annotationbutton-underline-tooltip' ) ], supportedSelections: [ 'linear' ] }
)
);
ve.ui.wikitextCommandRegistry.register(
new ve.ui.Command(
'subscript', 'mwWikitext', 'toggleWrapSelection',
{ args: [ '<sub>', '</sub>', OO.ui.deferMsg( 'visualeditor-annotationbutton-subscript-tooltip' ) ], supportedSelections: [ 'linear' ] }
)
);
ve.ui.wikitextCommandRegistry.register(
new ve.ui.Command(
'superscript', 'mwWikitext', 'toggleWrapSelection',
{ args: [ '<sup>', '</sup>', OO.ui.deferMsg( 'visualeditor-annotationbutton-superscript-tooltip' ) ], supportedSelections: [ 'linear' ] }
)
);
ve.ui.wikitextCommandRegistry.register(
new ve.ui.Command(
'big', 'mwWikitext', 'toggleWrapSelection',
{ args: [ '<big>', '</big>', OO.ui.deferMsg( 'visualeditor-annotationbutton-big-tooltip' ) ], supportedSelections: [ 'linear' ] }
)
);
ve.ui.wikitextCommandRegistry.register(
new ve.ui.Command(
'small', 'mwWikitext', 'toggleWrapSelection',
{ args: [ '<small>', '</small>', OO.ui.deferMsg( 'visualeditor-annotationbutton-small-tooltip' ) ], supportedSelections: [ 'linear' ] }
)
);
( function () {
function unformat( text ) {
/* Use lazy .+? in the middle so whitespace is matched to wrappers */
let headings;
if ( ( headings = text.match( /^((={1,6})\s*).+?(\s*\2\s*)$/ ) ) ) {
return [ headings[ 1 ].length, headings[ 3 ].length ];
}
let pre;
if ( ( pre = text.match( /^ +/ ) ) ) {
return [ pre[ 0 ].length, 0 ];
}
}
let heading = '';
for ( let i = 1; i <= 6; i++ ) {
heading += '=';
ve.ui.wikitextCommandRegistry.register(
new ve.ui.Command(
'heading' + i, 'mwWikitext', 'wrapLine',
{
args: [
heading + ' ',
' ' + heading,
// The following messages can be used here:
// * visualeditor-formatdropdown-format-heading1
// * visualeditor-formatdropdown-format-heading2
// * visualeditor-formatdropdown-format-heading3
// * visualeditor-formatdropdown-format-heading4
// * visualeditor-formatdropdown-format-heading5
// * visualeditor-formatdropdown-format-heading6
OO.ui.deferMsg( 'visualeditor-formatdropdown-format-heading' + i ),
unformat
],
supportedSelections: [ 'linear' ]
}
)
);
}
ve.ui.wikitextCommandRegistry.register(
new ve.ui.Command(
'paragraph', 'mwWikitext', 'wrapLine',
{ args: [ '', '', '', unformat ], supportedSelections: [ 'linear' ] }
)
);
ve.ui.wikitextCommandRegistry.register(
new ve.ui.Command(
'preformatted', 'mwWikitext', 'wrapLine',
{ args: [ ' ', '', OO.ui.deferMsg( 'visualeditor-formatdropdown-format-preformatted' ), unformat ], supportedSelections: [ 'linear' ] }
)
);
ve.ui.wikitextCommandRegistry.register(
new ve.ui.Command(
'blockquote', 'mwWikitext', 'toggleWrapSelection',
{ args: [ '<blockquote>', '</blockquote>', OO.ui.deferMsg( 'visualeditor-formatdropdown-format-blockquote' ) ], supportedSelections: [ 'linear' ] }
)
);
function unlist( keepType, text ) {
let matches;
if ( ( matches = text.match( /^[*#] */ ) ) && text.slice( 0, 1 ) !== keepType ) {
return [ matches[ 0 ].length, 0 ];
}
}
ve.ui.wikitextCommandRegistry.register(
new ve.ui.Command(
'number', 'mwWikitext', 'wrapLine',
{ args: [ '# ', '', OO.ui.deferMsg( 'visualeditor-listbutton-number-tooltip' ), unlist.bind( this, '#' ) ], supportedSelections: [ 'linear' ] }
)
);
ve.ui.wikitextCommandRegistry.register(
new ve.ui.Command(
'bullet', 'mwWikitext', 'wrapLine',
{ args: [ '* ', '', OO.ui.deferMsg( 'visualeditor-listbutton-bullet-tooltip' ), unlist.bind( this, '*' ) ], supportedSelections: [ 'linear' ] }
)
);
}() );
ve.ui.wikitextCommandRegistry.register(
new ve.ui.Command(
'comment', 'mwWikitext', 'toggleWrapSelection',
{ args: [ '<!-- ', ' -->', OO.ui.deferMsg( 'visualeditor-commentinspector-title' ) ], supportedSelections: [ 'linear' ] }
)
);
ve.ui.wikitextCommandRegistry.register(
new ve.ui.Command(
'insertTable', 'mwWikitext', 'toggleWrapSelection',
{
args: [
[ { type: 'paragraph' }, ...'{| class="wikitable"', { type: '/paragraph' } ],
[ { type: 'paragraph' }, ...'|}', { type: '/paragraph' } ],
function () {
return '' +
'|+ ' + ve.msg( 'visualeditor-dialog-table-caption' ) +
'\n' +
'! ' + ve.msg( 'visualeditor-table-format-header' ) + ' !! ' + ve.msg( 'visualeditor-table-format-header' ) +
'\n' +
'|-' +
'\n' +
'| ' + ve.msg( 'visualeditor-table-format-data' ) + ' || ' + ve.msg( 'visualeditor-table-format-data' );
}
],
supportedSelections: [ 'linear' ]
}
)
);
ve.ui.wikitextCommandRegistry.register(
new ve.ui.Command( 'mwNonBreakingSpace', 'content', 'insert', {
args: [
' ',
// annotate
true,
// collapseToEnd
true
],
supportedSelections: [ 'linear' ]
} )
);
|