amedama41 / docxbuilder Goto Github PK
View Code? Open in Web Editor NEWSphinx docx builder extension
Home Page: https://pypi.org/project/docxbuilder/
License: MIT License
Sphinx docx builder extension
Home Page: https://pypi.org/project/docxbuilder/
License: MIT License
If you specify a style file that has a Body Text
style with a non-zero left indentation (say 0,63 cm), the output docx file will have all paragraphs with zero left indentation (namely with style Body Text + Left 0 cm
). A minimal rst
will such as the following will do the trick:
================
This is a header
================
This is a bit of body text.
This is because the paragraph visitor makes new paragraphs with Contenxt
objects that have explicitly zero indentation.
If I set the indent to None
in the Paragraph
constructor I do get the correct style, but that seems a bit like a hack and I'm not sure what else that will break.
I copied style.docx
to my source directory and I only changed the document title, subject and author in LibreOffice Writer 6.3.2. I saved the file and ran a make docx
with a docx_style = 'style.docx'
in my conf.py
. This results in an exception:
# Sphinx version: 1.8.4
# Python version: 3.6.8 (CPython)
# Docutils version: 0.14
# Jinja2 version: 2.10
# Last messages:
# processing test.docx...
#
#
#
# resolving references...
#
#
#
# writing...
#
# Loaded extensions:
# sphinx.ext.mathjax (1.8.4) from /usr/local/lib/python3.6/site-packages/sphinx/ext/mathjax.py
# alabaster (0.7.12) from /usr/local/lib/python3.6/site-packages/alabaster/__init__.py
# sphinx.ext.todo (1.8.4) from /usr/local/lib/python3.6/site-packages/sphinx/ext/todo.py
# docxbuilder (unknown version) from /usr/local/lib/python3.6/site-packages/docxbuilder/__init__.py
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/sphinx/cmd/build.py", line 304, in build_main
app.build(args.force_all, filenames)
File "/usr/local/lib/python3.6/site-packages/sphinx/application.py", line 341, in build
self.builder.build_update()
File "/usr/local/lib/python3.6/site-packages/sphinx/builders/__init__.py", line 342, in build_update
self.build(['__all__'], to_build)
File "/usr/local/lib/python3.6/site-packages/sphinx/builders/__init__.py", line 412, in build
self.write(docnames, list(updated_docnames), method)
File "/usr/local/lib/python3.6/site-packages/docxbuilder/builder.py", line 115, in write
self.write_doc(docname, doctree)
File "/usr/local/lib/python3.6/site-packages/docxbuilder/builder.py", line 122, in write_doc
self.writer.write(doctree, destination)
File "/usr/local/lib/python3.6/site-packages/docutils/writers/__init__.py", line 80, in write
self.translate()
File "/usr/local/lib/python3.6/site-packages/docxbuilder/writer.py", line 163, in translate
visitor = self.builder.create_translator(self.document, self.builder)
File "/usr/local/lib/python3.6/site-packages/sphinx/builders/__init__.py", line 139, in create_translator
return self.app.registry.create_translator(self, *args)
File "/usr/local/lib/python3.6/site-packages/sphinx/registry.py", line 386, in create_translator
translator = translator_class(*args)
File "/usr/local/lib/python3.6/site-packages/docxbuilder/writer.py", line 832, in __init__
self._bullet_list_id = self._docx.get_bullet_list_num_id('List Bullet')
File "/usr/local/lib/python3.6/site-packages/docxbuilder/docx/docx.py", line 1458, in get_bullet_list_num_id
return self.style_docx.get_numbering_style_id(style_name)
File "/usr/local/lib/python3.6/site-packages/docxbuilder/docx/docx.py", line 1236, in get_numbering_style_id
style_elem, 'w:pPr/w:numPr/w:numId')[0]
IndexError: list index out of range
Any idea what is going on? The document title, subject and author are really the only things I have changed in the style file. When I replace the file by the original one, it works, but I'd like to modify the text fields on the cover page.
Is this project still alive?
When I try to build docx documentation with matplotlib, the images are not included in the document. Complete example:
# docs/conf.py
project = '…'
extensions = [
'matplotlib.sphinxext.plot_directive',
"docxbuilder",
]
Simple matplotlib plot
----------------------
.. plot::
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6])
plt.title("A plotting exammple")
produces a warning:
writing... /home/oles/sphinxword/docs/index.rst:: WARNING: Failed to get filepath
The plot files are both in the build directory, and in the plot_directive
subdirectory of the build directory. The HTML build works fine here.
All the images have a standard paragraph
style.
Do you reproduce the same problem ? Any idea what could be the cause ?
Thanks
Hi all.
I have a custom directive defined as an extension (in a similar way as TODO example on sphinx page.
Problem is that this extension is used for html output via visit_my_node/depart_my_node methods, but I would have liked to implement a similar thing for docx builder.
I saw in the documentation that I should probably use a translator, but I can't really figure out how.
How should I proceed?
If I have the following code in RST ...
.. note::
test
test
... The result is in DOCX:
In HTML:
It is better to implement it in the extension. However there is a workaround but I need more information: which style is used in DOCX for note (I see a table with invisible borders, but I cannot figure out which style I should customize for it)?
Hello and thank you for this great project.
At the moment it seems that docxbuilder does not handle images. Is there any workaround ?
Hello,
The language rendered in the docx paragraphs is english.
Is it possible to set another language in the rendered document ?
The csv-table
directive always produce a table with left-aligned cells, regardless of the :align:
option being set to center
or right
. I would expect the resulting table to respect the alignement option attached with the csv-table
directive, and default to left if none is provided.
In generated docx document there is not any entry in the toc table (except the toc header). I try to update TOC in the Ms Word and got the error 'No table of contents entries found.' with popup (see image)
This say - I have not any title with heading style. But it is incorrect. My document has many headers in their body.
It seems some toc generations error on macos.
If I delete this TOC and generate new one inside MSWord, toc generated correctly.
Hi,
An example table :
======= ==============================================================
01 **This Markup** does not translate to bold in my docx
======= ==============================================================
I did not find a workaround with table styles. In general I find docx table styles to be very confusing but that's an issue for microsoft. Some options like centered cells don't seem to do anything...
I did not try defining a character style for Bold and applying it my section like so:
:bold:`This Markup`
This could be a workaround if it works.
Thank you very much for this great project.
Current implmentation uses structured data type (sdt) object with "Cover Pages" docPartGallery as cover page.
However, there are the following problem for this.
Then, adding a new option to use first page or section as cover page.
In addition to the table of contents (i.e. the toctree
) is is possible to generate a "List of Figures" and "List of Tables" following the Table of Contents?
Hello,
i have noticed that the table caption is displayed at the top of the table. Is it possible to have it located at the bottom of the table?
I tried to modify the position of the caption in the style file without any effect in the generated document.
Thank you
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.