From 1267a4f5305ceb5f70e56e2b26f5daf21b560558 Mon Sep 17 00:00:00 2001 From: Cobus Theunissen Date: Thu, 26 Aug 2021 10:34:21 -0700 Subject: [PATCH 1/2] add xml support for file attachments --- src/fileAttachment.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/fileAttachment.js b/src/fileAttachment.js index 5ae62c4e..9fc25c48 100644 --- a/src/fileAttachment.js +++ b/src/fileAttachment.js @@ -64,6 +64,9 @@ class AbstractFile { const [JSZip, buffer] = await Promise.all([requireDefault(jszip.resolve()), this.arrayBuffer()]); return new ZipArchive(await JSZip.loadAsync(buffer)); } + async xml() { + return (new DOMParser).parseFromString(await (await remote_fetch(this)).text(), "application/xml"); + } } class FileAttachment extends AbstractFile { From 16a11f45165a04d6da932fb03787ecdcc7d9eecf Mon Sep 17 00:00:00 2001 From: CobusT Date: Thu, 26 Aug 2021 11:18:04 -0700 Subject: [PATCH 2/2] Update src/fileAttachment.js Co-authored-by: Mike Bostock --- src/fileAttachment.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/fileAttachment.js b/src/fileAttachment.js index 9fc25c48..ac2c4d44 100644 --- a/src/fileAttachment.js +++ b/src/fileAttachment.js @@ -64,8 +64,11 @@ class AbstractFile { const [JSZip, buffer] = await Promise.all([requireDefault(jszip.resolve()), this.arrayBuffer()]); return new ZipArchive(await JSZip.loadAsync(buffer)); } - async xml() { - return (new DOMParser).parseFromString(await (await remote_fetch(this)).text(), "application/xml"); + async xml(mimeType = "application/xml") { + return (new DOMParser).parseFromString(await this.text(), mimeType); + } + async html() { + return this.xml("text/html"); } }