md2word 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.
@@ -0,0 +1,78 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ *.egg-info/
24
+ .installed.cfg
25
+ *.egg
26
+
27
+ # PyInstaller
28
+ *.manifest
29
+ *.spec
30
+
31
+ # Installer logs
32
+ pip-log.txt
33
+ pip-delete-this-directory.txt
34
+
35
+ # Unit test / coverage reports
36
+ htmlcov/
37
+ .tox/
38
+ .nox/
39
+ .coverage
40
+ .coverage.*
41
+ .cache
42
+ nosetests.xml
43
+ coverage.xml
44
+ *.cover
45
+ *.py,cover
46
+ .hypothesis/
47
+ .pytest_cache/
48
+
49
+ # Translations
50
+ *.mo
51
+ *.pot
52
+
53
+ # Environments
54
+ .env
55
+ .venv
56
+ env/
57
+ venv/
58
+ ENV/
59
+ env.bak/
60
+ venv.bak/
61
+
62
+ # IDE
63
+ .idea/
64
+ .vscode/
65
+ *.swp
66
+ *.swo
67
+ *~
68
+
69
+ # OS
70
+ .DS_Store
71
+ Thumbs.db
72
+
73
+ # Project specific
74
+ images/
75
+ *.docx
76
+ config.json
77
+
78
+ .claude/
md2word-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 md2word contributors
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.
md2word-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,272 @@
1
+ Metadata-Version: 2.4
2
+ Name: md2word
3
+ Version: 0.1.0
4
+ Summary: Convert Markdown files to Word documents with extensive customization
5
+ Project-URL: Homepage, https://github.com/md2word/md2word
6
+ Project-URL: Documentation, https://github.com/md2word/md2word#readme
7
+ Project-URL: Repository, https://github.com/md2word/md2word
8
+ Project-URL: Issues, https://github.com/md2word/md2word/issues
9
+ Author: md2word contributors
10
+ License: MIT
11
+ License-File: LICENSE
12
+ Keywords: converter,document,docx,markdown,word
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Environment :: Console
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Intended Audience :: End Users/Desktop
17
+ Classifier: License :: OSI Approved :: MIT License
18
+ Classifier: Operating System :: OS Independent
19
+ Classifier: Programming Language :: Python :: 3
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Programming Language :: Python :: 3.13
24
+ Classifier: Topic :: Documentation
25
+ Classifier: Topic :: Office/Business :: Office Suites
26
+ Classifier: Topic :: Text Processing :: Markup :: Markdown
27
+ Requires-Python: >=3.10
28
+ Requires-Dist: html-for-docx>=1.0.0
29
+ Requires-Dist: httpx>=0.25.0
30
+ Requires-Dist: latex2mathml>=3.0.0
31
+ Requires-Dist: lxml>=5.0.0
32
+ Requires-Dist: markdown2>=2.4.0
33
+ Requires-Dist: mathml2omml>=0.0.2
34
+ Requires-Dist: pillow>=10.0.0
35
+ Requires-Dist: python-docx>=1.0.0
36
+ Description-Content-Type: text/markdown
37
+
38
+ # md2word
39
+
40
+ [中文文档](README_zh.md) | English
41
+
42
+ Convert Markdown files to Word documents (.docx) with extensive customization options.
43
+
44
+ ## Features
45
+
46
+ - Convert Markdown to Word documents
47
+ - Support for tables, code blocks, images, and more
48
+ - Automatic download and embedding of web images
49
+ - Automatic conversion of unsupported image formats (e.g., WebP)
50
+ - LaTeX formula support (converted to native Word equations)
51
+ - Configurable styles for headings, body text, and other elements
52
+ - Chinese font size support (e.g., "四号", "小四")
53
+ - Automatic heading numbering with multiple formats
54
+ - Optional table of contents generation
55
+
56
+ ## Installation
57
+
58
+ ### Using uv (recommended)
59
+
60
+ ```bash
61
+ # Install globally
62
+ uv tool install md2word
63
+
64
+ # Or run directly without installation
65
+ uvx md2word input.md
66
+ ```
67
+
68
+ ### Using pip
69
+
70
+ ```bash
71
+ pip install md2word
72
+ ```
73
+
74
+ ## Usage
75
+
76
+ ### Command Line
77
+
78
+ ```bash
79
+ # Basic conversion (outputs input.docx)
80
+ md2word input.md
81
+
82
+ # Specify output file
83
+ md2word input.md -o output.docx
84
+
85
+ # Use custom config file
86
+ md2word input.md -c my_config.json
87
+
88
+ # Add table of contents
89
+ md2word input.md --toc
90
+
91
+ # Custom TOC title and level
92
+ md2word input.md --toc --toc-title "Contents" --toc-level 4
93
+
94
+ # Generate default config file
95
+ md2word --init-config
96
+ ```
97
+
98
+ ### As a Python Library
99
+
100
+ ```python
101
+ import md2word
102
+
103
+ # Simple conversion
104
+ md2word.convert_file("input.md", "output.docx")
105
+
106
+ # With custom configuration
107
+ config = md2word.Config.from_file("config.json")
108
+ md2word.convert_file("input.md", "output.docx", config=config, toc=True)
109
+
110
+ # Convert from string
111
+ markdown_content = "# Hello World\n\nThis is a test."
112
+ md2word.convert(markdown_content, "output.docx")
113
+
114
+ # Programmatic configuration
115
+ config = md2word.Config()
116
+ config.default_font = "Arial"
117
+ config.styles["heading_1"] = md2word.StyleConfig(
118
+ font_name="Arial",
119
+ font_size=24,
120
+ bold=True,
121
+ alignment="center",
122
+ numbering_format="chapter",
123
+ )
124
+ md2word.convert_file("input.md", "output.docx", config=config)
125
+ ```
126
+
127
+ ## Configuration
128
+
129
+ Create a `config.json` file to customize document styles.
130
+
131
+ ### Example Configuration
132
+
133
+ ```json
134
+ {
135
+ "document": {
136
+ "default_font": "Arial",
137
+ "max_image_width_inches": 6.0
138
+ },
139
+ "styles": {
140
+ "heading_1": {
141
+ "font_name": "Arial",
142
+ "font_size": 24,
143
+ "bold": true,
144
+ "alignment": "center",
145
+ "line_spacing_rule": "exact",
146
+ "line_spacing_value": 28,
147
+ "numbering_format": "chapter"
148
+ },
149
+ "body": {
150
+ "font_name": "Times New Roman",
151
+ "font_size": 12,
152
+ "alignment": "justify",
153
+ "line_spacing_rule": "multiple",
154
+ "line_spacing_value": 1.5,
155
+ "first_line_indent": 2
156
+ }
157
+ }
158
+ }
159
+ ```
160
+
161
+ ### Style Properties
162
+
163
+ | Property | Type | Description |
164
+ |----------|------|-------------|
165
+ | `font_name` | string | Font name |
166
+ | `font_size` | number/string | Font size (points or Chinese size name) |
167
+ | `bold` | boolean | Bold text |
168
+ | `italic` | boolean | Italic text |
169
+ | `color` | string | Font color (hex, e.g., "000000") |
170
+ | `alignment` | string | Paragraph alignment: `left`/`center`/`right`/`justify` |
171
+ | `line_spacing_rule` | string | Line spacing mode (see below) |
172
+ | `line_spacing_value` | number | Line spacing value |
173
+ | `first_line_indent` | number | First line indent (in characters) |
174
+ | `left_indent` | float | Left indent (in inches) |
175
+ | `space_before` | number | Space before paragraph (points) |
176
+ | `space_after` | number | Space after paragraph (points) |
177
+ | `numbering_format` | string | Heading numbering format (see below) |
178
+
179
+ ### Line Spacing Modes
180
+
181
+ | Value | Description |
182
+ |-------|-------------|
183
+ | `single` | Single line spacing |
184
+ | `1.5` | 1.5 line spacing |
185
+ | `double` | Double line spacing |
186
+ | `multiple` | Multiple line spacing (use `line_spacing_value` as multiplier) |
187
+ | `exact` | Exact line spacing (use `line_spacing_value` in points) |
188
+ | `at_least` | Minimum line spacing (use `line_spacing_value` in points) |
189
+
190
+ ### Numbering Formats
191
+
192
+ | Format | Example |
193
+ |--------|---------|
194
+ | `chapter` | 第一章, 第二章, 第三章... |
195
+ | `section` | 第一节, 第二节, 第三节... |
196
+ | `chinese` | 一、二、三... |
197
+ | `chinese_paren` | (一)(二)(三)... |
198
+ | `arabic` | 1. 2. 3... |
199
+ | `arabic_paren` | (1) (2) (3)... |
200
+ | `arabic_bracket` | [1] [2] [3]... |
201
+ | `roman` | I. II. III... |
202
+ | `roman_lower` | i. ii. iii... |
203
+ | `letter` | A. B. C... |
204
+ | `letter_lower` | a. b. c... |
205
+ | `circle` | ① ② ③... |
206
+ | `none` | No numbering |
207
+
208
+ Custom format strings are also supported using `{n}` for Arabic numbers and `{cn}` for Chinese numbers.
209
+
210
+ ### Table Configuration
211
+
212
+ Configure table appearance in the `table` section:
213
+
214
+ ```json
215
+ {
216
+ "table": {
217
+ "border_style": "single",
218
+ "border_color": "000000",
219
+ "border_width": 4,
220
+ "header_background_color": "D9E2F3",
221
+ "cell_background_color": null,
222
+ "alternating_row_color": "F2F2F2",
223
+ "cell_padding_top": 2,
224
+ "cell_padding_bottom": 2,
225
+ "cell_padding_left": 5,
226
+ "cell_padding_right": 5,
227
+ "width_mode": "full",
228
+ "width_inches": null
229
+ }
230
+ }
231
+ ```
232
+
233
+ | Property | Type | Description |
234
+ |----------|------|-------------|
235
+ | `border_style` | string | Border style: `single`/`double`/`dotted`/`dashed`/`none` |
236
+ | `border_color` | string | Border color (hex, e.g., "000000") |
237
+ | `border_width` | number | Border width in 1/8 points (4 = 0.5pt, 8 = 1pt) |
238
+ | `header_background_color` | string | Header row background color (hex) |
239
+ | `cell_background_color` | string | Cell background color (hex) |
240
+ | `alternating_row_color` | string | Alternating row color for zebra striping (hex) |
241
+ | `cell_padding_*` | number | Cell padding in points (top/bottom/left/right) |
242
+ | `width_mode` | string | Table width mode: `auto`/`full`/`fixed` |
243
+ | `width_inches` | number | Fixed width in inches (when `width_mode` is "fixed") |
244
+
245
+ ### Chinese Font Sizes
246
+
247
+ | Name | Points | Name | Points |
248
+ |------|--------|------|--------|
249
+ | 初号 | 42 | 小初 | 36 |
250
+ | 一号 | 26 | 小一 | 24 |
251
+ | 二号 | 22 | 小二 | 18 |
252
+ | 三号 | 16 | 小三 | 15 |
253
+ | 四号 | 14 | 小四 | 12 |
254
+ | 五号 | 10.5 | 小五 | 9 |
255
+ | 六号 | 7.5 | 小六 | 6.5 |
256
+ | 七号 | 5.5 | 八号 | 5 |
257
+
258
+ ## Requirements
259
+
260
+ - Python >= 3.10
261
+ - markdown2
262
+ - python-docx
263
+ - html-for-docx
264
+ - httpx
265
+ - Pillow
266
+ - latex2mathml
267
+ - mathml2omml
268
+ - lxml
269
+
270
+ ## License
271
+
272
+ MIT
@@ -0,0 +1,235 @@
1
+ # md2word
2
+
3
+ [中文文档](README_zh.md) | English
4
+
5
+ Convert Markdown files to Word documents (.docx) with extensive customization options.
6
+
7
+ ## Features
8
+
9
+ - Convert Markdown to Word documents
10
+ - Support for tables, code blocks, images, and more
11
+ - Automatic download and embedding of web images
12
+ - Automatic conversion of unsupported image formats (e.g., WebP)
13
+ - LaTeX formula support (converted to native Word equations)
14
+ - Configurable styles for headings, body text, and other elements
15
+ - Chinese font size support (e.g., "四号", "小四")
16
+ - Automatic heading numbering with multiple formats
17
+ - Optional table of contents generation
18
+
19
+ ## Installation
20
+
21
+ ### Using uv (recommended)
22
+
23
+ ```bash
24
+ # Install globally
25
+ uv tool install md2word
26
+
27
+ # Or run directly without installation
28
+ uvx md2word input.md
29
+ ```
30
+
31
+ ### Using pip
32
+
33
+ ```bash
34
+ pip install md2word
35
+ ```
36
+
37
+ ## Usage
38
+
39
+ ### Command Line
40
+
41
+ ```bash
42
+ # Basic conversion (outputs input.docx)
43
+ md2word input.md
44
+
45
+ # Specify output file
46
+ md2word input.md -o output.docx
47
+
48
+ # Use custom config file
49
+ md2word input.md -c my_config.json
50
+
51
+ # Add table of contents
52
+ md2word input.md --toc
53
+
54
+ # Custom TOC title and level
55
+ md2word input.md --toc --toc-title "Contents" --toc-level 4
56
+
57
+ # Generate default config file
58
+ md2word --init-config
59
+ ```
60
+
61
+ ### As a Python Library
62
+
63
+ ```python
64
+ import md2word
65
+
66
+ # Simple conversion
67
+ md2word.convert_file("input.md", "output.docx")
68
+
69
+ # With custom configuration
70
+ config = md2word.Config.from_file("config.json")
71
+ md2word.convert_file("input.md", "output.docx", config=config, toc=True)
72
+
73
+ # Convert from string
74
+ markdown_content = "# Hello World\n\nThis is a test."
75
+ md2word.convert(markdown_content, "output.docx")
76
+
77
+ # Programmatic configuration
78
+ config = md2word.Config()
79
+ config.default_font = "Arial"
80
+ config.styles["heading_1"] = md2word.StyleConfig(
81
+ font_name="Arial",
82
+ font_size=24,
83
+ bold=True,
84
+ alignment="center",
85
+ numbering_format="chapter",
86
+ )
87
+ md2word.convert_file("input.md", "output.docx", config=config)
88
+ ```
89
+
90
+ ## Configuration
91
+
92
+ Create a `config.json` file to customize document styles.
93
+
94
+ ### Example Configuration
95
+
96
+ ```json
97
+ {
98
+ "document": {
99
+ "default_font": "Arial",
100
+ "max_image_width_inches": 6.0
101
+ },
102
+ "styles": {
103
+ "heading_1": {
104
+ "font_name": "Arial",
105
+ "font_size": 24,
106
+ "bold": true,
107
+ "alignment": "center",
108
+ "line_spacing_rule": "exact",
109
+ "line_spacing_value": 28,
110
+ "numbering_format": "chapter"
111
+ },
112
+ "body": {
113
+ "font_name": "Times New Roman",
114
+ "font_size": 12,
115
+ "alignment": "justify",
116
+ "line_spacing_rule": "multiple",
117
+ "line_spacing_value": 1.5,
118
+ "first_line_indent": 2
119
+ }
120
+ }
121
+ }
122
+ ```
123
+
124
+ ### Style Properties
125
+
126
+ | Property | Type | Description |
127
+ |----------|------|-------------|
128
+ | `font_name` | string | Font name |
129
+ | `font_size` | number/string | Font size (points or Chinese size name) |
130
+ | `bold` | boolean | Bold text |
131
+ | `italic` | boolean | Italic text |
132
+ | `color` | string | Font color (hex, e.g., "000000") |
133
+ | `alignment` | string | Paragraph alignment: `left`/`center`/`right`/`justify` |
134
+ | `line_spacing_rule` | string | Line spacing mode (see below) |
135
+ | `line_spacing_value` | number | Line spacing value |
136
+ | `first_line_indent` | number | First line indent (in characters) |
137
+ | `left_indent` | float | Left indent (in inches) |
138
+ | `space_before` | number | Space before paragraph (points) |
139
+ | `space_after` | number | Space after paragraph (points) |
140
+ | `numbering_format` | string | Heading numbering format (see below) |
141
+
142
+ ### Line Spacing Modes
143
+
144
+ | Value | Description |
145
+ |-------|-------------|
146
+ | `single` | Single line spacing |
147
+ | `1.5` | 1.5 line spacing |
148
+ | `double` | Double line spacing |
149
+ | `multiple` | Multiple line spacing (use `line_spacing_value` as multiplier) |
150
+ | `exact` | Exact line spacing (use `line_spacing_value` in points) |
151
+ | `at_least` | Minimum line spacing (use `line_spacing_value` in points) |
152
+
153
+ ### Numbering Formats
154
+
155
+ | Format | Example |
156
+ |--------|---------|
157
+ | `chapter` | 第一章, 第二章, 第三章... |
158
+ | `section` | 第一节, 第二节, 第三节... |
159
+ | `chinese` | 一、二、三... |
160
+ | `chinese_paren` | (一)(二)(三)... |
161
+ | `arabic` | 1. 2. 3... |
162
+ | `arabic_paren` | (1) (2) (3)... |
163
+ | `arabic_bracket` | [1] [2] [3]... |
164
+ | `roman` | I. II. III... |
165
+ | `roman_lower` | i. ii. iii... |
166
+ | `letter` | A. B. C... |
167
+ | `letter_lower` | a. b. c... |
168
+ | `circle` | ① ② ③... |
169
+ | `none` | No numbering |
170
+
171
+ Custom format strings are also supported using `{n}` for Arabic numbers and `{cn}` for Chinese numbers.
172
+
173
+ ### Table Configuration
174
+
175
+ Configure table appearance in the `table` section:
176
+
177
+ ```json
178
+ {
179
+ "table": {
180
+ "border_style": "single",
181
+ "border_color": "000000",
182
+ "border_width": 4,
183
+ "header_background_color": "D9E2F3",
184
+ "cell_background_color": null,
185
+ "alternating_row_color": "F2F2F2",
186
+ "cell_padding_top": 2,
187
+ "cell_padding_bottom": 2,
188
+ "cell_padding_left": 5,
189
+ "cell_padding_right": 5,
190
+ "width_mode": "full",
191
+ "width_inches": null
192
+ }
193
+ }
194
+ ```
195
+
196
+ | Property | Type | Description |
197
+ |----------|------|-------------|
198
+ | `border_style` | string | Border style: `single`/`double`/`dotted`/`dashed`/`none` |
199
+ | `border_color` | string | Border color (hex, e.g., "000000") |
200
+ | `border_width` | number | Border width in 1/8 points (4 = 0.5pt, 8 = 1pt) |
201
+ | `header_background_color` | string | Header row background color (hex) |
202
+ | `cell_background_color` | string | Cell background color (hex) |
203
+ | `alternating_row_color` | string | Alternating row color for zebra striping (hex) |
204
+ | `cell_padding_*` | number | Cell padding in points (top/bottom/left/right) |
205
+ | `width_mode` | string | Table width mode: `auto`/`full`/`fixed` |
206
+ | `width_inches` | number | Fixed width in inches (when `width_mode` is "fixed") |
207
+
208
+ ### Chinese Font Sizes
209
+
210
+ | Name | Points | Name | Points |
211
+ |------|--------|------|--------|
212
+ | 初号 | 42 | 小初 | 36 |
213
+ | 一号 | 26 | 小一 | 24 |
214
+ | 二号 | 22 | 小二 | 18 |
215
+ | 三号 | 16 | 小三 | 15 |
216
+ | 四号 | 14 | 小四 | 12 |
217
+ | 五号 | 10.5 | 小五 | 9 |
218
+ | 六号 | 7.5 | 小六 | 6.5 |
219
+ | 七号 | 5.5 | 八号 | 5 |
220
+
221
+ ## Requirements
222
+
223
+ - Python >= 3.10
224
+ - markdown2
225
+ - python-docx
226
+ - html-for-docx
227
+ - httpx
228
+ - Pillow
229
+ - latex2mathml
230
+ - mathml2omml
231
+ - lxml
232
+
233
+ ## License
234
+
235
+ MIT