sphinxcontrib-docx 0.1.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.
- sphinxcontrib_docx-0.1.0/LICENSE +11 -0
- sphinxcontrib_docx-0.1.0/MANIFEST.in +4 -0
- sphinxcontrib_docx-0.1.0/PKG-INFO +137 -0
- sphinxcontrib_docx-0.1.0/README.md +89 -0
- sphinxcontrib_docx-0.1.0/create_style_file.py +26 -0
- sphinxcontrib_docx-0.1.0/pyproject.toml +3 -0
- sphinxcontrib_docx-0.1.0/setup.cfg +4 -0
- sphinxcontrib_docx-0.1.0/setup.py +68 -0
- sphinxcontrib_docx-0.1.0/sphinxcontrib/docx/__init__.py +43 -0
- sphinxcontrib_docx-0.1.0/sphinxcontrib/docx/builder.py +147 -0
- sphinxcontrib_docx-0.1.0/sphinxcontrib/docx/docx/LICENSE.python-docx +22 -0
- sphinxcontrib_docx-0.1.0/sphinxcontrib/docx/docx/__init__.py +1 -0
- sphinxcontrib_docx-0.1.0/sphinxcontrib/docx/docx/docx.py +2199 -0
- sphinxcontrib_docx-0.1.0/sphinxcontrib/docx/highlight.py +151 -0
- sphinxcontrib_docx-0.1.0/sphinxcontrib/docx/quickstart.py +83 -0
- sphinxcontrib_docx-0.1.0/sphinxcontrib/docx/writer.py +2664 -0
- sphinxcontrib_docx-0.1.0/sphinxcontrib_docx.egg-info/PKG-INFO +137 -0
- sphinxcontrib_docx-0.1.0/sphinxcontrib_docx.egg-info/SOURCES.txt +58 -0
- sphinxcontrib_docx-0.1.0/sphinxcontrib_docx.egg-info/dependency_links.txt +1 -0
- sphinxcontrib_docx-0.1.0/sphinxcontrib_docx.egg-info/entry_points.txt +2 -0
- sphinxcontrib_docx-0.1.0/sphinxcontrib_docx.egg-info/requires.txt +7 -0
- sphinxcontrib_docx-0.1.0/sphinxcontrib_docx.egg-info/top_level.txt +1 -0
- sphinxcontrib_docx-0.1.0/style_file/docx/[Content_Types].xml +35 -0
- sphinxcontrib_docx-0.1.0/style_file/docx/_rels/.rels +7 -0
- sphinxcontrib_docx-0.1.0/style_file/docx/customXml/_rels/item1.xml.rels +4 -0
- sphinxcontrib_docx-0.1.0/style_file/docx/customXml/item1.xml +2 -0
- sphinxcontrib_docx-0.1.0/style_file/docx/customXml/itemProps1.xml +6 -0
- sphinxcontrib_docx-0.1.0/style_file/docx/docProps/app.xml +8 -0
- sphinxcontrib_docx-0.1.0/style_file/docx/docProps/core.xml +9 -0
- sphinxcontrib_docx-0.1.0/style_file/docx/docProps/custom.xml +6 -0
- sphinxcontrib_docx-0.1.0/style_file/docx/word/_rels/document.xml.rels +15 -0
- sphinxcontrib_docx-0.1.0/style_file/docx/word/document.xml +2007 -0
- sphinxcontrib_docx-0.1.0/style_file/docx/word/endnotes.xml +23 -0
- sphinxcontrib_docx-0.1.0/style_file/docx/word/fontTable.xml +89 -0
- sphinxcontrib_docx-0.1.0/style_file/docx/word/footnotes.xml +54 -0
- sphinxcontrib_docx-0.1.0/style_file/docx/word/glossary/_rels/document.xml.rels +8 -0
- sphinxcontrib_docx-0.1.0/style_file/docx/word/glossary/document.xml +2 -0
- sphinxcontrib_docx-0.1.0/style_file/docx/word/glossary/fontTable.xml +89 -0
- sphinxcontrib_docx-0.1.0/style_file/docx/word/glossary/settings.xml +53 -0
- sphinxcontrib_docx-0.1.0/style_file/docx/word/glossary/styles.xml +502 -0
- sphinxcontrib_docx-0.1.0/style_file/docx/word/glossary/stylesWithEffects.xml +189 -0
- sphinxcontrib_docx-0.1.0/style_file/docx/word/glossary/webSettings.xml +4 -0
- sphinxcontrib_docx-0.1.0/style_file/docx/word/media/image1.png +0 -0
- sphinxcontrib_docx-0.1.0/style_file/docx/word/numbering.xml +181 -0
- sphinxcontrib_docx-0.1.0/style_file/docx/word/settings.xml +119 -0
- sphinxcontrib_docx-0.1.0/style_file/docx/word/styles.xml +1048 -0
- sphinxcontrib_docx-0.1.0/style_file/docx/word/stylesWithEffects.xml +999 -0
- sphinxcontrib_docx-0.1.0/style_file/docx/word/theme/theme1.xml +316 -0
- sphinxcontrib_docx-0.1.0/style_file/docx/word/webSettings.xml +4 -0
- sphinxcontrib_docx-0.1.0/tests/test_build.py +61 -0
- sphinxcontrib_docx-0.1.0/tests/test_builder.py +41 -0
- sphinxcontrib_docx-0.1.0/tests/test_docx.py +241 -0
- sphinxcontrib_docx-0.1.0/tests/test_images.py +23 -0
- sphinxcontrib_docx-0.1.0/tests/test_language.py +139 -0
- sphinxcontrib_docx-0.1.0/tests/test_layout.py +168 -0
- sphinxcontrib_docx-0.1.0/tests/test_output_options.py +127 -0
- sphinxcontrib_docx-0.1.0/tests/test_packaging.py +56 -0
- sphinxcontrib_docx-0.1.0/tests/test_quickstart.py +62 -0
- sphinxcontrib_docx-0.1.0/tests/test_toc.py +203 -0
- sphinxcontrib_docx-0.1.0/tests/test_writer.py +24 -0
|
@@ -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) 2026 Jiandong Qiu
|
|
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,137 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sphinxcontrib-docx
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Sphinx docx builder extension
|
|
5
|
+
Home-page: https://github.com/qiujiandong/sphinxcontrib-docx
|
|
6
|
+
Author: amedama41
|
|
7
|
+
Author-email: kamo.devel41@gmail.com
|
|
8
|
+
Maintainer: Jiandong Qiu
|
|
9
|
+
Maintainer-email: qiujiandong1998@gmail.com
|
|
10
|
+
License: MIT
|
|
11
|
+
Project-URL: Source, https://github.com/qiujiandong/sphinxcontrib-docx
|
|
12
|
+
Project-URL: Issues, https://github.com/qiujiandong/sphinxcontrib-docx/issues
|
|
13
|
+
Project-URL: Documentation, https://qiujiandong.github.io/sphinxcontrib-docx/
|
|
14
|
+
Keywords: sphinx,extension,docx,OpenXML
|
|
15
|
+
Classifier: Framework :: Sphinx :: Extension
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Programming Language :: Python :: 3
|
|
21
|
+
Classifier: Topic :: Documentation :: Sphinx
|
|
22
|
+
Requires-Python: >=3.11
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
License-File: sphinxcontrib/docx/docx/LICENSE.python-docx
|
|
26
|
+
Requires-Dist: Sphinx>=4.2.0
|
|
27
|
+
Requires-Dist: lxml
|
|
28
|
+
Requires-Dist: pillow
|
|
29
|
+
Provides-Extra: math
|
|
30
|
+
Requires-Dist: latex2mathml; extra == "math"
|
|
31
|
+
Requires-Dist: mathml2omml; extra == "math"
|
|
32
|
+
Dynamic: author
|
|
33
|
+
Dynamic: author-email
|
|
34
|
+
Dynamic: classifier
|
|
35
|
+
Dynamic: description
|
|
36
|
+
Dynamic: description-content-type
|
|
37
|
+
Dynamic: home-page
|
|
38
|
+
Dynamic: keywords
|
|
39
|
+
Dynamic: license
|
|
40
|
+
Dynamic: license-file
|
|
41
|
+
Dynamic: maintainer
|
|
42
|
+
Dynamic: maintainer-email
|
|
43
|
+
Dynamic: project-url
|
|
44
|
+
Dynamic: provides-extra
|
|
45
|
+
Dynamic: requires-dist
|
|
46
|
+
Dynamic: requires-python
|
|
47
|
+
Dynamic: summary
|
|
48
|
+
|
|
49
|
+
[](https://github.com/qiujiandong/sphinxcontrib-docx/actions/workflows/tests.yml)
|
|
50
|
+
[](https://qiujiandong.github.io/sphinxcontrib-docx/)
|
|
51
|
+
[](https://pypi.org/project/sphinxcontrib-docx/)
|
|
52
|
+
[](https://github.com/qiujiandong/sphinxcontrib-docx/blob/develop/setup.py)
|
|
53
|
+
[](https://www.sphinx-doc.org/)
|
|
54
|
+
[](https://github.com/qiujiandong/sphinxcontrib-docx/blob/develop/LICENSE)
|
|
55
|
+
|
|
56
|
+
# sphinxcontrib-docx
|
|
57
|
+
|
|
58
|
+
Generate Word documents from Sphinx documentation, without requiring Microsoft
|
|
59
|
+
Word during the build.
|
|
60
|
+
|
|
61
|
+
> [!NOTE]
|
|
62
|
+
> This project is an independently maintained fork of
|
|
63
|
+
> [docxbuilder](https://github.com/amedama41/docxbuilder) 1.2.0, originally
|
|
64
|
+
> written by amedama41. Jiandong Qiu maintains this fork to continue development,
|
|
65
|
+
> fix bugs, and improve compatibility with supported Python and Sphinx versions.
|
|
66
|
+
|
|
67
|
+
## Features
|
|
68
|
+
|
|
69
|
+
* Generate DOCX documents with headings, tables, images, code blocks,
|
|
70
|
+
cross-references, footnotes, and a table of contents.
|
|
71
|
+
* Customize document styles and cover pages with a Word template.
|
|
72
|
+
* Set the document language through Sphinx's `language` configuration.
|
|
73
|
+
* Use language-aware theme fonts for Chinese, Japanese, and Korean documents.
|
|
74
|
+
* Convert mathematical expressions with the optional `math` dependencies.
|
|
75
|
+
|
|
76
|
+
## Requirements
|
|
77
|
+
|
|
78
|
+
* Python 3.11 or later is recommended. Python 3.10 reached end of life on
|
|
79
|
+
2026-10-01 and is no longer considered for compatibility testing. See the
|
|
80
|
+
[Python version status](https://devguide.python.org/versions/).
|
|
81
|
+
* Sphinx 4.2.0 or later. Earlier versions may work but are not supported or guaranteed.
|
|
82
|
+
* Runtime dependencies: Sphinx, lxml, and Pillow.
|
|
83
|
+
|
|
84
|
+
Graphviz is optional. Documents containing Graphviz directives require the
|
|
85
|
+
system `dot` executable; see the [Graphviz installation downloads](https://graphviz.org/download/).
|
|
86
|
+
Normal DOCX generation does not require it.
|
|
87
|
+
|
|
88
|
+
## Installation
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
python -m pip install sphinxcontrib-docx
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
For formula conversion, install the optional dependencies:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
python -m pip install 'sphinxcontrib-docx[math]'
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Quick start
|
|
101
|
+
|
|
102
|
+
Create a ready-to-build example project:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
sphinx-docx-quickstart demo
|
|
106
|
+
python -m sphinx -b docx demo/source demo/build/docx
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Open `demo/build/docx/preview.docx` in Word or another DOCX viewer.
|
|
110
|
+
Edit `demo/source/index.rst` and repeat the build command to preview changes.
|
|
111
|
+
The sample includes formatted text, lists, a table, and code.
|
|
112
|
+
|
|
113
|
+
The initializer accepts `--project`, `--author`, and `--language` (default: `en`).
|
|
114
|
+
It uses the bundled template and refuses to modify a nonempty directory.
|
|
115
|
+
|
|
116
|
+
For existing projects, language and font settings, and custom templates, see
|
|
117
|
+
[Configurations](https://qiujiandong.github.io/sphinxcontrib-docx/configurations.html).
|
|
118
|
+
|
|
119
|
+
## Known limitations
|
|
120
|
+
|
|
121
|
+
* Remote image URLs are not supported; download images and use local paths.
|
|
122
|
+
* Vertical alignment options for inline images are not supported.
|
|
123
|
+
* Fonts and final pagination depend on the application used to open the DOCX.
|
|
124
|
+
|
|
125
|
+
## Development
|
|
126
|
+
|
|
127
|
+
See the [development guide](https://qiujiandong.github.io/sphinxcontrib-docx/develop.html)
|
|
128
|
+
for environment setup, checks, live documentation preview, template maintenance,
|
|
129
|
+
commit conventions, and release procedures.
|
|
130
|
+
|
|
131
|
+
## License and maintenance
|
|
132
|
+
|
|
133
|
+
MIT License. Original copyright notices and third-party licenses are retained.
|
|
134
|
+
|
|
135
|
+
* Original author: amedama41.
|
|
136
|
+
* Fork maintainer: Jiandong Qiu <qiujiandong1998@gmail.com>.
|
|
137
|
+
* [Report an issue](https://github.com/qiujiandong/sphinxcontrib-docx/issues).
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
[](https://github.com/qiujiandong/sphinxcontrib-docx/actions/workflows/tests.yml)
|
|
2
|
+
[](https://qiujiandong.github.io/sphinxcontrib-docx/)
|
|
3
|
+
[](https://pypi.org/project/sphinxcontrib-docx/)
|
|
4
|
+
[](https://github.com/qiujiandong/sphinxcontrib-docx/blob/develop/setup.py)
|
|
5
|
+
[](https://www.sphinx-doc.org/)
|
|
6
|
+
[](https://github.com/qiujiandong/sphinxcontrib-docx/blob/develop/LICENSE)
|
|
7
|
+
|
|
8
|
+
# sphinxcontrib-docx
|
|
9
|
+
|
|
10
|
+
Generate Word documents from Sphinx documentation, without requiring Microsoft
|
|
11
|
+
Word during the build.
|
|
12
|
+
|
|
13
|
+
> [!NOTE]
|
|
14
|
+
> This project is an independently maintained fork of
|
|
15
|
+
> [docxbuilder](https://github.com/amedama41/docxbuilder) 1.2.0, originally
|
|
16
|
+
> written by amedama41. Jiandong Qiu maintains this fork to continue development,
|
|
17
|
+
> fix bugs, and improve compatibility with supported Python and Sphinx versions.
|
|
18
|
+
|
|
19
|
+
## Features
|
|
20
|
+
|
|
21
|
+
* Generate DOCX documents with headings, tables, images, code blocks,
|
|
22
|
+
cross-references, footnotes, and a table of contents.
|
|
23
|
+
* Customize document styles and cover pages with a Word template.
|
|
24
|
+
* Set the document language through Sphinx's `language` configuration.
|
|
25
|
+
* Use language-aware theme fonts for Chinese, Japanese, and Korean documents.
|
|
26
|
+
* Convert mathematical expressions with the optional `math` dependencies.
|
|
27
|
+
|
|
28
|
+
## Requirements
|
|
29
|
+
|
|
30
|
+
* Python 3.11 or later is recommended. Python 3.10 reached end of life on
|
|
31
|
+
2026-10-01 and is no longer considered for compatibility testing. See the
|
|
32
|
+
[Python version status](https://devguide.python.org/versions/).
|
|
33
|
+
* Sphinx 4.2.0 or later. Earlier versions may work but are not supported or guaranteed.
|
|
34
|
+
* Runtime dependencies: Sphinx, lxml, and Pillow.
|
|
35
|
+
|
|
36
|
+
Graphviz is optional. Documents containing Graphviz directives require the
|
|
37
|
+
system `dot` executable; see the [Graphviz installation downloads](https://graphviz.org/download/).
|
|
38
|
+
Normal DOCX generation does not require it.
|
|
39
|
+
|
|
40
|
+
## Installation
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
python -m pip install sphinxcontrib-docx
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
For formula conversion, install the optional dependencies:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
python -m pip install 'sphinxcontrib-docx[math]'
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Quick start
|
|
53
|
+
|
|
54
|
+
Create a ready-to-build example project:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
sphinx-docx-quickstart demo
|
|
58
|
+
python -m sphinx -b docx demo/source demo/build/docx
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Open `demo/build/docx/preview.docx` in Word or another DOCX viewer.
|
|
62
|
+
Edit `demo/source/index.rst` and repeat the build command to preview changes.
|
|
63
|
+
The sample includes formatted text, lists, a table, and code.
|
|
64
|
+
|
|
65
|
+
The initializer accepts `--project`, `--author`, and `--language` (default: `en`).
|
|
66
|
+
It uses the bundled template and refuses to modify a nonempty directory.
|
|
67
|
+
|
|
68
|
+
For existing projects, language and font settings, and custom templates, see
|
|
69
|
+
[Configurations](https://qiujiandong.github.io/sphinxcontrib-docx/configurations.html).
|
|
70
|
+
|
|
71
|
+
## Known limitations
|
|
72
|
+
|
|
73
|
+
* Remote image URLs are not supported; download images and use local paths.
|
|
74
|
+
* Vertical alignment options for inline images are not supported.
|
|
75
|
+
* Fonts and final pagination depend on the application used to open the DOCX.
|
|
76
|
+
|
|
77
|
+
## Development
|
|
78
|
+
|
|
79
|
+
See the [development guide](https://qiujiandong.github.io/sphinxcontrib-docx/develop.html)
|
|
80
|
+
for environment setup, checks, live documentation preview, template maintenance,
|
|
81
|
+
commit conventions, and release procedures.
|
|
82
|
+
|
|
83
|
+
## License and maintenance
|
|
84
|
+
|
|
85
|
+
MIT License. Original copyright notices and third-party licenses are retained.
|
|
86
|
+
|
|
87
|
+
* Original author: amedama41.
|
|
88
|
+
* Fork maintainer: Jiandong Qiu <qiujiandong1998@gmail.com>.
|
|
89
|
+
* [Report an issue](https://github.com/qiujiandong/sphinxcontrib-docx/issues).
|
|
@@ -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, 'sphinxcontrib/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,68 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
import os
|
|
3
|
+
import runpy
|
|
4
|
+
from setuptools.command.build_py import build_py
|
|
5
|
+
from setuptools import setup
|
|
6
|
+
|
|
7
|
+
class CustomBuild(build_py):
|
|
8
|
+
def run(self):
|
|
9
|
+
runpy.run_path(os.path.join(BASEDIR, 'create_style_file.py'), run_name='__main__')
|
|
10
|
+
return super(CustomBuild, self).run()
|
|
11
|
+
|
|
12
|
+
BASEDIR = os.path.dirname(os.path.abspath(__file__))
|
|
13
|
+
with open(os.path.join(BASEDIR, 'README.md'), 'r', encoding='utf-8') as f:
|
|
14
|
+
LONG_DESCRIPTION = f.read()
|
|
15
|
+
|
|
16
|
+
setup(
|
|
17
|
+
name='sphinxcontrib-docx',
|
|
18
|
+
version='0.1.0',
|
|
19
|
+
description='Sphinx docx builder extension',
|
|
20
|
+
long_description=LONG_DESCRIPTION,
|
|
21
|
+
long_description_content_type='text/markdown',
|
|
22
|
+
license='MIT',
|
|
23
|
+
license_files=['LICENSE', 'sphinxcontrib/docx/docx/LICENSE.python-docx'],
|
|
24
|
+
url='https://github.com/qiujiandong/sphinxcontrib-docx',
|
|
25
|
+
project_urls={
|
|
26
|
+
'Source': 'https://github.com/qiujiandong/sphinxcontrib-docx',
|
|
27
|
+
'Issues': 'https://github.com/qiujiandong/sphinxcontrib-docx/issues',
|
|
28
|
+
'Documentation': 'https://qiujiandong.github.io/sphinxcontrib-docx/',
|
|
29
|
+
},
|
|
30
|
+
maintainer='Jiandong Qiu',
|
|
31
|
+
maintainer_email='qiujiandong1998@gmail.com',
|
|
32
|
+
author='amedama41',
|
|
33
|
+
author_email='kamo.devel41@gmail.com',
|
|
34
|
+
keywords=['sphinx', 'extension', 'docx', 'OpenXML'],
|
|
35
|
+
packages=[
|
|
36
|
+
'sphinxcontrib.docx',
|
|
37
|
+
'sphinxcontrib.docx.docx',
|
|
38
|
+
],
|
|
39
|
+
entry_points={
|
|
40
|
+
'console_scripts': [
|
|
41
|
+
'sphinx-docx-quickstart=sphinxcontrib.docx.quickstart:main',
|
|
42
|
+
],
|
|
43
|
+
},
|
|
44
|
+
install_requires=[
|
|
45
|
+
"Sphinx>=4.2.0",
|
|
46
|
+
"lxml",
|
|
47
|
+
"pillow",
|
|
48
|
+
],
|
|
49
|
+
extras_require={
|
|
50
|
+
'math': ['latex2mathml', 'mathml2omml'],
|
|
51
|
+
},
|
|
52
|
+
python_requires='>=3.11',
|
|
53
|
+
package_data={
|
|
54
|
+
'sphinxcontrib.docx.docx': ['style.docx'],
|
|
55
|
+
},
|
|
56
|
+
classifiers=[
|
|
57
|
+
'Framework :: Sphinx :: Extension',
|
|
58
|
+
'Programming Language :: Python :: 3 :: Only',
|
|
59
|
+
'Programming Language :: Python :: 3.11',
|
|
60
|
+
'Programming Language :: Python :: 3.12',
|
|
61
|
+
'Programming Language :: Python :: 3.13',
|
|
62
|
+
'Programming Language :: Python :: 3',
|
|
63
|
+
'Topic :: Documentation :: Sphinx',
|
|
64
|
+
],
|
|
65
|
+
cmdclass={
|
|
66
|
+
'build_py': CustomBuild,
|
|
67
|
+
}
|
|
68
|
+
)
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
from sphinx.util.osutil import make_filename
|
|
2
|
+
from sphinxcontrib.docx.builder import DocxBuilder
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def setup(app):
|
|
6
|
+
app.add_builder(DocxBuilder)
|
|
7
|
+
|
|
8
|
+
def default_docx_documents(conf):
|
|
9
|
+
start_doc = conf.master_doc
|
|
10
|
+
filename = '%s.docx' % make_filename(conf.project)
|
|
11
|
+
title = conf.project
|
|
12
|
+
# author configuration value is available from Sphinx 1.8
|
|
13
|
+
author = getattr(conf, 'author', 'sphinxcontrib-docx')
|
|
14
|
+
properties = {
|
|
15
|
+
'title': title,
|
|
16
|
+
'creator': author,
|
|
17
|
+
'subject': '',
|
|
18
|
+
'category': '',
|
|
19
|
+
'description': 'This document was generated by sphinxcontrib-docx',
|
|
20
|
+
'keywords': ['python', 'Office Open XML', 'Word'],
|
|
21
|
+
}
|
|
22
|
+
toc_only = False
|
|
23
|
+
return [(start_doc, filename, properties, toc_only)]
|
|
24
|
+
|
|
25
|
+
app.add_config_value('docx_documents', default_docx_documents, 'env')
|
|
26
|
+
app.add_config_value('docx_style', '', 'env')
|
|
27
|
+
app.add_config_value('docx_pagebreak_before_section', 0, 'env')
|
|
28
|
+
app.add_config_value('docx_pagebreak_before_file', 0, 'env')
|
|
29
|
+
app.add_config_value('docx_pagebreak_before_table_of_contents', -1, 'env')
|
|
30
|
+
app.add_config_value('docx_pagebreak_after_table_of_contents', 0, 'env')
|
|
31
|
+
app.add_config_value('docx_coverpage', True, 'env')
|
|
32
|
+
app.add_config_value('docx_update_fields', False, 'env')
|
|
33
|
+
app.add_config_value('docx_hide_section_numbers', False, 'env')
|
|
34
|
+
app.add_config_value('docx_hide_subtoctrees', False, 'env')
|
|
35
|
+
app.add_config_value('docx_table_caption_position', 'above', 'env')
|
|
36
|
+
app.add_config_value('docx_table_options', {
|
|
37
|
+
'landscape_columns': 0,
|
|
38
|
+
'in_single_page': False,
|
|
39
|
+
'row_splittable': True,
|
|
40
|
+
'header_in_all_page': False,
|
|
41
|
+
}, 'env')
|
|
42
|
+
app.add_config_value('docx_style_names', {}, 'env')
|
|
43
|
+
app.add_config_value('docx_nested_character_style', True, 'env')
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
sphinxcontrib-docx
|
|
4
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
5
|
+
|
|
6
|
+
OpenXML Document Sphinx builder.
|
|
7
|
+
|
|
8
|
+
:copyright:
|
|
9
|
+
Copyright 2010 by shimizukawa at gmail dot com (Sphinx-users.jp).
|
|
10
|
+
:license: BSD, see LICENSE for details.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
import os
|
|
14
|
+
|
|
15
|
+
from docutils import nodes
|
|
16
|
+
from docutils.io import BinaryFileOutput
|
|
17
|
+
from sphinx import addnodes
|
|
18
|
+
from sphinx.builders import Builder
|
|
19
|
+
from sphinx.errors import ConfigError
|
|
20
|
+
from sphinx.util import logging
|
|
21
|
+
from sphinx.util.docutils import new_document
|
|
22
|
+
from sphinx.util.osutil import ensuredir
|
|
23
|
+
|
|
24
|
+
from sphinxcontrib.docx.writer import DocxWriter, DocxTranslator
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class DocxBuilder(Builder):
|
|
28
|
+
# pylint: disable=attribute-defined-outside-init
|
|
29
|
+
name = 'docx'
|
|
30
|
+
format = 'docx'
|
|
31
|
+
out_suffix = '.docx'
|
|
32
|
+
default_translator_class = DocxTranslator
|
|
33
|
+
|
|
34
|
+
def init(self):
|
|
35
|
+
if self.config.docx_table_caption_position not in ('above', 'below'):
|
|
36
|
+
raise ConfigError("docx_table_caption_position must be 'above' or 'below'")
|
|
37
|
+
self.imagedir = '_images'
|
|
38
|
+
self._logger = logging.getLogger('sphinxcontrib.docx')
|
|
39
|
+
self._docx_documents = []
|
|
40
|
+
|
|
41
|
+
def get_outdated_docs(self):
|
|
42
|
+
return 'pass'
|
|
43
|
+
|
|
44
|
+
def get_target_uri(self, docname, typ=None):
|
|
45
|
+
return docname
|
|
46
|
+
|
|
47
|
+
def prepare_writing(self, docnames):
|
|
48
|
+
for entry in self.config.docx_documents:
|
|
49
|
+
if entry[0] not in self.env.all_docs:
|
|
50
|
+
self._logger.warning(
|
|
51
|
+
'unknown document %s is found '
|
|
52
|
+
'in docx_documents' % entry[0])
|
|
53
|
+
continue
|
|
54
|
+
if not entry[1]:
|
|
55
|
+
self._logger.warning(
|
|
56
|
+
'invalid filename %s is found for %s '
|
|
57
|
+
'in docx_documents' % (entry[1], entry[0]))
|
|
58
|
+
continue
|
|
59
|
+
self._docx_documents.append(entry)
|
|
60
|
+
if not self._docx_documents:
|
|
61
|
+
self._logger.warning('no valid entry is found in docx_documents')
|
|
62
|
+
self.writer = DocxWriter(self)
|
|
63
|
+
|
|
64
|
+
def assemble_doctree(self, master, toctree_only):
|
|
65
|
+
tree = self.env.get_doctree(master)
|
|
66
|
+
if toctree_only:
|
|
67
|
+
doc = new_document('sphinxcontrib/docx/builder.py')
|
|
68
|
+
for toctree in tree.traverse(addnodes.toctree):
|
|
69
|
+
# ids is not assigned to toctree, but to the parent
|
|
70
|
+
toctree.get('ids').extend(toctree.parent.get('ids'))
|
|
71
|
+
doc.append(toctree)
|
|
72
|
+
tree = doc
|
|
73
|
+
tree = insert_all_toctrees(tree, master, self.env, [])
|
|
74
|
+
tree['docname'] = master
|
|
75
|
+
self._logger.info('')
|
|
76
|
+
# TODO: Support cross references
|
|
77
|
+
return tree
|
|
78
|
+
|
|
79
|
+
def make_numfig_map(self):
|
|
80
|
+
numfig_map = {}
|
|
81
|
+
for docname, item in self.env.toc_fignumbers.items():
|
|
82
|
+
for figtype, info in item.items():
|
|
83
|
+
prefix = self.config.numfig_format.get(figtype)
|
|
84
|
+
if prefix is None:
|
|
85
|
+
continue
|
|
86
|
+
_, num_map = numfig_map.setdefault(figtype, (prefix, {}))
|
|
87
|
+
for node_id, num in info.items():
|
|
88
|
+
key = '%s/%s' % (docname, node_id)
|
|
89
|
+
num_map[key] = num
|
|
90
|
+
return numfig_map
|
|
91
|
+
|
|
92
|
+
def make_numsec_map(self):
|
|
93
|
+
numsec_map = {}
|
|
94
|
+
for docname, info in self.env.toc_secnumbers.items():
|
|
95
|
+
for node_id, num in info.items():
|
|
96
|
+
key = '%s/%s' % (docname, node_id)
|
|
97
|
+
numsec_map[key] = num
|
|
98
|
+
return numsec_map
|
|
99
|
+
|
|
100
|
+
def write(self, build_docnames, updated_docnames, method='update'):
|
|
101
|
+
docnames = set(self.env.all_docs)
|
|
102
|
+
|
|
103
|
+
self._logger.info('preparing documents... ', nonl=True)
|
|
104
|
+
self.prepare_writing(docnames)
|
|
105
|
+
self._logger.info('done')
|
|
106
|
+
|
|
107
|
+
for entry in self._docx_documents:
|
|
108
|
+
start_doc, docname, props = entry[:3]
|
|
109
|
+
toctree_only = entry[3] if len(entry) > 3 else False
|
|
110
|
+
|
|
111
|
+
self._logger.info('processing %s... ' % docname, nonl=True)
|
|
112
|
+
doctree = self.assemble_doctree(start_doc, toctree_only)
|
|
113
|
+
self.doc_properties = props
|
|
114
|
+
self._logger.info('writing... ', nonl=True)
|
|
115
|
+
self.write_doc(docname, doctree)
|
|
116
|
+
self._logger.info('done')
|
|
117
|
+
|
|
118
|
+
def write_doc(self, docname, doctree):
|
|
119
|
+
outfilename = os.path.join(self.outdir, docname)
|
|
120
|
+
ensuredir(os.path.dirname(outfilename))
|
|
121
|
+
destination = BinaryFileOutput(destination_path=outfilename)
|
|
122
|
+
self.writer.write(doctree, destination)
|
|
123
|
+
|
|
124
|
+
def finish(self):
|
|
125
|
+
pass
|
|
126
|
+
|
|
127
|
+
def insert_all_toctrees(tree, docname, env, traversed):
|
|
128
|
+
tree = tree.deepcopy()
|
|
129
|
+
env.apply_post_transforms(tree, docname)
|
|
130
|
+
for toctreenode in tree.traverse(addnodes.toctree):
|
|
131
|
+
nodeid = 'docx_expanded_toctree%d' % id(toctreenode)
|
|
132
|
+
newnodes = nodes.container(ids=[nodeid])
|
|
133
|
+
toctreenode['docx_expanded_toctree_refid'] = nodeid
|
|
134
|
+
includefiles = toctreenode['includefiles']
|
|
135
|
+
for includefile in includefiles:
|
|
136
|
+
if includefile in traversed:
|
|
137
|
+
continue
|
|
138
|
+
traversed.append(includefile)
|
|
139
|
+
subtree = insert_all_toctrees(
|
|
140
|
+
env.get_doctree(includefile), includefile, env, traversed)
|
|
141
|
+
start_of_file = addnodes.start_of_file(docname=includefile)
|
|
142
|
+
start_of_file.children = subtree.children
|
|
143
|
+
newnodes.append(start_of_file)
|
|
144
|
+
parent = toctreenode.parent
|
|
145
|
+
index = parent.index(toctreenode)
|
|
146
|
+
parent.insert(index + 1, newnodes)
|
|
147
|
+
return tree
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2009-2010 Mike MacCana
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
|
4
|
+
obtaining a copy of this software and associated documentation
|
|
5
|
+
files (the "Software"), to deal in the Software without
|
|
6
|
+
restriction, including without limitation the rights to use,
|
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the
|
|
9
|
+
Software is furnished to do so, subject to the following
|
|
10
|
+
conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be
|
|
13
|
+
included in all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from sphinxcontrib.docx.docx.docx import *
|