r106314 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106313‎ | r106314 | r106315 >
Date:11:05, 15 December 2011
Author:gwicke
Status:deferred
Tags:
Comment:
Implement 1-char-minimum width for annotations, and some additonal minor
cleanup.
Modified paths:
  • /trunk/extensions/VisualEditor/modules/parser/mediawiki.DOMConverter.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.DOMConverter.js
@@ -8,7 +8,7 @@
99 }
1010
1111 /**
12 - * Convert a HTML DOM to WikiDom
 12+ * Convert HTML DOM to WikiDom
1313 *
1414 * @method
1515 * @param {Object} root of HTML DOM (usually the body element)
@@ -355,6 +355,13 @@
356356 break;
357357 }
358358 }
 359+ // Insert one char if no text was returned to satisfy WikiDom's
 360+ // 1-char-minimum width for annotations. Feels a bit icky, but likely
 361+ // simplifies editor internals.
 362+ if ( text === '' ) {
 363+ text = ' ';
 364+ offset++;
 365+ }
359366 annotations[0].range.end = offset;
360367 return {
361368 text: text,
@@ -369,10 +376,10 @@
370377 var attrib = attribs.item(i),
371378 key = attrib.name;
372379 if ( key.match( /^data-json-/ ) ) {
373 - // strip data- prefix from data-*
 380+ // strip data- prefix and decode
374381 out[key.replace( /^data-json-/, '' )] = JSON.parse(attrib.value);
375382 } else if ( key.match( /^data-/ ) ) {
376 - // strip data- prefix from data-*
 383+ // strip data- prefix
377384 out[key.replace( /^data-/, '' )] = attrib.value;
378385 } else {
379386 // prefix html properties with html/
@@ -389,10 +396,10 @@
390397 var attrib = attribs.item(i),
391398 key = attrib.name;
392399 if ( key.match( /^data-json-/ ) ) {
393 - // strip data- prefix from data-*
 400+ // strip data-json- prefix and decode
394401 out[key.replace( /^data-json-/, '' )] = JSON.parse(attrib.value);
395402 } else if ( key.match( /^data-/ ) ) {
396 - // strip data- prefix from data-*
 403+ // strip data- prefix
397404 out[key.replace( /^data-/, '' )] = attrib.value;
398405 } else {
399406 // pass through a few whitelisted keys
@@ -408,7 +415,7 @@
409416 return out;
410417 };
411418
412 -// Quick HACK: define Node constants
 419+// Quick HACK: define Node constants locally
413420 // https://developer.mozilla.org/en/nodeType
414421 var Node = {
415422 ELEMENT_NODE: 1,

Status & tagging log