Esanders has uploaded a new change for review. https://gerrit.wikimedia.org/r/111517
Change subject: Add 'forClipboard' mode to converter ...................................................................... Add 'forClipboard' mode to converter This allows us to generate HTML for the clipboard without having to worry about if it would confuse Parsoid. Change-Id: Ib29972472d12a7da6228acecae695f385b7133ef --- M modules/ve/ce/ve.ce.Surface.js M modules/ve/dm/ve.dm.Converter.js 2 files changed, 19 insertions(+), 4 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor refs/changes/17/111517/1 diff --git a/modules/ve/ce/ve.ce.Surface.js b/modules/ve/ce/ve.ce.Surface.js index ff393f7..18b1339 100644 --- a/modules/ve/ce/ve.ce.Surface.js +++ b/modules/ve/ce/ve.ce.Surface.js @@ -724,7 +724,7 @@ // Clone the elements in the slice slice.data.cloneElements(); - ve.dm.converter.getDomSubtreeFromModel( slice, this.$pasteTarget[0] ); + ve.dm.converter.getDomSubtreeFromModel( slice, this.$pasteTarget[0], true ); // Some browsers strip out spans when they match the styling of the // paste target (e.g. plain spans) so we must protect against this diff --git a/modules/ve/dm/ve.dm.Converter.js b/modules/ve/dm/ve.dm.Converter.js index 103e8ed..3ea10fe 100644 --- a/modules/ve/dm/ve.dm.Converter.js +++ b/modules/ve/dm/ve.dm.Converter.js @@ -26,6 +26,7 @@ this.documentData = null; this.store = null; this.internalList = null; + this.forClipboard = null; this.contextStack = null; }; @@ -265,6 +266,16 @@ */ ve.dm.Converter.prototype.getTargetHtmlDocument = function () { return this.targetDoc; +}; + +/** + * Is the current conversion for the clipboard + * + * @method + * @returns {boolean|null} The conversion is for the clipboard, or null if not converting + */ +ve.dm.Converter.prototype.isForClipboard = function () { + return this.forClipboard; }; /** @@ -1085,12 +1096,13 @@ * * @method * @param {ve.dm.Document} model Document model + * @param {boolean} [forClipboard=false] Conversion is for clipboard * @returns {HTMLDocument} Document containing the resulting HTML */ -ve.dm.Converter.prototype.getDomFromModel = function ( model ) { +ve.dm.Converter.prototype.getDomFromModel = function ( model, forClipboard ) { var doc = ve.createDocumentFromHtml( '' ); - this.getDomSubtreeFromModel( model, doc.body ); + this.getDomSubtreeFromModel( model, doc.body, forClipboard ); return doc; }; @@ -1101,12 +1113,14 @@ * @method * @param {ve.dm.Document} model Document model * @param {HTMLElement} container DOM element to add the generated elements to. Should be empty. + * @param {boolean} [forClipboard=false] Conversion is for clipboard */ -ve.dm.Converter.prototype.getDomSubtreeFromModel = function ( model, container ) { +ve.dm.Converter.prototype.getDomSubtreeFromModel = function ( model, container, forClipboard ) { // Set up the converter state this.documentData = model.getFullData(); this.store = model.getStore(); this.internalList = model.getInternalList(); + this.forClipboard = !!forClipboard; this.getDomSubtreeFromData( this.documentData, container, model.getInnerWhitespace() ); @@ -1114,6 +1128,7 @@ this.documentData = null; this.store = null; this.internalList = null; + this.forClipboard = null; }; /** -- To view, visit https://gerrit.wikimedia.org/r/111517 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib29972472d12a7da6228acecae695f385b7133ef Gerrit-PatchSet: 1 Gerrit-Project: VisualEditor/VisualEditor Gerrit-Branch: master Gerrit-Owner: Esanders <esand...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits