Aller au contenu

« Utilisateur:Tractopelle-jaune/Toolbar.js » : différence entre les versions

Une page de Wikipédia, l'encyclopédie libre.
Contenu supprimé Contenu ajouté
m nettoyage code
menu pour balises <syntaxhighlight></syntaxhighlight> + indentation code (compactage)
Ligne 26 : Ligne 26 :
label: 'Tracto-Tools',
label: 'Tracto-Tools',
groups: {
groups: {
'code': { label: 'Code' }
'code': { label: 'Code' }}}
}}},
},
section: 'tracto-tools',
section: 'tracto-tools',
Ligne 40 : Ligne 40 :
options: {
options: {
pre: '<code>',
pre: '<code>',
peri: '',
post: '</code>' }}},
post: '</code>'
}}},
'code-add-code-with-id': {
'code-add-code-with-id': {
type: 'button',
type: 'button',
Ligne 51 : Ligne 50 :
options: {
options: {
pre: '<code id="param-xxx">',
pre: '<code id="param-xxx">',
peri: '',
post: '</code>',
post: '</code>',
regex: /(?:<code>|\'{2,5}|\"|^( *))([^<>|{}\[\]#]+?)(?:<\/code>|\'{2,5}|\"|( *)$)/g,
regex: /(?:<code>|\'{2,5}|\"|^( *))([^<>|{}\[\]#]+?)(?:<\/code>|\'{2,5}|\"|( *)$)/g,
regexReplace: '$1<code id="param-$2">$2</code>$3'
regexReplace: '$1<code id="param-$2">$2</code>$3' }}},
}}},
'code-add-code-with-link-id': {
'code-add-code-with-link-id': {
type: 'button',
type: 'button',
Ligne 64 : Ligne 62 :
options: {
options: {
pre: '<code>[[#param-xxx|',
pre: '<code>[[#param-xxx|',
peri: '',
post: ']]</code>',
post: ']]</code>',
regex: /(?:<code>|\'{2,5}|\"|^( *))([^<>|{}\[\]#]+?)(?:<\/code>|\'{2,5}|\"|( *)$)/g,
regex: /(?:<code>|\'{2,5}|\"|^( *))([^<>|{}\[\]#]+?)(?:<\/code>|\'{2,5}|\"|( *)$)/g,
regexReplace: '$1<code>[[#param-$2|$2]]</code>$3'
regexReplace: '$1<code>[[#param-$2|$2]]</code>$3' }}},
}}},
'code-add-magic-word': {
'code-add-magic-word': {
label: 'Ajout balises code + lien vers Aide:Mot magique',
label: 'Ajout balises code + lien vers Aide:Mot magique',
Ligne 81 : Ligne 78 :
/* 1 2 3 4 5 6 7 8 9 10 11 12 */
/* 1 2 3 4 5 6 7 8 9 10 11 12 */
regex: /(?:<code>(?:<nowiki>)?|^( *))(?:(__)([A-Z]+)(__)|(\{\{)([A-Za-z0-9 _!]+):?(\}\})|(\{\{)m\|([A-Za-z0-9 _!]+)(\}\})|([A-Za-z0-9 _!]+):?)(?:(?:<\/nowiki>)?<\/code>|( *)$)/g,
regex: /(?:<code>(?:<nowiki>)?|^( *))(?:(__)([A-Z]+)(__)|(\{\{)([A-Za-z0-9 _!]+):?(\}\})|(\{\{)m\|([A-Za-z0-9 _!]+)(\}\})|([A-Za-z0-9 _!]+):?)(?:(?:<\/nowiki>)?<\/code>|( *)$)/g,
regexReplace: '$1<code>[[Aide:Mot magique#$3$6$9$11|<nowiki>$2$3$4$5$6$7$8$9$10$11</nowiki>]]</code>$12'
regexReplace: '$1<code>[[Aide:Mot magique#$3$6$9$11|<nowiki>$2$3$4$5$6$7$8$9$10$11</nowiki>]]</code>$12' }}},
}}},
'code-add-code+nowiki': {
'code-add-code+nowiki': {
type: 'button',
type: 'button',
Ligne 91 : Ligne 88 :
options: {
options: {
pre: '<code><nowiki>',
pre: '<code><nowiki>',
peri: '',
post: '</nowiki></code>' }}},
post: '</nowiki></code>'
}}},
'code-add-nowiki': {
'code-add-nowiki': {
type: 'button',
type: 'button',
Ligne 102 : Ligne 98 :
options: {
options: {
pre: '<nowiki>',
pre: '<nowiki>',
peri: '',
post: '</nowiki>' }}},
post: '</nowiki>'
}}},
'code-decode': {
'code-decode': {
type: 'button',
type: 'button',
Ligne 113 : Ligne 108 :
options: {
options: {
pre: '',
pre: '',
peri: '',
post: '',
regex: /(?:<code>|<nowiki>)+(.+?)(?:<\/nowiki>|<\/code>)+/g,
regex: /(?:<code>|<nowiki>)+(.+?)(?:<\/nowiki>|<\/code>)+/g,
regexReplace: '$1'
regexReplace: '$1' }}},
}}},
'code-apos2code': {
'code-apos2code': {
type: 'button',
type: 'button',
Ligne 126 : Ligne 119 :
options: {
options: {
pre: '<code>',
pre: '<code>',
peri: '',
post: '</code>',
post: '</code>',
regex: /(?:\'{2,5}(?:<code>)?(.+?)(?:<\/code>)?\'{2,5}|« *(?:<code>)?([^«»\n]+?)(?:<\/code>)? *»|\" *(?:<code>)?([^«»\n]+?)(?:<\/code>)? *\")/g,
regex: /(?:\'{2,5}(?:<code>)?(.+?)(?:<\/code>)?\'{2,5}|« *(?:<code>)?([^«»\n]+?)(?:<\/code>)? *»|\" *(?:<code>)?([^«»\n]+?)(?:<\/code>)? *\")/g,
regexReplace: '<code>$1$2$3</code>'
regexReplace: '<code>$1$2$3</code>' }}},
}}},
'code-code2definitionList': {
'code-code2definitionList': {
type: 'button',
type: 'button',
Ligne 139 : Ligne 131 :
options: {
options: {
pre: '; <code>',
pre: '; <code>',
peri: '',
post: '</code> : ',
post: '</code> : ',
regex: /^[*;]+ *(?:\'{2,5} *([^<>=\n;*]+?) *(?:[:=—–] *| +- +)?\'{2,5} *(?:[:=—–] *| +- +)?|(?:\'{2,5})?<code>((?:<nowiki>)?[^<>=\n;*]+?(?:<\/nowiki>)?)<\/code>(?:\'{2,5})? *(?:[:=—–] *| +- +)?|([^<>:=\n—–;*]+?) *[:=—–] *| +- +)/mg,
regex: /^[*;]+ *(?:\'{2,5} *([^<>=\n;*]+?) *(?:[:=—–] *| +- +)?\'{2,5} *(?:[:=—–] *| +- +)?|(?:\'{2,5})?<code>((?:<nowiki>)?[^<>=\n;*]+?(?:<\/nowiki>)?)<\/code>(?:\'{2,5})? *(?:[:=—–] *| +- +)?|([^<>:=\n—–;*]+?) *[:=—–] *| +- +)/mg,
regexReplace: '; <code>$1$2$3</code> : '
regexReplace: '; <code>$1$2$3</code> : ' }}}
}}}
} //<nowiki>
} //<nowiki>
});

