md-doc-converter 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- md_doc_converter-1.0.0/LICENSE +21 -0
- md_doc_converter-1.0.0/PKG-INFO +267 -0
- md_doc_converter-1.0.0/README.md +238 -0
- md_doc_converter-1.0.0/pyproject.toml +172 -0
- md_doc_converter-1.0.0/pyproject.toml.orig +153 -0
- md_doc_converter-1.0.0/src/md_doc_converter/__init__.py +1 -0
- md_doc_converter-1.0.0/src/md_doc_converter/__main__.py +101 -0
- md_doc_converter-1.0.0/src/md_doc_converter/assets/gfm-math.lua +34 -0
- md_doc_converter-1.0.0/src/md_doc_converter/assets/heading-ids.lua +14 -0
- md_doc_converter-1.0.0/src/md_doc_converter/assets/katex-render.mjs +32 -0
- md_doc_converter-1.0.0/src/md_doc_converter/assets/katex.lua +78 -0
- md_doc_converter-1.0.0/src/md_doc_converter/assets/markdown-body-close.html +1 -0
- md_doc_converter-1.0.0/src/md_doc_converter/assets/markdown-body-open.html +1 -0
- md_doc_converter-1.0.0/src/md_doc_converter/assets/mermaid-config.json +21 -0
- md_doc_converter-1.0.0/src/md_doc_converter/assets/mermaid.lua +291 -0
- md_doc_converter-1.0.0/src/md_doc_converter/assets/pandoc-defaults.yaml +28 -0
- md_doc_converter-1.0.0/src/md_doc_converter/assets/strip-colwidths.lua +9 -0
- md_doc_converter-1.0.0/src/md_doc_converter/assets/style-overrides.css +174 -0
- md_doc_converter-1.0.0/src/md_doc_converter/assets/table-code-pipes.lua +10 -0
- md_doc_converter-1.0.0/src/md_doc_converter/console.py +241 -0
- md_doc_converter-1.0.0/src/md_doc_converter/converters/__init__.py +1 -0
- md_doc_converter-1.0.0/src/md_doc_converter/converters/csv.py +158 -0
- md_doc_converter-1.0.0/src/md_doc_converter/converters/docx/__init__.py +1 -0
- md_doc_converter-1.0.0/src/md_doc_converter/converters/docx/bookmarks.py +156 -0
- md_doc_converter-1.0.0/src/md_doc_converter/converters/docx/cli.py +118 -0
- md_doc_converter-1.0.0/src/md_doc_converter/converters/docx/diagnostics.py +237 -0
- md_doc_converter-1.0.0/src/md_doc_converter/converters/docx/media.py +1104 -0
- md_doc_converter-1.0.0/src/md_doc_converter/converters/docx/models.py +136 -0
- md_doc_converter-1.0.0/src/md_doc_converter/converters/docx/navigation.py +448 -0
- md_doc_converter-1.0.0/src/md_doc_converter/converters/docx/normalization.py +421 -0
- md_doc_converter-1.0.0/src/md_doc_converter/converters/docx/ooxml.py +1953 -0
- md_doc_converter-1.0.0/src/md_doc_converter/converters/docx/package.py +113 -0
- md_doc_converter-1.0.0/src/md_doc_converter/converters/docx/pipeline.py +268 -0
- md_doc_converter-1.0.0/src/md_doc_converter/converters/docx/prepare.py +1744 -0
- md_doc_converter-1.0.0/src/md_doc_converter/converters/docx/publication.py +351 -0
- md_doc_converter-1.0.0/src/md_doc_converter/converters/docx/reference.py +545 -0
- md_doc_converter-1.0.0/src/md_doc_converter/converters/docx/tables.py +768 -0
- md_doc_converter-1.0.0/src/md_doc_converter/converters/docx/timings.py +131 -0
- md_doc_converter-1.0.0/src/md_doc_converter/converters/docx/transforms.py +883 -0
- md_doc_converter-1.0.0/src/md_doc_converter/converters/docx/tree.py +304 -0
- md_doc_converter-1.0.0/src/md_doc_converter/converters/docx/validation.py +205 -0
- md_doc_converter-1.0.0/src/md_doc_converter/converters/excel.py +354 -0
- md_doc_converter-1.0.0/src/md_doc_converter/converters/packages.py +35 -0
- md_doc_converter-1.0.0/src/md_doc_converter/download.py +49 -0
- md_doc_converter-1.0.0/src/md_doc_converter/executables.py +94 -0
- md_doc_converter-1.0.0/src/md_doc_converter/gitignore.py +104 -0
- md_doc_converter-1.0.0/src/md_doc_converter/markdown/__init__.py +1 -0
- md_doc_converter-1.0.0/src/md_doc_converter/markdown/document.py +255 -0
- md_doc_converter-1.0.0/src/md_doc_converter/markdown/file_paths.py +38 -0
- md_doc_converter-1.0.0/src/md_doc_converter/markdown/headings.py +201 -0
- md_doc_converter-1.0.0/src/md_doc_converter/markdown/preprocess.py +1061 -0
- md_doc_converter-1.0.0/src/md_doc_converter/markdown/syntax.py +269 -0
- md_doc_converter-1.0.0/src/md_doc_converter/markdown/tables.py +132 -0
- md_doc_converter-1.0.0/src/md_doc_converter/media_types.py +15 -0
- md_doc_converter-1.0.0/src/md_doc_converter/pandoc.py +143 -0
- md_doc_converter-1.0.0/src/md_doc_converter/rendering/__init__.py +1 -0
- md_doc_converter-1.0.0/src/md_doc_converter/rendering/header.py +27 -0
- md_doc_converter-1.0.0/src/md_doc_converter/rendering/pipeline.py +614 -0
- md_doc_converter-1.0.0/src/md_doc_converter/rendering/print-pdf.mjs +202 -0
- md_doc_converter-1.0.0/src/md_doc_converter/resources.py +21 -0
- md_doc_converter-1.0.0/src/md_doc_converter/toolchain/.npmrc +4 -0
- md_doc_converter-1.0.0/src/md_doc_converter/toolchain/__init__.py +1 -0
- md_doc_converter-1.0.0/src/md_doc_converter/toolchain/checks.py +343 -0
- md_doc_converter-1.0.0/src/md_doc_converter/toolchain/environment.py +211 -0
- md_doc_converter-1.0.0/src/md_doc_converter/toolchain/install.py +309 -0
- md_doc_converter-1.0.0/src/md_doc_converter/toolchain/package-lock.json +2374 -0
- md_doc_converter-1.0.0/src/md_doc_converter/toolchain/package.json +17 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Patrick Creighton
|
|
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.
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: md-doc-converter
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Convert Word, Excel and CSV documents to Markdown, and render Markdown to HTML and PDF
|
|
5
|
+
Keywords: markdown,docx,excel,csv,pdf,html,pandoc,mermaid,katex
|
|
6
|
+
Author: Patrick Creighton
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
10
|
+
Classifier: Environment :: Console
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
13
|
+
Classifier: Operating System :: MacOS
|
|
14
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
15
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
19
|
+
Classifier: Topic :: Office/Business
|
|
20
|
+
Classifier: Topic :: Text Processing :: Markup :: HTML
|
|
21
|
+
Classifier: Topic :: Text Processing :: Markup :: Markdown
|
|
22
|
+
Requires-Dist: openpyxl>=3.1.5
|
|
23
|
+
Requires-Python: >=3.15, <3.16
|
|
24
|
+
Project-URL: Repository, https://github.com/patrick-5546/md-doc-converter
|
|
25
|
+
Project-URL: Documentation, https://github.com/patrick-5546/md-doc-converter#readme
|
|
26
|
+
Project-URL: Issues, https://github.com/patrick-5546/md-doc-converter/issues
|
|
27
|
+
Project-URL: Changelog, https://github.com/patrick-5546/md-doc-converter/releases
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
# md-doc-converter
|
|
31
|
+
|
|
32
|
+
Convert Word, Excel and CSV documents to Markdown, and render Markdown to HTML
|
|
33
|
+
and PDF.
|
|
34
|
+
|
|
35
|
+
- **Word to Markdown:** converts with [Pandoc](https://pandoc.org/), keeping
|
|
36
|
+
images with their captions as alt text, tables, lists, links, bookmarks,
|
|
37
|
+
footnotes, equations and heading levels as Markdown can show them.
|
|
38
|
+
- **Excel and CSV to Markdown:** a table page per worksheet or CSV file, with
|
|
39
|
+
cell contents kept literal.
|
|
40
|
+
- **Markdown to HTML and PDF:** one file or a whole folder, with Mermaid
|
|
41
|
+
diagrams, KaTeX math, GitHub-style tables and code, heading bookmarks, page
|
|
42
|
+
numbers and optional header and footer text. The HTML is self-contained.
|
|
43
|
+
|
|
44
|
+
## Requirements
|
|
45
|
+
|
|
46
|
+
- Linux x86_64, macOS arm64 (Apple silicon) or Windows x86_64.
|
|
47
|
+
- Python 3.15. uv installs it if needed; on a host that cannot reach GitHub,
|
|
48
|
+
where uv downloads Python from, install Python 3.15 another way.
|
|
49
|
+
- [Node.js](https://nodejs.org/) 22.13 or newer, with npm, for rendering.
|
|
50
|
+
- Optional: LibreOffice 7.4 or newer (`libreoffice` or `soffice`, or where its
|
|
51
|
+
installer puts it on macOS and Windows) and Poppler (`pdftocairo`, `pdfinfo`
|
|
52
|
+
and `pdftotext`) to convert EMF and WMF drawings in Word documents to SVG, and
|
|
53
|
+
Git to skip Git-ignored files when converting or rendering a folder.
|
|
54
|
+
- Optional, on Linux: the Carlito font (`fonts-crosextra-carlito` in Debian and
|
|
55
|
+
Ubuntu), which has Calibri's metrics. Without Calibri or Carlito, text in
|
|
56
|
+
Calibri, which Office documents and drawings use, is drawn in another font,
|
|
57
|
+
which may not fit where Calibri did. On macOS, LibreOffice has its own
|
|
58
|
+
Carlito, but rendering draws text in Calibri in another font unless Calibri is
|
|
59
|
+
installed.
|
|
60
|
+
|
|
61
|
+
`md-doc-converter setup` installs the rest, including Pandoc for Word
|
|
62
|
+
conversion and rendering; see [Toolchain](#toolchain). Excel and CSV conversion
|
|
63
|
+
need neither Pandoc nor Node.js.
|
|
64
|
+
|
|
65
|
+
## Installation
|
|
66
|
+
|
|
67
|
+
Install the command from [PyPI](https://pypi.org/project/md-doc-converter/)
|
|
68
|
+
with [uv](https://docs.astral.sh/uv/):
|
|
69
|
+
|
|
70
|
+
```sh
|
|
71
|
+
uv tool install md-doc-converter
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Other installers of Python commands, such as [pipx](https://pipx.pypa.io/),
|
|
75
|
+
work too when they run Python 3.15. On a network that allows only a package
|
|
76
|
+
mirror, see [Package mirrors](#package-mirrors).
|
|
77
|
+
|
|
78
|
+
Install Node.js for rendering, and optionally LibreOffice and Poppler, from your
|
|
79
|
+
distribution's packages; [nvm](https://github.com/nvm-sh/nvm) also installs
|
|
80
|
+
Node.js without root. On macOS, install them with
|
|
81
|
+
[Homebrew](https://brew.sh/):
|
|
82
|
+
|
|
83
|
+
```sh
|
|
84
|
+
brew install node
|
|
85
|
+
brew install --cask libreoffice # optional
|
|
86
|
+
brew install poppler # optional
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
On Windows, install them with winget:
|
|
90
|
+
|
|
91
|
+
```powershell
|
|
92
|
+
winget install OpenJS.NodeJS.LTS
|
|
93
|
+
winget install TheDocumentFoundation.LibreOffice # optional
|
|
94
|
+
winget install oschwartz10612.Poppler # optional
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Then install the toolchain and check every prerequisite:
|
|
98
|
+
|
|
99
|
+
```sh
|
|
100
|
+
md-doc-converter setup
|
|
101
|
+
md-doc-converter doctor
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
For Word conversion only, `setup --no-render` installs just Pandoc and needs no
|
|
105
|
+
Node.js.
|
|
106
|
+
|
|
107
|
+
## Quick start
|
|
108
|
+
|
|
109
|
+
```sh
|
|
110
|
+
md-doc-converter docx-to-md docs/spec.docx # docs/spec.md and docs/.images/spec/
|
|
111
|
+
md-doc-converter md-to-html docs/spec.md # docs/spec.html
|
|
112
|
+
md-doc-converter md-to-pdf docs/spec.md --header "Design review" # docs/spec.pdf
|
|
113
|
+
md-doc-converter md-to-pdf docs # docs/docs.pdf, from every page in docs/
|
|
114
|
+
md-doc-converter excel-to-md data/pins.xlsx # one Markdown page per worksheet, beside it
|
|
115
|
+
md-doc-converter csv-to-md data # one Markdown page beside each CSV
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Every command writes next to its input unless `-o` selects another location,
|
|
119
|
+
and never changes its input.
|
|
120
|
+
|
|
121
|
+
## Commands
|
|
122
|
+
|
|
123
|
+
`md-doc-converter --help` lists the commands, and
|
|
124
|
+
`md-doc-converter COMMAND --help` a command's options. What each command does
|
|
125
|
+
is described in:
|
|
126
|
+
|
|
127
|
+
- [Word conversion](https://github.com/patrick-5546/md-doc-converter/blob/main/docs/word-conversion.md),
|
|
128
|
+
for `docx-to-md`: what the Markdown holds, the report, and converting again;
|
|
129
|
+
- [Excel and CSV conversion](https://github.com/patrick-5546/md-doc-converter/blob/main/docs/excel-and-csv.md),
|
|
130
|
+
for `excel-to-md`, `excel-to-csv` and `csv-to-md`: how worksheets and CSV
|
|
131
|
+
files become pages, and what makes clean output;
|
|
132
|
+
- [Rendering](https://github.com/patrick-5546/md-doc-converter/blob/main/docs/rendering.md),
|
|
133
|
+
for `md-to-html` and `md-to-pdf`: output names, folder input, how Markdown is
|
|
134
|
+
read, images from elsewhere, Mermaid diagrams, math, the page header and
|
|
135
|
+
footer, the document language, extra stylesheets, the PDF time limit and
|
|
136
|
+
table styling;
|
|
137
|
+
- [Installation](#installation) and [Toolchain](#toolchain), for `setup` and
|
|
138
|
+
`doctor`.
|
|
139
|
+
|
|
140
|
+
## Messages
|
|
141
|
+
|
|
142
|
+
`docx-to-md`, `md-to-html` and `md-to-pdf` warn about what they cannot carry
|
|
143
|
+
over or show as written, naming the file and, when it is known, the line:
|
|
144
|
+
|
|
145
|
+
```text
|
|
146
|
+
md-to-html: warning: docs/setup.md: broken anchor '#instal' (no matching heading or anchor)
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
They show the first three warnings of each kind and count the rest. `-v`,
|
|
150
|
+
`--verbose` shows every warning and the details of each step; `-q`, `--quiet`
|
|
151
|
+
shows only errors. The result, the last line, goes to standard output and the
|
|
152
|
+
rest to standard error, so `--verbose 2> conversion.log` keeps the whole report.
|
|
153
|
+
On a terminal, a status line names the running step, and warnings and errors are
|
|
154
|
+
colored unless `NO_COLOR` is set. A Windows console that cannot show them, such
|
|
155
|
+
as a legacy console, gets plain messages.
|
|
156
|
+
|
|
157
|
+
## Settings
|
|
158
|
+
|
|
159
|
+
Command-line options override these environment variables.
|
|
160
|
+
|
|
161
|
+
| Variable | Purpose |
|
|
162
|
+
| --- | --- |
|
|
163
|
+
| `MD_DOC_CONVERTER_HOME` | Toolchain directory (default `~/.local/share/md-doc-converter`, or `%LOCALAPPDATA%\md-doc-converter` on Windows) |
|
|
164
|
+
| `MD_DOC_CONVERTER_HEADER` | Default `--header` text |
|
|
165
|
+
| `MD_DOC_CONVERTER_FOOTER` | Default `--footer` text |
|
|
166
|
+
| `MD_DOC_CONVERTER_LANG` | Default `--lang` language tag (`en`) |
|
|
167
|
+
| `MD_DOC_CONVERTER_PDF_TIMEOUT` | Default `--pdf-timeout`, in seconds (600; `0` = no limit) |
|
|
168
|
+
|
|
169
|
+
## Toolchain
|
|
170
|
+
|
|
171
|
+
`setup` installs into `$MD_DOC_CONVERTER_HOME`, by default
|
|
172
|
+
`$XDG_DATA_HOME/md-doc-converter` or `~/.local/share/md-doc-converter`, and on
|
|
173
|
+
Windows `%LOCALAPPDATA%\md-doc-converter`:
|
|
174
|
+
|
|
175
|
+
- `bin/pandoc` (`bin\pandoc.exe` on Windows): Pandoc 3.12.1, the version
|
|
176
|
+
md-doc-converter is tested with, from its GitHub release, verified against a
|
|
177
|
+
pinned SHA-256 checksum;
|
|
178
|
+
- `node/`, for rendering: the Mermaid, KaTeX and Puppeteer npm packages from
|
|
179
|
+
the lockfile bundled with md-doc-converter, installed without their install
|
|
180
|
+
scripts or optional packages, which none needs;
|
|
181
|
+
- `puppeteer/`, for rendering: chrome-headless-shell, the build of headless
|
|
182
|
+
Chrome that the locked Puppeteer pins, which Mermaid and the PDF printer
|
|
183
|
+
share.
|
|
184
|
+
|
|
185
|
+
md-doc-converter looks in the toolchain's `bin/` first, so it uses this Pandoc
|
|
186
|
+
even when another one is installed. Without it, md-doc-converter uses the
|
|
187
|
+
Pandoc on `PATH`, and `doctor` warns when that is another version, which may
|
|
188
|
+
format some converted Markdown slightly differently.
|
|
189
|
+
|
|
190
|
+
`setup` skips what is already current. It reinstalls the npm packages and the
|
|
191
|
+
browser when a new md-doc-converter version changes them or a package is
|
|
192
|
+
missing, and the browser alone when only it is missing. So after upgrading the
|
|
193
|
+
command, with `uv tool upgrade md-doc-converter`, run `setup` again to bring
|
|
194
|
+
the toolchain up to date. `setup --force` reinstalls everything. To remove the
|
|
195
|
+
toolchain, delete its directory; to remove the command, run
|
|
196
|
+
`uv tool uninstall md-doc-converter`.
|
|
197
|
+
|
|
198
|
+
npm uses your npm configuration, including proxies and registry mirrors; see
|
|
199
|
+
[Package mirrors](#package-mirrors). On a host that cannot reach GitHub,
|
|
200
|
+
download the archive for your platform, `pandoc-3.12.1-linux-amd64.tar.gz`,
|
|
201
|
+
`pandoc-3.12.1-arm64-macOS.zip` or `pandoc-3.12.1-windows-x86_64.zip`, from the
|
|
202
|
+
[Pandoc 3.12.1 release](https://github.com/jgm/pandoc/releases/tag/3.12.1)
|
|
203
|
+
another way into a folder and pass that folder to `setup`, which still verifies
|
|
204
|
+
the archive's checksum:
|
|
205
|
+
|
|
206
|
+
```sh
|
|
207
|
+
md-doc-converter setup --downloads ~/downloads
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
## Network access
|
|
211
|
+
|
|
212
|
+
Only `setup` downloads software: Pandoc from GitHub, npm packages from your npm
|
|
213
|
+
registry, and chrome-headless-shell through Puppeteer from Google's Chrome for
|
|
214
|
+
Testing downloads. Conversion and rendering run locally and upload nothing.
|
|
215
|
+
Rendering downloads only the files that your `--extra-css` stylesheet names by
|
|
216
|
+
URL and, with `--download-images`, the images that a document shows by URL. It
|
|
217
|
+
is safe for documents from elsewhere; see
|
|
218
|
+
[Images and documents from elsewhere](https://github.com/patrick-5546/md-doc-converter/blob/main/docs/rendering.md#images-and-documents-from-elsewhere).
|
|
219
|
+
|
|
220
|
+
## Package mirrors
|
|
221
|
+
|
|
222
|
+
On a network that allows only a package mirror, such as an organization's proxy
|
|
223
|
+
of PyPI and npm, point each package manager at it:
|
|
224
|
+
|
|
225
|
+
- uv does not read pip's settings, such as `PIP_INDEX_URL`, so name the
|
|
226
|
+
mirror's PyPI index as you install:
|
|
227
|
+
|
|
228
|
+
```sh
|
|
229
|
+
uv tool install --default-index https://mirror.example/pypi/simple/ md-doc-converter
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
- npm, which `setup` runs, fetches the locked packages from your configured
|
|
233
|
+
registry, though the bundled lockfile names `registry.npmjs.org`:
|
|
234
|
+
|
|
235
|
+
```sh
|
|
236
|
+
npm config set registry https://mirror.example/npm/
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
A mirror that holds new releases for a week still has every package: the
|
|
240
|
+
bundled npm lockfile names only releases at least a week old, and
|
|
241
|
+
`uv tool install` takes the newest md-doc-converter and openpyxl, its one
|
|
242
|
+
Python dependency, that the mirror has; a new md-doc-converter release reaches
|
|
243
|
+
the mirror a week after PyPI. For a checkout, see
|
|
244
|
+
[Package mirrors](https://github.com/patrick-5546/md-doc-converter/blob/main/docs/development.md#package-mirrors)
|
|
245
|
+
in the development guide.
|
|
246
|
+
|
|
247
|
+
## Troubleshooting
|
|
248
|
+
|
|
249
|
+
- Run `md-doc-converter doctor` first; it names each missing prerequisite and
|
|
250
|
+
how to install it.
|
|
251
|
+
- If the browser cannot start on Linux, install the shared libraries that Chrome
|
|
252
|
+
needs on your distribution. On hosts that restrict unprivileged user
|
|
253
|
+
namespaces, such as Ubuntu 23.10 and later, Chrome's sandbox needs that
|
|
254
|
+
restriction lifted (`kernel.apparmor_restrict_unprivileged_userns=0`).
|
|
255
|
+
- If a large PDF times out, raise `--pdf-timeout`, or set it to `0`.
|
|
256
|
+
- On Windows, a PDF that is open in a viewer cannot be replaced: close it and
|
|
257
|
+
render again. The previous PDF is left unchanged.
|
|
258
|
+
- On Windows, a link or image target in Markdown names a local file by its
|
|
259
|
+
path, relative or absolute, with slashes: `../images/chart.png` or
|
|
260
|
+
`/C:/docs/images/chart.png`, as a `file:///C:/docs/images/chart.png` URL
|
|
261
|
+
does.
|
|
262
|
+
|
|
263
|
+
## Development
|
|
264
|
+
|
|
265
|
+
See [Development](https://github.com/patrick-5546/md-doc-converter/blob/main/docs/development.md)
|
|
266
|
+
for the layout, the uv and make workflow, the test suites, continuous
|
|
267
|
+
integration and releasing.
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
# md-doc-converter
|
|
2
|
+
|
|
3
|
+
Convert Word, Excel and CSV documents to Markdown, and render Markdown to HTML
|
|
4
|
+
and PDF.
|
|
5
|
+
|
|
6
|
+
- **Word to Markdown:** converts with [Pandoc](https://pandoc.org/), keeping
|
|
7
|
+
images with their captions as alt text, tables, lists, links, bookmarks,
|
|
8
|
+
footnotes, equations and heading levels as Markdown can show them.
|
|
9
|
+
- **Excel and CSV to Markdown:** a table page per worksheet or CSV file, with
|
|
10
|
+
cell contents kept literal.
|
|
11
|
+
- **Markdown to HTML and PDF:** one file or a whole folder, with Mermaid
|
|
12
|
+
diagrams, KaTeX math, GitHub-style tables and code, heading bookmarks, page
|
|
13
|
+
numbers and optional header and footer text. The HTML is self-contained.
|
|
14
|
+
|
|
15
|
+
## Requirements
|
|
16
|
+
|
|
17
|
+
- Linux x86_64, macOS arm64 (Apple silicon) or Windows x86_64.
|
|
18
|
+
- Python 3.15. uv installs it if needed; on a host that cannot reach GitHub,
|
|
19
|
+
where uv downloads Python from, install Python 3.15 another way.
|
|
20
|
+
- [Node.js](https://nodejs.org/) 22.13 or newer, with npm, for rendering.
|
|
21
|
+
- Optional: LibreOffice 7.4 or newer (`libreoffice` or `soffice`, or where its
|
|
22
|
+
installer puts it on macOS and Windows) and Poppler (`pdftocairo`, `pdfinfo`
|
|
23
|
+
and `pdftotext`) to convert EMF and WMF drawings in Word documents to SVG, and
|
|
24
|
+
Git to skip Git-ignored files when converting or rendering a folder.
|
|
25
|
+
- Optional, on Linux: the Carlito font (`fonts-crosextra-carlito` in Debian and
|
|
26
|
+
Ubuntu), which has Calibri's metrics. Without Calibri or Carlito, text in
|
|
27
|
+
Calibri, which Office documents and drawings use, is drawn in another font,
|
|
28
|
+
which may not fit where Calibri did. On macOS, LibreOffice has its own
|
|
29
|
+
Carlito, but rendering draws text in Calibri in another font unless Calibri is
|
|
30
|
+
installed.
|
|
31
|
+
|
|
32
|
+
`md-doc-converter setup` installs the rest, including Pandoc for Word
|
|
33
|
+
conversion and rendering; see [Toolchain](#toolchain). Excel and CSV conversion
|
|
34
|
+
need neither Pandoc nor Node.js.
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
|
|
38
|
+
Install the command from [PyPI](https://pypi.org/project/md-doc-converter/)
|
|
39
|
+
with [uv](https://docs.astral.sh/uv/):
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
uv tool install md-doc-converter
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Other installers of Python commands, such as [pipx](https://pipx.pypa.io/),
|
|
46
|
+
work too when they run Python 3.15. On a network that allows only a package
|
|
47
|
+
mirror, see [Package mirrors](#package-mirrors).
|
|
48
|
+
|
|
49
|
+
Install Node.js for rendering, and optionally LibreOffice and Poppler, from your
|
|
50
|
+
distribution's packages; [nvm](https://github.com/nvm-sh/nvm) also installs
|
|
51
|
+
Node.js without root. On macOS, install them with
|
|
52
|
+
[Homebrew](https://brew.sh/):
|
|
53
|
+
|
|
54
|
+
```sh
|
|
55
|
+
brew install node
|
|
56
|
+
brew install --cask libreoffice # optional
|
|
57
|
+
brew install poppler # optional
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
On Windows, install them with winget:
|
|
61
|
+
|
|
62
|
+
```powershell
|
|
63
|
+
winget install OpenJS.NodeJS.LTS
|
|
64
|
+
winget install TheDocumentFoundation.LibreOffice # optional
|
|
65
|
+
winget install oschwartz10612.Poppler # optional
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Then install the toolchain and check every prerequisite:
|
|
69
|
+
|
|
70
|
+
```sh
|
|
71
|
+
md-doc-converter setup
|
|
72
|
+
md-doc-converter doctor
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
For Word conversion only, `setup --no-render` installs just Pandoc and needs no
|
|
76
|
+
Node.js.
|
|
77
|
+
|
|
78
|
+
## Quick start
|
|
79
|
+
|
|
80
|
+
```sh
|
|
81
|
+
md-doc-converter docx-to-md docs/spec.docx # docs/spec.md and docs/.images/spec/
|
|
82
|
+
md-doc-converter md-to-html docs/spec.md # docs/spec.html
|
|
83
|
+
md-doc-converter md-to-pdf docs/spec.md --header "Design review" # docs/spec.pdf
|
|
84
|
+
md-doc-converter md-to-pdf docs # docs/docs.pdf, from every page in docs/
|
|
85
|
+
md-doc-converter excel-to-md data/pins.xlsx # one Markdown page per worksheet, beside it
|
|
86
|
+
md-doc-converter csv-to-md data # one Markdown page beside each CSV
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Every command writes next to its input unless `-o` selects another location,
|
|
90
|
+
and never changes its input.
|
|
91
|
+
|
|
92
|
+
## Commands
|
|
93
|
+
|
|
94
|
+
`md-doc-converter --help` lists the commands, and
|
|
95
|
+
`md-doc-converter COMMAND --help` a command's options. What each command does
|
|
96
|
+
is described in:
|
|
97
|
+
|
|
98
|
+
- [Word conversion](https://github.com/patrick-5546/md-doc-converter/blob/main/docs/word-conversion.md),
|
|
99
|
+
for `docx-to-md`: what the Markdown holds, the report, and converting again;
|
|
100
|
+
- [Excel and CSV conversion](https://github.com/patrick-5546/md-doc-converter/blob/main/docs/excel-and-csv.md),
|
|
101
|
+
for `excel-to-md`, `excel-to-csv` and `csv-to-md`: how worksheets and CSV
|
|
102
|
+
files become pages, and what makes clean output;
|
|
103
|
+
- [Rendering](https://github.com/patrick-5546/md-doc-converter/blob/main/docs/rendering.md),
|
|
104
|
+
for `md-to-html` and `md-to-pdf`: output names, folder input, how Markdown is
|
|
105
|
+
read, images from elsewhere, Mermaid diagrams, math, the page header and
|
|
106
|
+
footer, the document language, extra stylesheets, the PDF time limit and
|
|
107
|
+
table styling;
|
|
108
|
+
- [Installation](#installation) and [Toolchain](#toolchain), for `setup` and
|
|
109
|
+
`doctor`.
|
|
110
|
+
|
|
111
|
+
## Messages
|
|
112
|
+
|
|
113
|
+
`docx-to-md`, `md-to-html` and `md-to-pdf` warn about what they cannot carry
|
|
114
|
+
over or show as written, naming the file and, when it is known, the line:
|
|
115
|
+
|
|
116
|
+
```text
|
|
117
|
+
md-to-html: warning: docs/setup.md: broken anchor '#instal' (no matching heading or anchor)
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
They show the first three warnings of each kind and count the rest. `-v`,
|
|
121
|
+
`--verbose` shows every warning and the details of each step; `-q`, `--quiet`
|
|
122
|
+
shows only errors. The result, the last line, goes to standard output and the
|
|
123
|
+
rest to standard error, so `--verbose 2> conversion.log` keeps the whole report.
|
|
124
|
+
On a terminal, a status line names the running step, and warnings and errors are
|
|
125
|
+
colored unless `NO_COLOR` is set. A Windows console that cannot show them, such
|
|
126
|
+
as a legacy console, gets plain messages.
|
|
127
|
+
|
|
128
|
+
## Settings
|
|
129
|
+
|
|
130
|
+
Command-line options override these environment variables.
|
|
131
|
+
|
|
132
|
+
| Variable | Purpose |
|
|
133
|
+
| --- | --- |
|
|
134
|
+
| `MD_DOC_CONVERTER_HOME` | Toolchain directory (default `~/.local/share/md-doc-converter`, or `%LOCALAPPDATA%\md-doc-converter` on Windows) |
|
|
135
|
+
| `MD_DOC_CONVERTER_HEADER` | Default `--header` text |
|
|
136
|
+
| `MD_DOC_CONVERTER_FOOTER` | Default `--footer` text |
|
|
137
|
+
| `MD_DOC_CONVERTER_LANG` | Default `--lang` language tag (`en`) |
|
|
138
|
+
| `MD_DOC_CONVERTER_PDF_TIMEOUT` | Default `--pdf-timeout`, in seconds (600; `0` = no limit) |
|
|
139
|
+
|
|
140
|
+
## Toolchain
|
|
141
|
+
|
|
142
|
+
`setup` installs into `$MD_DOC_CONVERTER_HOME`, by default
|
|
143
|
+
`$XDG_DATA_HOME/md-doc-converter` or `~/.local/share/md-doc-converter`, and on
|
|
144
|
+
Windows `%LOCALAPPDATA%\md-doc-converter`:
|
|
145
|
+
|
|
146
|
+
- `bin/pandoc` (`bin\pandoc.exe` on Windows): Pandoc 3.12.1, the version
|
|
147
|
+
md-doc-converter is tested with, from its GitHub release, verified against a
|
|
148
|
+
pinned SHA-256 checksum;
|
|
149
|
+
- `node/`, for rendering: the Mermaid, KaTeX and Puppeteer npm packages from
|
|
150
|
+
the lockfile bundled with md-doc-converter, installed without their install
|
|
151
|
+
scripts or optional packages, which none needs;
|
|
152
|
+
- `puppeteer/`, for rendering: chrome-headless-shell, the build of headless
|
|
153
|
+
Chrome that the locked Puppeteer pins, which Mermaid and the PDF printer
|
|
154
|
+
share.
|
|
155
|
+
|
|
156
|
+
md-doc-converter looks in the toolchain's `bin/` first, so it uses this Pandoc
|
|
157
|
+
even when another one is installed. Without it, md-doc-converter uses the
|
|
158
|
+
Pandoc on `PATH`, and `doctor` warns when that is another version, which may
|
|
159
|
+
format some converted Markdown slightly differently.
|
|
160
|
+
|
|
161
|
+
`setup` skips what is already current. It reinstalls the npm packages and the
|
|
162
|
+
browser when a new md-doc-converter version changes them or a package is
|
|
163
|
+
missing, and the browser alone when only it is missing. So after upgrading the
|
|
164
|
+
command, with `uv tool upgrade md-doc-converter`, run `setup` again to bring
|
|
165
|
+
the toolchain up to date. `setup --force` reinstalls everything. To remove the
|
|
166
|
+
toolchain, delete its directory; to remove the command, run
|
|
167
|
+
`uv tool uninstall md-doc-converter`.
|
|
168
|
+
|
|
169
|
+
npm uses your npm configuration, including proxies and registry mirrors; see
|
|
170
|
+
[Package mirrors](#package-mirrors). On a host that cannot reach GitHub,
|
|
171
|
+
download the archive for your platform, `pandoc-3.12.1-linux-amd64.tar.gz`,
|
|
172
|
+
`pandoc-3.12.1-arm64-macOS.zip` or `pandoc-3.12.1-windows-x86_64.zip`, from the
|
|
173
|
+
[Pandoc 3.12.1 release](https://github.com/jgm/pandoc/releases/tag/3.12.1)
|
|
174
|
+
another way into a folder and pass that folder to `setup`, which still verifies
|
|
175
|
+
the archive's checksum:
|
|
176
|
+
|
|
177
|
+
```sh
|
|
178
|
+
md-doc-converter setup --downloads ~/downloads
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## Network access
|
|
182
|
+
|
|
183
|
+
Only `setup` downloads software: Pandoc from GitHub, npm packages from your npm
|
|
184
|
+
registry, and chrome-headless-shell through Puppeteer from Google's Chrome for
|
|
185
|
+
Testing downloads. Conversion and rendering run locally and upload nothing.
|
|
186
|
+
Rendering downloads only the files that your `--extra-css` stylesheet names by
|
|
187
|
+
URL and, with `--download-images`, the images that a document shows by URL. It
|
|
188
|
+
is safe for documents from elsewhere; see
|
|
189
|
+
[Images and documents from elsewhere](https://github.com/patrick-5546/md-doc-converter/blob/main/docs/rendering.md#images-and-documents-from-elsewhere).
|
|
190
|
+
|
|
191
|
+
## Package mirrors
|
|
192
|
+
|
|
193
|
+
On a network that allows only a package mirror, such as an organization's proxy
|
|
194
|
+
of PyPI and npm, point each package manager at it:
|
|
195
|
+
|
|
196
|
+
- uv does not read pip's settings, such as `PIP_INDEX_URL`, so name the
|
|
197
|
+
mirror's PyPI index as you install:
|
|
198
|
+
|
|
199
|
+
```sh
|
|
200
|
+
uv tool install --default-index https://mirror.example/pypi/simple/ md-doc-converter
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
- npm, which `setup` runs, fetches the locked packages from your configured
|
|
204
|
+
registry, though the bundled lockfile names `registry.npmjs.org`:
|
|
205
|
+
|
|
206
|
+
```sh
|
|
207
|
+
npm config set registry https://mirror.example/npm/
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
A mirror that holds new releases for a week still has every package: the
|
|
211
|
+
bundled npm lockfile names only releases at least a week old, and
|
|
212
|
+
`uv tool install` takes the newest md-doc-converter and openpyxl, its one
|
|
213
|
+
Python dependency, that the mirror has; a new md-doc-converter release reaches
|
|
214
|
+
the mirror a week after PyPI. For a checkout, see
|
|
215
|
+
[Package mirrors](https://github.com/patrick-5546/md-doc-converter/blob/main/docs/development.md#package-mirrors)
|
|
216
|
+
in the development guide.
|
|
217
|
+
|
|
218
|
+
## Troubleshooting
|
|
219
|
+
|
|
220
|
+
- Run `md-doc-converter doctor` first; it names each missing prerequisite and
|
|
221
|
+
how to install it.
|
|
222
|
+
- If the browser cannot start on Linux, install the shared libraries that Chrome
|
|
223
|
+
needs on your distribution. On hosts that restrict unprivileged user
|
|
224
|
+
namespaces, such as Ubuntu 23.10 and later, Chrome's sandbox needs that
|
|
225
|
+
restriction lifted (`kernel.apparmor_restrict_unprivileged_userns=0`).
|
|
226
|
+
- If a large PDF times out, raise `--pdf-timeout`, or set it to `0`.
|
|
227
|
+
- On Windows, a PDF that is open in a viewer cannot be replaced: close it and
|
|
228
|
+
render again. The previous PDF is left unchanged.
|
|
229
|
+
- On Windows, a link or image target in Markdown names a local file by its
|
|
230
|
+
path, relative or absolute, with slashes: `../images/chart.png` or
|
|
231
|
+
`/C:/docs/images/chart.png`, as a `file:///C:/docs/images/chart.png` URL
|
|
232
|
+
does.
|
|
233
|
+
|
|
234
|
+
## Development
|
|
235
|
+
|
|
236
|
+
See [Development](https://github.com/patrick-5546/md-doc-converter/blob/main/docs/development.md)
|
|
237
|
+
for the layout, the uv and make workflow, the test suites, continuous
|
|
238
|
+
integration and releasing.
|