deno.land / x / sheetjs@v0.18.3 / bits / 57_cmntxml.js

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* 18.7 Comments */function parse_comments_xml(data/*:string*/, opts)/*:Array<RawComment>*/ { /* 18.7.6 CT_Comments */ if(data.match(/<(?:\w+:)?comments *\/>/)) return []; var authors/*:Array<string>*/ = []; var commentList/*:Array<RawComment>*/ = []; var authtag = data.match(/<(?:\w+:)?authors>([\s\S]*)<\/(?:\w+:)?authors>/); if(authtag && authtag[1]) authtag[1].split(/<\/\w*:?author>/).forEach(function(x) { if(x === "" || x.trim() === "") return; var a = x.match(/<(?:\w+:)?author[^>]*>(.*)/); if(a) authors.push(a[1]); }); var cmnttag = data.match(/<(?:\w+:)?commentList>([\s\S]*)<\/(?:\w+:)?commentList>/); if(cmnttag && cmnttag[1]) cmnttag[1].split(/<\/\w*:?comment>/).forEach(function(x) { if(x === "" || x.trim() === "") return; var cm = x.match(/<(?:\w+:)?comment[^>]*>/); if(!cm) return; var y = parsexmltag(cm[0]); var comment/*:RawComment*/ = ({ author: y.authorId && authors[y.authorId] || "sheetjsghost", ref: y.ref, guid: y.guid }/*:any*/); var cell = decode_cell(y.ref); if(opts.sheetRows && opts.sheetRows <= cell.r) return; var textMatch = x.match(/<(?:\w+:)?text>([\s\S]*)<\/(?:\w+:)?text>/); var rt = !!textMatch && !!textMatch[1] && parse_si(textMatch[1]) || {r:"",t:"",h:""}; comment.r = rt.r; if(rt.r == "<t></t>") rt.t = rt.h = ""; comment.t = (rt.t||"").replace(/\r\n/g,"\n").replace(/\r/g,"\n"); if(opts.cellHTML) comment.h = rt.h; commentList.push(comment); }); return commentList;}
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/*:Array<string>*/ = []; o.push("<authors>"); data.forEach(function(x) { x[1].forEach(function(w) { var a = escapexml(w.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>'); o.push(writetag("t", c.t == null ? "" : escapexml(c.t))); o.push('</text></comment>'); }); }); o.push("</commentList>"); if(o.length>2) { o[o.length] = ('</comments>'); o[1]=o[1].replace("/>",">"); } return o.join("");}
sheetjs

Version Info

Tagged at
2 years ago