docx2md 1.0.2__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.
- docx2md-1.0.2/LICENSE +21 -0
- docx2md-1.0.2/PKG-INFO +101 -0
- docx2md-1.0.2/README.md +69 -0
- docx2md-1.0.2/README.rst +80 -0
- docx2md-1.0.2/jp-README.md +71 -0
- docx2md-1.0.2/pyproject.toml +37 -0
- docx2md-1.0.2/setup.cfg +4 -0
- docx2md-1.0.2/src/docx2md/__init__.py +1 -0
- docx2md-1.0.2/src/docx2md/__main__.py +99 -0
- docx2md-1.0.2/src/docx2md/convert.py +14 -0
- docx2md-1.0.2/src/docx2md/converter.py +306 -0
- docx2md-1.0.2/src/docx2md/docxfile.py +45 -0
- docx2md-1.0.2/src/docx2md/docxmedia.py +76 -0
- docx2md-1.0.2/src/docx2md/utils.py +18 -0
- docx2md-1.0.2/src/docx2md/version.py +1 -0
- docx2md-1.0.2/src/docx2md.egg-info/PKG-INFO +101 -0
- docx2md-1.0.2/src/docx2md.egg-info/SOURCES.txt +28 -0
- docx2md-1.0.2/src/docx2md.egg-info/dependency_links.txt +1 -0
- docx2md-1.0.2/src/docx2md.egg-info/entry_points.txt +2 -0
- docx2md-1.0.2/src/docx2md.egg-info/requires.txt +6 -0
- docx2md-1.0.2/src/docx2md.egg-info/top_level.txt +1 -0
- docx2md-1.0.2/tests/test_docxfile.py +27 -0
- docx2md-1.0.2/tests/test_docxmedia.py +54 -0
- docx2md-1.0.2/tests/test_drawing.py +69 -0
- docx2md-1.0.2/tests/test_function.py +43 -0
- docx2md-1.0.2/tests/test_heading.py +41 -0
- docx2md-1.0.2/tests/test_list.py +75 -0
- docx2md-1.0.2/tests/test_media.py +14 -0
- docx2md-1.0.2/tests/test_paragraph.py +69 -0
- docx2md-1.0.2/tests/test_table.py +100 -0
docx2md-1.0.2/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021-2025 Toshihiko Ichida
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
docx2md-1.0.2/PKG-INFO
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: docx2md
|
|
3
|
+
Version: 1.0.2
|
|
4
|
+
Summary: convert .docx to .md
|
|
5
|
+
Author-email: dogatana <dogatana@gmail.com>
|
|
6
|
+
Project-URL: Homepage, https://github.com/dogatana/docx2md
|
|
7
|
+
Project-URL: Bug Tracker, https://github.com/dogatana/docx2md/issues
|
|
8
|
+
Classifier: Programming Language :: Python
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Environment :: Other Environment
|
|
13
|
+
Classifier: Intended Audience :: Other Audience
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Topic :: Text Editors
|
|
17
|
+
Classifier: Topic :: Text Editors :: Documentation
|
|
18
|
+
Classifier: Topic :: Text Editors :: Word Processors
|
|
19
|
+
Classifier: Topic :: Text Processing
|
|
20
|
+
Classifier: Topic :: Text Processing :: Markup
|
|
21
|
+
Classifier: Topic :: Text Processing :: Markup :: Markdown
|
|
22
|
+
Classifier: Topic :: Utilities
|
|
23
|
+
Requires-Python: >=3.10
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Requires-Dist: lxml
|
|
27
|
+
Requires-Dist: Pillow
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: build; extra == "dev"
|
|
30
|
+
Requires-Dist: twine; extra == "dev"
|
|
31
|
+
Dynamic: license-file
|
|
32
|
+
|
|
33
|
+
# docx2md
|
|
34
|
+
|
|
35
|
+
Converts Microsoft Word document files (.docx extension) to Markdown files.
|
|
36
|
+
|
|
37
|
+
## Install
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
pip install docx2md
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## How to use
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
usage: docx2md [-h] [-m] [-v] [--debug] SRC.docx DST.md
|
|
47
|
+
|
|
48
|
+
positional arguments:
|
|
49
|
+
SRC.docx Microsoft Word file to read
|
|
50
|
+
DST.md Markdown file to write
|
|
51
|
+
|
|
52
|
+
optional arguments:
|
|
53
|
+
-h, --help show this help message and exit
|
|
54
|
+
-m, --md_table use Markdown table notation instead of <table>
|
|
55
|
+
-v, --version show version
|
|
56
|
+
--debug for debug
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Tables
|
|
60
|
+
|
|
61
|
+
A table is output as ```<table id="table(n)">```. ```id``` is the order of output, starting from 1.
|
|
62
|
+
|
|
63
|
+
If ```--md_table``` is specified, the output will use ```|```, but the title line item will be ```#``` fixed.
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
| # | # | # |
|
|
67
|
+
|---|---|---|
|
|
68
|
+
|a|b|c|
|
|
69
|
+
|d|e|f|
|
|
70
|
+
|g|h|i|
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Pictures
|
|
74
|
+
|
|
75
|
+
Images will be output as ```<img id="image(n)">```.
|
|
76
|
+
The ```id``` is output in order starting from 1.
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
## Examples
|
|
80
|
+
|
|
81
|
+
* source: [docx](example/example.docx)
|
|
82
|
+
* result: [Markdown](example/example/README.md)
|
|
83
|
+
|
|
84
|
+
## Elements that can be converted
|
|
85
|
+
|
|
86
|
+
* Tables (including merged cells)
|
|
87
|
+
* Lists (also with numbers as bullets)
|
|
88
|
+
* Headings
|
|
89
|
+
* Embedded images
|
|
90
|
+
* Page breaks (converted to ```<div class="break"></div>```)
|
|
91
|
+
* Line breaks within paragraphs (converted to ```<br>```)
|
|
92
|
+
* Text boxes (inserted in the body)
|
|
93
|
+
|
|
94
|
+
## Elements that cannot be converted (only known ones)
|
|
95
|
+
|
|
96
|
+
* Table of Contents
|
|
97
|
+
* Text decoration (bold and etc...)
|
|
98
|
+
|
|
99
|
+
## License
|
|
100
|
+
|
|
101
|
+
MIT
|
docx2md-1.0.2/README.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# docx2md
|
|
2
|
+
|
|
3
|
+
Converts Microsoft Word document files (.docx extension) to Markdown files.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
pip install docx2md
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## How to use
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
usage: docx2md [-h] [-m] [-v] [--debug] SRC.docx DST.md
|
|
15
|
+
|
|
16
|
+
positional arguments:
|
|
17
|
+
SRC.docx Microsoft Word file to read
|
|
18
|
+
DST.md Markdown file to write
|
|
19
|
+
|
|
20
|
+
optional arguments:
|
|
21
|
+
-h, --help show this help message and exit
|
|
22
|
+
-m, --md_table use Markdown table notation instead of <table>
|
|
23
|
+
-v, --version show version
|
|
24
|
+
--debug for debug
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Tables
|
|
28
|
+
|
|
29
|
+
A table is output as ```<table id="table(n)">```. ```id``` is the order of output, starting from 1.
|
|
30
|
+
|
|
31
|
+
If ```--md_table``` is specified, the output will use ```|```, but the title line item will be ```#``` fixed.
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
| # | # | # |
|
|
35
|
+
|---|---|---|
|
|
36
|
+
|a|b|c|
|
|
37
|
+
|d|e|f|
|
|
38
|
+
|g|h|i|
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Pictures
|
|
42
|
+
|
|
43
|
+
Images will be output as ```<img id="image(n)">```.
|
|
44
|
+
The ```id``` is output in order starting from 1.
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
## Examples
|
|
48
|
+
|
|
49
|
+
* source: [docx](example/example.docx)
|
|
50
|
+
* result: [Markdown](example/example/README.md)
|
|
51
|
+
|
|
52
|
+
## Elements that can be converted
|
|
53
|
+
|
|
54
|
+
* Tables (including merged cells)
|
|
55
|
+
* Lists (also with numbers as bullets)
|
|
56
|
+
* Headings
|
|
57
|
+
* Embedded images
|
|
58
|
+
* Page breaks (converted to ```<div class="break"></div>```)
|
|
59
|
+
* Line breaks within paragraphs (converted to ```<br>```)
|
|
60
|
+
* Text boxes (inserted in the body)
|
|
61
|
+
|
|
62
|
+
## Elements that cannot be converted (only known ones)
|
|
63
|
+
|
|
64
|
+
* Table of Contents
|
|
65
|
+
* Text decoration (bold and etc...)
|
|
66
|
+
|
|
67
|
+
## License
|
|
68
|
+
|
|
69
|
+
MIT
|
docx2md-1.0.2/README.rst
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
docx2md
|
|
2
|
+
=======
|
|
3
|
+
|
|
4
|
+
Converts Microsoft Word document files (.docx extension) to Markdown
|
|
5
|
+
files.
|
|
6
|
+
|
|
7
|
+
Install
|
|
8
|
+
-------
|
|
9
|
+
|
|
10
|
+
::
|
|
11
|
+
|
|
12
|
+
pip install docx2md
|
|
13
|
+
|
|
14
|
+
How to use
|
|
15
|
+
----------
|
|
16
|
+
|
|
17
|
+
::
|
|
18
|
+
|
|
19
|
+
usage: python -m docx2md [-h] [-m] [-v] [--debug] SRC.docx DST.md
|
|
20
|
+
|
|
21
|
+
positional arguments:
|
|
22
|
+
SRC.docx Microsoft Word file to read
|
|
23
|
+
DST.md Markdown file to write
|
|
24
|
+
|
|
25
|
+
optional arguments:
|
|
26
|
+
-h, --help show this help message and exit
|
|
27
|
+
-m, --md_table use Markdown table notation instead of <table>
|
|
28
|
+
-v, --version show version
|
|
29
|
+
--debug for debug
|
|
30
|
+
|
|
31
|
+
Tables
|
|
32
|
+
~~~~~~
|
|
33
|
+
|
|
34
|
+
A table is output as ``<table id="table(n)">``. ``id`` is the order of
|
|
35
|
+
output, starting from 1.
|
|
36
|
+
|
|
37
|
+
If ``--md_table`` is specified, the output will use ``|``, but the title
|
|
38
|
+
line item will be ``#`` fixed.
|
|
39
|
+
|
|
40
|
+
::
|
|
41
|
+
|
|
42
|
+
| # | # | # |
|
|
43
|
+
|---|---|---|
|
|
44
|
+
|a|b|c|
|
|
45
|
+
|d|e|f|
|
|
46
|
+
|g|h|i|
|
|
47
|
+
|
|
48
|
+
Pictures
|
|
49
|
+
~~~~~~~~
|
|
50
|
+
|
|
51
|
+
Images will be output as ``<img id="image(n)">``. The ``id`` is output
|
|
52
|
+
in order starting from 1.
|
|
53
|
+
|
|
54
|
+
Examples
|
|
55
|
+
--------
|
|
56
|
+
|
|
57
|
+
- source: `docx <example/example.docx>`__
|
|
58
|
+
- result: `Markdown <example/example/README.md>`__
|
|
59
|
+
|
|
60
|
+
Elements that can be converted
|
|
61
|
+
------------------------------
|
|
62
|
+
|
|
63
|
+
- Tables (including merged cells)
|
|
64
|
+
- Lists (also with numbers as bullets)
|
|
65
|
+
- Headings
|
|
66
|
+
- Embedded images
|
|
67
|
+
- Page breaks (converted to ``<div class="break"></div>``)
|
|
68
|
+
- Line breaks within paragraphs (converted to ``<br>``)
|
|
69
|
+
- Text boxes (inserted in the body)
|
|
70
|
+
|
|
71
|
+
Elements that cannot be converted (only known ones)
|
|
72
|
+
---------------------------------------------------
|
|
73
|
+
|
|
74
|
+
- Table of Contents
|
|
75
|
+
- Text decoration (bold and etc�c)
|
|
76
|
+
|
|
77
|
+
License
|
|
78
|
+
-------
|
|
79
|
+
|
|
80
|
+
MIT
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# docx2md
|
|
2
|
+
|
|
3
|
+
Microsoft Word の文書ファイル(拡張子 .docx)をMarkdown ファイルへ変換します。
|
|
4
|
+
|
|
5
|
+
## インストール
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
pip install docx2md
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 利用方法
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
usage: python -m docx2md [-h] [-m] [-v] [--debug] SRC.docx DST.md
|
|
15
|
+
|
|
16
|
+
positional arguments:
|
|
17
|
+
SRC.docx Microsoft Word file to read
|
|
18
|
+
DST.md Markdown file to write
|
|
19
|
+
|
|
20
|
+
optional arguments:
|
|
21
|
+
-h, --help show this help message and exit
|
|
22
|
+
-m, --md_table use Markdown table notation instead of <table>
|
|
23
|
+
-v, --version show version
|
|
24
|
+
--debug for debug
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## 表について
|
|
28
|
+
|
|
29
|
+
表は ```<table id="table(n)">``` で出力します。
|
|
30
|
+
```id``` は 1から始まる出力順です。
|
|
31
|
+
|
|
32
|
+
```--md_table``` を指定すると、```|``` を使用して出力しますが、タイトル行の項目は ```#``` 固定です。
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
| # | # | # |
|
|
36
|
+
|---|---|---|
|
|
37
|
+
|a|b|c|
|
|
38
|
+
|d|e|f|
|
|
39
|
+
|g|h|i|
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## 画像について
|
|
43
|
+
|
|
44
|
+
画像は ```<img id="image(n)">``` で出力します。
|
|
45
|
+
```id``` は 1から始まる出力順です。
|
|
46
|
+
|
|
47
|
+
## 変換例
|
|
48
|
+
|
|
49
|
+
* source: [docx](example/example.docx)
|
|
50
|
+
* result: [Markdown](example/example/README.md)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
## 変換可能な要素
|
|
54
|
+
|
|
55
|
+
* テーブル(結合セルも含む)
|
|
56
|
+
* リスト(数字付きも箇条書きとなる)
|
|
57
|
+
* 見出し
|
|
58
|
+
* 埋め込み画像
|
|
59
|
+
* 改ページ(```<div class="break"></div>``` へ変換)
|
|
60
|
+
* 段落内改行(```<br>``` へ変換)
|
|
61
|
+
* テキストボックス(本文に挿入)
|
|
62
|
+
|
|
63
|
+
## 変換できないもの(分かっているもののみ)
|
|
64
|
+
|
|
65
|
+
* 目次
|
|
66
|
+
* 文字装飾
|
|
67
|
+
|
|
68
|
+
## ライセンス
|
|
69
|
+
|
|
70
|
+
MIT
|
|
71
|
+
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "docx2md"
|
|
3
|
+
version = "1.0.2"
|
|
4
|
+
authors = [{ name = "dogatana", email = "dogatana@gmail.com" }]
|
|
5
|
+
description = "convert .docx to .md"
|
|
6
|
+
readme = "README.md"
|
|
7
|
+
requires-python = ">=3.10"
|
|
8
|
+
classifiers = [
|
|
9
|
+
"Programming Language :: Python",
|
|
10
|
+
"Programming Language :: Python :: 3",
|
|
11
|
+
"Development Status :: 5 - Production/Stable",
|
|
12
|
+
"Intended Audience :: Developers",
|
|
13
|
+
"Environment :: Other Environment",
|
|
14
|
+
"Intended Audience :: Other Audience",
|
|
15
|
+
"License :: OSI Approved :: MIT License",
|
|
16
|
+
"Operating System :: OS Independent",
|
|
17
|
+
"Topic :: Text Editors",
|
|
18
|
+
"Topic :: Text Editors :: Documentation",
|
|
19
|
+
"Topic :: Text Editors :: Word Processors",
|
|
20
|
+
"Topic :: Text Processing",
|
|
21
|
+
"Topic :: Text Processing :: Markup",
|
|
22
|
+
"Topic :: Text Processing :: Markup :: Markdown",
|
|
23
|
+
"Topic :: Utilities",
|
|
24
|
+
]
|
|
25
|
+
license-files = ["LICENSE"]
|
|
26
|
+
|
|
27
|
+
dependencies = ["lxml", "Pillow"]
|
|
28
|
+
|
|
29
|
+
[project.scripts]
|
|
30
|
+
docx2md = "docx2md.__main__:main"
|
|
31
|
+
|
|
32
|
+
[project.optional-dependencies]
|
|
33
|
+
dev = ["build", "twine"]
|
|
34
|
+
|
|
35
|
+
[project.urls]
|
|
36
|
+
"Homepage" = "https://github.com/dogatana/docx2md"
|
|
37
|
+
"Bug Tracker" = "https://github.com/dogatana/docx2md/issues"
|
docx2md-1.0.2/setup.cfg
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# placeholder
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import os.path
|
|
3
|
+
|
|
4
|
+
from .converter import Converter
|
|
5
|
+
from .docxfile import DocxFile
|
|
6
|
+
from .docxmedia import DocxMedia
|
|
7
|
+
from .version import VERSION
|
|
8
|
+
|
|
9
|
+
PROG = os.path.basename(os.path.dirname(__file__))
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def main():
|
|
13
|
+
args = parse_args()
|
|
14
|
+
docx = create_docx(args.src)
|
|
15
|
+
check_target_dir(args.dst)
|
|
16
|
+
target_dir = os.path.dirname(args.dst)
|
|
17
|
+
|
|
18
|
+
if args.debug:
|
|
19
|
+
save_keyfile(docx, target_dir)
|
|
20
|
+
|
|
21
|
+
media = DocxMedia(docx)
|
|
22
|
+
md_text = convert(docx, target_dir, media, args.md_table)
|
|
23
|
+
# md_text = re.sub(r"\n{2,}( *\* )", "\n\\1", md_text)
|
|
24
|
+
save_md(args.dst, md_text)
|
|
25
|
+
|
|
26
|
+
media.save(target_dir)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def parse_args():
|
|
30
|
+
parser = argparse.ArgumentParser(prog=PROG)
|
|
31
|
+
parser.add_argument("src", metavar="SRC.docx", help="Microsoft Word file to read")
|
|
32
|
+
parser.add_argument(
|
|
33
|
+
"dst",
|
|
34
|
+
metavar="DST.md",
|
|
35
|
+
help="Markdown file to write",
|
|
36
|
+
default="./README.md",
|
|
37
|
+
)
|
|
38
|
+
parser.add_argument(
|
|
39
|
+
"-m",
|
|
40
|
+
"--md_table",
|
|
41
|
+
action="store_true",
|
|
42
|
+
help="use Markdown table notation instead of <table>",
|
|
43
|
+
default=False,
|
|
44
|
+
)
|
|
45
|
+
parser.add_argument(
|
|
46
|
+
"-v",
|
|
47
|
+
"--version",
|
|
48
|
+
help="show version",
|
|
49
|
+
action="version",
|
|
50
|
+
version=VERSION,
|
|
51
|
+
)
|
|
52
|
+
parser.add_argument("--debug", help="for debug", action="store_true", default=False)
|
|
53
|
+
return parser.parse_args()
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def create_docx(file):
|
|
57
|
+
try:
|
|
58
|
+
return DocxFile(file)
|
|
59
|
+
except Exception as e:
|
|
60
|
+
print(e)
|
|
61
|
+
exit()
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def check_target_dir(file):
|
|
65
|
+
dir = os.path.dirname(file)
|
|
66
|
+
if dir == "":
|
|
67
|
+
return
|
|
68
|
+
if os.path.isdir(dir):
|
|
69
|
+
return
|
|
70
|
+
if os.path.exists(dir):
|
|
71
|
+
print(f"cannot write to {file}")
|
|
72
|
+
exit()
|
|
73
|
+
os.makedirs(dir)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def save_keyfile(docx, target_dir):
|
|
77
|
+
def save_xml(file, text):
|
|
78
|
+
print("# save", file)
|
|
79
|
+
with open(file, "wb") as f:
|
|
80
|
+
f.write(text)
|
|
81
|
+
|
|
82
|
+
save_xml(os.path.join(target_dir, "document.xml"), docx.document())
|
|
83
|
+
save_xml(os.path.join(target_dir, "document.xml.rels"), docx.rels())
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def convert(docx, target_dir, media, use_md_table):
|
|
87
|
+
xml_text = docx.document()
|
|
88
|
+
converter = Converter(xml_text, media, use_md_table)
|
|
89
|
+
return converter.convert()
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def save_md(file, text):
|
|
93
|
+
print("# save", file)
|
|
94
|
+
with open(file, "w", encoding="utf-8") as f:
|
|
95
|
+
f.write(text)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
if __name__ == "__main__":
|
|
99
|
+
main()
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from .converter import Converter
|
|
2
|
+
from .docxfile import DocxFile
|
|
3
|
+
from .docxmedia import DocxMedia
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def do_convert(docx_file: str, use_md_table=False) -> str:
|
|
7
|
+
"""convert docx_file to Markdown text and return it"""
|
|
8
|
+
try:
|
|
9
|
+
docx = DocxFile(docx_file)
|
|
10
|
+
media = DocxMedia(docx)
|
|
11
|
+
converter = Converter(docx.document(), media, use_md_table)
|
|
12
|
+
return converter.convert()
|
|
13
|
+
except Exception as e:
|
|
14
|
+
return f"Exception: {e}"
|