mherkazandjian / docxsphinx Goto Github PK
View Code? Open in Web Editor NEWGenerate word documents from sphinx documentation
Generate word documents from sphinx documentation
This project looks great, but it's not working on recent Sphinx versions.
Here's what I get on Sphinx >v5:
# sphinx-build -M docx -l en --
<...>
writing...
Exception occurred:
File "$PWD/.venv/3.8-64/lib/python3.8/site-packages/docutils/nodes.py", line 575, in __getitem__
return self.children[key]
IndexError: list index out of range
I got the full tracelog, clean of secret data here:
# Sphinx version: 5.2.3
# Python version: 3.8.16 (CPython)
# Docutils version: 0.15 release
# Jinja2 version: 3.1.2
# Last messages:
# <...>
#
# writing...
# Loaded extensions:
# sphinx.ext.mathjax (5.2.3) from $PWD/.venv/3.8-64/lib/python3.8/site-packages/sphinx/ext/mathjax.py
# sphinxcontrib.applehelp (1.0.2) from $PWD/.venv/3.8-64/lib/python3.8/site-packages/sphinxcontrib/applehelp/__init__.py
# sphinxcontrib.devhelp (1.0.2) from $PWD/.venv/3.8-64/lib/python3.8/site-packages/sphinxcontrib/devhelp/__init__.py
# sphinxcontrib.htmlhelp (2.0.0) from $PWD/.venv/3.8-64/lib/python3.8/site-packages/sphinxcontrib/htmlhelp/__init__.py
# sphinxcontrib.serializinghtml (1.1.5) from $PWD/.venv/3.8-64/lib/python3.8/site-packages/sphinxcontrib/serializinghtml/__init__.py
# sphinxcontrib.qthelp (1.0.3) from $PWD/.venv/3.8-64/lib/python3.8/site-packages/sphinxcontrib/qthelp/__init__.py
# alabaster (0.7.12) from $PWD/.venv/3.8-64/lib/python3.8/site-packages/alabaster/__init__.py
# sphinx.ext.intersphinx (5.2.3) from $PWD/.venv/3.8-64/lib/python3.8/site-packages/sphinx/ext/intersphinx.py
# sphinx.ext.graphviz (5.2.3) from $PWD/.venv/3.8-64/lib/python3.8/site-packages/sphinx/ext/graphviz.py
# sphinx.ext.autodoc.preserve_defaults (1.0) from $PWD/.venv/3.8-64/lib/python3.8/site-packages/sphinx/ext/autodoc/preserve_defaults.py
# sphinx.ext.autodoc.type_comment (5.2.3) from $PWD/.venv/3.8-64/lib/python3.8/site-packages/sphinx/ext/autodoc/type_comment.py
# sphinx.ext.autodoc (5.2.3) from $PWD/.venv/3.8-64/lib/python3.8/site-packages/sphinx/ext/autodoc/__init__.py
# sphinx.ext.napoleon (5.2.3) from $PWD/.venv/3.8-64/lib/python3.8/site-packages/sphinx/ext/napoleon/__init__.py
# sphinx.ext.autosummary (5.2.3) from $PWD/.venv/3.8-64/lib/python3.8/site-packages/sphinx/ext/autosummary/__init__.py
# sphinx_automodapi.autodoc_enhancements (unknown version) from $PWD/.venv/3.8-64/lib/python3.8/site-packages/sphinx_automodapi/autodoc_enhancements.py
# sphinx.ext.inheritance_diagram (5.2.3) from $PWD/.venv/3.8-64/lib/python3.8/site-packages/sphinx/ext/inheritance_diagram.py
# sphinx_automodapi.automodsumm (unknown version) from $PWD/.venv/3.8-64/lib/python3.8/site-packages/sphinx_automodapi/automodsumm.py
# sphinx_automodapi.automodapi (unknown version) from $PWD/.venv/3.8-64/lib/python3.8/site-packages/sphinx_automodapi/automodapi.py
# sphinx_automodapi.smart_resolver (unknown version) from $PWD/.venv/3.8-64/lib/python3.8/site-packages/sphinx_automodapi/smart_resolver.py
# sphinx.ext.todo (5.2.3) from $PWD/.venv/3.8-64/lib/python3.8/site-packages/sphinx/ext/todo.py
# sphinx.ext.extlinks (5.2.3) from $PWD/.venv/3.8-64/lib/python3.8/site-packages/sphinx/ext/extlinks.py
# docxsphinx (unknown version) from $PWD/.venv/3.8-64/lib/python3.8/site-packages/docxsphinx/__init__.py
Traceback (most recent call last):
File "$PWD/.venv/3.8-64/lib/python3.8/site-packages/sphinx/cmd/build.py", line 279, in build_main
app.build(args.force_all, filenames)
File "$PWD/.venv/3.8-64/lib/python3.8/site-packages/sphinx/application.py", line 350, in build
self.builder.build_update()
File "$PWD/.venv/3.8-64/lib/python3.8/site-packages/sphinx/builders/__init__.py", line 299, in build_update
self.build(['__all__'], to_build)
File "$PWD/.venv/3.8-64/lib/python3.8/site-packages/sphinx/builders/__init__.py", line 368, in build
self.write(docnames, list(updated_docnames), method)
File "$PWD/.venv/3.8-64/lib/python3.8/site-packages/docxsphinx/builder.py", line 85, in write
self.write_doc(docname, doctree)
File "$PWD/.venv/3.8-64/lib/python3.8/site-packages/docxsphinx/builder.py", line 90, in write_doc
self.writer.write(doctree, destination)
File "$PWD/.venv/3.8-64/lib/python3.8/site-packages/docutils/writers/__init__.py", line 78, in write
self.translate()
File "$PWD/.venv/3.8-64/lib/python3.8/site-packages/docxsphinx/writer.py", line 98, in translate
self.document.walkabout(visitor)
File "$PWD/.venv/3.8-64/lib/python3.8/site-packages/docutils/nodes.py", line 180, in walkabout
if child.walkabout(visitor):
File "$PWD/.venv/3.8-64/lib/python3.8/site-packages/docutils/nodes.py", line 172, in walkabout
visitor.dispatch_visit(self)
File "$PWD/.venv/3.8-64/lib/python3.8/site-packages/docutils/nodes.py", line 1900, in dispatch_visit
return method(node)
File "$PWD/.venv/3.8-64/lib/python3.8/site-packages/docxsphinx/writer.py", line 1106, in visit_comment
comment = node[0]
File "$PWD/.venv/3.8-64/lib/python3.8/site-packages/docutils/nodes.py", line 575, in __getitem__
return self.children[key]
IndexError: list index out of range
Hopefully this helps.
Sphinx output:
Exception occurred:
File "/usr/local/lib/python3.8/dist-packages/docx/api.py", line 28, in Document
raise ValueError(tmpl % (docx, document_part.content_type))
ValueError: file 'source/internal-long-style.dotx' is not a Word file,
content type is 'application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xml'
What is the correct content type? My dotx file is a direct export from MS Word. Are there any limitations to versions of MS Word? Or to cloud/desktop variants of MS Office?
Error log:
# Sphinx version: 3.5.1
# Python version: 3.8.5 (CPython)
# Docutils version: 0.15 release
# Jinja2 version: 2.11.3
# Last messages:
# reading sources... [ 66%] 01 Decision Record
# reading sources... [100%] index
#
# looking for now-outdated files...
# none found
# pickling environment...
# done
# checking consistency...
# done
# preparing documents...
# Loaded extensions:
# sphinx.ext.mathjax (3.5.1) from /usr/local/lib/python3.8/dist-packages/sphinx/ext/mathjax.py
# sphinxcontrib.applehelp (1.0.2) from /usr/local/lib/python3.8/dist-packages/sphinxcontrib/applehelp/>
# sphinxcontrib.devhelp (1.0.2) from /usr/local/lib/python3.8/dist-packages/sphinxcontrib/devhelp/__in>
# sphinxcontrib.htmlhelp (1.0.3) from /usr/local/lib/python3.8/dist-packages/sphinxcontrib/htmlhelp/__>
# sphinxcontrib.serializinghtml (1.1.4) from /usr/local/lib/python3.8/dist-packages/sphinxcontrib/seri>
# sphinxcontrib.qthelp (1.0.3) from /usr/local/lib/python3.8/dist-packages/sphinxcontrib/qthelp/__init>
# alabaster (0.7.12) from /usr/local/lib/python3.8/dist-packages/alabaster/__init__.py
# sphinx.ext.todo (3.5.1) from /usr/local/lib/python3.8/dist-packages/sphinx/ext/todo.py
# docxsphinx (unknown version) from /usr/local/lib/python3.8/dist-packages/docxsphinx/__init__.py
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/sphinx/cmd/build.py", line 280, in build_main
app.build(args.force_all, filenames)
File "/usr/local/lib/python3.8/dist-packages/sphinx/application.py", line 352, in build
self.builder.build_update()
File "/usr/local/lib/python3.8/dist-packages/sphinx/builders/__init__.py", line 293, in build_update
self.build(['__all__'], to_build)
File "/usr/local/lib/python3.8/dist-packages/sphinx/builders/__init__.py", line 360, in build
self.write(docnames, list(updated_docnames), method)
File "/usr/local/lib/python3.8/dist-packages/docxsphinx/builder.py", line 77, in write
self.prepare_writing(docnames)
File "/usr/local/lib/python3.8/dist-packages/docxsphinx/builder.py", line 62, in prepare_writing
self.writer = DocxWriter(self)
File "/usr/local/lib/python3.8/dist-packages/docxsphinx/writer.py", line 83, in __init__
dc = Document(os.path.join('source', self.template_dir))
File "/usr/local/lib/python3.8/dist-packages/docx/api.py", line 28, in Document
raise ValueError(tmpl % (docx, document_part.content_type))
ValueError: file 'source/internal-long-style.dotx' is not a Word file,
content type is 'application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xml'
See #8
There seems to be an issue when sphinx==1.8.5
is used.
try
pip install -r requirements.txt
where requirements.txt has the following content:
pytest==6.1.2
docutils==0.15
sphinx==1.8.5
python-docx>=0.8.6
nose==1.3.7
the same behavior is observed for higher versions of sphinx, e.g 3.3.0.
I think this is related to unicode related text in the .rst
files. #24 seems to be related.
another issue is with logger. There is a depracation warning that has been added in sphinx==1.8.5 for that.
With reference to a .docx document generated with the execution of the command make html docx the image caption is not displayed under the image but it is displayed after the last text available before the image call.
For example, in the code reported below, the caption Image caption is reported after General Test. resulting in General Test.Image caption.
The same issue has been detected, during the generation of the .docx document, with the image reported in the example: https://github.com/mherkazandjian/docxsphinx/blob/master/examples/sample_1/source/index.rst
Also the numbered reference :numref:`` is not working despite the usage of numfig=True in the conf.py file
Could you please help me to solve this issue?
Kind regards
Code:
`General Test.
.. _First-figure:
.. figure:: _static/Life_cycle_of_the_product.png
Image caption
An example is shown in :ref:First-figure
.
plain reference :ref:First-figure
named reference :ref:XXXXX <First-figure>
numbered reference :numref:First-figure
`
In conf.py
one can specify a path for the templates. E.g.
# 'docx_template' need *.docx or *.dotx template file name. default is None.
docx_template = 'template.docx'
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
However, the templates_path
is ignored.
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/sphinx/cmd/build.py", line 280, in build_main
app.build(args.force_all, filenames)
File "/usr/local/lib/python3.7/dist-packages/sphinx/application.py", line 352, in build
self.builder.build_update()
File "/usr/local/lib/python3.7/dist-packages/sphinx/builders/init.py", line 294, in build_update
self.build(['all'], to_build)
File "/usr/local/lib/python3.7/dist-packages/sphinx/builders/init.py", line 361, in build
self.write(docnames, list(updated_docnames), method)
File "/usr/local/lib/python3.7/dist-packages/docxsphinx/builder.py", line 85, in write
self.write_doc(docname, doctree)
File "/usr/local/lib/python3.7/dist-packages/docxsphinx/builder.py", line 90, in write_doc
self.writer.write(doctree, destination)
File "/usr/local/lib/python3.7/dist-packages/docutils/writers/init.py", line 78, in write
self.translate()
File "/usr/local/lib/python3.7/dist-packages/docxsphinx/writer.py", line 98, in translate
self.document.walkabout(visitor)
File "/usr/local/lib/python3.7/dist-packages/docutils/nodes.py", line 214, in walkabout
if child.walkabout(visitor):
File "/usr/local/lib/python3.7/dist-packages/docutils/nodes.py", line 214, in walkabout
if child.walkabout(visitor):
File "/usr/local/lib/python3.7/dist-packages/docutils/nodes.py", line 214, in walkabout
if child.walkabout(visitor):
[Previous line repeated 2 more times]
File "/usr/local/lib/python3.7/dist-packages/docutils/nodes.py", line 206, in walkabout
visitor.dispatch_visit(self)
File "/usr/local/lib/python3.7/dist-packages/docutils/nodes.py", line 1995, in dispatch_visit
return method(node)
File "/usr/local/lib/python3.7/dist-packages/docxsphinx/writer.py", line 1106, in visit_comment
comment = node[0]
File "/usr/local/lib/python3.7/dist-packages/docutils/nodes.py", line 627, in getitem
return self.children[key]
IndexError: list index out of range
based on debian 10.8
Our current default template is not empty but has Japanese text in it. So all demo's look ugly.
The code currently doesn't work in Python 2 anymore, and will therefore not work on LODEEN
dumping table data was disabled in 278600a
E.g. http://docutils.sourceforge.net/docs/user/rst/quickref.html#hyperlink-targets
This seems to use visit_target
and visit_reference
.
Or see intro.rst of Sphinx documentation
Hello!
It would be very useful to have options in the conf.py to define a set of separate documents that would be generated from different "master" docs, similar to the built-in latex builder.
For example: Let's have this Sphinx project:
I want document A and document B in separate output files and use different stylesheets.
I could define that in the conf.py as follows:
docx_documents = [
('documentA', 'Document01.docx', dotx_stylesheetA, toctree_only),
('documentB', 'Document02.docx', dotx_stylesheetB, toctree_only),
...
]
Then make docx
would build Document01.docx
from the file documentA.rst
using docx_stylesheetA
and Document02.docx
from the file documentB.rst
using docx_stylesheetB
.
Perhaps code from the latex builder could be reused.
Thanks a lot for looking into this!
+-------------------+----------------------------+------------+------------+
| **Prepared by:** | | Date: | Signature: |
+-------------------+----------------------------+------------+------------+
| J\. Smith | foo | 01/11/2020 | |
+-------------------+----------------------------+------------+------------+
| **Contributors:** | | Date: | Signature: |
+-------------------+----------------------------+------------+------------+
| C\. Prime | XXX | | |
| | | | |
| J\. Foo | YYY | | |
+-------------------+----------------------------+------------+------------+
| **Authorised:** | | Date: | Signature: |
+-------------------+----------------------------+------------+------------+
in the above example the \.
part is problematic with docutils 0.16
when parsing the .rst to a dom and then to a etree via lxml
@hugobuddel . Thanks for your efforts with this tool.
I was trying to get two things working. Based on the *.rst file (middle below), I am able to output html and pdf with sections numbered as well as embedded images, however neither work when outputting to a docx. Is this possible, do you know? Perhaps I'm just missing some added configuration?
Thanks.
The heading size for sections included via toctrees is rendered incorrectly in Word. Consider this example:
index.rst
:
*************
Chapter title
*************
.. toctree::
section
section.rst
:
Section title
=============
.. toctree::
subsection
subsection.rst
:
Subsection title
----------------
Some text goes here.
In the resulting Word file, all headings are of the same size (namely Heading 1
). This is incorrect -- they should have descending header sizes.
When compiling the above example to singlehtml
, the resulting HTML file does have the correct descending header sizes (namely <h1>
, <h2>
, and <h3>
).
In contrast, when putting all the content in a single .rst
file:
*************
Chapter title
*************
Section title
=============
Subsection title
----------------
Some text goes here.
the resulting Word file does have the correct header sizes.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.