2016-05-26 12:08:26 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor Wikitext command registry
|
|
|
|
*
|
2020-01-08 17:13:04 +00:00
|
|
|
* @copyright 2011-2020 VisualEditor Team and others; see http://ve.mit-license.org
|
2016-05-26 12:08:26 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 */
|
|
|
|
|
|
|
|
/**
|
2019-09-05 00:49:48 +00:00
|
|
|
* Get data for a given symbolic name.
|
|
|
|
*
|
|
|
|
* See https://doc.wikimedia.org/oojs/master/OO.Registry.html
|
|
|
|
*
|
|
|
|
* @param {string} name Symbolic name
|
|
|
|
* @return {Mixed|undefined} Data associated with symbolic name
|
2016-05-26 12:08:26 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWWikitextCommandRegistry.prototype.lookup = function ( name ) {
|
|
|
|
// Parent method
|
|
|
|
var 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 ) {
|
|
|
|
var 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 */
|
2022-01-13 11:10:02 +00:00
|
|
|
var matches = /^(''([^'].*|.*[^'])''|'{5,}([^'].*|.*[^'])'{5,})$/.test( text );
|
2016-05-26 12:08:26 +00:00
|
|
|
|
|
|
|
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' ] }
|
|
|
|
)
|
|
|
|
);
|
2016-10-08 02:44:52 +00:00
|
|
|
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' ] }
|
|
|
|
)
|
|
|
|
);
|
2016-05-26 12:08:26 +00:00
|
|
|
|
|
|
|
( function () {
|
|
|
|
|
|
|
|
function unformat( text ) {
|
|
|
|
/* Use lazy .+? in the middle so whitespace is matched to wrappers */
|
2022-02-21 18:07:07 +00:00
|
|
|
var headings;
|
2016-05-26 12:08:26 +00:00
|
|
|
if ( ( headings = text.match( /^((={1,6})\s*).+?(\s*\2\s*)$/ ) ) ) {
|
|
|
|
return [ headings[ 1 ].length, headings[ 3 ].length ];
|
|
|
|
}
|
2022-02-21 18:07:07 +00:00
|
|
|
var pre;
|
2016-05-26 12:08:26 +00:00
|
|
|
if ( ( pre = text.match( /^ +/ ) ) ) {
|
|
|
|
return [ pre[ 0 ].length, 0 ];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-21 18:07:07 +00:00
|
|
|
var heading = '';
|
|
|
|
for ( var i = 1; i <= 6; i++ ) {
|
2016-05-26 12:08:26 +00:00
|
|
|
heading += '=';
|
|
|
|
ve.ui.wikitextCommandRegistry.register(
|
|
|
|
new ve.ui.Command(
|
|
|
|
'heading' + i, 'mwWikitext', 'wrapLine',
|
|
|
|
{
|
|
|
|
args: [
|
|
|
|
heading + ' ',
|
|
|
|
' ' + heading,
|
2019-11-01 16:20:22 +00:00
|
|
|
// 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
|
2016-05-26 12:08:26 +00:00
|
|
|
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(
|
2019-04-19 22:13:45 +00:00
|
|
|
'blockquote', 'mwWikitext', 'toggleWrapSelection',
|
|
|
|
{ args: [ '<blockquote>', '</blockquote>', OO.ui.deferMsg( 'visualeditor-formatdropdown-format-blockquote' ) ], supportedSelections: [ 'linear' ] }
|
2016-05-26 12:08:26 +00:00
|
|
|
)
|
|
|
|
);
|
2016-10-03 20:10:21 +00:00
|
|
|
|
|
|
|
function unlist( keepType, text ) {
|
|
|
|
var 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' ] }
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2016-11-12 14:43:43 +00:00
|
|
|
}() );
|
2016-05-26 12:08:26 +00:00
|
|
|
|
|
|
|
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',
|
|
|
|
{
|
2017-07-10 15:16:11 +00:00
|
|
|
args: [
|
|
|
|
[ { type: 'paragraph' } ].concat( '{| class="wikitable"'.split( '' ) ).concat( { type: '/paragraph' } ),
|
|
|
|
[ { type: 'paragraph' } ].concat( '|}'.split( '' ) ).concat( { type: '/paragraph' } ),
|
|
|
|
function () {
|
|
|
|
return '' +
|
2023-11-03 15:48:55 +00:00
|
|
|
'|+ ' + ve.msg( 'visualeditor-dialog-table-caption' ) +
|
2017-07-10 15:16:11 +00:00
|
|
|
'\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' );
|
|
|
|
}
|
|
|
|
],
|
2016-05-26 12:08:26 +00:00
|
|
|
supportedSelections: [ 'linear' ]
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
2015-11-29 17:37:10 +00:00
|
|
|
|
|
|
|
ve.ui.wikitextCommandRegistry.register(
|
|
|
|
new ve.ui.Command( 'mwNonBreakingSpace', 'content', 'insert', {
|
|
|
|
args: [
|
|
|
|
' ',
|
|
|
|
// annotate
|
|
|
|
true,
|
|
|
|
// collapseToEnd
|
|
|
|
true
|
|
|
|
],
|
|
|
|
supportedSelections: [ 'linear' ]
|
|
|
|
} )
|
|
|
|
);
|