cleanup...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2023-12-13 02:17:08 +03:00
parent 6dfd4a308a
commit 5cd04af9f2

View File

@ -133,17 +133,6 @@ var getMarkdownOffset = function(markdown, text, i){
m = p } } m = p } }
return m - t } return m - t }
// NOTE: this is the same as .innerText but will not add extra "\n" after
// each block element...
var getTexts = function(elem, res=[]){
for(var n of elem.childNodes){
n.nodeType == n.TEXT_NODE ?
res.push(n.textContent)
: getTexts(n, res) }
return res }
var getText = function(elem){
return getTexts(elem).join('') }
var offsetAt = function(A, B, i){ var offsetAt = function(A, B, i){
i ??= A.length-1 i ??= A.length-1
var o = 0 var o = 0
@ -157,39 +146,17 @@ var offsetAt = function(A, B, i){
p = o } p = o }
return o } return o }
// // NOTE: this is the same as .innerText but will not add extra "\n" after
// offsetMap( // each block element...
// 'abMcdefg', var getTexts = function(elem, res=[]){
// 'abcdeXfg') for(var n of elem.childNodes){
// -> [0, 0, , -1, -1, -1, 0, 0] n.nodeType == n.TEXT_NODE ?
// res.push(n.textContent)
// XXX this is still wrong -- the problem is that in more complex cases : getTexts(n, res) }
// this finds a non-optimal solution... return res }
// m = `text text text var getText = function(elem){
// <div> return getTexts(elem).join('') }
// block element
// </div>
// this line, and above placement of completely broken`
// t = 'text text text\n\n\nblock element\n\n\nthis line, and above placement of completely broken '
// o = offsetMap(m, t)
// // this should reproduce common sections...
// console.log('---', o.map(function(e, i){ return m[i+e] }).join(''))
// XXX can we cheat here???
// XXX do we need this???
var offsetMap = function(A, B, m=[]){
var o = 0
var p = 0
for(var n=0; n < A.length; n++){
while(A[n] != B[n+o]){
if(n+o >= B.length){
m.length += 1
o = p-1
break }
o++ }
A[n] == B[n+o]
&& m.push(o)
p = o }
return m }