sphinx-docx 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. sphinx_docx-1.0.0/CHANGELOG.rst +11 -0
  2. sphinx_docx-1.0.0/LICENSE +11 -0
  3. sphinx_docx-1.0.0/MANIFEST.in +16 -0
  4. sphinx_docx-1.0.0/PKG-INFO +290 -0
  5. sphinx_docx-1.0.0/README.rst +247 -0
  6. sphinx_docx-1.0.0/create_style_file.py +26 -0
  7. sphinx_docx-1.0.0/pyproject.toml +62 -0
  8. sphinx_docx-1.0.0/setup.cfg +4 -0
  9. sphinx_docx-1.0.0/setup.py +39 -0
  10. sphinx_docx-1.0.0/sphinx_docx/__init__.py +59 -0
  11. sphinx_docx-1.0.0/sphinx_docx/builder.py +180 -0
  12. sphinx_docx-1.0.0/sphinx_docx/docx/LICENSE.python-docx +22 -0
  13. sphinx_docx-1.0.0/sphinx_docx/docx/__init__.py +1 -0
  14. sphinx_docx-1.0.0/sphinx_docx/docx/docx.py +2910 -0
  15. sphinx_docx-1.0.0/sphinx_docx/docx/style.docx +0 -0
  16. sphinx_docx-1.0.0/sphinx_docx/highlight.py +255 -0
  17. sphinx_docx-1.0.0/sphinx_docx/writer.py +3708 -0
  18. sphinx_docx-1.0.0/sphinx_docx.egg-info/PKG-INFO +290 -0
  19. sphinx_docx-1.0.0/sphinx_docx.egg-info/SOURCES.txt +47 -0
  20. sphinx_docx-1.0.0/sphinx_docx.egg-info/dependency_links.txt +1 -0
  21. sphinx_docx-1.0.0/sphinx_docx.egg-info/requires.txt +14 -0
  22. sphinx_docx-1.0.0/sphinx_docx.egg-info/top_level.txt +1 -0
  23. sphinx_docx-1.0.0/style_file/docx/[Content_Types].xml +2 -0
  24. sphinx_docx-1.0.0/style_file/docx/_rels/.rels +2 -0
  25. sphinx_docx-1.0.0/style_file/docx/customXml/_rels/item1.xml.rels +2 -0
  26. sphinx_docx-1.0.0/style_file/docx/customXml/item1.xml +2 -0
  27. sphinx_docx-1.0.0/style_file/docx/customXml/itemProps1.xml +2 -0
  28. sphinx_docx-1.0.0/style_file/docx/docProps/app.xml +2 -0
  29. sphinx_docx-1.0.0/style_file/docx/docProps/core.xml +2 -0
  30. sphinx_docx-1.0.0/style_file/docx/docProps/custom.xml +2 -0
  31. sphinx_docx-1.0.0/style_file/docx/word/_rels/document.xml.rels +2 -0
  32. sphinx_docx-1.0.0/style_file/docx/word/document.xml +2 -0
  33. sphinx_docx-1.0.0/style_file/docx/word/endnotes.xml +23 -0
  34. sphinx_docx-1.0.0/style_file/docx/word/fontTable.xml +89 -0
  35. sphinx_docx-1.0.0/style_file/docx/word/footnotes.xml +2 -0
  36. sphinx_docx-1.0.0/style_file/docx/word/glossary/_rels/document.xml.rels +2 -0
  37. sphinx_docx-1.0.0/style_file/docx/word/glossary/document.xml +2 -0
  38. sphinx_docx-1.0.0/style_file/docx/word/glossary/fontTable.xml +89 -0
  39. sphinx_docx-1.0.0/style_file/docx/word/glossary/settings.xml +53 -0
  40. sphinx_docx-1.0.0/style_file/docx/word/glossary/styles.xml +502 -0
  41. sphinx_docx-1.0.0/style_file/docx/word/glossary/stylesWithEffects.xml +189 -0
  42. sphinx_docx-1.0.0/style_file/docx/word/glossary/webSettings.xml +4 -0
  43. sphinx_docx-1.0.0/style_file/docx/word/media/image1.png +0 -0
  44. sphinx_docx-1.0.0/style_file/docx/word/numbering.xml +2 -0
  45. sphinx_docx-1.0.0/style_file/docx/word/settings.xml +119 -0
  46. sphinx_docx-1.0.0/style_file/docx/word/styles.xml +1048 -0
  47. sphinx_docx-1.0.0/style_file/docx/word/stylesWithEffects.xml +999 -0
  48. sphinx_docx-1.0.0/style_file/docx/word/theme/theme1.xml +316 -0
  49. sphinx_docx-1.0.0/style_file/docx/word/webSettings.xml +4 -0
