2017-04-02 06:47:25 +00:00
|
|
|
/* 18.7 Comments */
|
2017-02-10 19:23:01 +00:00
|
|
|
function parse_comments_xml(data/*:string*/, opts)/*:Array<Comment>*/ {
|
2017-04-02 06:47:25 +00:00
|
|
|
/* 18.7.6 CT_Comments */
|
2014-04-03 22:51:54 +00:00
|
|
|
if(data.match(/<(?:\w+:)?comments *\/>/)) return [];
|
2014-03-29 02:05:50 +00:00
|
|
|
var authors = [];
|
|
|
|
var commentList = [];
|
2017-06-24 06:51:37 +00:00
|
|
|
var authtag = data.match(/<(?:\w+:)?authors>([\s\S]*)<\/(?:\w+:)?authors>/);
|
2017-02-10 19:23:01 +00:00
|
|
|
if(authtag && authtag[1]) authtag[1].split(/<\/\w*:?author>/).forEach(function(x) {
|
2014-03-29 02:05:50 +00:00
|
|
|
if(x === "" || x.trim() === "") return;
|
2017-02-10 19:23:01 +00:00
|
|
|
var a = x.match(/<(?:\w+:)?author[^>]*>(.*)/);
|
|
|
|
if(a) authors.push(a[1]);
|
2014-03-29 02:05:50 +00:00
|
|
|
});
|
2017-06-24 06:51:37 +00:00
|
|
|
var cmnttag = data.match(/<(?:\w+:)?commentList>([\s\S]*)<\/(?:\w+:)?commentList>/);
|
2017-02-10 19:23:01 +00:00
|
|
|
if(cmnttag && cmnttag[1]) cmnttag[1].split(/<\/\w*:?comment>/).forEach(function(x, index) {
|
2014-03-29 02:05:50 +00:00
|
|
|
if(x === "" || x.trim() === "") return;
|
2017-02-10 19:23:01 +00:00
|
|
|
var cm = x.match(/<(?:\w+:)?comment[^>]*>/);
|
|
|
|
if(!cm) return;
|
|
|
|
var y = parsexmltag(cm[0]);
|
2017-09-22 22:18:51 +00:00
|
|
|
var comment/*:Comment*/ = ({ author: y.authorId && authors[y.authorId] || "sheetjsghost", ref: y.ref, guid: y.guid }/*:any*/);
|
2014-03-29 02:05:50 +00:00
|
|
|
var cell = decode_cell(y.ref);
|
|
|
|
if(opts.sheetRows && opts.sheetRows <= cell.r) return;
|
2017-06-24 06:51:37 +00:00
|
|
|
var textMatch = x.match(/<(?:\w+:)?text>([\s\S]*)<\/(?:\w+:)?text>/);
|
2017-04-03 00:16:03 +00:00
|
|
|
var rt = !!textMatch && !!textMatch[1] && parse_si(textMatch[1]) || {r:"",t:"",h:""};
|
2014-03-29 02:05:50 +00:00
|
|
|
comment.r = rt.r;
|
2017-04-03 00:16:03 +00:00
|
|
|
if(rt.r == "<t></t>") rt.t = rt.h = "";
|
2017-04-02 06:47:25 +00:00
|
|
|
comment.t = rt.t.replace(/\r\n/g,"\n").replace(/\r/g,"\n");
|
2014-03-29 02:05:50 +00:00
|
|
|
if(opts.cellHTML) comment.h = rt.h;
|
|
|
|
commentList.push(comment);
|
|
|
|
});
|
|
|
|
return commentList;
|
|
|
|
}
|
2014-05-29 22:30:03 +00:00
|
|
|
|
2017-04-02 06:47:25 +00:00
|
|
|
var CMNT_XML_ROOT = writextag('comments', null, { 'xmlns': XMLNS.main[0] });
|
|
|
|
function write_comments_xml(data, opts) {
|
|
|
|
var o = [XML_HEADER, CMNT_XML_ROOT];
|
|
|
|
|
|
|
|
var iauthor = [];
|
|
|
|
o.push("<authors>");
|
|
|
|
data.map(function(x) { return x[1]; }).forEach(function(comment) {
|
|
|
|
comment.map(function(x) { return escapexml(x.a); }).forEach(function(a) {
|
|
|
|
if(iauthor.indexOf(a) > -1) return;
|
|
|
|
iauthor.push(a);
|
|
|
|
o.push("<author>" + a + "</author>");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
o.push("</authors>");
|
|
|
|
o.push("<commentList>");
|
|
|
|
data.forEach(function(d) {
|
|
|
|
d[1].forEach(function(c) {
|
|
|
|
/* 18.7.3 CT_Comment */
|
|
|
|
o.push('<comment ref="' + d[0] + '" authorId="' + iauthor.indexOf(escapexml(c.a)) + '"><text>');
|
2017-04-03 00:16:03 +00:00
|
|
|
o.push(writetag("t", c.t == null ? "" : c.t));
|
2017-04-02 06:47:25 +00:00
|
|
|
o.push('</text></comment>');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
o.push("</commentList>");
|
|
|
|
if(o.length>2) { o[o.length] = ('</comments>'); o[1]=o[1].replace("/>",">"); }
|
|
|
|
return o.join("");
|
|
|
|
}
|