r106208 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106207‎ | r106208 | r106209 >
Date:16:22, 14 December 2011
Author:gwicke
Status:deferred (Comments)
Tags:
Comment:
Handle a few more element types, and reset offset for each leaf node. Not sure
if the latter is correct, as the documentation at
https://www.mediawiki.org/wiki/Visual_editor/Software_design#Data_Structures
and the actual sample WikiDom in the editor sandbox seem to disagree on this
point.
Modified paths:
  • /trunk/extensions/VisualEditor/modules/parser/mediawiki.DOMConverter.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.DOMConverter.js
@@ -52,7 +52,7 @@
5353 }
5454 return res;
5555 case 'li':
56 - case 'dl':
 56+ case 'dt':
5757 case 'dd':
5858 return {
5959 handler: this._convertHTMLBranch,
@@ -63,6 +63,46 @@
6464 handler: this._convertHTMLLeaf,
6565 type: 'pre'
6666 };
 67+ case 'table':
 68+ return {
 69+ handler: this._convertHTMLBranch,
 70+ type: 'table'
 71+ };
 72+ case 'tbody':
 73+ return {
 74+ handler: this._convertHTMLBranch,
 75+ type: 'tbody' // not in WikiDom!
 76+ };
 77+ case 'tr':
 78+ return {
 79+ handler: this._convertHTMLBranch,
 80+ type: 'tableRow'
 81+ };
 82+ case 'th':
 83+ return {
 84+ handler: this._convertHTMLBranch,
 85+ type: 'tableHeading'
 86+ };
 87+ case 'td':
 88+ return {
 89+ handler: this._convertHTMLBranch,
 90+ type: 'tableCell'
 91+ };
 92+ case 'caption':
 93+ return {
 94+ handler: this._convertHTMLBranch,
 95+ type: 'caption'
 96+ };
 97+ case 'table':
 98+ return {
 99+ handler: this._convertHTMLBranch,
 100+ type: 'table'
 101+ };
 102+ case 'hr':
 103+ return {
 104+ handler: this._convertHTMLLeaf,
 105+ type: 'horizontalRule' // XXX?
 106+ };
67107 case 'ul':
68108 case 'ol':
69109 case 'dl':
@@ -70,6 +110,20 @@
71111 handler: this._convertHTMLBranch,
72112 type: 'list'
73113 };
 114+ case 'center':
 115+ //XXX: center is block-level in HTML, not sure what it should be
 116+ //in WikiDOM..
 117+ return {
 118+ handler: this._convertHTMLBranch,
 119+ type: 'center'
 120+ };
 121+ case 'blockquote':
 122+ //XXX: blockquote is block-level in HTML, not sure what it should be
 123+ //in WikiDOM..
 124+ return {
 125+ handler: this._convertHTMLBranch,
 126+ type: 'blockquote'
 127+ };
74128 default:
75129 console.log( 'HTML to Wiki DOM conversion error. Unsupported node name ' +
76130 nodeName );
@@ -90,6 +144,12 @@
91145 return 'textStyle/span';
92146 case 'a':
93147 return 'link/unknown'; // XXX: distinguish internal / external etc
 148+ case 'template':
 149+ return 'object/template';
 150+ case 'ref':
 151+ return 'object/hook';
 152+ case 'includeonly':
 153+ return 'object/includeonly'; // XXX
94154 default:
95155 if ( warn ) {
96156 console.log( 'HTML to Wiki DOM conversion error. Unsupported html annotation ' +
@@ -159,6 +219,7 @@
160220 var parNode = null;
161221
162222 function newPara () {
 223+ offset = 0;
163224 parNode = {
164225 type: 'paragraph',
165226 content: {
@@ -192,7 +253,7 @@
193254 parNode = null;
194255 // Call a handler for the particular node type
195256 var hi = this.getHTMLHandlerInfo( cnode.nodeName );
196 - var res = hi.handler.call(this, cnode, offset + 1, hi.type );
 257+ var res = hi.handler.call(this, cnode, 0, hi.type );
197258 if ( hi.attribs ) {
198259 $.extend( res.node.attributes, hi.attribs );
199260 }
@@ -230,6 +291,9 @@
231292 * @returns {Object} WikiDom object
232293 */
233294 DOMConverter.prototype._convertHTMLLeaf = function ( node, offset, type ) {
 295+ // XXX Does the offset in every leaf start at zero?
 296+ offset = 0;
 297+
234298 var children = node.childNodes,
235299 wnode = {
236300 type: type,

Follow-up revisions

RevisionCommit summaryAuthorDate
r106312Follow-up to r106208 and r106207. Both good catches, thanks Yair! As this code...gwicke10:13, 15 December 2011

Comments

#Comment by Yair rand (talk | contribs)   05:18, 15 December 2011

I see two "case 'table':"s.

Status & tagging log