From 02147937408b6547b7106e4b62a385f1cc904d56 Mon Sep 17 00:00:00 2001 From: ed Date: Wed, 5 Jan 2022 18:57:05 +0100 Subject: [PATCH] fix garbage in markdown output --- copyparty/web/md.js | 15 +++++++++------ copyparty/web/util.js | 6 +++--- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/copyparty/web/md.js b/copyparty/web/md.js index 194dbb5a..355a16c2 100644 --- a/copyparty/web/md.js +++ b/copyparty/web/md.js @@ -85,13 +85,13 @@ function copydom(src, dst, lv) { var rpl = []; for (var a = sc.length - 1; a >= 0; a--) { - var st = sc[a].tagName, - dt = dc[a].tagName; + var st = sc[a].tagName || sc[a].nodeType, + dt = dc[a].tagName || dc[a].nodeType; if (st !== dt) { dbg("replace L%d (%d/%d) type %s/%s", lv, a, sc.length, st, dt); - rpl.push(a); - continue; + dst.innerHTML = src.innerHTML; + return; } var sa = sc[a].attributes || [], @@ -140,8 +140,11 @@ function copydom(src, dst, lv) { // repl is reversed; build top-down var nbytes = 0; for (var a = rpl.length - 1; a >= 0; a--) { - var html = sc[rpl[a]].outerHTML; - dc[rpl[a]].outerHTML = html; + var i = rpl[a], + prop = sc[i].nodeType == 1 ? 'outerHTML' : 'nodeValue'; + + var html = sc[i][prop]; + dc[i][prop] = html; nbytes += html.length; } if (nbytes > 0) diff --git a/copyparty/web/util.js b/copyparty/web/util.js index 37168a5e..670b9a7d 100644 --- a/copyparty/web/util.js +++ b/copyparty/web/util.js @@ -222,15 +222,15 @@ if (!String.prototype.endsWith) return this.substring(this_len - search.length, this_len) === search; }; -if (!String.startsWith) +if (!String.prototype.startsWith) String.prototype.startsWith = function (s, i) { i = i > 0 ? i | 0 : 0; return this.substring(i, i + s.length) === s; }; -if (!String.trimEnd) +if (!String.prototype.trimEnd) String.prototype.trimEnd = String.prototype.trimRight = function () { - return this.replace(/[ \t\r\n]+$/m, ''); + return this.replace(/[ \t\r\n]+$/, ''); }; if (!Element.prototype.matches)