From 6c9010f9d13910ae6f53ba6cbd0cdd131db7a559 Mon Sep 17 00:00:00 2001 From: SheetJS Date: Fri, 2 Sep 2022 03:29:25 -0400 Subject: [PATCH] comment fallback (fixes #2779 h/t @AbhinanduReddy) --- bits/57_cmntxml.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/bits/57_cmntxml.js b/bits/57_cmntxml.js index 1471a28..a55e411 100644 --- a/bits/57_cmntxml.js +++ b/bits/57_cmntxml.js @@ -50,21 +50,27 @@ function write_comments_xml(data/*::, opts*/) { o.push(""); data.forEach(function(d) { /* 18.7.3 CT_Comment */ - var lastauthor = 0, ts = []; + var lastauthor = 0, ts = [], tcnt = 0; if(d[1][0] && d[1][0].T && d[1][0].ID) lastauthor = iauthor.indexOf("tc=" + d[1][0].ID); - else d[1].forEach(function(c) { + d[1].forEach(function(c) { if(c.a) lastauthor = iauthor.indexOf(escapexml(c.a)); - ts.push(c.t||""); + if(c.T) ++tcnt; + ts.push(writetag("t", c.t == null ? "" : escapexml(c.t))); }); - o.push(''); - if(ts.length <= 1) o.push(writetag("t", escapexml(ts[0]||""))); - else { + if(tcnt === 0) { + d[1].forEach(function(c) { + o.push(''); + o.push(writetag("t", c.t == null ? "" : escapexml(c.t))); + o.push(''); + }); + } else { /* based on Threaded Comments -> Comments projection */ + o.push(''); var t = "Comment:\n " + (ts[0]) + "\n"; for(var i = 1; i < ts.length; ++i) t += "Reply:\n " + ts[i] + "\n"; o.push(writetag("t", escapexml(t))); + o.push(''); } - o.push(''); }); o.push(""); if(o.length>2) { o[o.length] = (''); o[1]=o[1].replace("/>",">"); }