python-openxml / python-docx

Create and modify Word documents with Python
MIT License
4.59k stars 1.13k forks source link

[QUESTION] How to replace URL with custom content #862

Closed utcdj closed 4 years ago

utcdj commented 4 years ago

The company that I work for has a docx file that describes the specification for messages of a proprietary messaging protocol. This is a large document containing a large number of messages as well as other technical information.

Recently, I developed a DSL to describe these messages. With this DSL, I can automatically generate the parser/builder code as well as the message spec in a format similar to those in the existing document (with headings and tables). I used python-docx to generate these specs.

Because there are a large number of existing messages, I'd like to be able to incrementally translate the existing messages (and add new messages) to the DSL over time. That way it's not a large porting effort that introduces a lot of down time.

The scheme I came up with was to place a URL for the DSL message sources within the document (something like: myproto://specfile.ext). Then write a tool that looks for these special URLs and compile specfile.ext and replace the URL with the generated documentation.

I imagine, this is possible with python-docx, but I haven't been able to figure out how. Could you provide some hints on how to do this please?

scanny commented 4 years ago

Maybe check out this project: https://docxtpl.readthedocs.io/en/latest/