mirror of
https://github.com/flynx/pWiki.git
synced 2025-10-29 10:00:08 +00:00
cleanup...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
6dfd4a308a
commit
5cd04af9f2
@ -133,17 +133,6 @@ var getMarkdownOffset = function(markdown, text, i){
|
||||
m = p } }
|
||||
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){
|
||||
i ??= A.length-1
|
||||
var o = 0
|
||||
@ -157,39 +146,17 @@ var offsetAt = function(A, B, i){
|
||||
p = o }
|
||||
return o }
|
||||
|
||||
//
|
||||
// offsetMap(
|
||||
// 'abMcdefg',
|
||||
// 'abcdeXfg')
|
||||
// -> [0, 0, , -1, -1, -1, 0, 0]
|
||||
//
|
||||
// XXX this is still wrong -- the problem is that in more complex cases
|
||||
// this finds a non-optimal solution...
|
||||
// m = `text text text
|
||||
// <div>
|
||||
// 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 }
|
||||
// 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('') }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user