Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php |
— | — | @@ -72,8 +72,8 @@ |
73 | 73 | array( 'src' => 'js/plugins/jquery.namespaceSelect.js', 'version' => 1 ), |
74 | 74 | array( 'src' => 'js/plugins/jquery.suggestions.js', 'version' => 7 ), |
75 | 75 | array( 'src' => 'js/plugins/jquery.textSelection.js', 'version' => 26 ), |
76 | | - array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 72 ), |
77 | | - array( 'src' => 'js/plugins/jquery.wikiEditor.highlight.js', 'version' => 23 ), |
| 76 | + array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 73 ), |
| 77 | + array( 'src' => 'js/plugins/jquery.wikiEditor.highlight.js', 'version' => 24 ), |
78 | 78 | array( 'src' => 'js/plugins/jquery.wikiEditor.toolbar.js', 'version' => 45 ), |
79 | 79 | array( 'src' => 'js/plugins/jquery.wikiEditor.dialogs.js', 'version' => 11 ), |
80 | 80 | array( 'src' => 'js/plugins/jquery.wikiEditor.toc.js', 'version' => 74 ), |
— | — | @@ -82,10 +82,10 @@ |
83 | 83 | array( 'src' => 'js/plugins/jquery.wikiEditor.publish.js', 'version' => 2 ), |
84 | 84 | ), |
85 | 85 | 'combined' => array( |
86 | | - array( 'src' => 'js/plugins.combined.js', 'version' => 184 ), |
| 86 | + array( 'src' => 'js/plugins.combined.js', 'version' => 185 ), |
87 | 87 | ), |
88 | 88 | 'minified' => array( |
89 | | - array( 'src' => 'js/plugins.combined.min.js', 'version' => 184 ), |
| 89 | + array( 'src' => 'js/plugins.combined.min.js', 'version' => 185 ), |
90 | 90 | ), |
91 | 91 | ), |
92 | 92 | ); |
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js |
— | — | @@ -425,8 +425,6 @@ |
426 | 426 | if ( !selText ) { |
427 | 427 | selText = options.peri; |
428 | 428 | selectAfter = true; |
429 | | - } else if ( options.splitlines ) { |
430 | | - selTextArr = selText.split( /\n/ ); |
431 | 429 | } else if ( options.replace ) { |
432 | 430 | selText = options.peri; |
433 | 431 | } else if ( selText.charAt( selText.length - 1 ) == ' ' ) { |
— | — | @@ -435,6 +433,10 @@ |
436 | 434 | selText = selText.substring( 0, selText.length - 1 ); |
437 | 435 | post += ' '; |
438 | 436 | } |
| 437 | + if ( options.splitlines ) { |
| 438 | + selTextArr = selText.split( /\n/ ); |
| 439 | + } |
| 440 | + |
439 | 441 | if ( context.$iframe[0].contentWindow.getSelection ) { |
440 | 442 | // Firefox and Opera |
441 | 443 | var range = context.$iframe[0].contentWindow.getSelection().getRangeAt( 0 ); |
— | — | @@ -504,7 +506,9 @@ |
505 | 507 | if ( options.splitlines ) { |
506 | 508 | for( var i = 0; i < selTextArr.length; i++ ) { |
507 | 509 | insertText = insertText + pre + selTextArr[i] + post; |
508 | | - if( i != selTextArr.length - 1 ) insertText += "\n"; |
| 510 | + if( i != selTextArr.length - 1 ) { |
| 511 | + insertText += "\n"; |
| 512 | + } |
509 | 513 | } |
510 | 514 | } else { |
511 | 515 | insertText = pre + selText + post; |
— | — | @@ -548,10 +552,10 @@ |
549 | 553 | if ( !sc || !ec ) { |
550 | 554 | var s = context.fn.getOffset( start ); |
551 | 555 | var e = context.fn.getOffset( end ); |
552 | | - sc = s.node; |
553 | | - ec = e.node; |
554 | | - start = s.offset; |
555 | | - end = e.offset; |
| 556 | + sc = s ? s.node : null; |
| 557 | + ec = e ? e.node : null; |
| 558 | + start = s ? s.offset : null; |
| 559 | + end = e ? e.offset : null; |
556 | 560 | } |
557 | 561 | if ( !sc || !ec ) { |
558 | 562 | // The requested offset isn't in the offsets array |
— | — | @@ -775,21 +779,25 @@ |
776 | 780 | return context.offsets[offset]; |
777 | 781 | } |
778 | 782 | // Our offset is not pre-cached. Find the highest offset below it and interpolate |
779 | | - var lowerBound = 0; |
| 783 | + var lowerBound = -1; |
780 | 784 | for ( var o in context.offsets ) { |
781 | 785 | if ( o > offset ) { |
782 | 786 | break; |
783 | 787 | } |
784 | 788 | lowerBound = o; |
785 | 789 | } |
| 790 | + if ( !( lowerBound in context.offsets ) ) { |
| 791 | + // Weird edge case: either offset is too large or the document is empty |
| 792 | + return null; |
| 793 | + } |
786 | 794 | var base = context.offsets[lowerBound]; |
787 | 795 | return context.offsets[offset] = { |
788 | 796 | 'node': base.node, |
789 | 797 | 'offset': base.offset + offset - o, |
790 | 798 | 'length': base.length, |
791 | 799 | 'depth': base.depth, |
792 | | - 'lastTextNode': lastTextNode, |
793 | | - 'lastTextNodeDepth': lastTextNodeDepth |
| 800 | + 'lastTextNode': base.lastTextNode, |
| 801 | + 'lastTextNodeDepth': base.lastTextNodeDepth |
794 | 802 | }; |
795 | 803 | }, |
796 | 804 | 'purgeOffsets': function() { |
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.highlight.js |
— | — | @@ -157,6 +157,10 @@ |
158 | 158 | // if a marker starts or ends halfway one. |
159 | 159 | var start = markers[i].start; |
160 | 160 | var s = context.fn.getOffset( start ); |
| 161 | + if ( !s ) { |
| 162 | + // This shouldn't happen |
| 163 | + continue; |
| 164 | + } |
161 | 165 | var startNode = s.node; |
162 | 166 | var startDepth = s.depth; |
163 | 167 | // The next marker starts somewhere in this textNode or at this BR |
— | — | @@ -178,6 +182,10 @@ |
179 | 183 | |
180 | 184 | var end = markers[i].end; |
181 | 185 | var e = context.fn.getOffset( end ); |
| 186 | + if ( !e ) { |
| 187 | + // This shouldn't happen |
| 188 | + continue; |
| 189 | + } |
182 | 190 | var endNode = e.node; |
183 | 191 | var endDepth = e.depth; |
184 | 192 | if ( e.offset < e.length - 1 ) { |
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js |
— | — | @@ -6849,8 +6849,6 @@ |
6850 | 6850 | if ( !selText ) { |
6851 | 6851 | selText = options.peri; |
6852 | 6852 | selectAfter = true; |
6853 | | - } else if ( options.splitlines ) { |
6854 | | - selTextArr = selText.split( /\n/ ); |
6855 | 6853 | } else if ( options.replace ) { |
6856 | 6854 | selText = options.peri; |
6857 | 6855 | } else if ( selText.charAt( selText.length - 1 ) == ' ' ) { |
— | — | @@ -6859,6 +6857,10 @@ |
6860 | 6858 | selText = selText.substring( 0, selText.length - 1 ); |
6861 | 6859 | post += ' '; |
6862 | 6860 | } |
| 6861 | + if ( options.splitlines ) { |
| 6862 | + selTextArr = selText.split( /\n/ ); |
| 6863 | + } |
| 6864 | + |
6863 | 6865 | if ( context.$iframe[0].contentWindow.getSelection ) { |
6864 | 6866 | // Firefox and Opera |
6865 | 6867 | var range = context.$iframe[0].contentWindow.getSelection().getRangeAt( 0 ); |
— | — | @@ -6928,7 +6930,9 @@ |
6929 | 6931 | if ( options.splitlines ) { |
6930 | 6932 | for( var i = 0; i < selTextArr.length; i++ ) { |
6931 | 6933 | insertText = insertText + pre + selTextArr[i] + post; |
6932 | | - if( i != selTextArr.length - 1 ) insertText += "\n"; |
| 6934 | + if( i != selTextArr.length - 1 ) { |
| 6935 | + insertText += "\n"; |
| 6936 | + } |
6933 | 6937 | } |
6934 | 6938 | } else { |
6935 | 6939 | insertText = pre + selText + post; |
— | — | @@ -6972,10 +6976,10 @@ |
6973 | 6977 | if ( !sc || !ec ) { |
6974 | 6978 | var s = context.fn.getOffset( start ); |
6975 | 6979 | var e = context.fn.getOffset( end ); |
6976 | | - sc = s.node; |
6977 | | - ec = e.node; |
6978 | | - start = s.offset; |
6979 | | - end = e.offset; |
| 6980 | + sc = s ? s.node : null; |
| 6981 | + ec = e ? e.node : null; |
| 6982 | + start = s ? s.offset : null; |
| 6983 | + end = e ? e.offset : null; |
6980 | 6984 | } |
6981 | 6985 | if ( !sc || !ec ) { |
6982 | 6986 | // The requested offset isn't in the offsets array |
— | — | @@ -7199,21 +7203,25 @@ |
7200 | 7204 | return context.offsets[offset]; |
7201 | 7205 | } |
7202 | 7206 | // Our offset is not pre-cached. Find the highest offset below it and interpolate |
7203 | | - var lowerBound = 0; |
| 7207 | + var lowerBound = -1; |
7204 | 7208 | for ( var o in context.offsets ) { |
7205 | 7209 | if ( o > offset ) { |
7206 | 7210 | break; |
7207 | 7211 | } |
7208 | 7212 | lowerBound = o; |
7209 | 7213 | } |
| 7214 | + if ( !( lowerBound in context.offsets ) ) { |
| 7215 | + // Weird edge case: either offset is too large or the document is empty |
| 7216 | + return null; |
| 7217 | + } |
7210 | 7218 | var base = context.offsets[lowerBound]; |
7211 | 7219 | return context.offsets[offset] = { |
7212 | 7220 | 'node': base.node, |
7213 | 7221 | 'offset': base.offset + offset - o, |
7214 | 7222 | 'length': base.length, |
7215 | 7223 | 'depth': base.depth, |
7216 | | - 'lastTextNode': lastTextNode, |
7217 | | - 'lastTextNodeDepth': lastTextNodeDepth |
| 7224 | + 'lastTextNode': base.lastTextNode, |
| 7225 | + 'lastTextNodeDepth': base.lastTextNodeDepth |
7218 | 7226 | }; |
7219 | 7227 | }, |
7220 | 7228 | 'purgeOffsets': function() { |
— | — | @@ -7711,6 +7719,10 @@ |
7712 | 7720 | // if a marker starts or ends halfway one. |
7713 | 7721 | var start = markers[i].start; |
7714 | 7722 | var s = context.fn.getOffset( start ); |
| 7723 | + if ( !s ) { |
| 7724 | + // This shouldn't happen |
| 7725 | + continue; |
| 7726 | + } |
7715 | 7727 | var startNode = s.node; |
7716 | 7728 | var startDepth = s.depth; |
7717 | 7729 | // The next marker starts somewhere in this textNode or at this BR |
— | — | @@ -7732,6 +7744,10 @@ |
7733 | 7745 | |
7734 | 7746 | var end = markers[i].end; |
7735 | 7747 | var e = context.fn.getOffset( end ); |
| 7748 | + if ( !e ) { |
| 7749 | + // This shouldn't happen |
| 7750 | + continue; |
| 7751 | + } |
7736 | 7752 | var endNode = e.node; |
7737 | 7753 | var endDepth = e.depth; |
7738 | 7754 | if ( e.offset < e.length - 1 ) { |
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js |
— | — | @@ -452,16 +452,17 @@ |
453 | 453 | html.replace(/\r?\n/g,"").replace(/\<br[^\>]*\>/gi,"\n").replace(/ /g," ").replace(/\<p[^\>]*\>/gi,"\n").replace(/\<\/p[^\>]*\>/gi,"") |
454 | 454 | +'</pre>');$pre.find('.wikiEditor-noinclude').each(function(){$(this).remove();});$pre.find('.wikiEditor-tab').each(function(){$(this).text("\t")});return $pre.text();},'getContents':function(){return context.fn.htmlToText(context.$content.html());},'getSelection':function(){var retval;if(context.$iframe[0].contentWindow.getSelection){retval=context.$iframe[0].contentWindow.getSelection();}else if(context.$iframe[0].contentWindow.document.selection){retval=context.$iframe[0].contentWindow.document.selection.createRange();} |
455 | 455 | if(typeof retval.text!='undefined'){retval=context.fn.htmlToText(retval.htmlText);}else if(retval.toString){retval=retval.toString();} |
456 | | -return retval;},'encapsulateSelection':function(options){var selText=$(this).textSelection('getSelection');var selTextArr;var selectAfter=false;var pre=options.pre,post=options.post;if(!selText){selText=options.peri;selectAfter=true;}else if(options.splitlines){selTextArr=selText.split(/\n/);}else if(options.replace){selText=options.peri;}else if(selText.charAt(selText.length-1)==' '){selText=selText.substring(0,selText.length-1);post+=' ';} |
| 456 | +return retval;},'encapsulateSelection':function(options){var selText=$(this).textSelection('getSelection');var selTextArr;var selectAfter=false;var pre=options.pre,post=options.post;if(!selText){selText=options.peri;selectAfter=true;}else if(options.replace){selText=options.peri;}else if(selText.charAt(selText.length-1)==' '){selText=selText.substring(0,selText.length-1);post+=' ';} |
| 457 | +if(options.splitlines){selTextArr=selText.split(/\n/);} |
457 | 458 | if(context.$iframe[0].contentWindow.getSelection){var range=context.$iframe[0].contentWindow.getSelection().getRangeAt(0);if(options.ownline){var body=context.$content.get(0);if(range.startOffset!=0&&range.startContainer!=body){pre="\n"+options.pre;} |
458 | 459 | if(range.endContainer!=body){post+="\n";}} |
459 | 460 | var insertText="";if(options.splitlines){for(var i=0;i<selTextArr.length;i++){insertText=insertText+pre+selTextArr[i]+post;if(i!=selTextArr.length-1)insertText+="\n";}}else{insertText=pre+selText+post;} |
460 | 461 | var insertLines=insertText.split("\n");range.extractContents();var lastNode;for(var i=insertLines.length-1;i>=0;i--){range.insertNode(context.$iframe[0].contentWindow.document.createTextNode(insertLines[i]));if(i>0){lastNode=range.insertNode(context.$iframe[0].contentWindow.document.createElement('br'));}} |
461 | 462 | if(lastNode){context.fn.scrollToTop(lastNode);}}else if(context.$iframe[0].contentWindow.document.selection){context.$iframe[0].contentWindow.focus();var range=context.$iframe[0].contentWindow.document.selection.createRange();if(options.ownline&&range.moveStart){var range2=context.$iframe[0].contentWindow.document.selection.createRange();range2.collapse();range2.moveStart('character',-1);if(range2.text!="\r"&&range2.text!="\n"&&range2.text!=""){pre="\n"+pre;} |
462 | 463 | var range3=context.$iframe[0].contentWindow.document.selection.createRange();range3.collapse(false);range3.moveEnd('character',1);if(range3.text!="\r"&&range3.text!="\n"&&range3.text!=""){post+="\n";}} |
463 | | -var insertText="";if(options.splitlines){for(var i=0;i<selTextArr.length;i++){insertText=insertText+pre+selTextArr[i]+post;if(i!=selTextArr.length-1)insertText+="\n";}}else{insertText=pre+selText+post;} |
| 464 | +var insertText="";if(options.splitlines){for(var i=0;i<selTextArr.length;i++){insertText=insertText+pre+selTextArr[i]+post;if(i!=selTextArr.length-1){insertText+="\n";}}}else{insertText=pre+selText+post;} |
464 | 465 | range.pasteHTML(insertText.replace(/\</g,'<').replace(/>/g,'>').replace(/\r?\n/g,'<br />'));} |
465 | | -$(context.$iframe[0].contentWindow.document).trigger('encapsulateSelection',[pre,options.peri,post,options.ownline,options.replace]);return context.$textarea;},'getCaretPosition':function(options){},'setSelection':function(options){var sc=options.startContainer,ec=options.endContainer;sc=sc&&sc.jquery?sc[0]:sc;ec=ec&&ec.jquery?ec[0]:ec;if(context.$iframe[0].contentWindow.getSelection){var start=options.start,end=options.end;if(!sc||!ec){var s=context.fn.getOffset(start);var e=context.fn.getOffset(end);sc=s.node;ec=e.node;start=s.offset;end=e.offset;} |
| 466 | +$(context.$iframe[0].contentWindow.document).trigger('encapsulateSelection',[pre,options.peri,post,options.ownline,options.replace]);return context.$textarea;},'getCaretPosition':function(options){},'setSelection':function(options){var sc=options.startContainer,ec=options.endContainer;sc=sc&&sc.jquery?sc[0]:sc;ec=ec&&ec.jquery?ec[0]:ec;if(context.$iframe[0].contentWindow.getSelection){var start=options.start,end=options.end;if(!sc||!ec){var s=context.fn.getOffset(start);var e=context.fn.getOffset(end);sc=s?s.node:null;ec=e?e.node:null;start=s?s.offset:null;end=e?e.offset:null;} |
466 | 467 | if(!sc||!ec){return context.$textarea;} |
467 | 468 | var sel=context.$iframe[0].contentWindow.getSelection();while(sc.firstChild&&sc.nodeName!='#text'){sc=sc.firstChild;} |
468 | 469 | while(ec.firstChild&&ec.nodeName!='#text'){ec=ec.firstChild;} |
— | — | @@ -486,9 +487,10 @@ |
487 | 488 | var node=start.jquery?start.get(0):start;var depth=0;var inP=node.nodeName=="P";do{while(node&&(' '+node.className+' ').indexOf(' wikiEditor-noinclude ')!=-1){node=node.nextSibling;} |
488 | 489 | if(node&&node.firstChild){node=node.firstChild;depth++;if(node.nodeName=="P"){inP=true;}}}while(node&&node.firstChild);return new Traverser(node,depth,inP);},'getOffset':function(offset){if(!context.offsets){context.fn.refreshOffsets();} |
489 | 490 | if(offset in context.offsets){return context.offsets[offset];} |
490 | | -var lowerBound=0;for(var o in context.offsets){if(o>offset){break;} |
| 491 | +var lowerBound=-1;for(var o in context.offsets){if(o>offset){break;} |
491 | 492 | lowerBound=o;} |
492 | | -var base=context.offsets[lowerBound];return context.offsets[offset]={'node':base.node,'offset':base.offset+offset-o,'length':base.length,'depth':base.depth,'lastTextNode':lastTextNode,'lastTextNodeDepth':lastTextNodeDepth};},'purgeOffsets':function(){context.offsets=null;},'refreshOffsets':function(){context.offsets=[];var t=context.fn.traverser(context.$content);var pos=0,lastTextNode=null,lastTextNodeDepth=null;while(t){if(t.node.nodeName!='#text'&&t.node.nodeName!='BR'){t=t.next();continue;} |
| 493 | +if(!(lowerBound in context.offsets)){return null;} |
| 494 | +var base=context.offsets[lowerBound];return context.offsets[offset]={'node':base.node,'offset':base.offset+offset-o,'length':base.length,'depth':base.depth,'lastTextNode':base.lastTextNode,'lastTextNodeDepth':base.lastTextNodeDepth};},'purgeOffsets':function(){context.offsets=null;},'refreshOffsets':function(){context.offsets=[];var t=context.fn.traverser(context.$content);var pos=0,lastTextNode=null,lastTextNodeDepth=null;while(t){if(t.node.nodeName!='#text'&&t.node.nodeName!='BR'){t=t.next();continue;} |
493 | 495 | var nextPos=t.node.nodeName=='#text'?pos+t.node.nodeValue.length:pos+1;var nextT=t.next();var leavingP=t.inP&&nextT&&!nextT.inP;context.offsets[pos]={'node':t.node,'offset':0,'length':nextPos-pos+(leavingP?1:0),'depth':t.depth,'lastTextNode':lastTextNode,'lastTextNodeDepth':lastTextNodeDepth};if(leavingP){context.offsets[nextPos]={'node':t.node,'offset':nextPos-pos,'length':nextPos-pos+1,'depth':t.depth,'lastTextNode':lastTextNode,'lastTextNodeDepth':lastTextNodeDepth};} |
494 | 496 | pos=nextPos+(leavingP?1:0);if(t.node.nodeName=='#text'){lastTextNode=t.node;lastTextNodeDepth=t.depth;} |
495 | 497 | t=nextT;}}};context.$textarea.wrap($('<div></div>').addClass('wikiEditor-ui')).wrap($('<div></div>').addClass('wikiEditor-ui-view wikiEditor-ui-view-wikitext')).wrap($('<div></div>').addClass('wikiEditor-ui-left')).wrap($('<div></div>').addClass('wikiEditor-ui-bottom')).wrap($('<div></div>').addClass('wikiEditor-ui-text'));context.$ui=context.$textarea.parent().parent().parent().parent().parent();context.$wikitext=context.$textarea.parent().parent().parent().parent();context.$wikitext.before($('<div></div>').addClass('wikiEditor-ui-controls').append($('<div></div>').addClass('wikiEditor-ui-tabs').hide()).append($('<div></div>').addClass('wikiEditor-ui-buttons'))).before($('<div style="clear:both;"></div>'));context.$controls=context.$ui.find('.wikiEditor-ui-buttons').hide();context.$buttons=context.$ui.find('.wikiEditor-ui-buttons');context.$tabs=context.$ui.find('.wikiEditor-ui-tabs');context.$ui.after($('<div style="clear:both;"></div>'));context.$wikitext.append($('<div></div>').addClass('wikiEditor-ui-right'));context.$wikitext.find('.wikiEditor-ui-left').prepend($('<div></div>').addClass('wikiEditor-ui-top'));context.view='wikitext';$(window).resize(function(event){context.fn.trigger('resize',event)});context.$iframe=$('<iframe></iframe>').attr({'frameBorder':0,'border':0,'src':wgScriptPath+'/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.html?'+'instance='+context.instance+'&ts='+(new Date()).getTime(),'id':'wikiEditor-iframe-'+context.instance}).css({'backgroundColor':'white','width':'100%','height':context.$textarea.height(),'display':'none','overflow-y':'scroll','overflow-x':'hidden'}).insertAfter(context.$textarea).load(function(){if(!this.isSecondRun){context.$iframe[0].contentWindow.document.designMode='on';if($.browser.msie){this.isSecondRun=true;return;}} |
— | — | @@ -506,9 +508,11 @@ |
507 | 509 | var tokenArray=context.modules.highlight.tokenArray=[];var text=context.fn.getContents();for(module in context.modules){if(module in $.wikiEditor.modules&&'exp'in $.wikiEditor.modules[module]){for(var i=0;i<$.wikiEditor.modules[module].exp.length;i++){var regex=$.wikiEditor.modules[module].exp[i].regex;var label=$.wikiEditor.modules[module].exp[i].label;var markAfter=false;if(typeof $.wikiEditor.modules[module].exp[i].markAfter!='undefined'){markAfter=true;} |
508 | 510 | match=text.match(regex);var oldOffset=0;while(match!=null){var markOffset=0;var tokenStart=match.index+oldOffset+markOffset;if(markAfter){markOffset+=match[0].length;} |
509 | 511 | tokenArray.push(new Token(match.index+oldOffset+markOffset,label,tokenStart,match));oldOffset+=match.index+match[0].length;newSubstring=text.substring(oldOffset);match=newSubstring.match(regex);}}}} |
510 | | -tokenArray.sort(function(a,b){return a.offset-b.offset||a.tokenStart-b.tokenStart;});context.fn.trigger('scan');},mark:function(context,division,tokens){var markers=context.modules.highlight.markers=[];context.fn.trigger('mark');markers.sort(function(a,b){return a.start-b.start||a.end-b.end;});for(var i=0;i<markers.length;i++){var start=markers[i].start;var s=context.fn.getOffset(start);var startNode=s.node;var startDepth=s.depth;if(s.offset>0){startNode=startNode.splitText(s.offset);} |
| 512 | +tokenArray.sort(function(a,b){return a.offset-b.offset||a.tokenStart-b.tokenStart;});context.fn.trigger('scan');},mark:function(context,division,tokens){var markers=context.modules.highlight.markers=[];context.fn.trigger('mark');markers.sort(function(a,b){return a.start-b.start||a.end-b.end;});for(var i=0;i<markers.length;i++){var start=markers[i].start;var s=context.fn.getOffset(start);if(!s){continue;} |
| 513 | +var startNode=s.node;var startDepth=s.depth;if(s.offset>0){startNode=startNode.splitText(s.offset);} |
511 | 514 | while(startNode.nodeName=='BR'&&start+1 in offsets){start++;startNode=s.node;startDepth=s.depth;} |
512 | | -var end=markers[i].end;var e=context.fn.getOffset(end);var endNode=e.node;var endDepth=e.depth;if(e.offset<e.length-1){endNode.splitText(e.offset+1);} |
| 515 | +var end=markers[i].end;var e=context.fn.getOffset(end);if(!e){continue;} |
| 516 | +var endNode=e.node;var endDepth=e.depth;if(e.offset<e.length-1){endNode.splitText(e.offset+1);} |
513 | 517 | if(endNode.nodeName=='BR'){endNode=e.lastTextNode;endDepth=e.lastTextNodeDepth;} |
514 | 518 | var ca1=startNode,ca2=endNode;if(startDepth>endDepth){for(var j=0;j<startDepth-endDepth&&ca1;j++){ca1=ca1.parentNode.firstChild==ca1?ca1.parentNode:null;}} |
515 | 519 | else if(startDepth<endDepth){for(var j=0;j<endDepth-startDepth&&ca2;j++){ca2=ca2.parentNode.lastChild==ca2?ca2.parentNode:null;}} |