$('#wpTextbox1').wikiEditor('addToToolbar',
{
sections: {
'menu-autres': {
type: 'booklet',
label: 'Menu autres',
pages: {
'syntaxhighlight': { label: 'SyntaxHighlight', layout: 'characters' }}}
},
section: 'menu-autres',
page: 'syntaxhighlight',
characters: [ {
label: '<syntaxhighlight lang="xxx">',
action: {
type: 'encapsulate',
options: {
pre: '<syntaxhighlight lang="xxx">\n',
post: '\n</syntaxhighlight>',
regex: /(?:<code><nowiki>|<code>|<pre>)([\D\d]+?)(?:<\/pre>|<\/nowiki><\/code>|<\/code>)/g,
regexReplace: '<syntaxhighlight lang="xxx">\n$1\n</syntaxhighlight>' }}}, {
label: '<syntaxhighlight lang="xxx" inline>',
action: {
type: 'encapsulate',
options: {
pre: '<syntaxhighlight lang="xxx" inline>',
post: '</syntaxhighlight>',
regex: /(?:<code><nowiki>|<code>|<pre>)([\D\d]+?)(?:<\/pre>|<\/nowiki><\/code>|<\/code>)/g,
regexReplace: '<syntaxhighlight lang="xxx" inline>$1</syntaxhighlight>' }}}, {
label: '<syntaxhighlight lang="xxx" line>',
action: {
type: 'encapsulate',
options: {
pre: '<syntaxhighlight lang="xxx" line>\n',
post: '\n</syntaxhighlight>',
regex: /(?:<code><nowiki>|<code>|<pre>)([\D\d]+?)(?:<\/pre>|<\/nowiki><\/code>|<\/code>)/g,
regexReplace: '<syntaxhighlight lang="xxx" line>\n$1\n</syntaxhighlight>' }}}, {
label: '<syntaxhighlight lang="xxx" highlight="">',
action: {
type: 'encapsulate',
options: {
pre: '<syntaxhighlight lang="xxx" highlight="x,x-x">\n',
post: '\n</syntaxhighlight>',
regex: /(?:<code><nowiki>|<code>|<pre>)([\D\d]+?)(?:<\/pre>|<\/nowiki><\/code>|<\/code>)/g,
regexReplace: '<syntaxhighlight lang="xxx" highlight="">\n$1\n</syntaxhighlight>' }}}, {
label: '<syntaxhighlight lang="xxx" line start="x">',
action: {
type: 'encapsulate',
options: {
pre: '<syntaxhighlight lang="xxx" line start="x">\n',
post: '\n</syntaxhighlight>',
regex: /(?:<code><nowiki>|<code>|<pre>)([\D\d]+?)(?:<\/pre>|<\/nowiki><\/code>|<\/code>)/g,
regexReplace: '<syntaxhighlight lang="xxx" line start="x">\n$1\n</syntaxhighlight>' }}}
]
});
});
};
};

