Cscott has uploaded a new change for review. https://gerrit.wikimedia.org/r/230146
Change subject: WIP: Detect pastes of wikitext or bare autolinks and auto-convert them. ...................................................................... WIP: Detect pastes of wikitext or bare autolinks and auto-convert them. Change-Id: I26a4cd8dc5b7e7caf16ca081dbe7baf6a7db8e5c --- A modules/ve-mw/ui/ve.ui.MWWikitextTransferHandler.js 1 file changed, 70 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor refs/changes/46/230146/1 diff --git a/modules/ve-mw/ui/ve.ui.MWWikitextTransferHandler.js b/modules/ve-mw/ui/ve.ui.MWWikitextTransferHandler.js new file mode 100644 index 0000000..d27bb13 --- /dev/null +++ b/modules/ve-mw/ui/ve.ui.MWWikitextTransferHandler.js @@ -0,0 +1,70 @@ +/*! + * VisualEditor UserInterface MWWikitextTransferHandler class. + * + * @copyright 2011-2015 VisualEditor Team and others; see http://ve.mit-license.org + */ + +/** + * Detect an attempt to paste wikitext, and convert it to proper + * HTML. + * + * @class + * @extends ve.ui.PlainTextStringTransferHandler + * + * @constructor + * @param {ve.ui.Surface} surface + * @param {ve.ui.DataTransferItem} item + */ +ve.ui.MWWikitextTransferHandler = function VeUiMWWikitextTransferHandler() { + // Parent constructor + ve.ui.MWWikitextTransferHandler.super.apply( this, arguments ); +}; + +/* Inheritance */ + +OO.inheritClass( ve.ui.MWWikitextTransferHandler, ve.ui.PlainTextStringTransferHandler ); + +/* Static properties */ + +ve.ui.MWWikitextTransferHandler.static.name = 'wikitext'; + +ve.ui.MWWikitextTransferHandler.static.handlesPaste = true; + +/** + * Heuristic pattern which attempts to discover wikitext, without + * incurring too many false positives. + * + * Currently the pattern looks for ==...==, [[...]], or {{...}} + * which occur on a single line. + */ +ve.ui.MWWikitextTransferHandler.static.matchRegExp = + /(^\s*(={2,6})[^=\r\n]+\1\s*$)|\[\[[^\]\r\n]+\]\]|\{\{[^\}\r\n]+\}\}/m; +ve.ui.MWWikitextTransferHandler.static.matchFunction = function ( item ) { + // Use a heuristic regexp. + // This test could be made more sophisticated in the future. + var text = item.getAsString(); + if ( this.constructor.static.matchRegExp.test( text ) ) { + return true; + } + // Detect autolink opportunities. + if (/^\s*http:\/\/\w\S*\s*$/.test( text ) || + /^\s*(RFC|ISBN|PMID)[-\s0-9]+\s*$/.test( text ) ) { + return true; + } + return false; +}; + +/* Methods */ + +/** + * @inheritdoc + */ +ve.ui.MWWikitextTransferHandler.prototype.process = function () { + var text = this.item.getAsString(); + // XXX convert text to dataToInsert, using parsoid + this.resolve( dataToInsert ); +}; + +/* Registration */ + +ve.ui.dataTransferHandlerFactory.register( ve.ui.MWWikitextTransferHandler ); -- To view, visit https://gerrit.wikimedia.org/r/230146 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I26a4cd8dc5b7e7caf16ca081dbe7baf6a7db8e5c Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/VisualEditor Gerrit-Branch: master Gerrit-Owner: Cscott <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
