From cd097bed3d9a1184602247e635227501c9106227 Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Mon, 2 Oct 2017 16:50:38 +0100 Subject: [PATCH] Allow MediaWiki extensions to use self closing tags Parsoid now supports this by setting body to null. Change-Id: I24d856f0cffeacb00cb2b757e34315bc02b595d0 --- modules/ve-mw/ui/ve.ui.MWExtensionWindow.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/modules/ve-mw/ui/ve.ui.MWExtensionWindow.js b/modules/ve-mw/ui/ve.ui.MWExtensionWindow.js index 0529b2cd40..274638311e 100644 --- a/modules/ve-mw/ui/ve.ui.MWExtensionWindow.js +++ b/modules/ve-mw/ui/ve.ui.MWExtensionWindow.js @@ -37,6 +37,17 @@ OO.initClass( ve.ui.MWExtensionWindow ); */ ve.ui.MWExtensionWindow.static.allowedEmpty = false; +/** + * Tell Parsoid to self-close tags when the body is empty + * + * i.e. `` -> `` + * + * @static + * @property {boolean} + * @inheritable + */ +ve.ui.MWExtensionWindow.static.selfCloseEmptyBody = false; + /** * Inspector's directionality, 'ltr' or 'rtl' * @@ -242,6 +253,10 @@ ve.ui.MWExtensionWindow.prototype.updateMwData = function ( mwData ) { // Prevent that by escaping the first angle bracket '<' to '<'. (bug 57429) value = value.replace( new RegExp( '<(/' + tagName + '\\s*>)', 'gi' ), '<$1' ); - mwData.body = mwData.body || {}; - mwData.body.extsrc = value; + if ( value.trim() === '' && this.constructor.static.selfCloseEmptyBody ) { + mwData.body = null; + } else { + mwData.body = mwData.body || {}; + mwData.body.extsrc = value; + } };