r101436 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101435‎ | r101436 | r101437 >
Date:23:46, 31 October 2011
Author:catrope
Status:deferred
Tags:
Comment:
Commit code that fixes more insertion tests. Or something. I really don't remember what this code does any more, it's been lying around in my working copy for too long.
Modified paths:
  • /trunk/parsers/wikidom/lib/hype/models/es.DocumentModel.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/hype/models/es.DocumentModel.js
@@ -794,16 +794,16 @@
795795 workingData = data.slice( 0 );
796796 }
797797 workingData.splice( i, 1 );
 798+ } else {
 799+ element = stack.pop();
 800+ if ( element != data[i].type.substr( 1 ) ) {
 801+ // Closing doesn't match what's expected
 802+ // This means the input is malformed and cannot possibly
 803+ // have been a fragment taken from well-formed data
 804+ throw 'Input is malformed: expected /' + element + ' but got ' + data[i].type +
 805+ ' at index ' + i;
 806+ }
798807 }
799 -
800 - element = stack.pop();
801 - if ( element != data[i].type.substr( 1 ) ) {
802 - // Closing doesn't match what's expected
803 - // This means the input is malformed and cannot possibly
804 - // have been a fragment taken from well-formed data
805 - throw 'Input is malformed: expected /' + element + ' but got ' + data[i].type +
806 - ' at index ' + i;
807 - }
808808 }
809809 }
810810
@@ -839,14 +839,23 @@
840840 }
841841
842842 if ( es.DocumentModel.containsElementData( insertedData ) ) {
843 - if ( isStructuralLoc ) {
 843+ if ( insertedData[0].type !== undefined && insertedData[0].type.charAt( 0 ) != '/' ) {
 844+ // insertedData starts with an opening, so this is really intended to insert structure
 845+ // Balance it to make it sane, if it's not already
 846+ // TODO we need an actual validator and check that the insertion is really valid
844847 insertedData = balance( insertedData );
 848+ if ( !isStructuralLoc ) {
 849+ // We're inserting structure at a content location,
 850+ // so we need to split up the wrapping element
 851+ wrappingElementType = this.getNodeFromOffset( offset ).getElementType();
 852+ var arr = [ { 'type': '/' + wrappingElementType }, { 'type': wrappingElementType } ];
 853+ es.insertIntoArray( arr, 1, insertedData );
 854+ insertedData = arr;
 855+ }
 856+ // else we're inserting structure at a structural location, which is fine
845857 } else {
846 - // We're inserting structure at a content location,
847 - // so we need to split up the wrapping element
848 - wrappingElementType = this.getNodeFromOffset( offset ).getElementType();
849 - insertedData = [ { 'type': '/' + wrappingElementType }, { 'type': wrappingElementType } ];
850 - es.insertIntoArray( insertedData, 1, data );
 858+ // insertedData starts with content but contains structure
 859+ // TODO balance and validate, will be different for this case
851860 }
852861 } else {
853862 if ( isStructuralLoc ) {

Status & tagging log