diff --git a/src/__tests__/__snapshots__/indexNode.test.ts.snap b/src/__tests__/__snapshots__/indexNode.test.ts.snap index f07ff3fe..3e6c95a7 100644 --- a/src/__tests__/__snapshots__/indexNode.test.ts.snap +++ b/src/__tests__/__snapshots__/indexNode.test.ts.snap @@ -26179,6 +26179,470 @@ Array [ exports[`noSandbox Template processing 112b failFast: true has the same behaviour as when failFast is undefined 1`] = `[Error: Error executing command: INS notavailable notavailable is not defined]`; +exports[`noSandbox Template processing 131 correctly handles Office 365 .docx files 1`] = ` +Object { + "_attrs": Object { + "mc:Ignorable": "w14 w15 wp14", + "xmlns:m": "http://schemas.openxmlformats.org/officeDocument/2006/math", + "xmlns:mc": "http://schemas.openxmlformats.org/markup-compatibility/2006", + "xmlns:o": "urn:schemas-microsoft-com:office:office", + "xmlns:r": "http://schemas.openxmlformats.org/officeDocument/2006/relationships", + "xmlns:v": "urn:schemas-microsoft-com:vml", + "xmlns:w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main", + "xmlns:w10": "urn:schemas-microsoft-com:office:word", + "xmlns:w14": "http://schemas.microsoft.com/office/word/2010/wordml", + "xmlns:w15": "http://schemas.microsoft.com/office/word/2012/wordml", + "xmlns:wne": "http://schemas.microsoft.com/office/word/2006/wordml", + "xmlns:wp": "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing", + "xmlns:wp14": "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing", + "xmlns:wpc": "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas", + "xmlns:wpg": "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup", + "xmlns:wpi": "http://schemas.microsoft.com/office/word/2010/wordprocessingInk", + "xmlns:wps": "http://schemas.microsoft.com/office/word/2010/wordprocessingShape", + }, + "_children": Array [ + Object { + "_attrs": Object {}, + "_children": Array [ + Object { + "_attrs": Object { + "w14:paraId": "3BFEFB25", + "wp14:noSpellErr": "1", + "wp14:textId": "2AD722EA", + "xmlns:wp14": "http://schemas.microsoft.com/office/word/2010/wordml", + }, + "_children": Array [ + Object { + "_attrs": Object { + "w:id": "0", + "w:name": "_GoBack", + }, + "_children": Array [], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:bookmarkStart", + }, + Object { + "_attrs": Object { + "w:id": "0", + }, + "_children": Array [], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:bookmarkEnd", + }, + Object { + "_attrs": Object { + "w:rsidR": "4C197E99", + }, + "_children": Array [ + Object { + "_attrs": Object {}, + "_children": Array [], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:rPr", + }, + Object { + "_attrs": Object { + "xml:space": "preserve", + }, + "_children": Array [ + Object { + "_children": Array [], + "_fTextNode": true, + "_parent": [Circular], + "_text": "first value!", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:t", + }, + Object { + "_attrs": Object { + "xml:space": "preserve", + }, + "_children": Array [ + Object { + "_children": Array [], + "_fTextNode": true, + "_parent": [Circular], + "_text": "", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:t", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:r", + }, + Object { + "_attrs": Object { + "w:type": "gramStart", + }, + "_children": Array [], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:proofErr", + }, + Object { + "_attrs": Object { + "w:rsidR": "4C197E99", + }, + "_children": Array [ + Object { + "_attrs": Object {}, + "_children": Array [], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:rPr", + }, + Object { + "_attrs": Object { + "xml:space": "preserve", + }, + "_children": Array [ + Object { + "_children": Array [], + "_fTextNode": true, + "_parent": [Circular], + "_text": "", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:t", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:r", + }, + Object { + "_attrs": Object { + "w:type": "gramEnd", + }, + "_children": Array [], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:proofErr", + }, + Object { + "_attrs": Object { + "w:rsidR": "4C197E99", + }, + "_children": Array [ + Object { + "_attrs": Object {}, + "_children": Array [], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:rPr", + }, + Object { + "_attrs": Object { + "xml:space": "preserve", + }, + "_children": Array [ + Object { + "_children": Array [], + "_fTextNode": true, + "_parent": [Circular], + "_text": " ", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:t", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:r", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:p", + }, + Object { + "_attrs": Object { + "w14:paraId": "5DAB0FCA", + "w14:textId": "67F23F00", + "w:rsidP": "4C197E99", + "w:rsidR": "4C197E99", + "w:rsidRDefault": "4C197E99", + }, + "_children": Array [ + Object { + "_attrs": Object {}, + "_children": Array [ + Object { + "_attrs": Object { + "w:val": "Normal", + }, + "_children": Array [], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:pStyle", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:pPr", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:p", + }, + Object { + "_attrs": Object { + "w14:paraId": "4DEFE58C", + "w14:textId": "03755723", + "w:rsidP": "4C197E99", + "w:rsidR": "4C197E99", + "w:rsidRDefault": "4C197E99", + }, + "_children": Array [ + Object { + "_attrs": Object {}, + "_children": Array [ + Object { + "_attrs": Object { + "w:val": "Normal", + }, + "_children": Array [], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:pStyle", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:pPr", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:p", + }, + Object { + "_attrs": Object { + "w14:noSpellErr": "1", + "w14:paraId": "664E8C7B", + "w14:textId": "388D7CD7", + "w:rsidP": "4C197E99", + "w:rsidR": "4C197E99", + "w:rsidRDefault": "4C197E99", + }, + "_children": Array [ + Object { + "_attrs": Object {}, + "_children": Array [ + Object { + "_attrs": Object { + "w:val": "Normal", + }, + "_children": Array [], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:pStyle", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:pPr", + }, + Object { + "_attrs": Object { + "w:rsidR": "4C197E99", + }, + "_children": Array [ + Object { + "_attrs": Object {}, + "_children": Array [], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:rPr", + }, + Object { + "_attrs": Object { + "xml:space": "preserve", + }, + "_children": Array [ + Object { + "_children": Array [], + "_fTextNode": true, + "_parent": [Circular], + "_text": "second value!", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:t", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:r", + }, + Object { + "_attrs": Object { + "w:type": "gramStart", + }, + "_children": Array [], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:proofErr", + }, + Object { + "_attrs": Object { + "w:rsidR": "4C197E99", + }, + "_children": Array [ + Object { + "_attrs": Object {}, + "_children": Array [], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:rPr", + }, + Object { + "_attrs": Object { + "xml:space": "preserve", + }, + "_children": Array [ + Object { + "_children": Array [], + "_fTextNode": true, + "_parent": [Circular], + "_text": "", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:t", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:r", + }, + Object { + "_attrs": Object { + "w:type": "gramEnd", + }, + "_children": Array [], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:proofErr", + }, + Object { + "_attrs": Object { + "w:rsidR": "4C197E99", + }, + "_children": Array [ + Object { + "_attrs": Object {}, + "_children": Array [], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:rPr", + }, + Object { + "_attrs": Object { + "xml:space": "preserve", + }, + "_children": Array [ + Object { + "_children": Array [], + "_fTextNode": true, + "_parent": [Circular], + "_text": "", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:t", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:r", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:p", + }, + Object { + "_attrs": Object {}, + "_children": Array [ + Object { + "_attrs": Object { + "w:h": "16838", + "w:orient": "portrait", + "w:w": "11906", + }, + "_children": Array [], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:pgSz", + }, + Object { + "_attrs": Object { + "w:bottom": "1440", + "w:footer": "720", + "w:gutter": "0", + "w:header": "720", + "w:left": "1440", + "w:right": "1440", + "w:top": "1440", + }, + "_children": Array [], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:pgMar", + }, + Object { + "_attrs": Object { + "w:space": "720", + }, + "_children": Array [], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:cols", + }, + Object { + "_attrs": Object { + "w:linePitch": "360", + }, + "_children": Array [], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:docGrid", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:sectPr", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:body", + }, + ], + "_fTextNode": false, + "_tag": "w:document", +} +`; + exports[`noSandbox Template processing avoids confusion between variable name and built-in command 1`] = ` Object { "_attrs": Object { @@ -51043,17 +51507,325 @@ Object { "_children": Array [], "_fTextNode": false, "_parent": [Circular], - "_tag": "w:bookmarkStart", + "_tag": "w:bookmarkStart", + }, + Object { + "_attrs": Object { + "w:id": "0", + }, + "_children": Array [], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:bookmarkEnd", + }, + Object { + "_attrs": Object { + "w:rsidRPr": "007856C0", + }, + "_children": Array [ + Object { + "_attrs": Object { + "xml:space": "preserve", + }, + "_children": Array [ + Object { + "_children": Array [], + "_fTextNode": true, + "_parent": [Circular], + "_text": "hong", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:t", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:r", + }, + Object { + "_attrs": Object { + "w:type": "spellStart", + }, + "_children": Array [], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:proofErr", + }, + Object { + "_attrs": Object { + "w:rsidR": "00D85011", + "w:rsidRPr": "007856C0", + }, + "_children": Array [ + Object { + "_attrs": Object {}, + "_children": Array [ + Object { + "_attrs": Object { + "w:ascii": "MS Gothic", + "w:cs": "MS Gothic", + "w:eastAsia": "MS Gothic", + "w:hAnsi": "MS Gothic", + "w:hint": "eastAsia", + }, + "_children": Array [], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:rFonts", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:rPr", + }, + Object { + "_attrs": Object { + "xml:space": "preserve", + }, + "_children": Array [ + Object { + "_children": Array [], + "_fTextNode": true, + "_parent": [Circular], + "_text": "", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:t", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:r", + }, + Object { + "_attrs": Object { + "w:type": "spellEnd", + }, + "_children": Array [], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:proofErr", + }, + Object { + "_attrs": Object { + "w:rsidRPr": "007856C0", + }, + "_children": Array [ + Object { + "_attrs": Object { + "xml:space": "preserve", + }, + "_children": Array [ + Object { + "_children": Array [], + "_fTextNode": true, + "_parent": [Circular], + "_text": "", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:t", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:r", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:p", + }, + Object { + "_attrs": Object { + "w14:paraId": "60A37F38", + "w14:textId": "4190B879", + "w:rsidP": "007856C0", + "w:rsidR": "00D85011", + "w:rsidRDefault": "00D85011", + "w:rsidRPr": "007856C0", + }, + "_children": Array [], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:p", + }, + Object { + "_attrs": Object { + "w14:paraId": "297A6708", + "w14:textId": "09F8E8D0", + "w:rsidP": "007856C0", + "w:rsidR": "00D85011", + "w:rsidRDefault": "007856C0", + "w:rsidRPr": "007856C0", + }, + "_children": Array [ + Object { + "_attrs": Object { + "w:rsidRPr": "007856C0", + }, + "_children": Array [ + Object { + "_attrs": Object { + "xml:space": "preserve", + }, + "_children": Array [ + Object { + "_children": Array [], + "_fTextNode": true, + "_parent": [Circular], + "_text": "junyao", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:t", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:r", + }, + Object { + "_attrs": Object { + "w:type": "spellStart", + }, + "_children": Array [], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:proofErr", + }, + Object { + "_attrs": Object { + "w:rsidR": "00D85011", + "w:rsidRPr": "007856C0", + }, + "_children": Array [ + Object { + "_attrs": Object {}, + "_children": Array [ + Object { + "_attrs": Object { + "w:ascii": "Microsoft JhengHei", + "w:cs": "Microsoft JhengHei", + "w:eastAsia": "Microsoft JhengHei", + "w:hAnsi": "Microsoft JhengHei", + "w:hint": "eastAsia", + }, + "_children": Array [], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:rFonts", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:rPr", + }, + Object { + "_attrs": Object { + "xml:space": "preserve", + }, + "_children": Array [ + Object { + "_children": Array [], + "_fTextNode": true, + "_parent": [Circular], + "_text": "", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:t", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:r", + }, + Object { + "_attrs": Object { + "w:type": "spellEnd", + }, + "_children": Array [], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:proofErr", }, Object { "_attrs": Object { - "w:id": "0", + "w:rsidRPr": "007856C0", }, - "_children": Array [], + "_children": Array [ + Object { + "_attrs": Object { + "xml:space": "preserve", + }, + "_children": Array [ + Object { + "_children": Array [], + "_fTextNode": true, + "_parent": [Circular], + "_text": "", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:t", + }, + ], "_fTextNode": false, "_parent": [Circular], - "_tag": "w:bookmarkEnd", + "_tag": "w:r", }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:p", + }, + Object { + "_attrs": Object { + "w14:paraId": "762D637D", + "w14:textId": "77777777", + "w:rsidP": "005B2341", + "w:rsidR": "005B2341", + "w:rsidRDefault": "005B2341", + "w:rsidRPr": "007856C0", + }, + "_children": Array [], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:p", + }, + Object { + "_attrs": Object { + "w14:paraId": "464E9D08", + "w14:textId": "77777777", + "w:rsidP": "005B2341", + "w:rsidR": "005B2341", + "w:rsidRDefault": "005B2341", + "w:rsidRPr": "007856C0", + }, + "_children": Array [], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:p", + }, + Object { + "_attrs": Object { + "w14:paraId": "50EB2807", + "w14:textId": "5BBC6233", + "w:rsidP": "005B2341", + "w:rsidR": "005B2341", + "w:rsidRDefault": "005B2341", + "w:rsidRPr": "007856C0", + }, + "_children": Array [ Object { "_attrs": Object { "w:rsidRPr": "007856C0", @@ -51080,6 +51852,30 @@ Object { "_parent": [Circular], "_tag": "w:r", }, + Object { + "_attrs": Object {}, + "_children": Array [ + Object { + "_attrs": Object { + "xml:space": "preserve", + }, + "_children": Array [ + Object { + "_children": Array [], + "_fTextNode": true, + "_parent": [Circular], + "_text": "", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:t", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:r", + }, Object { "_attrs": Object { "w:type": "spellStart", @@ -51091,7 +51887,6 @@ Object { }, Object { "_attrs": Object { - "w:rsidR": "00D85011", "w:rsidRPr": "007856C0", }, "_children": Array [ @@ -51179,11 +51974,11 @@ Object { }, Object { "_attrs": Object { - "w14:paraId": "60A37F38", - "w14:textId": "4190B879", - "w:rsidP": "007856C0", - "w:rsidR": "00D85011", - "w:rsidRDefault": "00D85011", + "w14:paraId": "686B7280", + "w14:textId": "77777777", + "w:rsidP": "005B2341", + "w:rsidR": "005B2341", + "w:rsidRDefault": "005B2341", "w:rsidRPr": "007856C0", }, "_children": Array [], @@ -51193,12 +51988,11 @@ Object { }, Object { "_attrs": Object { - "w14:paraId": "297A6708", - "w14:textId": "09F8E8D0", + "w14:paraId": "576C70BA", + "w14:textId": "651026D3", "w:rsidP": "007856C0", - "w:rsidR": "00D85011", - "w:rsidRDefault": "007856C0", - "w:rsidRPr": "007856C0", + "w:rsidR": "005B2341", + "w:rsidRDefault": "005B2341", }, "_children": Array [ Object { @@ -51227,6 +52021,30 @@ Object { "_parent": [Circular], "_tag": "w:r", }, + Object { + "_attrs": Object {}, + "_children": Array [ + Object { + "_attrs": Object { + "xml:space": "preserve", + }, + "_children": Array [ + Object { + "_children": Array [], + "_fTextNode": true, + "_parent": [Circular], + "_text": "", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:t", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:r", + }, Object { "_attrs": Object { "w:type": "spellStart", @@ -51238,7 +52056,6 @@ Object { }, Object { "_attrs": Object { - "w:rsidR": "00D85011", "w:rsidRPr": "007856C0", }, "_children": Array [ @@ -51326,7 +52143,7 @@ Object { }, Object { "_attrs": Object { - "w14:paraId": "762D637D", + "w14:paraId": "64757D95", "w14:textId": "77777777", "w:rsidP": "005B2341", "w:rsidR": "005B2341", @@ -51340,7 +52157,7 @@ Object { }, Object { "_attrs": Object { - "w14:paraId": "464E9D08", + "w14:paraId": "0A5FB851", "w14:textId": "77777777", "w:rsidP": "005B2341", "w:rsidR": "005B2341", @@ -51354,8 +52171,8 @@ Object { }, Object { "_attrs": Object { - "w14:paraId": "50EB2807", - "w14:textId": "5BBC6233", + "w14:paraId": "152EA038", + "w14:textId": "264863A8", "w:rsidP": "005B2341", "w:rsidR": "005B2341", "w:rsidRDefault": "005B2341", @@ -51510,7 +52327,7 @@ Object { }, Object { "_attrs": Object { - "w14:paraId": "686B7280", + "w14:paraId": "38C53EF0", "w14:textId": "77777777", "w:rsidP": "005B2341", "w:rsidR": "005B2341", @@ -51524,11 +52341,12 @@ Object { }, Object { "_attrs": Object { - "w14:paraId": "576C70BA", - "w14:textId": "651026D3", - "w:rsidP": "007856C0", + "w14:paraId": "020C58AE", + "w14:textId": "4A70A699", + "w:rsidP": "005B2341", "w:rsidR": "005B2341", "w:rsidRDefault": "005B2341", + "w:rsidRPr": "007856C0", }, "_children": Array [ Object { @@ -51679,7 +52497,7 @@ Object { }, Object { "_attrs": Object { - "w14:paraId": "64757D95", + "w14:paraId": "2EB2B65F", "w14:textId": "77777777", "w:rsidP": "005B2341", "w:rsidR": "005B2341", @@ -51693,9 +52511,9 @@ Object { }, Object { "_attrs": Object { - "w14:paraId": "0A5FB851", + "w14:paraId": "33412000", "w14:textId": "77777777", - "w:rsidP": "005B2341", + "w:rsidP": "007856C0", "w:rsidR": "005B2341", "w:rsidRDefault": "005B2341", "w:rsidRPr": "007856C0", @@ -51707,42 +52525,141 @@ Object { }, Object { "_attrs": Object { - "w14:paraId": "152EA038", - "w14:textId": "264863A8", - "w:rsidP": "005B2341", - "w:rsidR": "005B2341", - "w:rsidRDefault": "005B2341", - "w:rsidRPr": "007856C0", + "w:rsidR": "005B2341", + "w:rsidRPr": "007856C0", + "w:rsidSect": "0019199C", + }, + "_children": Array [ + Object { + "_attrs": Object { + "w:h": "16840", + "w:w": "11900", + }, + "_children": Array [], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:pgSz", + }, + Object { + "_attrs": Object { + "w:bottom": "1440", + "w:footer": "708", + "w:gutter": "0", + "w:header": "708", + "w:left": "1440", + "w:right": "1440", + "w:top": "1440", + }, + "_children": Array [], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:pgMar", + }, + Object { + "_attrs": Object { + "w:space": "708", + }, + "_children": Array [], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:cols", + }, + Object { + "_attrs": Object { + "w:linePitch": "360", + }, + "_children": Array [], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:docGrid", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:sectPr", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:body", + }, + ], + "_fTextNode": false, + "_tag": "w:document", +} +`; + +exports[`sandbox Template processing 107b non-alphanumeric INS commands (e.g. Chinese) with custom delimiter 1`] = ` +Object { + "_attrs": Object { + "mc:Ignorable": "w14 w15 w16se w16cid wp14", + "xmlns:aink": "http://schemas.microsoft.com/office/drawing/2016/ink", + "xmlns:am3d": "http://schemas.microsoft.com/office/drawing/2017/model3d", + "xmlns:cx": "http://schemas.microsoft.com/office/drawing/2014/chartex", + "xmlns:cx1": "http://schemas.microsoft.com/office/drawing/2015/9/8/chartex", + "xmlns:cx2": "http://schemas.microsoft.com/office/drawing/2015/10/21/chartex", + "xmlns:cx3": "http://schemas.microsoft.com/office/drawing/2016/5/9/chartex", + "xmlns:cx4": "http://schemas.microsoft.com/office/drawing/2016/5/10/chartex", + "xmlns:cx5": "http://schemas.microsoft.com/office/drawing/2016/5/11/chartex", + "xmlns:cx6": "http://schemas.microsoft.com/office/drawing/2016/5/12/chartex", + "xmlns:cx7": "http://schemas.microsoft.com/office/drawing/2016/5/13/chartex", + "xmlns:cx8": "http://schemas.microsoft.com/office/drawing/2016/5/14/chartex", + "xmlns:m": "http://schemas.openxmlformats.org/officeDocument/2006/math", + "xmlns:mc": "http://schemas.openxmlformats.org/markup-compatibility/2006", + "xmlns:o": "urn:schemas-microsoft-com:office:office", + "xmlns:r": "http://schemas.openxmlformats.org/officeDocument/2006/relationships", + "xmlns:v": "urn:schemas-microsoft-com:vml", + "xmlns:w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main", + "xmlns:w10": "urn:schemas-microsoft-com:office:word", + "xmlns:w14": "http://schemas.microsoft.com/office/word/2010/wordml", + "xmlns:w15": "http://schemas.microsoft.com/office/word/2012/wordml", + "xmlns:w16cid": "http://schemas.microsoft.com/office/word/2016/wordml/cid", + "xmlns:w16se": "http://schemas.microsoft.com/office/word/2015/wordml/symex", + "xmlns:wne": "http://schemas.microsoft.com/office/word/2006/wordml", + "xmlns:wp": "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing", + "xmlns:wp14": "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing", + "xmlns:wpc": "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas", + "xmlns:wpg": "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup", + "xmlns:wpi": "http://schemas.microsoft.com/office/word/2010/wordprocessingInk", + "xmlns:wps": "http://schemas.microsoft.com/office/word/2010/wordprocessingShape", + }, + "_children": Array [ + Object { + "_attrs": Object {}, + "_children": Array [ + Object { + "_attrs": Object { + "w14:paraId": "6BF6C63C", + "w14:textId": "03D60101", + "w:rsidP": "00F95E1F", + "w:rsidR": "00F35C33", + "w:rsidRDefault": "00D85011", + "w:rsidRPr": "00F95E1F", }, "_children": Array [ Object { "_attrs": Object { - "w:rsidRPr": "007856C0", + "w:id": "0", + "w:name": "_GoBack", }, - "_children": Array [ - Object { - "_attrs": Object { - "xml:space": "preserve", - }, - "_children": Array [ - Object { - "_children": Array [], - "_fTextNode": true, - "_parent": [Circular], - "_text": "hong", - }, - ], - "_fTextNode": false, - "_parent": [Circular], - "_tag": "w:t", - }, - ], + "_children": Array [], "_fTextNode": false, "_parent": [Circular], - "_tag": "w:r", + "_tag": "w:bookmarkStart", }, Object { - "_attrs": Object {}, + "_attrs": Object { + "w:id": "0", + }, + "_children": Array [], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:bookmarkEnd", + }, + Object { + "_attrs": Object { + "w:rsidRPr": "00F95E1F", + }, "_children": Array [ Object { "_attrs": Object { @@ -51753,7 +52670,7 @@ Object { "_children": Array [], "_fTextNode": true, "_parent": [Circular], - "_text": "", + "_text": "hong", }, ], "_fTextNode": false, @@ -51776,7 +52693,7 @@ Object { }, Object { "_attrs": Object { - "w:rsidRPr": "007856C0", + "w:rsidRPr": "00F95E1F", }, "_children": Array [ Object { @@ -51832,7 +52749,7 @@ Object { }, Object { "_attrs": Object { - "w:rsidRPr": "007856C0", + "w:rsidRPr": "00F95E1F", }, "_children": Array [ Object { @@ -51863,12 +52780,12 @@ Object { }, Object { "_attrs": Object { - "w14:paraId": "38C53EF0", - "w14:textId": "77777777", - "w:rsidP": "005B2341", - "w:rsidR": "005B2341", - "w:rsidRDefault": "005B2341", - "w:rsidRPr": "007856C0", + "w14:paraId": "60A37F38", + "w14:textId": "4190B879", + "w:rsidP": "00F95E1F", + "w:rsidR": "00D85011", + "w:rsidRDefault": "00D85011", + "w:rsidRPr": "00F95E1F", }, "_children": Array [], "_fTextNode": false, @@ -51877,17 +52794,17 @@ Object { }, Object { "_attrs": Object { - "w14:paraId": "020C58AE", - "w14:textId": "4A70A699", - "w:rsidP": "005B2341", - "w:rsidR": "005B2341", - "w:rsidRDefault": "005B2341", - "w:rsidRPr": "007856C0", + "w14:paraId": "297A6708", + "w14:textId": "0C0851F2", + "w:rsidP": "00F95E1F", + "w:rsidR": "00D85011", + "w:rsidRDefault": "00D85011", + "w:rsidRPr": "00F95E1F", }, "_children": Array [ Object { "_attrs": Object { - "w:rsidRPr": "007856C0", + "w:rsidRPr": "00F95E1F", }, "_children": Array [ Object { @@ -51911,30 +52828,6 @@ Object { "_parent": [Circular], "_tag": "w:r", }, - Object { - "_attrs": Object {}, - "_children": Array [ - Object { - "_attrs": Object { - "xml:space": "preserve", - }, - "_children": Array [ - Object { - "_children": Array [], - "_fTextNode": true, - "_parent": [Circular], - "_text": "", - }, - ], - "_fTextNode": false, - "_parent": [Circular], - "_tag": "w:t", - }, - ], - "_fTextNode": false, - "_parent": [Circular], - "_tag": "w:r", - }, Object { "_attrs": Object { "w:type": "spellStart", @@ -51946,7 +52839,7 @@ Object { }, Object { "_attrs": Object { - "w:rsidRPr": "007856C0", + "w:rsidRPr": "00F95E1F", }, "_children": Array [ Object { @@ -52002,7 +52895,7 @@ Object { }, Object { "_attrs": Object { - "w:rsidRPr": "007856C0", + "w:rsidRPr": "00F95E1F", }, "_children": Array [ Object { @@ -52033,26 +52926,12 @@ Object { }, Object { "_attrs": Object { - "w14:paraId": "2EB2B65F", - "w14:textId": "77777777", - "w:rsidP": "005B2341", - "w:rsidR": "005B2341", - "w:rsidRDefault": "005B2341", - "w:rsidRPr": "007856C0", - }, - "_children": Array [], - "_fTextNode": false, - "_parent": [Circular], - "_tag": "w:p", - }, - Object { - "_attrs": Object { - "w14:paraId": "33412000", - "w14:textId": "77777777", - "w:rsidP": "007856C0", - "w:rsidR": "005B2341", - "w:rsidRDefault": "005B2341", - "w:rsidRPr": "007856C0", + "w14:paraId": "6FE1B114", + "w14:textId": "315C8C84", + "w:rsidP": "00F95E1F", + "w:rsidR": "00D85011", + "w:rsidRDefault": "00D85011", + "w:rsidRPr": "00F95E1F", }, "_children": Array [], "_fTextNode": false, @@ -52061,141 +52940,42 @@ Object { }, Object { "_attrs": Object { - "w:rsidR": "005B2341", - "w:rsidRPr": "007856C0", - "w:rsidSect": "0019199C", - }, - "_children": Array [ - Object { - "_attrs": Object { - "w:h": "16840", - "w:w": "11900", - }, - "_children": Array [], - "_fTextNode": false, - "_parent": [Circular], - "_tag": "w:pgSz", - }, - Object { - "_attrs": Object { - "w:bottom": "1440", - "w:footer": "708", - "w:gutter": "0", - "w:header": "708", - "w:left": "1440", - "w:right": "1440", - "w:top": "1440", - }, - "_children": Array [], - "_fTextNode": false, - "_parent": [Circular], - "_tag": "w:pgMar", - }, - Object { - "_attrs": Object { - "w:space": "708", - }, - "_children": Array [], - "_fTextNode": false, - "_parent": [Circular], - "_tag": "w:cols", - }, - Object { - "_attrs": Object { - "w:linePitch": "360", - }, - "_children": Array [], - "_fTextNode": false, - "_parent": [Circular], - "_tag": "w:docGrid", - }, - ], - "_fTextNode": false, - "_parent": [Circular], - "_tag": "w:sectPr", - }, - ], - "_fTextNode": false, - "_parent": [Circular], - "_tag": "w:body", - }, - ], - "_fTextNode": false, - "_tag": "w:document", -} -`; - -exports[`sandbox Template processing 107b non-alphanumeric INS commands (e.g. Chinese) with custom delimiter 1`] = ` -Object { - "_attrs": Object { - "mc:Ignorable": "w14 w15 w16se w16cid wp14", - "xmlns:aink": "http://schemas.microsoft.com/office/drawing/2016/ink", - "xmlns:am3d": "http://schemas.microsoft.com/office/drawing/2017/model3d", - "xmlns:cx": "http://schemas.microsoft.com/office/drawing/2014/chartex", - "xmlns:cx1": "http://schemas.microsoft.com/office/drawing/2015/9/8/chartex", - "xmlns:cx2": "http://schemas.microsoft.com/office/drawing/2015/10/21/chartex", - "xmlns:cx3": "http://schemas.microsoft.com/office/drawing/2016/5/9/chartex", - "xmlns:cx4": "http://schemas.microsoft.com/office/drawing/2016/5/10/chartex", - "xmlns:cx5": "http://schemas.microsoft.com/office/drawing/2016/5/11/chartex", - "xmlns:cx6": "http://schemas.microsoft.com/office/drawing/2016/5/12/chartex", - "xmlns:cx7": "http://schemas.microsoft.com/office/drawing/2016/5/13/chartex", - "xmlns:cx8": "http://schemas.microsoft.com/office/drawing/2016/5/14/chartex", - "xmlns:m": "http://schemas.openxmlformats.org/officeDocument/2006/math", - "xmlns:mc": "http://schemas.openxmlformats.org/markup-compatibility/2006", - "xmlns:o": "urn:schemas-microsoft-com:office:office", - "xmlns:r": "http://schemas.openxmlformats.org/officeDocument/2006/relationships", - "xmlns:v": "urn:schemas-microsoft-com:vml", - "xmlns:w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main", - "xmlns:w10": "urn:schemas-microsoft-com:office:word", - "xmlns:w14": "http://schemas.microsoft.com/office/word/2010/wordml", - "xmlns:w15": "http://schemas.microsoft.com/office/word/2012/wordml", - "xmlns:w16cid": "http://schemas.microsoft.com/office/word/2016/wordml/cid", - "xmlns:w16se": "http://schemas.microsoft.com/office/word/2015/wordml/symex", - "xmlns:wne": "http://schemas.microsoft.com/office/word/2006/wordml", - "xmlns:wp": "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing", - "xmlns:wp14": "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing", - "xmlns:wpc": "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas", - "xmlns:wpg": "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup", - "xmlns:wpi": "http://schemas.microsoft.com/office/word/2010/wordprocessingInk", - "xmlns:wps": "http://schemas.microsoft.com/office/word/2010/wordprocessingShape", - }, - "_children": Array [ - Object { - "_attrs": Object {}, - "_children": Array [ - Object { - "_attrs": Object { - "w14:paraId": "6BF6C63C", - "w14:textId": "03D60101", + "w14:paraId": "6742E140", + "w14:textId": "43F12D8C", "w:rsidP": "00F95E1F", - "w:rsidR": "00F35C33", - "w:rsidRDefault": "00D85011", + "w:rsidR": "00F95E1F", + "w:rsidRDefault": "00F95E1F", "w:rsidRPr": "00F95E1F", }, "_children": Array [ Object { "_attrs": Object { - "w:id": "0", - "w:name": "_GoBack", - }, - "_children": Array [], - "_fTextNode": false, - "_parent": [Circular], - "_tag": "w:bookmarkStart", - }, - Object { - "_attrs": Object { - "w:id": "0", + "w:rsidRPr": "00F95E1F", }, - "_children": Array [], + "_children": Array [ + Object { + "_attrs": Object { + "xml:space": "preserve", + }, + "_children": Array [ + Object { + "_children": Array [], + "_fTextNode": true, + "_parent": [Circular], + "_text": "hong", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:t", + }, + ], "_fTextNode": false, "_parent": [Circular], - "_tag": "w:bookmarkEnd", + "_tag": "w:r", }, Object { - "_attrs": Object { - "w:rsidRPr": "00F95E1F", - }, + "_attrs": Object {}, "_children": Array [ Object { "_attrs": Object { @@ -52206,7 +52986,7 @@ Object { "_children": Array [], "_fTextNode": true, "_parent": [Circular], - "_text": "hong", + "_text": "", }, ], "_fTextNode": false, @@ -52316,11 +53096,11 @@ Object { }, Object { "_attrs": Object { - "w14:paraId": "60A37F38", - "w14:textId": "4190B879", + "w14:paraId": "0BC84266", + "w14:textId": "77777777", "w:rsidP": "00F95E1F", - "w:rsidR": "00D85011", - "w:rsidRDefault": "00D85011", + "w:rsidR": "00F95E1F", + "w:rsidRDefault": "00F95E1F", "w:rsidRPr": "00F95E1F", }, "_children": Array [], @@ -52330,12 +53110,11 @@ Object { }, Object { "_attrs": Object { - "w14:paraId": "297A6708", - "w14:textId": "0C0851F2", + "w14:paraId": "46877074", + "w14:textId": "338B35A6", "w:rsidP": "00F95E1F", - "w:rsidR": "00D85011", - "w:rsidRDefault": "00D85011", - "w:rsidRPr": "00F95E1F", + "w:rsidR": "00F95E1F", + "w:rsidRDefault": "00F95E1F", }, "_children": Array [ Object { @@ -52364,6 +53143,30 @@ Object { "_parent": [Circular], "_tag": "w:r", }, + Object { + "_attrs": Object {}, + "_children": Array [ + Object { + "_attrs": Object { + "xml:space": "preserve", + }, + "_children": Array [ + Object { + "_children": Array [], + "_fTextNode": true, + "_parent": [Circular], + "_text": "", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:t", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:r", + }, Object { "_attrs": Object { "w:type": "spellStart", @@ -52462,12 +53265,11 @@ Object { }, Object { "_attrs": Object { - "w14:paraId": "6FE1B114", - "w14:textId": "315C8C84", + "w14:paraId": "7E960016", + "w14:textId": "5B8E4394", "w:rsidP": "00F95E1F", - "w:rsidR": "00D85011", - "w:rsidRDefault": "00D85011", - "w:rsidRPr": "00F95E1F", + "w:rsidR": "00F95E1F", + "w:rsidRDefault": "00F95E1F", }, "_children": Array [], "_fTextNode": false, @@ -52476,8 +53278,8 @@ Object { }, Object { "_attrs": Object { - "w14:paraId": "6742E140", - "w14:textId": "43F12D8C", + "w14:paraId": "107BB8B5", + "w14:textId": "46BE478F", "w:rsidP": "00F95E1F", "w:rsidR": "00F95E1F", "w:rsidRDefault": "00F95E1F", @@ -52632,7 +53434,7 @@ Object { }, Object { "_attrs": Object { - "w14:paraId": "0BC84266", + "w14:paraId": "7569C168", "w14:textId": "77777777", "w:rsidP": "00F95E1F", "w:rsidR": "00F95E1F", @@ -52646,11 +53448,12 @@ Object { }, Object { "_attrs": Object { - "w14:paraId": "46877074", - "w14:textId": "338B35A6", + "w14:paraId": "752DA1D2", + "w14:textId": "511C7589", "w:rsidP": "00F95E1F", "w:rsidR": "00F95E1F", "w:rsidRDefault": "00F95E1F", + "w:rsidRPr": "00F95E1F", }, "_children": Array [ Object { @@ -52757,76 +53560,202 @@ Object { ], "_fTextNode": false, "_parent": [Circular], - "_tag": "w:r", + "_tag": "w:r", + }, + Object { + "_attrs": Object { + "w:type": "spellEnd", + }, + "_children": Array [], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:proofErr", + }, + Object { + "_attrs": Object { + "w:rsidRPr": "00F95E1F", + }, + "_children": Array [ + Object { + "_attrs": Object { + "xml:space": "preserve", + }, + "_children": Array [ + Object { + "_children": Array [], + "_fTextNode": true, + "_parent": [Circular], + "_text": "", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:t", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:r", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:p", + }, + Object { + "_attrs": Object { + "w14:paraId": "7BC35AB4", + "w14:textId": "77777777", + "w:rsidP": "00F95E1F", + "w:rsidR": "00F95E1F", + "w:rsidRDefault": "00F95E1F", + "w:rsidRPr": "00F95E1F", + }, + "_children": Array [], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:p", + }, + Object { + "_attrs": Object { + "w:rsidR": "00F95E1F", + "w:rsidRPr": "00F95E1F", + "w:rsidSect": "0019199C", + }, + "_children": Array [ + Object { + "_attrs": Object { + "w:h": "16840", + "w:w": "11900", + }, + "_children": Array [], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:pgSz", + }, + Object { + "_attrs": Object { + "w:bottom": "1440", + "w:footer": "708", + "w:gutter": "0", + "w:header": "708", + "w:left": "1440", + "w:right": "1440", + "w:top": "1440", + }, + "_children": Array [], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:pgMar", + }, + Object { + "_attrs": Object { + "w:space": "708", + }, + "_children": Array [], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:cols", + }, + Object { + "_attrs": Object { + "w:linePitch": "360", + }, + "_children": Array [], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:docGrid", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:sectPr", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:body", + }, + ], + "_fTextNode": false, + "_tag": "w:document", +} +`; + +exports[`sandbox Template processing 112a failFast: false lists all errors in the document before failing. 1`] = ` +Array [ + [Error: Error executing command: INS notavailable notavailable is not defined], + [Error: Error executing command: INS something something is not defined], + [Error: Error executing command: END-FOR company Invalid command: END-FOR company], +] +`; + +exports[`sandbox Template processing 112b failFast: true has the same behaviour as when failFast is undefined 1`] = `[Error: Error executing command: INS notavailable notavailable is not defined]`; + +exports[`sandbox Template processing 131 correctly handles Office 365 .docx files 1`] = ` +Object { + "_attrs": Object { + "mc:Ignorable": "w14 w15 wp14", + "xmlns:m": "http://schemas.openxmlformats.org/officeDocument/2006/math", + "xmlns:mc": "http://schemas.openxmlformats.org/markup-compatibility/2006", + "xmlns:o": "urn:schemas-microsoft-com:office:office", + "xmlns:r": "http://schemas.openxmlformats.org/officeDocument/2006/relationships", + "xmlns:v": "urn:schemas-microsoft-com:vml", + "xmlns:w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main", + "xmlns:w10": "urn:schemas-microsoft-com:office:word", + "xmlns:w14": "http://schemas.microsoft.com/office/word/2010/wordml", + "xmlns:w15": "http://schemas.microsoft.com/office/word/2012/wordml", + "xmlns:wne": "http://schemas.microsoft.com/office/word/2006/wordml", + "xmlns:wp": "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing", + "xmlns:wp14": "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing", + "xmlns:wpc": "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas", + "xmlns:wpg": "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup", + "xmlns:wpi": "http://schemas.microsoft.com/office/word/2010/wordprocessingInk", + "xmlns:wps": "http://schemas.microsoft.com/office/word/2010/wordprocessingShape", + }, + "_children": Array [ + Object { + "_attrs": Object {}, + "_children": Array [ + Object { + "_attrs": Object { + "w14:paraId": "3BFEFB25", + "wp14:noSpellErr": "1", + "wp14:textId": "2AD722EA", + "xmlns:wp14": "http://schemas.microsoft.com/office/word/2010/wordml", + }, + "_children": Array [ + Object { + "_attrs": Object { + "w:id": "0", + "w:name": "_GoBack", + }, + "_children": Array [], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:bookmarkStart", }, Object { "_attrs": Object { - "w:type": "spellEnd", + "w:id": "0", }, "_children": Array [], "_fTextNode": false, "_parent": [Circular], - "_tag": "w:proofErr", + "_tag": "w:bookmarkEnd", }, Object { "_attrs": Object { - "w:rsidRPr": "00F95E1F", + "w:rsidR": "4C197E99", }, "_children": Array [ Object { - "_attrs": Object { - "xml:space": "preserve", - }, - "_children": Array [ - Object { - "_children": Array [], - "_fTextNode": true, - "_parent": [Circular], - "_text": "", - }, - ], + "_attrs": Object {}, + "_children": Array [], "_fTextNode": false, "_parent": [Circular], - "_tag": "w:t", + "_tag": "w:rPr", }, - ], - "_fTextNode": false, - "_parent": [Circular], - "_tag": "w:r", - }, - ], - "_fTextNode": false, - "_parent": [Circular], - "_tag": "w:p", - }, - Object { - "_attrs": Object { - "w14:paraId": "7E960016", - "w14:textId": "5B8E4394", - "w:rsidP": "00F95E1F", - "w:rsidR": "00F95E1F", - "w:rsidRDefault": "00F95E1F", - }, - "_children": Array [], - "_fTextNode": false, - "_parent": [Circular], - "_tag": "w:p", - }, - Object { - "_attrs": Object { - "w14:paraId": "107BB8B5", - "w14:textId": "46BE478F", - "w:rsidP": "00F95E1F", - "w:rsidR": "00F95E1F", - "w:rsidRDefault": "00F95E1F", - "w:rsidRPr": "00F95E1F", - }, - "_children": Array [ - Object { - "_attrs": Object { - "w:rsidRPr": "00F95E1F", - }, - "_children": Array [ Object { "_attrs": Object { "xml:space": "preserve", @@ -52836,21 +53765,13 @@ Object { "_children": Array [], "_fTextNode": true, "_parent": [Circular], - "_text": "hong", + "_text": "first value!", }, ], "_fTextNode": false, "_parent": [Circular], "_tag": "w:t", }, - ], - "_fTextNode": false, - "_parent": [Circular], - "_tag": "w:r", - }, - Object { - "_attrs": Object {}, - "_children": Array [ Object { "_attrs": Object { "xml:space": "preserve", @@ -52874,7 +53795,7 @@ Object { }, Object { "_attrs": Object { - "w:type": "spellStart", + "w:type": "gramStart", }, "_children": Array [], "_fTextNode": false, @@ -52883,26 +53804,12 @@ Object { }, Object { "_attrs": Object { - "w:rsidRPr": "00F95E1F", + "w:rsidR": "4C197E99", }, "_children": Array [ Object { "_attrs": Object {}, - "_children": Array [ - Object { - "_attrs": Object { - "w:ascii": "MS Gothic", - "w:cs": "MS Gothic", - "w:eastAsia": "MS Gothic", - "w:hAnsi": "MS Gothic", - "w:hint": "eastAsia", - }, - "_children": Array [], - "_fTextNode": false, - "_parent": [Circular], - "_tag": "w:rFonts", - }, - ], + "_children": Array [], "_fTextNode": false, "_parent": [Circular], "_tag": "w:rPr", @@ -52930,7 +53837,7 @@ Object { }, Object { "_attrs": Object { - "w:type": "spellEnd", + "w:type": "gramEnd", }, "_children": Array [], "_fTextNode": false, @@ -52939,9 +53846,16 @@ Object { }, Object { "_attrs": Object { - "w:rsidRPr": "00F95E1F", + "w:rsidR": "4C197E99", }, "_children": Array [ + Object { + "_attrs": Object {}, + "_children": Array [], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:rPr", + }, Object { "_attrs": Object { "xml:space": "preserve", @@ -52951,7 +53865,7 @@ Object { "_children": Array [], "_fTextNode": true, "_parent": [Circular], - "_text": "", + "_text": " ", }, ], "_fTextNode": false, @@ -52970,57 +53884,105 @@ Object { }, Object { "_attrs": Object { - "w14:paraId": "7569C168", - "w14:textId": "77777777", - "w:rsidP": "00F95E1F", - "w:rsidR": "00F95E1F", - "w:rsidRDefault": "00F95E1F", - "w:rsidRPr": "00F95E1F", + "w14:paraId": "5DAB0FCA", + "w14:textId": "67F23F00", + "w:rsidP": "4C197E99", + "w:rsidR": "4C197E99", + "w:rsidRDefault": "4C197E99", }, - "_children": Array [], + "_children": Array [ + Object { + "_attrs": Object {}, + "_children": Array [ + Object { + "_attrs": Object { + "w:val": "Normal", + }, + "_children": Array [], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:pStyle", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:pPr", + }, + ], "_fTextNode": false, "_parent": [Circular], "_tag": "w:p", }, Object { "_attrs": Object { - "w14:paraId": "752DA1D2", - "w14:textId": "511C7589", - "w:rsidP": "00F95E1F", - "w:rsidR": "00F95E1F", - "w:rsidRDefault": "00F95E1F", - "w:rsidRPr": "00F95E1F", + "w14:paraId": "4DEFE58C", + "w14:textId": "03755723", + "w:rsidP": "4C197E99", + "w:rsidR": "4C197E99", + "w:rsidRDefault": "4C197E99", }, "_children": Array [ Object { - "_attrs": Object { - "w:rsidRPr": "00F95E1F", - }, + "_attrs": Object {}, "_children": Array [ Object { "_attrs": Object { - "xml:space": "preserve", + "w:val": "Normal", }, - "_children": Array [ - Object { - "_children": Array [], - "_fTextNode": true, - "_parent": [Circular], - "_text": "junyao", - }, - ], + "_children": Array [], "_fTextNode": false, "_parent": [Circular], - "_tag": "w:t", + "_tag": "w:pStyle", }, ], "_fTextNode": false, "_parent": [Circular], - "_tag": "w:r", + "_tag": "w:pPr", }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:p", + }, + Object { + "_attrs": Object { + "w14:noSpellErr": "1", + "w14:paraId": "664E8C7B", + "w14:textId": "388D7CD7", + "w:rsidP": "4C197E99", + "w:rsidR": "4C197E99", + "w:rsidRDefault": "4C197E99", + }, + "_children": Array [ Object { "_attrs": Object {}, "_children": Array [ + Object { + "_attrs": Object { + "w:val": "Normal", + }, + "_children": Array [], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:pStyle", + }, + ], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:pPr", + }, + Object { + "_attrs": Object { + "w:rsidR": "4C197E99", + }, + "_children": Array [ + Object { + "_attrs": Object {}, + "_children": Array [], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:rPr", + }, Object { "_attrs": Object { "xml:space": "preserve", @@ -53030,7 +53992,7 @@ Object { "_children": Array [], "_fTextNode": true, "_parent": [Circular], - "_text": "", + "_text": "second value!", }, ], "_fTextNode": false, @@ -53044,7 +54006,7 @@ Object { }, Object { "_attrs": Object { - "w:type": "spellStart", + "w:type": "gramStart", }, "_children": Array [], "_fTextNode": false, @@ -53053,26 +54015,12 @@ Object { }, Object { "_attrs": Object { - "w:rsidRPr": "00F95E1F", + "w:rsidR": "4C197E99", }, "_children": Array [ Object { "_attrs": Object {}, - "_children": Array [ - Object { - "_attrs": Object { - "w:ascii": "Microsoft JhengHei", - "w:cs": "Microsoft JhengHei", - "w:eastAsia": "Microsoft JhengHei", - "w:hAnsi": "Microsoft JhengHei", - "w:hint": "eastAsia", - }, - "_children": Array [], - "_fTextNode": false, - "_parent": [Circular], - "_tag": "w:rFonts", - }, - ], + "_children": Array [], "_fTextNode": false, "_parent": [Circular], "_tag": "w:rPr", @@ -53100,7 +54048,7 @@ Object { }, Object { "_attrs": Object { - "w:type": "spellEnd", + "w:type": "gramEnd", }, "_children": Array [], "_fTextNode": false, @@ -53109,9 +54057,16 @@ Object { }, Object { "_attrs": Object { - "w:rsidRPr": "00F95E1F", + "w:rsidR": "4C197E99", }, "_children": Array [ + Object { + "_attrs": Object {}, + "_children": Array [], + "_fTextNode": false, + "_parent": [Circular], + "_tag": "w:rPr", + }, Object { "_attrs": Object { "xml:space": "preserve", @@ -53139,30 +54094,13 @@ Object { "_tag": "w:p", }, Object { - "_attrs": Object { - "w14:paraId": "7BC35AB4", - "w14:textId": "77777777", - "w:rsidP": "00F95E1F", - "w:rsidR": "00F95E1F", - "w:rsidRDefault": "00F95E1F", - "w:rsidRPr": "00F95E1F", - }, - "_children": Array [], - "_fTextNode": false, - "_parent": [Circular], - "_tag": "w:p", - }, - Object { - "_attrs": Object { - "w:rsidR": "00F95E1F", - "w:rsidRPr": "00F95E1F", - "w:rsidSect": "0019199C", - }, + "_attrs": Object {}, "_children": Array [ Object { "_attrs": Object { - "w:h": "16840", - "w:w": "11900", + "w:h": "16838", + "w:orient": "portrait", + "w:w": "11906", }, "_children": Array [], "_fTextNode": false, @@ -53172,9 +54110,9 @@ Object { Object { "_attrs": Object { "w:bottom": "1440", - "w:footer": "708", + "w:footer": "720", "w:gutter": "0", - "w:header": "708", + "w:header": "720", "w:left": "1440", "w:right": "1440", "w:top": "1440", @@ -53186,7 +54124,7 @@ Object { }, Object { "_attrs": Object { - "w:space": "708", + "w:space": "720", }, "_children": Array [], "_fTextNode": false, @@ -53218,16 +54156,6 @@ Object { } `; -exports[`sandbox Template processing 112a failFast: false lists all errors in the document before failing. 1`] = ` -Array [ - [Error: Error executing command: INS notavailable notavailable is not defined], - [Error: Error executing command: INS something something is not defined], - [Error: Error executing command: END-FOR company Invalid command: END-FOR company], -] -`; - -exports[`sandbox Template processing 112b failFast: true has the same behaviour as when failFast is undefined 1`] = `[Error: Error executing command: INS notavailable notavailable is not defined]`; - exports[`sandbox Template processing avoids confusion between variable name and built-in command 1`] = ` Object { "_attrs": Object { diff --git a/src/__tests__/indexNode.test.ts b/src/__tests__/indexNode.test.ts index 30ca1afe..6b33dbb0 100755 --- a/src/__tests__/indexNode.test.ts +++ b/src/__tests__/indexNode.test.ts @@ -1035,6 +1035,7 @@ Morbi dignissim consequat ex, non finibus est faucibus sodales. Integer sed just test2: 'second value!', }, failFast: true, + cmdDelimiter: ['{', '}'], }, 'JS' ); diff --git a/src/__tests__/unit.test.ts b/src/__tests__/unit.test.ts new file mode 100644 index 00000000..73e3e64c --- /dev/null +++ b/src/__tests__/unit.test.ts @@ -0,0 +1,25 @@ +import path from 'path'; +import { zipLoad } from '../zip'; +import { readContentTypes, getMainDoc } from '../main'; +import fs from 'fs'; + +describe('[Content_Types].xml parser', () => { + it('Correctly finds the main document xml file in a regular .docx file', async () => { + const template = await fs.promises.readFile( + path.join(__dirname, 'fixtures', 'simpleQuery.docx') + ); + const zip = await zipLoad(template); + const content_types = await readContentTypes(zip); + const main_doc = getMainDoc(content_types); + expect(main_doc).toStrictEqual('document.xml'); + }); + it('Correctly finds the main document xml file in an Office365 .docx file', async () => { + const template = await fs.promises.readFile( + path.join(__dirname, 'fixtures', 'office365.docx') + ); + const zip = await zipLoad(template); + const content_types = await readContentTypes(zip); + const main_doc = getMainDoc(content_types); + expect(main_doc).toStrictEqual('document2.xml'); + }); +}); diff --git a/src/main.ts b/src/main.ts index fca03c50..245cd21e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -17,6 +17,7 @@ import { Images, Links, Node, + NonTextNode, } from './types'; import { addChild, newNonTextNode } from './reportUtils'; import log from './debug'; @@ -101,9 +102,9 @@ async function createReport( // --------------------------------------------------------- DEBUG && log.debug('finding main template file (e.g. document.xml)'); // See issue #131. Office365 files may name the main template file document2.xml or something else - // TODO: so we'll have to parse the content-types 'manifest' file first and retrieve the template file's name first. + // So we'll have to parse the content-types 'manifest' file first and retrieve the template file's name first. const contentTypes = await readContentTypes(zip); - const mainDocument = 'document.xml'; // TODO: for now + const mainDocument = getMainDoc(contentTypes); DEBUG && log.debug('Reading template...'); const templateXml = await zipGetText(zip, `${templatePath}/${mainDocument}`); @@ -291,11 +292,31 @@ async function createReport( return output; } -async function readContentTypes(zip: JSZip): Promise { +export async function readContentTypes(zip: JSZip): Promise { const contentTypesXml = await zipGetText(zip, CONTENT_TYPES_PATH); if (contentTypesXml == null) throw new Error(`${CONTENT_TYPES_PATH} could not be read`); - return await parseXml(contentTypesXml); + const node = await parseXml(contentTypesXml); + if (node._fTextNode) + throw new Error(`${CONTENT_TYPES_PATH} is a text node when parsed`); + return node; +} + +export function getMainDoc(contentTypes: NonTextNode): string { + const MAIN_DOC_MIME = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml' as const; + for (const t of contentTypes._children) { + if (!t._fTextNode) { + if (t._attrs.ContentType === MAIN_DOC_MIME) { + const path = t._attrs.PartName; + if (path) { + return path.replace('/word/', ''); + } + } + } + } + throw new Error( + `Could not find main document (e.g. document.xml) in ${CONTENT_TYPES_PATH}` + ); } // ========================================== diff --git a/src/types.ts b/src/types.ts index 4d3dace5..cb90b40b 100755 --- a/src/types.ts +++ b/src/types.ts @@ -21,6 +21,8 @@ export type NonTextNode = BaseNode & { // Simplified; only need this property _attrs: { [key: string]: QualifiedAttribute | string } & { Extension?: string; + ContentType?: string; + PartName?: string; }; };