Version du 1 mai 2022 à 23:53

//<nowiki>

/* Boutons supplémentaires pour la barre d'outils WikiEditor (barre d'outils par défaut) */
// [[mw:Extension:WikiEditor/Toolbar customization]]

/* Check if view is in edit mode and that the required modules are available. Then, customize the toolbar … */
if ( $.inArray( mw.config.get( 'wgAction' ), [ 'edit', 'submit' ] ) !== -1 ) {
	mw.loader.using( 'user.options' ).then( function () {
		// This can be the string "0" if the user disabled the preference ([[phab:T54542#555387]])
		if ( mw.user.options.get( 'usebetatoolbar' ) == 1 ) {
			$.when(
				mw.loader.using( 'ext.wikiEditor' ), $.ready
			).then( customizeToolbar );
		}
	} );
}

/* Barre d'outils supplémentaires */

// Boutons supplémentaires
var customizeToolbar = function() { $('#wpTextbox1').wikiEditor('addToToolbar',
{
	sections: {
		'tracto-tools': {
			type: 'toolbar',
			label: 'Tracto-Tools',
			groups: {
				'code': { label: 'Code' }}}
	},
	
	section: 'tracto-tools',
	group: 'code',
	tools: { //</nowiki>
		'code-add-code': {
			type: 'button',
			label: 'Ajouter balises <code></code>',
			icon: '//upload.wikimedia.org/wikipedia/commons/thumb/4/45/Farm-Fresh_script_code.png/22px-Farm-Fresh_script_code.png',
			action:	{
				type: 'encapsulate',
				options: {
					pre: '<code>',
					post: '</code>' }}},
		
		'code-add-code-with-id': {
			type: 'button',
			label: 'Ajouter balises <code id=""></code> avec l\'id contenant le texte séléctionné',
			icon: '//upload.wikimedia.org/wikipedia/commons/thumb/9/9b/Farm-Fresh_script_go.png/22px-Farm-Fresh_script_go.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: '<code id="param-xxx">',
					post: '</code>',
					regex: /(?:<code>|\'{2,5}|\"|^( *))([^<>|{}\[\]#]+?)(?:<\/code>|\'{2,5}|\"|( *)$)/g,
					regexReplace: '$1<code id="param-$2">$2</code>$3' }}},
		
		'code-add-code-with-link-id': {
			type: 'button',
			label: 'Ajouter balises <code>[[#param-xxx|...]]</code> avec lien vers le paramètre séléctionné',
			icon: '//upload.wikimedia.org/wikipedia/commons/thumb/6/68/Farm-Fresh_script_link.png/22px-Farm-Fresh_script_link.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: '<code>[[#param-xxx|',
					post: ']]</code>',
					regex: /(?:<code>|\'{2,5}|\"|^( *))([^<>|{}\[\]#]+?)(?:<\/code>|\'{2,5}|\"|( *)$)/g,
					regexReplace: '$1<code>[[#param-$2|$2]]</code>$3' }}},
		
		'code-add-magic-word': {
			label: 'Ajout balises code + lien vers Aide:Mot magique',
			type: 'button',
			icon: '//upload.wikimedia.org/wikipedia/commons/thumb/6/61/Farm-Fresh_script_palette.png/22px-Farm-Fresh_script_palette.png',
			action:	{
				type: 'encapsulate',
				options: {
					pre: '<code>[[Aide:Mot magique#XXX|<nowiki>',
					peri: 'XXX',
					post: '</nowiki>]]</code>',
					/*                               1       2   3       4    5     6                  7      8        9                10     11                                             12   */
					regex: /(?:<code>(?:<nowiki>)?|^( *))(?:(__)([A-Z]+)(__)|(\{\{)([A-Za-z0-9 _!]+):?(\}\})|(\{\{)m\|([A-Za-z0-9 _!]+)(\}\})|([A-Za-z0-9 _!]+):?)(?:(?:<\/nowiki>)?<\/code>|( *)$)/g,
					regexReplace: '$1<code>[[Aide:Mot magique#$3$6$9$11|<nowiki>$2$3$4$5$6$7$8$9$10$11</nowiki>]]</code>$12' }}},
		
		'code-add-code+nowiki': {
			type: 'button',
			label: 'Ajouter balises <code><nowiki></nowiki></code>',
			icon: '//upload.wikimedia.org/wikipedia/commons/thumb/a/ac/Farm-Fresh_script_visual_studio.png/22px-Farm-Fresh_script_visual_studio.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: '<code><nowiki>',
					post: '</nowiki></code>' }}},
		
		'code-add-nowiki': {
			type: 'button',
			label: 'Ajouter balises <nowiki></nowiki>',
			icon: '//upload.wikimedia.org/wikipedia/commons/thumb/f/f3/Farm-Fresh_script_code_red.png/22px-Farm-Fresh_script_code_red.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: '<nowiki>',
					post: '</nowiki>' }}},
		
		'code-decode': {
			type: 'button',
			label: 'De-code',
			icon: '//upload.wikimedia.org/wikipedia/commons/thumb/8/87/Farm-Fresh_script_delete.png/22px-Farm-Fresh_script_delete.png',
			action: {
				type: 'replace',
				options: {
					pre: '',
					regex: /(?:<code>|<nowiki>)+(.+?)(?:<\/nowiki>|<\/code>)+/g,
					regexReplace: '$1' }}},
		
		'code-apos2code': {
			type: 'button',
			label: 'Remplacer \'\'\'texte\'\'\' par <code>texte</code>',
			icon: '//upload.wikimedia.org/wikipedia/commons/thumb/b/be/Farm-Fresh_script_flash.png/22px-Farm-Fresh_script_flash.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: '<code>',
					post: '</code>',
					regex: /(?:\'{2,5}(?:<code>)?(.+?)(?:<\/code>)?\'{2,5}|« *(?:<code>)?([^«»\n]+?)(?:<\/code>)? *»|\" *(?:<code>)?([^«»\n]+?)(?:<\/code>)? *\")/g,
					regexReplace: '<code>$1$2$3</code>' }}},
		
		'code-code2definitionList': {
			type: 'button',
			label: 'Remplacer "* \'\'\'<code>param</code>\'\'\' : " par "; <code>param</code> : " sur toutes les lignes sélectionnées',
			icon: '//upload.wikimedia.org/wikipedia/commons/thumb/8/89/Farm-Fresh_macro_show_all_actions.png/22px-Farm-Fresh_macro_show_all_actions.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: '; <code>',
					post: '</code> : ',
					regex: /^[*;]+ *(?:\'{2,5} *([^<>=\n;*]+?) *(?:[:=—–] *| +- +)?\'{2,5} *(?:[:=—–] *| +- +)?|(?:\'{2,5})?<code>((?:<nowiki>)?[^<>=\n;*]+?(?:<\/nowiki>)?)<\/code>(?:\'{2,5})? *(?:[:=—–] *| +- +)?|([^<>:=\n—–;*]+?) *[:=—–] *| +- +)/mg,
					regexReplace: '; <code>$1$2$3</code> : ' }}}
	} //<nowiki>
});

