mediawiki-extensions-Visual.../modules/ve-mw/ui/ve.ui.MWWikitextTransferRegistry.js
Ed Sanders 47508d3245 Add regex for detecting labelled external links in pasted wikitext
Bug: T134227
Change-Id: Icb390cca6f4ee299dd59ec5d15894b734879f394
2016-05-04 16:20:05 +01:00

43 lines
1 KiB
JavaScript

/*!
* VisualEditor MediaWiki WikitextTransferRegistry and registrations.
*
* @copyright 2011-2016 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* Heuristic patterns which attempts to discover wikitext, without
* incurring too many false positives.
*
* Rules can be regular expressions or strings
*/
ve.ui.mwWikitextTransferRegistry = new OO.Registry();
ve.ui.mwWikitextTransferRegistry.register(
'heading',
// ==...== on a single line of max 80 characters
/(^\s*(={2,6})[^=\r\n]{1,80}\2\s*$)/m
);
ve.ui.mwWikitextTransferRegistry.register(
'internalLink',
// [[...]] on a single line of max 80 characters
/\[\[.{1,80}\]\]/m
);
ve.init.platform.getInitializedPromise().done( function () {
ve.ui.mwWikitextTransferRegistry.register(
'externalLink',
// [url label]
new RegExp(
'\\[' + ve.init.platform.getUnanchoredExternalLinkUrlProtocolsRegExp().source + '\\S+ [^\\]]+\\]',
'i'
)
);
} );
ve.ui.mwWikitextTransferRegistry.register(
'template',
'{{'
);