Catrope has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/74072


Change subject: Allow annotations to render nothing
......................................................................

Allow annotations to render nothing

This effectively unwraps the annotation. Annotations can do this by
returning an empty array from their toDomElements() function.

Right now this is only supported for annotations, but once the converter
is rewritten to be entirely bottom-up, this is trivial to support for
other model types, and could even be used to implement unwrapping of
wrapper paragraph.

Change-Id: Ia572fd0610afccccfe795c257c0de9d003330f13
---
M modules/ve/dm/ve.dm.Annotation.js
M modules/ve/dm/ve.dm.Converter.js
2 files changed, 15 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor 
refs/changes/72/74072/1

diff --git a/modules/ve/dm/ve.dm.Annotation.js 
b/modules/ve/dm/ve.dm.Annotation.js
index d0e5623..b04d576 100644
--- a/modules/ve/dm/ve.dm.Annotation.js
+++ b/modules/ve/dm/ve.dm.Annotation.js
@@ -52,8 +52,10 @@
  * Static function to convert a linear model data element for this annotation 
type back to
  * a DOM element.
  *
- * As a special facility for annotations, the annotated content that the 
returned element will
- * wrap around is passed in as childDomElements.
+ * As special facilities for annotations, the annotated content that the 
returned element will
+ * wrap around is passed in as childDomElements, and this function may return 
an empty array to
+ * indicate that the annotation should produce no output. In that case, the 
child DOM elements will
+ * not be wrapped in anything and will be inserted directly into this 
annotation's parent.
  *
  * @static
  * @inheritable
@@ -62,7 +64,7 @@
  * @param {HTMLDocument} doc HTML document for creating elements
  * @param {ve.dm.Converter} converter Converter object to optionally call 
.getDomSubtreeFromData() on
  * @param {HTMLElement[]} childDomElements Children that will be appended to 
the returned element
- * @returns {HTMLElement[]} DOM elements; only the first element is used
+ * @returns {HTMLElement[]} Array of DOM elements; only the first element is 
used; may be empty
  */
 ve.dm.Annotation.static.toDomElements = function ( /*dataElement, doc, 
converter, childDomElements*/ ) {
        throw new Error( 've.dm.Annotation subclass must implement 
toDomElements' );
diff --git a/modules/ve/dm/ve.dm.Converter.js b/modules/ve/dm/ve.dm.Converter.js
index a176801..685fe34 100644
--- a/modules/ve/dm/ve.dm.Converter.js
+++ b/modules/ve/dm/ve.dm.Converter.js
@@ -309,7 +309,7 @@
                return false;
        }
        domElements = nodeClass.static.toDomElements( dataElements, doc, this, 
childDomElements );
-       if ( !domElements || !domElements.length ) {
+       if ( ( !domElements || !domElements.length ) && !( nodeClass.prototype 
instanceof ve.dm.Annotation ) ) {
                throw new Error( 'toDomElements() failed to return an array 
when converting element of type ' + dataElement.type );
        }
        if ( dataElement.htmlAttributes ) {
@@ -1009,10 +1009,16 @@
                annotationElement = conv.getDomElementsFromDataElement(
                        annotation.getElement(), doc, annotatedChildDomElements
                )[0];
-               for ( i = 0, len = annotatedChildDomElements.length; i < len; 
i++ ) {
-                       annotationElement.appendChild( 
annotatedChildDomElements[i] );
+               if ( annotationElement ) {
+                       for ( i = 0, len = annotatedChildDomElements.length; i 
< len; i++ ) {
+                               annotationElement.appendChild( 
annotatedChildDomElements[i] );
+                       }
+                       annotatedDomElements.push( annotationElement );
+               } else {
+                       for ( i = 0, len = annotatedChildDomElements.length; i 
< len; i++ ) {
+                               annotatedDomElements.push( 
annotatedChildDomElements[i] );
+                       }
                }
-               annotatedDomElements.push( annotationElement );
        }
 
        function findEndOfNode( i ) {

-- 
To view, visit https://gerrit.wikimedia.org/r/74072
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia572fd0610afccccfe795c257c0de9d003330f13
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Catrope <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to