(function() { var editor = window.document.getElementById('wiki__text'); var lines = editor.value.split('\n'); var next = function(l, n) { var a = lines[l].substr(n).indexOf('^'); var b = lines[l].substr(n).indexOf('|'); if(a === -1 && b === -1) { return -1; } var r; if(b === -1) { r = a + n; } else if(a === -1) { r = b + n; } else { r = (b < a ? b : a) + n; } if(r > 0 && lines[l].charAt(r - 1) === '|' || lines[l].charAt(r - 1) === '^') { while(lines[l].charAt(n) !== '|' && lines[l].charAt(n) !== '^') { n++; } return next(l, n+1); } else { return r; } }; var insert = function(c, l, n, p) { var s = ''; for(var i=0;i