extensions/VisualEditor/modules/ve-mw/ui/datatransferhandlers/ve.ui.MWWikitextPlainTextStringTransferHandler.js
raw symbols SCIP| 1 | /*! |
| 2 | * VisualEditor UserInterface MWWikitextPlainTextStringTransferHandler. |
| 3 | * |
| 4 | * @copyright See AUTHORS.txt |
| 5 | */ |
| 6 | |
| 7 | /** |
| 8 | * Detect an attempt to paste plain text or wikitext, and allow it to be directly pasted without escaping it. |
| 9 | * |
| 10 | * This handler is only registered in source mode, as that's the mode where users are interacting |
| 11 | * with the plain-text equivalent of the content already. Without this handler, a paste with `text/plain` |
| 12 | * and `text/html` content would take the html content, run it through the normal paste flow, then convert |
| 13 | * the resultant HTML into wikitext via parsoid. This would have the side-effect of escaping any wikitext |
| 14 | * content that's in the paste with nowiki, which probably isn't what the paster actually wants. |
| 15 | * |
| 16 | * We also catch anything which has `text/x-wiki`, since it has explicitly come from a source-mode part |
| 17 | * of VE, and contains something that's definitely wikitext. |
| 18 | * |
| 19 | * @class |
| 20 | * @extends ve.ui.PlainTextStringTransferHandler |
| 21 | * |
| 22 | * @constructor |
| 23 | * @param {ve.ui.Surface} surface |
| 24 | * @param {ve.ui.DataTransferItem} item |
| 25 | */ |
| 26 | ve.ui.MWWikitextPlainTextStringTransferHandler = function VeUiMWWikitextPlainTextStringTransferHandler() { |
| 27 | // Parent constructor |
| 28 | ve.ui.MWWikitextPlainTextStringTransferHandler.super.apply( this, arguments ); |
| 29 | }; |
| 30 | |
| 31 | /* Inheritance */ |
| 32 | |
| 33 | OO.inheritClass( ve.ui.MWWikitextPlainTextStringTransferHandler, ve.ui.PlainTextStringTransferHandler ); |
| 34 | |
| 35 | /* Static properties */ |
| 36 | |
| 37 | ve.ui.MWWikitextPlainTextStringTransferHandler.static.name = 'wikitextPlainTextString'; |
| 38 | |
| 39 | ve.ui.MWWikitextPlainTextStringTransferHandler.static.types = [ |
| 40 | ...ve.ui.MWWikitextPlainTextStringTransferHandler.super.static.types, |
| 41 | 'text/x-wiki' |
| 42 | ]; |
| 43 | |
| 44 | ve.ui.MWWikitextPlainTextStringTransferHandler.static.handlesPaste = true; |
| 45 | |
| 46 | /* Methods */ |
| 47 | |
| 48 | /** |
| 49 | * @inheritdoc |
| 50 | */ |
| 51 | ve.ui.MWWikitextPlainTextStringTransferHandler.prototype.process = function () { |
| 52 | this.resolve( this.item.getAsString() ); |
| 53 | }; |
| 54 | |
| 55 | /* Registration */ |
| 56 | |
| 57 | ve.ui.wikitextDataTransferHandlerFactory.register( ve.ui.MWWikitextPlainTextStringTransferHandler ); |