Bartosz Dziewoński has uploaded a new change for review.

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

Change subject: Generate CommentNodes more leniently
......................................................................

Generate CommentNodes more leniently

Previously we only allowed them in the middle of text. Now we allow
them everywhere that they can be rendered.

* Extracted new method #isValidChildNodeType in ve.dm.Converter.
* Added more torture tests to 'comments.html' in standalone demo.

Bug: T73085
Change-Id: I9f5ee4a058b42f870154d489804ef52601bd7d1e
---
M demos/ve/pages/comments.html
M src/dm/nodes/ve.dm.CommentNode.js
M src/dm/ve.dm.Converter.js
3 files changed, 40 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor 
refs/changes/51/192051/1

diff --git a/demos/ve/pages/comments.html b/demos/ve/pages/comments.html
index 816bd27..02d2b2c 100644
--- a/demos/ve/pages/comments.html
+++ b/demos/ve/pages/comments.html
@@ -25,5 +25,24 @@
 --> Baz! Empty comment: <!----></h2>
 <p><!-- Bar2 --></p>
 <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. 
Lorem Ipsum has been the industry's standard dummy text ever <!-- Bar3 --> 
since the 1500s, when an unknown printer took a galley of type and scrambled it 
to make a type specimen book. It has survived not only five centuries, but 
<!--And this comment goes on forever to demonstrate that users won't see the 
whole context, just the first few characters until they run out of room.-->also 
the leap into electronic typesetting, remaining essentially unchanged.</p>
+<p><!-- At the beginning of paragraph -->Paragraph text.</p>
 <p><b>Foo <!-- Bar4 --> Baz!</b></p>
 <p><i>Foo <!-- Bar5 --></i> Baz!</p>
+
+<ol>
+<!-- 1 -->
+<li><!-- 2 -->List item one.</li>
+<li>List item two.<!-- 3 --></li>
+<!-- 4 -->
+<li>List item three.</li>
+<!-- 5 -->
+</ol>
+
+<dl>
+<!-- 1 -->
+<dt><!-- 2 -->Definition term</dt>
+<dd>Definition one.<!-- 3 --></dd>
+<!-- 4 -->
+<dd>Definition two.</dd>
+<!-- 5 -->
+</dl>
diff --git a/src/dm/nodes/ve.dm.CommentNode.js 
b/src/dm/nodes/ve.dm.CommentNode.js
index 67af0a9..1279916 100644
--- a/src/dm/nodes/ve.dm.CommentNode.js
+++ b/src/dm/nodes/ve.dm.CommentNode.js
@@ -38,9 +38,8 @@
                domElements[0].data :
                domElements[0].getAttribute( 'data-ve-comment' );
        return {
-               // Only use CommentNode for comments in ContentBranchNodes; 
otherwise use
-               // CommentMetaItem
-               type: converter.isExpectingContent() && text !== '' ? 'comment' 
: 'commentMeta',
+               // Disallows comment nodes between table rows and such
+               type: converter.isValidChildNodeType( 'comment' ) && text !== 
'' ? 'comment' : 'commentMeta',
                attributes: {
                        text: text
                }
diff --git a/src/dm/ve.dm.Converter.js b/src/dm/ve.dm.Converter.js
index 025a3e3..300db97 100644
--- a/src/dm/ve.dm.Converter.js
+++ b/src/dm/ve.dm.Converter.js
@@ -275,6 +275,23 @@
 };
 
 /**
+ * Whether the converter can currently accept a child node with the given type.
+ *
+ * @method
+ * @param {string} nodeType
+ * @returns {boolean|null} Whether the node type is valid, or null if not 
converting
+ */
+ve.dm.Converter.prototype.isValidChildNodeType = function ( nodeType ) {
+       var childTypes,
+               context = this.getCurrentContext();
+       if ( !context ) {
+               return null;
+       }
+       childTypes = this.nodeFactory.getChildNodeTypes( context.branchType );
+       return ( childTypes === null || ve.indexOf( nodeType, childTypes ) !== 
-1 );
+};
+
+/**
  * Whether the conversion is currently inside a wrapper paragraph generated by 
the converter.
  * Note that this is specific to the current recursion level.
  *
@@ -580,7 +597,7 @@
                return true;
        }
 
-       var i, childNode, childNodes, childDataElements, text, childTypes, 
matches,
+       var i, childNode, childNodes, childDataElements, text, matches,
                wrappingParagraph, prevElement, childAnnotations, modelName, 
modelClass,
                annotation, childIsContent, aboutGroup, emptyParagraph,
                modelRegistry = this.modelRegistry,
@@ -911,11 +928,10 @@
 
        // If we're closing a node that doesn't have any children, but could 
contain a paragraph,
        // add a paragraph. This prevents things like empty list items
-       childTypes = this.nodeFactory.getChildNodeTypes( context.branchType );
        if ( context.branchType !== 'paragraph' && wrapperElement && 
data[data.length - 1] === wrapperElement &&
                !context.inWrapper && !this.nodeFactory.canNodeContainContent( 
context.branchType ) &&
                !this.nodeFactory.isNodeContent( context.branchType ) &&
-               ( childTypes === null || ve.indexOf( 'paragraph', childTypes ) 
!== -1 )
+               this.isValidChildNodeType( 'paragraph' )
        ) {
                emptyParagraph = { type: 'paragraph', internal: { generated: 
'empty' } };
                processNextWhitespace( emptyParagraph );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9f5ee4a058b42f870154d489804ef52601bd7d1e
Gerrit-PatchSet: 1
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Bartosz Dziewoński <[email protected]>

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

Reply via email to