@@ -0,0 +1,11 @@
1
+ Release 1.0.0 (2026-09-11)
2
+ --------------------------
3
+
4
+ First release under the name ``sphinx-docx``. Moved everything over from
5
+ sphinx_docxbuilder-jm, which is now deprecated. The import name changed from
6
+ ``docxbuilder`` to ``sphinx_docx``; every ``docx_*`` configuration value and
7
+ the ``docx`` builder name are unchanged, so only the ``extensions`` entry in
8
+ **conf.py** has to be updated.
9
+
10
+ The history before this point is the fork's, and of the ``docxbuilder``
11
+ project it descends from.
@@ -0,0 +1,11 @@
1
+ Copyright (c) 2009-2010 Mike MacCana
2
+ Copyright (c) 2010 Takayuki SHIMIZUKAWA
3
+ Copyright (c) 2011 Isao Hara
4
+ Copyright (c) 2019 amedama41
5
+ Copyright (c) 2022-2026 Nefti-sama
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8
+
9
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,16 @@
1
+ include LICENSE
2
+ include CHANGELOG.rst
3
+ include sphinx_docx/docx/LICENSE.python-docx
4
+
5
+ # style.docx is generated at build time from these by create_style_file.py,
6
+ # so both have to travel in the sdist for it to be buildable.
7
+ include create_style_file.py
8
+ recursive-include style_file/docx *
9
+
10
+ exclude .gitattributes
11
+ exclude .pylintrc
12
+ exclude .readthedocs.yml
13
+ prune .github
14
+ prune .spec
15
+ prune docs
16
+ prune style_file/source
@@ -0,0 +1,290 @@
1
+ Metadata-Version: 2.4
2
+ Name: sphinx-docx
3
+ Version: 1.0.0
4
+ Summary: Sphinx extension that builds Word (.docx) documents
5
+ Author: Nefti-sama
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/Nefti-sama/sphinx-docx
8
+ Project-URL: Repository, https://github.com/Nefti-sama/sphinx-docx
9
+ Project-URL: Issues, https://github.com/Nefti-sama/sphinx-docx/issues
10
+ Project-URL: Changelog, https://github.com/Nefti-sama/sphinx-docx/blob/main/CHANGELOG.rst
11
+ Keywords: sphinx,sphinx-extension,docx,word,openxml,ooxml
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Environment :: Console
14
+ Classifier: Framework :: Sphinx
15
+ Classifier: Framework :: Sphinx :: Extension
16
+ Classifier: Intended Audience :: Developers
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3 :: Only
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Programming Language :: Python :: 3.14
23
+ Classifier: Topic :: Documentation :: Sphinx
24
+ Classifier: Topic :: Text Processing :: Markup
25
+ Classifier: Topic :: Software Development :: Documentation
26
+ Requires-Python: >=3.12
27
+ Description-Content-Type: text/x-rst
28
+ License-File: LICENSE
29
+ License-File: sphinx_docx/docx/LICENSE.python-docx
30
+ Requires-Dist: Sphinx>=9.0
31
+ Requires-Dist: docutils>=0.22
32
+ Requires-Dist: Pygments>=2.12
33
+ Requires-Dist: lxml>=4.4
34
+ Requires-Dist: Pillow>=6.1
35
+ Requires-Dist: cairosvg>=2.5
36
+ Requires-Dist: six>=1.16
37
+ Provides-Extra: math
38
+ Requires-Dist: latex2mathml; extra == "math"
39
+ Requires-Dist: mathml2omml; extra == "math"
40
+ Provides-Extra: docs
41
+ Requires-Dist: sphinx-rtd-theme>=0.4.3; extra == "docs"
42
+ Dynamic: license-file
43
+
44
+ ###########
45
+ sphinx-docx
46
+ ###########
47
+
48
+ sphinx-docx is a Sphinx extension to build docx formatted documents. The
49
+ distribution is ``sphinx-docx``; the module you import and name in
50
+ ``extensions`` is ``sphinx_docx``.
51
+
52
+ .. note::
53
+
54
+ This extension butchered the `original docxbuilder <https://github.com/amedama41/docxbuilder>`_ to add some functionality.
55
+
56
+ Added:
57
+
58
+ * SVG images: the vector is embedded for Word 2016+, with a png fallback
59
+ * Multiple cover pages (`<https://github.com/amedama41/docxbuilder/pull/12>`_)
60
+ * Directives the original ignored: ``autosummary``, ``inheritance-diagram``,
61
+ ``productionlist``, ``acks``, and PEP 695 type parameters in signatures
62
+ * Per-admonition styles, so ``.. note::`` and ``.. warning::`` can look different
63
+ * Sphinx 9 / docutils 0.22 compatibility (``findall``, ``FileOutput``)
64
+ * Common color names for the highlight of ``:emphasize-lines:``
65
+
66
+
67
+ ************
68
+ Requirements
69
+ ************
70
+
71
+ :Python: 3.12 or later (developed and tested on 3.14)
72
+ :Sphinx: 9.x or later
73
+
74
+ *******
75
+ Install
76
+ *******
77
+
78
+ ::
79
+
80
+ pip install sphinx-docx
81
+
82
+ For ``.. math::`` and the math role, which are rendered as OMML::
83
+
84
+ pip install "sphinx-docx[math]"
85
+
86
+ Then add it to **conf.py**::
87
+
88
+ extensions = [
89
+ "sphinx_docx",
90
+ ]
91
+
92
+ and build with::
93
+
94
+ sphinx-build -b docx source build/docx
95
+
96
+ The development version::
97
+
98
+ pip install "sphinx-docx @ git+https://github.com/Nefti-sama/sphinx-docx.git"
99
+
100
+ ***********
101
+ Development
102
+ ***********
103
+
104
+ The default style file ``sphinx_docx/docx/style.docx`` is generated, not
105
+ committed: ``create_style_file.py`` zips ``style_file/docx/`` into it, and
106
+ ``.gitignore`` excludes the result. ``setup.py`` hooks that into ``build_py``,
107
+ which both a wheel build and a PEP 660 editable install run, so
108
+ ``pip install -e .`` produces it.
109
+
110
+ Working straight from a clone without installing, regenerate it by hand after
111
+ ``git clean -xdf`` or ``make clean``::
112
+
113
+ python create_style_file.py
114
+
115
+ Without it, any build which does not set ``docx_style`` in **conf.py** aborts
116
+ with::
117
+
118
+ FileNotFoundError: [Errno 2] No such file or directory: '.../sphinx_docx/docx/style.docx'
119
+
120
+ Edit the default style under ``style_file/docx/``, not ``style.docx`` itself;
121
+ the latter is overwritten on the next regeneration. ``make update_style_file``
122
+ does the full round trip, rebuilding ``style_file/docx/`` from the Sphinx
123
+ project in ``style_file/`` first; note that it calls
124
+ ``./create_style_file.py``, which needs the executable bit and a ``python``
125
+ on PATH.
126
+
127
+ *****
128
+ Usage
129
+ *****
130
+
131
+ Add 'sphinx_docx' to ``extensions`` configuration of **conf.py**:
132
+
133
+ .. code:: python
134
+
135
+ extensions = ['sphinx_docx']
136
+
137
+ and build your documents::
138
+
139
+ make docx
140
+
141
+ You can control the generated document by adding configurations into ``conf.py``:
142
+
143
+ .. code:: python
144
+
145
+ docx_documents = [
146
+ ('index', 'sphinx_docx.docx', {
147
+ 'title': project,
148
+ 'creator': author,
149
+ 'subject': 'A manual of sphinx_docx',
150
+ }, True),
151
+ ]
152
+ docx_style = 'path/to/custom_style.docx'
153
+ docx_pagebreak_before_section = 1
154
+
155
+ For more details, see `the (original) documentation <https://docxbuilder.readthedocs.io/en/latest/>`_.
156
+
157
+ SVG images
158
+ ==========
159
+
160
+ Use ``.. image::`` or ``.. figure::`` with an ``.svg`` file, as with any other
161
+ image::
162
+
163
+ .. image:: diagram.svg
164
+ :width: 12cm
165
+
166
+ Each SVG is embedded twice: the vector original, which Word 2016 and later
167
+ draw sharp at any zoom, and a png rendered with cairosvg for older clients.
168
+
169
+ Sizing follows the SVG's own ``width`` and ``height`` in any absolute unit
170
+ (``px``, ``pt``, ``pc``, ``in``, ``cm``, ``mm``), falling back to the
171
+ ``viewBox`` when they are missing or relative. ``:width:`` and ``:height:``
172
+ override that as usual.
173
+
174
+ ``cairosvg`` is installed as a dependency. Without it the build still
175
+ succeeds; every SVG is skipped with a warning instead of aborting.
176
+
177
+ Images an SVG pulls in with an ``href`` (another svg, a bitmap) are inlined as
178
+ data URIs, so they survive the move into the docx. References made through CSS
179
+ ``url()`` are not, and draw empty (#TODO).
180
+
181
+ CSS custom properties are substituted before either renderer sees the file,
182
+ because neither cairosvg nor Word implements them. ``var(--bg, #ffffff)``
183
+ becomes ``#ffffff``; a ``var()`` with no fallback takes the value declared for
184
+ it elsewhere in the file, and one with neither becomes ``none``. Drawio
185
+ emit these constantly -- a recent draw.io SVG is full of them -- and
186
+ without the substitution cairosvg fails the whole image with ``invalid literal
187
+ for int() with base 16``.
188
+
189
+ Directives
190
+ ==========
191
+
192
+ Beyond what the original builder handles:
193
+
194
+ .. list-table::
195
+ :header-rows: 1
196
+
197
+ * - Directive
198
+ - Rendered as
199
+ * - ``.. autosummary::``
200
+ - the summary table, and with ``:toctree:`` the generated stub pages
201
+ * - ``.. inheritance-diagram::``
202
+ - a graphviz image, through the same path as ``.. graphviz::``
203
+ * - ``.. productionlist::``
204
+ - a borderless two-column table, styled ``Production List``
205
+ * - ``.. acks::``
206
+ - the contained bullet list
207
+ * - ``.. py:class:: Widget[T]``
208
+ - PEP 695 type parameters, in square brackets
209
+
210
+ Admonitions take one table style per type, not a shared one: ``.. note::``
211
+ uses ``Admonition Note``, ``.. warning::`` uses ``Admonition Warning``, and a
212
+ ``.. admonition:: My Title`` uses ``Admonition My Title``. Define the style in
213
+ your style file to change how that one type looks. Types you do not define get
214
+ a style created from ``Based Admonition``, so nothing breaks if it is missing.
215
+
216
+ Code highlighting
217
+ =================
218
+
219
+ ``:emphasize-lines:`` highlights a line with the ``highlight_color`` of the
220
+ Pygments style, which is normally a hex string. A common color name is
221
+ accepted too:
222
+
223
+ .. code:: python
224
+
225
+ # in conf.py, or a style module on sys.path
226
+ from pygments.styles.default import DefaultStyle
227
+
228
+ class MyStyle(DefaultStyle):
229
+ highlight_color = 'lightgreen'
230
+
231
+ pygments_style = 'mystyle.MyStyle'
232
+
233
+ Word does not take a color here: its ``w:highlight`` accepts only the fifteen
234
+ names of the OOXML ``ST_HighlightColor`` list, and a file using any other name
235
+ is invalid. So the requested color is snapped to the nearest name Word does
236
+ have, matching hue before brightness. ``lightgreen`` and ``lime`` highlight
237
+ green, ``orange`` and ``gold`` yellow, ``navy`` dark blue.
238
+
239
+
240
+ Style file
241
+ ==========
242
+
243
+ Generated docx file's design is customized by a style file
244
+ (The default style is ``sphinx_docx/docx/style.docx``).
245
+ The style file is a docx file, which defines some paragraph,
246
+ character, and table styles.
247
+
248
+ The below lists shows typical styles.
249
+
250
+ Character styles:
251
+
252
+ * Emphasis
253
+ * Strong
254
+ * Literal
255
+ * Hyperlink
256
+ * Footnote Reference
257
+
258
+ Paragraph styles:
259
+
260
+ * Body Text
261
+ * Footnote Text
262
+ * Definition Term
263
+ * Literal Block
264
+ * Image Caption, Table Caution, Literal Caption
265
+ * Heading 1, Heading 2, ..., Heading *N*
266
+ * TOC Heading
267
+ * toc 1, toc 2, ..., toc *N*
268
+ * List Bullet
269
+ * List Number
270
+
271
+ Table styles:
272
+
273
+ * Table
274
+ * Field List
275
+ * Production List
276
+ * Admonition, Admonition Note, Admonition Warning, ...
277
+
278
+ ****
279
+ TODO
280
+ ****
281
+
282
+ - Support URL path for images.
283
+ - Follow CSS ``url()`` references inside SVG images.
284
+
285
+ *******
286
+ Licence
287
+ *******
288
+
289
+ MIT Licence
290
+
@@ -0,0 +1,247 @@
1
+ ###########
2
+ sphinx-docx
3
+ ###########
4
+
5
+ sphinx-docx is a Sphinx extension to build docx formatted documents. The
6
+ distribution is ``sphinx-docx``; the module you import and name in
7
+ ``extensions`` is ``sphinx_docx``.
8
+
9
+ .. note::
10
+
11
+ This extension butchered the `original docxbuilder <https://github.com/amedama41/docxbuilder>`_ to add some functionality.
12
+
13
+ Added:
14
+
15
+ * SVG images: the vector is embedded for Word 2016+, with a png fallback
16
+ * Multiple cover pages (`<https://github.com/amedama41/docxbuilder/pull/12>`_)
17
+ * Directives the original ignored: ``autosummary``, ``inheritance-diagram``,
18
+ ``productionlist``, ``acks``, and PEP 695 type parameters in signatures
19
+ * Per-admonition styles, so ``.. note::`` and ``.. warning::`` can look different
20
+ * Sphinx 9 / docutils 0.22 compatibility (``findall``, ``FileOutput``)
21
+ * Common color names for the highlight of ``:emphasize-lines:``
22
+
23
+
24
+ ************
25
+ Requirements
26
+ ************
27
+
28
+ :Python: 3.12 or later (developed and tested on 3.14)
29
+ :Sphinx: 9.x or later
30
+
31
+ *******
32
+ Install
33
+ *******
34
+
35
+ ::
36
+
37
+ pip install sphinx-docx
38
+
39
+ For ``.. math::`` and the math role, which are rendered as OMML::
40
+
41
+ pip install "sphinx-docx[math]"
42
+
43
+ Then add it to **conf.py**::
44
+
45
+ extensions = [
46
+ "sphinx_docx",
47
+ ]
48
+
49
+ and build with::
50
+
51
+ sphinx-build -b docx source build/docx
52
+
53
+ The development version::
54
+
55
+ pip install "sphinx-docx @ git+https://github.com/Nefti-sama/sphinx-docx.git"
56
+
57
+ ***********
58
+ Development
59
+ ***********
60
+
61
+ The default style file ``sphinx_docx/docx/style.docx`` is generated, not
62
+ committed: ``create_style_file.py`` zips ``style_file/docx/`` into it, and
63
+ ``.gitignore`` excludes the result. ``setup.py`` hooks that into ``build_py``,
64
+ which both a wheel build and a PEP 660 editable install run, so
65
+ ``pip install -e .`` produces it.
66
+
67
+ Working straight from a clone without installing, regenerate it by hand after
68
+ ``git clean -xdf`` or ``make clean``::
69
+
70
+ python create_style_file.py
71
+
72
+ Without it, any build which does not set ``docx_style`` in **conf.py** aborts
73
+ with::
74
+
75
+ FileNotFoundError: [Errno 2] No such file or directory: '.../sphinx_docx/docx/style.docx'
76
+
77
+ Edit the default style under ``style_file/docx/``, not ``style.docx`` itself;
78
+ the latter is overwritten on the next regeneration. ``make update_style_file``
79
+ does the full round trip, rebuilding ``style_file/docx/`` from the Sphinx
80
+ project in ``style_file/`` first; note that it calls
81
+ ``./create_style_file.py``, which needs the executable bit and a ``python``
82
+ on PATH.
83
+
84
+ *****
85
+ Usage
86
+ *****
87
+
88
+ Add 'sphinx_docx' to ``extensions`` configuration of **conf.py**:
89
+
90
+ .. code:: python
91
+
92
+ extensions = ['sphinx_docx']
93
+
94
+ and build your documents::
95
+
96
+ make docx
97
+
98
+ You can control the generated document by adding configurations into ``conf.py``:
99
+
100
+ .. code:: python
101
+
102
+ docx_documents = [
103
+ ('index', 'sphinx_docx.docx', {
104
+ 'title': project,
105
+ 'creator': author,
106
+ 'subject': 'A manual of sphinx_docx',
107
+ }, True),
108
+ ]
109
+ docx_style = 'path/to/custom_style.docx'
110
+ docx_pagebreak_before_section = 1
111
+
112
+ For more details, see `the (original) documentation <https://docxbuilder.readthedocs.io/en/latest/>`_.
113
+
114
+ SVG images
115
+ ==========
116
+
117
+ Use ``.. image::`` or ``.. figure::`` with an ``.svg`` file, as with any other
118
+ image::
119
+
120
+ .. image:: diagram.svg
121
+ :width: 12cm
122
+
123
+ Each SVG is embedded twice: the vector original, which Word 2016 and later
124
+ draw sharp at any zoom, and a png rendered with cairosvg for older clients.
125
+
126
+ Sizing follows the SVG's own ``width`` and ``height`` in any absolute unit
127
+ (``px``, ``pt``, ``pc``, ``in``, ``cm``, ``mm``), falling back to the
128
+ ``viewBox`` when they are missing or relative. ``:width:`` and ``:height:``
129
+ override that as usual.
130
+
131
+ ``cairosvg`` is installed as a dependency. Without it the build still
132
+ succeeds; every SVG is skipped with a warning instead of aborting.
133
+
134
+ Images an SVG pulls in with an ``href`` (another svg, a bitmap) are inlined as
135
+ data URIs, so they survive the move into the docx. References made through CSS
136
+ ``url()`` are not, and draw empty (#TODO).
137
+
138
+ CSS custom properties are substituted before either renderer sees the file,
139
+ because neither cairosvg nor Word implements them. ``var(--bg, #ffffff)``
140
+ becomes ``#ffffff``; a ``var()`` with no fallback takes the value declared for
141
+ it elsewhere in the file, and one with neither becomes ``none``. Drawio
142
+ emit these constantly -- a recent draw.io SVG is full of them -- and
143
+ without the substitution cairosvg fails the whole image with ``invalid literal
144
+ for int() with base 16``.
145
+
146
+ Directives
147
+ ==========
148
+
149
+ Beyond what the original builder handles:
150
+
151
+ .. list-table::
152
+ :header-rows: 1
153
+
154
+ * - Directive
155
+ - Rendered as
156
+ * - ``.. autosummary::``
157
+ - the summary table, and with ``:toctree:`` the generated stub pages
158
+ * - ``.. inheritance-diagram::``
159
+ - a graphviz image, through the same path as ``.. graphviz::``
160
+ * - ``.. productionlist::``
161
+ - a borderless two-column table, styled ``Production List``
162
+ * - ``.. acks::``
163
+ - the contained bullet list
164
+ * - ``.. py:class:: Widget[T]``
165
+ - PEP 695 type parameters, in square brackets
166
+
167
+ Admonitions take one table style per type, not a shared one: ``.. note::``
168
+ uses ``Admonition Note``, ``.. warning::`` uses ``Admonition Warning``, and a
169
+ ``.. admonition:: My Title`` uses ``Admonition My Title``. Define the style in
170
+ your style file to change how that one type looks. Types you do not define get
171
+ a style created from ``Based Admonition``, so nothing breaks if it is missing.
172
+
173
+ Code highlighting
174
+ =================
175
+
176
+ ``:emphasize-lines:`` highlights a line with the ``highlight_color`` of the
177
+ Pygments style, which is normally a hex string. A common color name is
178
+ accepted too:
179
+
180
+ .. code:: python
181
+
182
+ # in conf.py, or a style module on sys.path
183
+ from pygments.styles.default import DefaultStyle
184
+
185
+ class MyStyle(DefaultStyle):
186
+ highlight_color = 'lightgreen'
187
+
188
+ pygments_style = 'mystyle.MyStyle'
189
+
190
+ Word does not take a color here: its ``w:highlight`` accepts only the fifteen
191
+ names of the OOXML ``ST_HighlightColor`` list, and a file using any other name
192
+ is invalid. So the requested color is snapped to the nearest name Word does
193
+ have, matching hue before brightness. ``lightgreen`` and ``lime`` highlight
194
+ green, ``orange`` and ``gold`` yellow, ``navy`` dark blue.
195
+
196
+
197
+ Style file
198
+ ==========
199
+
200
+ Generated docx file's design is customized by a style file
201
+ (The default style is ``sphinx_docx/docx/style.docx``).
202
+ The style file is a docx file, which defines some paragraph,
203
+ character, and table styles.
204
+
205
+ The below lists shows typical styles.
206
+
207
+ Character styles:
208
+
209
+ * Emphasis
210
+ * Strong
211
+ * Literal
212
+ * Hyperlink
213
+ * Footnote Reference
214
+
215
+ Paragraph styles:
216
+
217
+ * Body Text
218
+ * Footnote Text
219
+ * Definition Term
220
+ * Literal Block
221
+ * Image Caption, Table Caution, Literal Caption
222
+ * Heading 1, Heading 2, ..., Heading *N*
223
+ * TOC Heading
224
+ * toc 1, toc 2, ..., toc *N*
225
+ * List Bullet
226
+ * List Number
227
+
228
+ Table styles:
229
+
230
+ * Table
231
+ * Field List
232
+ * Production List
233
+ * Admonition, Admonition Note, Admonition Warning, ...
234
+
235
+ ****
236
+ TODO
237
+ ****
238
+
239
+ - Support URL path for images.
240
+ - Follow CSS ``url()`` references inside SVG images.
241
+
242
+ *******
243
+ Licence
244
+ *******
245
+
246
+ MIT Licence
247
+
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/python
2
+ # -*- coding: utf-8 -*-
3
+ from __future__ import print_function
4
+ import os
5
+ import zipfile
6
+
7
+ def create_style_file():
8
+ base_dir = os.path.dirname(os.path.abspath(__file__))
9
+ style_file_path = os.path.normpath(
10
+ os.path.join(base_dir, 'sphinx_docx/docx/style.docx'))
11
+ print('creating %s' % style_file_path)
12
+ style_file = zipfile.ZipFile(
13
+ style_file_path, mode='w', compression=zipfile.ZIP_DEFLATED)
14
+ def addfile(dirpath, rootpath):
15
+ for filename in os.listdir(dirpath):
16
+ path = os.path.join(dirpath, filename)
17
+ if os.path.isdir(path):
18
+ addfile(path, rootpath + filename + '/')
19
+ else:
20
+ style_file.write(path, rootpath + filename)
21
+ addfile(os.path.join(base_dir, 'style_file/docx'), '')
22
+ style_file.close()
23
+
24
+ if __name__ == '__main__':
25
+ create_style_file()
26
+
@@ -0,0 +1,62 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "sphinx-docx"
7
+ version = "1.0.0"
8
+ description = "Sphinx extension that builds Word (.docx) documents"
9
+ readme = { file = "README.rst", content-type = "text/x-rst" }
10
+ requires-python = ">=3.12"
11
+ license = "MIT"
12
+ license-files = ["LICENSE", "sphinx_docx/docx/LICENSE.python-docx"]
13
+ authors = [{ name = "Nefti-sama" }]
14
+ keywords = ["sphinx", "sphinx-extension", "docx", "word", "openxml", "ooxml"]
15
+
16
+ # cairosvg and Pillow are imported lazily, only when a document contains an
17
+ # SVG or a raster image, but SVG support is a headline feature of this fork so
18
+ # they are hard requirements rather than an extra.
19
+ dependencies = [
20
+ "Sphinx>=9.0",
21
+ "docutils>=0.22",
22
+ "Pygments>=2.12",
23
+ "lxml>=4.4",
24
+ "Pillow>=6.1",
25
+ "cairosvg>=2.5",
26
+ "six>=1.16",
27
+ ]
28
+
29
+ classifiers = [
30
+ "Development Status :: 4 - Beta",
31
+ "Environment :: Console",
32
+ "Framework :: Sphinx",
33
+ "Framework :: Sphinx :: Extension",
34
+ "Intended Audience :: Developers",
35
+ "Operating System :: OS Independent",
36
+ "Programming Language :: Python :: 3",
37
+ "Programming Language :: Python :: 3 :: Only",
38
+ "Programming Language :: Python :: 3.12",
39
+ "Programming Language :: Python :: 3.13",
40
+ "Programming Language :: Python :: 3.14",
41
+ "Topic :: Documentation :: Sphinx",
42
+ "Topic :: Text Processing :: Markup",
43
+ "Topic :: Software Development :: Documentation",
44
+ ]
45
+
46
+ [project.optional-dependencies]
47
+ # `.. math::` and the math role are rendered as OMML through these.
48
+ math = ["latex2mathml", "mathml2omml"]
49
+ docs = ["sphinx-rtd-theme>=0.4.3"]
50
+
51
+ [project.urls]
52
+ Homepage = "https://github.com/Nefti-sama/sphinx-docx"
53
+ Repository = "https://github.com/Nefti-sama/sphinx-docx"
54
+ Issues = "https://github.com/Nefti-sama/sphinx-docx/issues"
55
+ Changelog = "https://github.com/Nefti-sama/sphinx-docx/blob/main/CHANGELOG.rst"
56
+
57
+ [tool.setuptools]
58
+ packages = ["sphinx_docx", "sphinx_docx.docx"]
59
+
60
+ [tool.setuptools.package-data]
61
+ # Generated from style_file/docx/ by create_style_file.py at build time.
62
+ "sphinx_docx.docx" = ["style.docx"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+