dolanmiu / docx

Easily generate and modify .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.
https://docx.js.org/
MIT License
4.06k stars 463 forks source link

fix: Ensure necessary namespaces are in patched doc #2698

Open joshkel opened 3 days ago

joshkel commented 3 days ago

Word for the web, for example, may generate .docx files with a very limited set of XML namespaces:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">

Using one of these files as the template / source for a docx.js patch may result in errors from missing namespaces.

To fix this, I added the handful of namespaces that appear to be needed by docx.js's elements. It may be better to include the full set of namespaces from the Document class. If you'd prefer I do that, please let me know.

I did some refactoring to simplify this and to cut down on duplicate namespace references. If you'd prefer I handle this differently, please let me know.

Fixes #2697