| 
									
										
										
										
											2017-04-02 06:47:25 +00:00
										 |  |  | /* 18.7 Comments */ | 
					
						
							| 
									
										
										
										
											2017-12-30 05:40:35 +00:00
										 |  |  | function parse_comments_xml(data/*:string*/, opts)/*:Array<RawComment>*/ { | 
					
						
							| 
									
										
										
										
											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 []; | 
					
						
							| 
									
										
										
										
											2017-12-30 05:40:35 +00:00
										 |  |  | 	var authors/*:Array<string>*/ = []; | 
					
						
							|  |  |  | 	var commentList/*:Array<RawComment>*/ = []; | 
					
						
							| 
									
										
										
										
											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>/); | 
					
						
							| 
									
										
										
										
											2018-01-23 09:07:51 +00:00
										 |  |  | 	if(cmnttag && cmnttag[1]) cmnttag[1].split(/<\/\w*:?comment>/).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 cm = x.match(/<(?:\w+:)?comment[^>]*>/); | 
					
						
							|  |  |  | 		if(!cm) return; | 
					
						
							|  |  |  | 		var y = parsexmltag(cm[0]); | 
					
						
							| 
									
										
										
										
											2017-12-30 05:40:35 +00:00
										 |  |  | 		var comment/*:RawComment*/ = ({ 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] }); | 
					
						
							| 
									
										
										
										
											2018-01-23 09:07:51 +00:00
										 |  |  | function write_comments_xml(data/*::, opts*/) { | 
					
						
							| 
									
										
										
										
											2017-04-02 06:47:25 +00:00
										 |  |  | 	var o = [XML_HEADER, CMNT_XML_ROOT]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-30 05:40:35 +00:00
										 |  |  | 	var iauthor/*:Array<string>*/ = []; | 
					
						
							| 
									
										
										
										
											2017-04-02 06:47:25 +00:00
										 |  |  | 	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(""); | 
					
						
							|  |  |  | } |