mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 02:23:58 +00:00
Implement 1-char-minimum width for annotations, and some additonal minor
cleanup.
This commit is contained in:
parent
22ba27295b
commit
e98dd9e722
|
@ -8,7 +8,7 @@ function DOMConverter () {
|
|||
}
|
||||
|
||||
/**
|
||||
* Convert a HTML DOM to WikiDom
|
||||
* Convert HTML DOM to WikiDom
|
||||
*
|
||||
* @method
|
||||
* @param {Object} root of HTML DOM (usually the body element)
|
||||
|
@ -355,6 +355,13 @@ DOMConverter.prototype._convertHTMLAnnotation = function ( node, offset, type )
|
|||
break;
|
||||
}
|
||||
}
|
||||
// Insert one char if no text was returned to satisfy WikiDom's
|
||||
// 1-char-minimum width for annotations. Feels a bit icky, but likely
|
||||
// simplifies editor internals.
|
||||
if ( text === '' ) {
|
||||
text = ' ';
|
||||
offset++;
|
||||
}
|
||||
annotations[0].range.end = offset;
|
||||
return {
|
||||
text: text,
|
||||
|
@ -369,10 +376,10 @@ DOMConverter.prototype._HTMLPropertiesToWikiAttributes = function ( elem ) {
|
|||
var attrib = attribs.item(i),
|
||||
key = attrib.name;
|
||||
if ( key.match( /^data-json-/ ) ) {
|
||||
// strip data- prefix from data-*
|
||||
// strip data- prefix and decode
|
||||
out[key.replace( /^data-json-/, '' )] = JSON.parse(attrib.value);
|
||||
} else if ( key.match( /^data-/ ) ) {
|
||||
// strip data- prefix from data-*
|
||||
// strip data- prefix
|
||||
out[key.replace( /^data-/, '' )] = attrib.value;
|
||||
} else {
|
||||
// prefix html properties with html/
|
||||
|
@ -389,10 +396,10 @@ DOMConverter.prototype._HTMLPropertiesToWikiData = function ( elem ) {
|
|||
var attrib = attribs.item(i),
|
||||
key = attrib.name;
|
||||
if ( key.match( /^data-json-/ ) ) {
|
||||
// strip data- prefix from data-*
|
||||
// strip data-json- prefix and decode
|
||||
out[key.replace( /^data-json-/, '' )] = JSON.parse(attrib.value);
|
||||
} else if ( key.match( /^data-/ ) ) {
|
||||
// strip data- prefix from data-*
|
||||
// strip data- prefix
|
||||
out[key.replace( /^data-/, '' )] = attrib.value;
|
||||
} else {
|
||||
// pass through a few whitelisted keys
|
||||
|
@ -408,7 +415,7 @@ DOMConverter.prototype._HTMLPropertiesToWikiData = function ( elem ) {
|
|||
return out;
|
||||
};
|
||||
|
||||
// Quick HACK: define Node constants
|
||||
// Quick HACK: define Node constants locally
|
||||
// https://developer.mozilla.org/en/nodeType
|
||||
var Node = {
|
||||
ELEMENT_NODE: 1,
|
||||
|
|
Loading…
Reference in a new issue