$('#wpTextbox1').wikiEditor('addToToolbar',
{
	sections: {
		'menu-autres': {
			type: 'booklet',
			label: 'Menu autres',
			pages: {
				'syntaxhighlight': { label: 'SyntaxHighlight', layout: 'characters' }}}
	},
	
	section: 'menu-autres',
	page: 'syntaxhighlight',
	characters: [ {
		label: '<syntaxhighlight lang="xxx">',
		action: {
			type: 'encapsulate',
			options: {
				pre: '<syntaxhighlight lang="xxx">\n',
				post: '\n</syntaxhighlight>',
				regex: /(?:<code><nowiki>|<code>|<pre>)([\D\d]+?)(?:<\/pre>|<\/nowiki><\/code>|<\/code>)/g,
				regexReplace: '<syntaxhighlight lang="xxx">\n$1\n</syntaxhighlight>' }}}, {
		
		label: '<syntaxhighlight lang="xxx" inline>',
		action: {
			type: 'encapsulate',
			options: {
				pre: '<syntaxhighlight lang="xxx" inline>',
				post: '</syntaxhighlight>',
				regex: /(?:<code><nowiki>|<code>|<pre>)([\D\d]+?)(?:<\/pre>|<\/nowiki><\/code>|<\/code>)/g,
				regexReplace: '<syntaxhighlight lang="xxx" inline>$1</syntaxhighlight>' }}}, {
		
		label: '<syntaxhighlight lang="xxx" line>',
		action: {
			type: 'encapsulate',
			options: {
				pre: '<syntaxhighlight lang="xxx" line>\n',
				post: '\n</syntaxhighlight>',
				regex: /(?:<code><nowiki>|<code>|<pre>)([\D\d]+?)(?:<\/pre>|<\/nowiki><\/code>|<\/code>)/g,
				regexReplace: '<syntaxhighlight lang="xxx" line>\n$1\n</syntaxhighlight>' }}}, {
		
		label: '<syntaxhighlight lang="xxx" highlight="">',
		action: {
			type: 'encapsulate',
			options: {
				pre: '<syntaxhighlight lang="xxx" highlight="x,x-x">\n',
				post: '\n</syntaxhighlight>',
				regex: /(?:<code><nowiki>|<code>|<pre>)([\D\d]+?)(?:<\/pre>|<\/nowiki><\/code>|<\/code>)/g,
				regexReplace: '<syntaxhighlight lang="xxx" highlight="">\n$1\n</syntaxhighlight>' }}}, {
		
		label: '<syntaxhighlight lang="xxx" line start="x">',
		action: {
			type: 'encapsulate',
			options: {
				pre: '<syntaxhighlight lang="xxx" line start="x">\n',
				post: '\n</syntaxhighlight>',
				regex: /(?:<code><nowiki>|<code>|<pre>)([\D\d]+?)(?:<\/pre>|<\/nowiki><\/code>|<\/code>)/g,
				regexReplace: '<syntaxhighlight lang="xxx" line start="x">\n$1\n</syntaxhighlight>' }}}
	]
});
};
// </nowiki>