markdocx 2.0.0__tar.gz → 3.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.
@@ -1,12 +1,12 @@
1
- # Python-generated files
2
- __pycache__/
3
- *.py[oc]
4
- build/
5
- dist/
6
- wheels/
7
- *.egg-info
8
-
9
- # Virtual environments
10
- .venv
11
-
12
-
1
+ # Python-generated files
2
+ __pycache__/
3
+ *.py[oc]
4
+ build/
5
+ dist/
6
+ wheels/
7
+ *.egg-info
8
+
9
+ # Virtual environments
10
+ .venv
11
+
12
+
@@ -1 +1 @@
1
- 3.14
1
+ 3.14
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 shynneri
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.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 shynneri
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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: markdocx
3
- Version: 2.0.0
3
+ Version: 3.0.0
4
4
  Summary: Convert AI-generated Markdown textbooks to polished DOCX with native math equations and syntax-highlighted code
5
5
  License-Expression: MIT
6
6
  License-File: LICENSE
@@ -10,6 +10,7 @@ Requires-Dist: lxml==6.0.2
10
10
  Requires-Dist: markdown-it-py==4.0.0
11
11
  Requires-Dist: matplotlib==3.10.8
12
12
  Requires-Dist: mdit-py-plugins==0.5.0
13
+ Requires-Dist: networkx>=3.6.1
13
14
  Requires-Dist: pillow==12.1.0
14
15
  Requires-Dist: pygments==2.19.2
15
16
  Requires-Dist: python-docx==1.2.0
@@ -39,7 +40,7 @@ Large language models (ChatGPT, Claude, Gemini, …) produce great Markdown, but
39
40
  - Code blocks lose their highlighting
40
41
  - Tables, lists, and blockquotes need manual reformatting
41
42
 
42
- **markdocx** bridges that gap. Feed it a Markdown file that follows a few simple rules and get a publication-ready `.docx` — math rendered as native Word OMML equations, code with VS Code–style colors, and everything else properly formatted.
43
+ **markdocx** bridges that gap. Feed it a Markdown file that follows a few simple rules and get a publication-ready `.docx` — math rendered as native Word OMML equations, code with VS Code–style colors, diagrams rendered as images, and everything else properly formatted.
43
44
 
44
45
  ## Features
45
46
 
@@ -49,6 +50,10 @@ Large language models (ChatGPT, Claude, Gemini, …) produce great Markdown, but
49
50
  | **Code** | 30+ languages with Pygments syntax highlighting, VS Code light theme, language labels |
50
51
  | **Tables** | Auto-formatted Table Grid — bold header row, left/center/right alignment, inline math in cells |
51
52
  | **Lists** | Bullet (•◦▪) and numbered lists, up to 6 nesting levels |
53
+ | **Matrix** | `\`\`\`matrix` blocks → visual matrix diagrams with brackets, labels, and captions |
54
+ | **Charts** | `\`\`\`chart` blocks → bar, line, pie, and scatter charts via matplotlib |
55
+ | **Graphs** | `\`\`\`graph` blocks → network/graph diagrams with weighted edges via networkx |
56
+ | **Workflows** | `\`\`\`workflow` blocks → flowcharts with decision diamonds, process boxes, and arrows |
52
57
  | **Other** | Blockquotes, horizontal rules, clickable hyperlinks, local images, footnotes |
53
58
 
54
59
  ## Quick Start
@@ -124,9 +129,10 @@ Markdown file
124
129
 
125
130
 
126
131
  docx_builder.py ─── walks the token stream, builds Word elements
127
- ├── math_renderer.py ─── LaTeX → MathML → OMML (native Word equations)
128
- ├── code_renderer.py ─── Pygments lexer → colored Word runs
129
- └── styles.py ─── fonts, colors, spacing presets
132
+ ├── math_renderer.py ─── LaTeX → MathML → OMML (native Word equations)
133
+ ├── code_renderer.py ─── Pygments lexer → colored Word runs
134
+ ├── diagram_renderer.py ─── matrix / chart / graph / workflow → PNG images
135
+ └── styles.py ─── fonts, colors, spacing presets
130
136
 
