lalalic / docx4js

a javascript docx parser
363 stars 66 forks source link

An issue with handling blip without embed #70

Open savinskiy-konstantin opened 1 year ago

savinskiy-konstantin commented 1 year ago

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Part of pptx slide structure:

<p:blipFill>
    <a:blip>
        <a:extLst>
            <a:ext uri="{79A0055B-C67C-407E-A111-50E730381C1C}">
                <a14:useLocalDpi
                    xmlns:a14="http://schemas.microsoft.com/office/drawing/2010/main"
                    val="0"/>
            </a:ext>
        </a:extLst>
    </a:blip>
    <a:srcRect/>
    <a:stretch>
        <a:fillRect/>
    </a:stretch>
</p:blipFill>

Today I used patch-package to patch docx4js@3.2.20 for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/docx4js/lib/openxml/drawml/index.js b/node_modules/docx4js/lib/openxml/drawml/index.js
index 5096ddd..53f7dc9 100644
--- a/node_modules/docx4js/lib/openxml/drawml/index.js
+++ b/node_modules/docx4js/lib/openxml/drawml/index.js
@@ -64,6 +64,7 @@ exports.default = function (od) {
                 url = _n$attribs["r:link"];

             if (url) return { url: url };
+            if (!embed) return;
             var part = od.$(n).part();
             return new _part2.default(part, od.doc).getRel(embed);
         },
diff --git a/node_modules/docx4js/src/openxml/drawml/index.js b/node_modules/docx4js/src/openxml/drawml/index.js
index 23f665e..5c15bd6 100644
--- a/node_modules/docx4js/src/openxml/drawml/index.js
+++ b/node_modules/docx4js/src/openxml/drawml/index.js
@@ -17,6 +17,8 @@ export default od=>({
         const {attribs:{"r:embed":embed, "r:link":url}}=n
         if(url)
             return {url}
+        if(!embed)
+            return;
         const part=od.$(n).part()
         return new Part(part,od.doc).getRel(embed)
     },

This issue body was partially generated by patch-package.

lalalic commented 2 months ago

merged