131
137
 
132
138
  .docx file ─── python-docx output
@@ -146,6 +152,55 @@ LaTeX string → latex2mathml → MathML → XSLT → OMML → Word paragraph
146
152
  Source code → Pygments lexer + VS Code theme → colored Word runs inside a shaded table cell
147
153
  ```
148
154
 
155
+ ### Diagram Pipeline
156
+
157
+ Fenced code blocks with special language identifiers (`matrix`, `chart`, `graph`, `workflow`) are rendered as PNG images via matplotlib/networkx and embedded in the document.
158
+
159
+ ````markdown
160
+ ```matrix
161
+ name: A
162
+ 1 2 3
163
+ 4 5 6
164
+ 7 8 9
165
+ caption: Matrix A (3×3)
166
+ ```
167
+
168
+ ```chart
169
+ type: bar
170
+ title: Algorithm Performance
171
+ labels: Bubble Sort, Merge Sort, Quick Sort
172
+ Time (ms): 450, 38, 35
173
+ caption: Figure 1: Sorting comparison
174
+ ```
175
+
176
+ ```graph
177
+ directed: true
178
+ title: Shortest Path
179
+ A -> B: 5
180
+ B -> C: 3
181
+ A -> C: 7
182
+ caption: Figure 2: Weighted directed graph
183
+ ```
184
+
185
+ ```workflow
186
+ title: Login Process
187
+ [Start]
188
+ <User Input>
189
+ (Validate Credentials)
190
+ {Valid?}
191
+ (Grant Access)
192
+ [End]
193
+ caption: Figure 3: Authentication workflow
194
+ ```
195
+ ````
196
+
197
+ | Block type | Formats | Rendered via |
198
+ |:-----------|:--------|:-------------|
199
+ | `matrix` | Simple text or JSON | matplotlib |
200
+ | `chart` | Simple key-value or JSON — bar, line, pie, scatter | matplotlib |
201
+ | `graph` | Edge list (`A -> B: 5`) or JSON — directed/undirected | matplotlib + networkx |
202
+ | `workflow` | Step notation (`[Start]`, `(Process)`, `{Decision}`, `<I/O>`) or JSON | matplotlib |
203
+
149
204
  ## Project Structure
150
205
 
151
206
  ```
@@ -158,10 +213,11 @@ markdocx/
158
213
  │ ├── cli.py # CLI entry point (markdocx command)
159
214
  │ ├── core.py # Top-level orchestrator
160
215
  │ ├── md_parser.py # Markdown → token stream
161
- │ ├── math_renderer.py # LaTeX → OMML (native Word math)
162
- │ ├── code_renderer.py # Code → syntax-highlighted Word runs
163
- │ ├── docx_builder.py # Token streamDOCX elements
164
- └── styles.py # Fonts, colors, and layout presets
216
+ │ ├── math_renderer.py # LaTeX → OMML (native Word math)
217
+ │ ├── code_renderer.py # Code → syntax-highlighted Word runs
218
+ │ ├── diagram_renderer.py # Matrix / Chart / Graph / Workflow PNG
219
+ ├── docx_builder.py # Token stream DOCX elements
220
+ │ └── styles.py # Fonts, colors, and layout presets
165
221
  └── rule/
166
222
  ├── ai_gen_doc_rule.md # AI writing rules (Vietnamese)
167
223
  └── ai_gen_doc_rule_en.md # AI writing rules (English)
@@ -177,8 +233,9 @@ markdocx/
177
233
  | [latex2mathml](https://github.com/roniemartinez/latex2mathml) | 3.78.1 | LaTeX → MathML conversion |
178
234
  | [lxml](https://lxml.de/) | 6.0.2 | XML/XSLT processing |
179
235
  | [Pygments](https://pygments.org/) | 2.19.2 | Syntax highlighting |
180
- | [matplotlib](https://matplotlib.org/) | 3.10.8 | LaTeX rendering (fallback) |
236
+ | [matplotlib](https://matplotlib.org/) | 3.10.8 | Chart, matrix, workflow rendering |
181
237
  | [Pillow](https://python-pillow.org/) | 12.1.0 | Image processing |
238
+ | [networkx](https://networkx.org/) | 3.4+ | Graph/network diagram layouts |
182
239
 
183
240
  ## AI Writing Rules
184
241
 
@@ -1,189 +1,245 @@
1
- <div align="center">
2
-
3
- # markdocx
4
-
5
- **A Markdown-to-Word converter built for AI-generated textbooks**
6
-
7
- Convert Markdown files — complete with LaTeX math, syntax-highlighted code, tables, and images — into polished `.docx` documents in one command.
8
-
9
- [![PyPI](https://img.shields.io/pypi/v/markdocx.svg)](https://pypi.org/project/markdocx/)
10
- [![Python 3.10+](https://img.shields.io/badge/python-3.10%2B-blue.svg)](https://www.python.org/downloads/)
11
- [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
12
-
13
- </div>
14
-
15
- ---
16
-
17
- ## Why This Exists
18
-
19
- Large language models (ChatGPT, Claude, Gemini, …) produce great Markdown, but the journey from `.md` to a well-formatted **Word document** is painful:
20
-
21
- - LaTeX formulas become plain text or broken images
22
- - Code blocks lose their highlighting
23
- - Tables, lists, and blockquotes need manual reformatting
24
-
25
- **markdocx** bridges that gap. Feed it a Markdown file that follows a few simple rules and get a publication-ready `.docx` — math rendered as native Word OMML equations, code with VS Code–style colors, and everything else properly formatted.
26
-
27
- ## Features
28
-
29
- | Category | What you get |
30
- |:---------|:-------------|
31
- | **Math** | Inline (`$...$`) and display (`$$...$$`) LaTeX → native OMML equations in Word |
32
- | **Code** | 30+ languages with Pygments syntax highlighting, VS Code light theme, language labels |
33
- | **Tables** | Auto-formatted Table Grid — bold header row, left/center/right alignment, inline math in cells |
34
- | **Lists** | Bullet (•◦▪) and numbered lists, up to 6 nesting levels |
35
- | **Other** | Blockquotes, horizontal rules, clickable hyperlinks, local images, footnotes |
36
-
37
- ## Quick Start
38
-
39
- ### Installation
40
-
41
- ```bash
42
- # Using uv (recommended)
43
- uv add markdocx
44
-
45
- # Or using pip
46
- pip install markdocx
47
- ```
48
-
49
- <details>
50
- <summary>Install from source (for development)</summary>
51
-
52
- ```bash
53
- git clone https://github.com/shynerri-source/markdocx.git
54
- cd markdocx
55
- uv sync # or: pip install -e .
56
- ```
57
-
58
- </details>
59
-
60
- ### Usage
61
-
62
- #### CLI
63
-
64
- ```bash
65
- # Convert a single file
66
- markdocx input.md
67
- markdocx input.md -o output.docx
68
-
69
- # Convert an entire directory
70
- markdocx ./chapters/ -o ./output/
71
-
72
- # Recursively search subdirectories
73
- markdocx ./chapters/ -o ./output/ -r
74
-
75
- # Verbose logging
76
- markdocx input.md -v
77
- ```
78
-
79
- #### Python API
80
-
81
- ```python
82
- from markdocx import convert_file, convert_directory
83
-
84
- # Single file
85
- convert_file("input.md", "output.docx")
86
-
87
- # Entire directory
88
- results = convert_directory("./chapters/", output_dir="./output/", recursive=True)
89
- ```
90
-
91
- ### CLI Options
92
-
93
- | Flag | Description |
94
- |:-----|:------------|
95
- | `input` | Markdown file or directory to convert |
96
- | `-o, --output` | Output file or directory path |
97
- | `-r, --recursive` | Recursively find `.md` files in subdirectories |
98
- | `-v, --verbose` | Show detailed processing logs |
99
-
100
- ## How It Works
101
-
102
- ```
103
- Markdown file
104
-
105
-
106
- md_parser.py ─── markdown-it-py tokenizer
107
-
108
-
109
- docx_builder.py ─── walks the token stream, builds Word elements
110
- ├── math_renderer.py ─── LaTeX → MathML → OMML (native Word equations)
111
- ├── code_renderer.py ─── Pygments lexer → colored Word runs
112
- └── styles.py ─── fonts, colors, spacing presets
113
-
114
-
115
- .docx file ─── python-docx output
116
- ```
117
-
118
- ### Math Pipeline
119
-
120
- LaTeX is converted to **native OMML** (Office Math Markup Language), not images. This means formulas are editable, scale perfectly, and look like they were typed in Word's equation editor.
121
-
122
- ```
123
- LaTeX string → latex2mathml → MathML → XSLT → OMML → Word paragraph
124
- ```
125
-
126
- ### Code Pipeline
127
-
128
- ```
129
- Source code → Pygments lexer + VS Code theme → colored Word runs inside a shaded table cell
130
- ```
131
-
132
- ## Project Structure
133
-
134
- ```
135
- markdocx/
136
- ├── main.py # Convenience entry point
137
- ├── pyproject.toml # Project metadata & dependencies
138
- ├── src/
139
- │ └── markdocx/ # Installable package
140
- │ ├── __init__.py # Public API (convert_file, convert_directory)
141
- │ ├── cli.py # CLI entry point (markdocx command)
142
- │ ├── core.py # Top-level orchestrator
143
- │ ├── md_parser.py # Markdown → token stream
144
- │ ├── math_renderer.py # LaTeX → OMML (native Word math)
145
- │ ├── code_renderer.py # Code → syntax-highlighted Word runs
146
- │ ├── docx_builder.py # Token stream → DOCX elements
147
- │ └── styles.py # Fonts, colors, and layout presets
148
- └── rule/
149
- ├── ai_gen_doc_rule.md # AI writing rules (Vietnamese)
150
- └── ai_gen_doc_rule_en.md # AI writing rules (English)
151
- ```
152
-
153
- ## Dependencies
154
-
155
- | Package | Version | Role |
156
- |:--------|:--------|:-----|
157
- | [python-docx](https://python-docx.readthedocs.io/) | 1.2.0 | DOCX generation |
158
- | [markdown-it-py](https://github.com/executablebooks/markdown-it-py) | 4.0.0 | Markdown parsing |
159
- | [mdit-py-plugins](https://github.com/executablebooks/mdit-py-plugins) | 0.5.0 | Math & footnote plugins |
160
- | [latex2mathml](https://github.com/roniemartinez/latex2mathml) | 3.78.1 | LaTeX → MathML conversion |
161
- | [lxml](https://lxml.de/) | 6.0.2 | XML/XSLT processing |
162
- | [Pygments](https://pygments.org/) | 2.19.2 | Syntax highlighting |
163
- | [matplotlib](https://matplotlib.org/) | 3.10.8 | LaTeX rendering (fallback) |
164
- | [Pillow](https://python-pillow.org/) | 12.1.0 | Image processing |
165
-
166
- ## AI Writing Rules
167
-
168
- The `rule/` directory contains detailed guidelines for prompting AI models to produce Markdown that converts cleanly:
169
-
170
- | File | Language | Description |
171
- |:-----|:---------|:------------|
172
- | `rule/ai_gen_doc_rule.md` | Vietnamese | Full rule set — heading structure, LaTeX constraints, code block format, tables, etc. |
173
- | `rule/ai_gen_doc_rule_en.md` | English | Same rules, English version |
174
-
175
- **How to use:** Paste the contents of the appropriate rule file into your AI system prompt (or at the start of the conversation) before asking it to write textbook content.
176
-
177
- ## Contributing
178
-
179
- Contributions are welcome. Please open an issue first to discuss what you'd like to change.
180
-
181
- 1. Fork the repository
182
- 2. Create a feature branch (`git checkout -b feature/amazing-feature`)
183
- 3. Commit your changes (`git commit -m 'Add amazing feature'`)
184
- 4. Push to the branch (`git push origin feature/amazing-feature`)
185
- 5. Open a Pull Request
186
-
187
- ## License
188
-
189
- This project is licensed under the MIT License — see the [LICENSE](LICENSE) file for details.
1
+ <div align="center">
2
+
3
+ # markdocx
4
+
5
+ **A Markdown-to-Word converter built for AI-generated textbooks**
6
+
7
+ Convert Markdown files — complete with LaTeX math, syntax-highlighted code, tables, and images — into polished `.docx` documents in one command.
8
+
9
+ [![PyPI](https://img.shields.io/pypi/v/markdocx.svg)](https://pypi.org/project/markdocx/)
10
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10%2B-blue.svg)](https://www.python.org/downloads/)
11
+ [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
12
+
13
+ </div>
14
+
15
+ ---
16
+
17
+ ## Why This Exists
18
+
19
+ Large language models (ChatGPT, Claude, Gemini, …) produce great Markdown, but the journey from `.md` to a well-formatted **Word document** is painful:
20
+
21
+ - LaTeX formulas become plain text or broken images
22
+ - Code blocks lose their highlighting
23
+ - Tables, lists, and blockquotes need manual reformatting
24
+
25
+ **markdocx** bridges that gap. Feed it a Markdown file that follows a few simple rules and get a publication-ready `.docx` — math rendered as native Word OMML equations, code with VS Code–style colors, diagrams rendered as images, and everything else properly formatted.
26
+
27
+ ## Features
28
+
29
+ | Category | What you get |
30
+ |:---------|:-------------|
31
+ | **Math** | Inline (`$...$`) and display (`$$...$$`) LaTeX → native OMML equations in Word |
32
+ | **Code** | 30+ languages with Pygments syntax highlighting, VS Code light theme, language labels |
33
+ | **Tables** | Auto-formatted Table Grid — bold header row, left/center/right alignment, inline math in cells |
34
+ | **Lists** | Bullet (•◦▪) and numbered lists, up to 6 nesting levels |
35
+ | **Matrix** | `\`\`\`matrix` blocks visual matrix diagrams with brackets, labels, and captions |
36
+ | **Charts** | `\`\`\`chart` blocks → bar, line, pie, and scatter charts via matplotlib |
37
+ | **Graphs** | `\`\`\`graph` blocks → network/graph diagrams with weighted edges via networkx |
38
+ | **Workflows** | `\`\`\`workflow` blocks → flowcharts with decision diamonds, process boxes, and arrows |
39
+ | **Other** | Blockquotes, horizontal rules, clickable hyperlinks, local images, footnotes |
40
+
41
+ ## Quick Start
42
+
43
+ ### Installation
44
+
45
+ ```bash
46
+ # Using uv (recommended)
47
+ uv add markdocx
48
+
49
+ # Or using pip
50
+ pip install markdocx
51
+ ```
52
+
53
+ <details>
54
+ <summary>Install from source (for development)</summary>
55
+
56
+ ```bash
57
+ git clone https://github.com/shynerri-source/markdocx.git
58
+ cd markdocx
59
+ uv sync # or: pip install -e .
60
+ ```
61
+
62
+ </details>
63
+
64
+ ### Usage
65
+
66
+ #### CLI
67
+
68
+ ```bash
69
+ # Convert a single file
70
+ markdocx input.md
71
+ markdocx input.md -o output.docx
72
+
73
+ # Convert an entire directory
74
+ markdocx ./chapters/ -o ./output/
75
+
76
+ # Recursively search subdirectories
77
+ markdocx ./chapters/ -o ./output/ -r
78
+
79
+ # Verbose logging
80
+ markdocx input.md -v
81
+ ```
82
+
83
+ #### Python API
84
+
85
+ ```python
86
+ from markdocx import convert_file, convert_directory
87
+
88
+ # Single file
89
+ convert_file("input.md", "output.docx")
90
+
91
+ # Entire directory
92
+ results = convert_directory("./chapters/", output_dir="./output/", recursive=True)
93
+ ```
94
+
95
+ ### CLI Options
96
+
97
+ | Flag | Description |
98
+ |:-----|:------------|
99
+ | `input` | Markdown file or directory to convert |
100
+ | `-o, --output` | Output file or directory path |
101
+ | `-r, --recursive` | Recursively find `.md` files in subdirectories |
102
+ | `-v, --verbose` | Show detailed processing logs |
103
+
104
+ ## How It Works
105
+
106
+ ```
107
+ Markdown file
108
+
109
+
110
+ md_parser.py ─── markdown-it-py tokenizer
111
+
112
+
113
+ docx_builder.py ─── walks the token stream, builds Word elements
114
+ ├── math_renderer.py ─── LaTeX → MathML → OMML (native Word equations)
115
+ ├── code_renderer.py ─── Pygments lexer → colored Word runs
116
+ ├── diagram_renderer.py ─── matrix / chart / graph / workflow → PNG images
117
+ └── styles.py ─── fonts, colors, spacing presets
118
+
119
+
120
+ .docx file ─── python-docx output
121
+ ```
122
+
123
+ ### Math Pipeline
124
+
125
+ LaTeX is converted to **native OMML** (Office Math Markup Language), not images. This means formulas are editable, scale perfectly, and look like they were typed in Word's equation editor.
126
+
127
+ ```
128
+ LaTeX string → latex2mathml → MathML → XSLT → OMML → Word paragraph
129
+ ```
130
+
131
+ ### Code Pipeline
132
+
133
+ ```
134
+ Source code → Pygments lexer + VS Code theme → colored Word runs inside a shaded table cell
135
+ ```
136
+
137
+ ### Diagram Pipeline
138
+
139
+ Fenced code blocks with special language identifiers (`matrix`, `chart`, `graph`, `workflow`) are rendered as PNG images via matplotlib/networkx and embedded in the document.
140
+
141
+ ````markdown
142
+ ```matrix
143
+ name: A
144
+ 1 2 3
145
+ 4 5 6
146
+ 7 8 9
147
+ caption: Matrix A (3×3)
148
+ ```
149
+
150
+ ```chart
151
+ type: bar
152
+ title: Algorithm Performance
153
+ labels: Bubble Sort, Merge Sort, Quick Sort
154
+ Time (ms): 450, 38, 35
155
+ caption: Figure 1: Sorting comparison
156
+ ```
157
+
158
+ ```graph
159
+ directed: true
160
+ title: Shortest Path
161
+ A -> B: 5
162
+ B -> C: 3
163
+ A -> C: 7
164
+ caption: Figure 2: Weighted directed graph
165
+ ```
166
+
167
+ ```workflow
168
+ title: Login Process
169
+ [Start]
170
+ <User Input>
171
+ (Validate Credentials)
172
+ {Valid?}
173
+ (Grant Access)
174
+ [End]
175
+ caption: Figure 3: Authentication workflow
176
+ ```
177
+ ````
178
+
179
+ | Block type | Formats | Rendered via |
180
+ |:-----------|:--------|:-------------|
181
+ | `matrix` | Simple text or JSON | matplotlib |
182
+ | `chart` | Simple key-value or JSON bar, line, pie, scatter | matplotlib |
183
+ | `graph` | Edge list (`A -> B: 5`) or JSON — directed/undirected | matplotlib + networkx |
184
+ | `workflow` | Step notation (`[Start]`, `(Process)`, `{Decision}`, `<I/O>`) or JSON | matplotlib |
185
+
186
+ ## Project Structure
187
+
188
+ ```
189
+ markdocx/
190
+ ├── main.py # Convenience entry point
191
+ ├── pyproject.toml # Project metadata & dependencies
192
+ ├── src/
193
+ │ └── markdocx/ # Installable package
194
+ │ ├── __init__.py # Public API (convert_file, convert_directory)
195
+ │ ├── cli.py # CLI entry point (markdocx command)
196
+ │ ├── core.py # Top-level orchestrator
197
+ │ ├── md_parser.py # Markdown → token stream
198
+ │ ├── math_renderer.py # LaTeX → OMML (native Word math)
199
+ │ ├── code_renderer.py # Code → syntax-highlighted Word runs
200
+ │ ├── diagram_renderer.py # Matrix / Chart / Graph / Workflow → PNG
201
+ │ ├── docx_builder.py # Token stream → DOCX elements
202
+ │ └── styles.py # Fonts, colors, and layout presets
203
+ └── rule/
204
+ ├── ai_gen_doc_rule.md # AI writing rules (Vietnamese)
205
+ └── ai_gen_doc_rule_en.md # AI writing rules (English)
206
+ ```
207
+
208
+ ## Dependencies
209
+
210
+ | Package | Version | Role |
211
+ |:--------|:--------|:-----|
212
+ | [python-docx](https://python-docx.readthedocs.io/) | 1.2.0 | DOCX generation |
213
+ | [markdown-it-py](https://github.com/executablebooks/markdown-it-py) | 4.0.0 | Markdown parsing |
214
+ | [mdit-py-plugins](https://github.com/executablebooks/mdit-py-plugins) | 0.5.0 | Math & footnote plugins |
215
+ | [latex2mathml](https://github.com/roniemartinez/latex2mathml) | 3.78.1 | LaTeX → MathML conversion |
216
+ | [lxml](https://lxml.de/) | 6.0.2 | XML/XSLT processing |
217
+ | [Pygments](https://pygments.org/) | 2.19.2 | Syntax highlighting |
218
+ | [matplotlib](https://matplotlib.org/) | 3.10.8 | Chart, matrix, workflow rendering |
219
+ | [Pillow](https://python-pillow.org/) | 12.1.0 | Image processing |
220
+ | [networkx](https://networkx.org/) | 3.4+ | Graph/network diagram layouts |
221
+
222
+ ## AI Writing Rules
223
+
224
+ The `rule/` directory contains detailed guidelines for prompting AI models to produce Markdown that converts cleanly:
225
+
226
+ | File | Language | Description |
227
+ |:-----|:---------|:------------|
228
+ | `rule/ai_gen_doc_rule.md` | Vietnamese | Full rule set — heading structure, LaTeX constraints, code block format, tables, etc. |
229
+ | `rule/ai_gen_doc_rule_en.md` | English | Same rules, English version |
230
+
231
+ **How to use:** Paste the contents of the appropriate rule file into your AI system prompt (or at the start of the conversation) before asking it to write textbook content.
232
+
233
+ ## Contributing
234
+
235
+ Contributions are welcome. Please open an issue first to discuss what you'd like to change.
236
+
237
+ 1. Fork the repository
238
+ 2. Create a feature branch (`git checkout -b feature/amazing-feature`)
239
+ 3. Commit your changes (`git commit -m 'Add amazing feature'`)
240
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
241
+ 5. Open a Pull Request
242
+
243
+ ## License
244
+
245
+ This project is licensed under the MIT License — see the [LICENSE](LICENSE) file for details.