multi-convert 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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) [2026] [Cobra Chicken]
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,74 @@
1
+ Metadata-Version: 2.4
2
+ Name: multi_convert
3
+ Version: 0.1.0
4
+ Summary: A python package for converting multiple document formats
5
+ Home-page: https://github.com/tasteslikecobrachicken/multi_convert
6
+ Author: Cobra Chicken
7
+ Author-email: Cobra Chicken <tasteslikecobrachicken@gmail.com>
8
+ Project-URL: Homepage, https://github.com/tasteslikecobrachicken/multi_convert
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.10
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: markdown>=3.5
16
+ Requires-Dist: markdown-pdf>=1.4
17
+ Requires-Dist: html2text>=2024.2.26
18
+ Requires-Dist: pypdf>=4.0
19
+ Provides-Extra: test
20
+ Requires-Dist: pytest>=8; extra == "test"
21
+ Dynamic: author
22
+ Dynamic: home-page
23
+ Dynamic: license-file
24
+ Dynamic: requires-python
25
+
26
+ # multi_convert
27
+
28
+ Python package for converting document formats between Markdown, HTML, and PDF.
29
+
30
+ ## Installation
31
+
32
+ ```bash
33
+ pip install multi_convert
34
+ ```
35
+
36
+ Requires Python 3.10 or newer.
37
+
38
+ ## Usage
39
+
40
+ ### Library
41
+
42
+ ```python
43
+ from multi_convert import convert
44
+
45
+ convert("notes.md", "notes.pdf")
46
+ convert("page.html", "page.md")
47
+ ```
48
+
49
+ Both formats are inferred from the file extensions. `convert` returns the output
50
+ path and raises `ConversionError` if the input is missing or either extension is
51
+ not one of `.md`, `.html`, or `.pdf`.
52
+
53
+ ### Command line
54
+
55
+ ```bash
56
+ multi-convert notes.md notes.pdf
57
+ ```
58
+
59
+ ## Supported conversions
60
+
61
+ | From | To |
62
+ | --- | --- |
63
+ | Markdown | HTML, PDF |
64
+ | HTML | Markdown, PDF |
65
+ | PDF | Markdown, HTML |
66
+
67
+ Every conversion routes through Markdown as an intermediate representation.
68
+ Because PDF text extraction recovers plain text only, converting *from* PDF
69
+ loses headings, tables, and emphasis; the other five directions preserve
70
+ structure.
71
+
72
+ ## License
73
+
74
+ MIT
@@ -0,0 +1,49 @@
1
+ # multi_convert
2
+
3
+ Python package for converting document formats between Markdown, HTML, and PDF.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install multi_convert
9
+ ```
10
+
11
+ Requires Python 3.10 or newer.
12
+
13
+ ## Usage
14
+
15
+ ### Library
16
+
17
+ ```python
18
+ from multi_convert import convert
19
+
20
+ convert("notes.md", "notes.pdf")
21
+ convert("page.html", "page.md")
22
+ ```
23
+
24
+ Both formats are inferred from the file extensions. `convert` returns the output
25
+ path and raises `ConversionError` if the input is missing or either extension is
26
+ not one of `.md`, `.html`, or `.pdf`.
27
+
28
+ ### Command line
29
+
30
+ ```bash
31
+ multi-convert notes.md notes.pdf
32
+ ```
33
+
34
+ ## Supported conversions
35
+
36
+ | From | To |
37
+ | --- | --- |
38
+ | Markdown | HTML, PDF |
39
+ | HTML | Markdown, PDF |
40
+ | PDF | Markdown, HTML |
41
+
42
+ Every conversion routes through Markdown as an intermediate representation.
43
+ Because PDF text extraction recovers plain text only, converting *from* PDF
44
+ loses headings, tables, and emphasis; the other five directions preserve
45
+ structure.
46
+
47
+ ## License
48
+
49
+ MIT
@@ -0,0 +1,39 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "multi_convert"
7
+ version = "0.1.0"
8
+ authors = [
9
+ { name="Cobra Chicken", email="tasteslikecobrachicken@gmail.com" },
10
+ ]
11
+ description = "A python package for converting multiple document formats"
12
+ readme = "README.md"
13
+ requires-python = ">=3.10"
14
+ classifiers = [
15
+ "Programming Language :: Python :: 3",
16
+ "License :: OSI Approved :: MIT License",
17
+ "Operating System :: OS Independent",
18
+ ]
19
+ dependencies = [
20
+ "markdown>=3.5",
21
+ "markdown-pdf>=1.4",
22
+ "html2text>=2024.2.26",
23
+ "pypdf>=4.0",
24
+ ]
25
+
26
+ [project.optional-dependencies]
27
+ test = ["pytest>=8"]
28
+
29
+ [project.scripts]
30
+ multi-convert = "multi_convert.cli:main"
31
+
32
+ [project.urls]
33
+ Homepage = "https://github.com/tasteslikecobrachicken/multi_convert"
34
+
35
+ [tool.setuptools.packages.find]
36
+ where = ["src"]
37
+
38
+ [tool.pytest.ini_options]
39
+ testpaths = ["tests"]
@@ -0,0 +1,7 @@
1
+ [metadata]
2
+ license_files = LICENSE
3
+
4
+ [egg_info]
5
+ tag_build =
6
+ tag_date = 0
7
+
@@ -0,0 +1,36 @@
1
+ import os
2
+ from setuptools import setup, find_packages
3
+
4
+ this_directory = os.path.abspath(os.path.dirname(__file__))
5
+ with open(os.path.join(this_directory, "README.md"), encoding="utf-8") as f:
6
+ long_description = f.read()
7
+
8
+ setup(
9
+ name="multi_convert",
10
+ version="0.1.0",
11
+ author="Cobra Chicken",
12
+ author_email="tasteslikecobrachicken@gmail.com",
13
+ description="A python package for converting multiple document formats",
14
+ long_description=long_description,
15
+ long_description_content_type="text/markdown",
16
+ url="https://github.com/tasteslikecobrachicken/multi_convert",
17
+ packages=find_packages(exclude=["tests", "tests.*"]),
18
+ python_requires=">=3.10",
19
+ install_requires=[
20
+ "markdown>=3.5",
21
+ "markdown-pdf>=1.4",
22
+ "html2text>=2024.2.26",
23
+ "pypdf>=4.0",
24
+ ],
25
+ extras_require={},
26
+ entry_points={
27
+ "console_scripts": [
28
+ "multi-convert=multi_convert.cli:main",
29
+ ],
30
+ },
31
+ classifiers=[
32
+ "Programming Language :: Python :: 3",
33
+ "License :: OSI Approved :: MIT License",
34
+ "Operating System :: OS Independent",
35
+ ],
36
+ )
@@ -0,0 +1,5 @@
1
+ """Convert documents between Markdown, HTML, and PDF."""
2
+
3
+ from .core import FORMATS, ConversionError, convert
4
+
5
+ __all__ = ["FORMATS", "ConversionError", "convert"]
@@ -0,0 +1,23 @@
1
+ """Command line interface for multi_convert."""
2
+
3
+ import argparse
4
+ from pathlib import Path
5
+
6
+ from .core import ConversionError, convert
7
+
8
+
9
+ def main():
10
+ parser = argparse.ArgumentParser(
11
+ prog="multi-convert",
12
+ description="Convert documents between Markdown, HTML, and PDF.",
13
+ )
14
+ parser.add_argument("input", type=Path, help="File to convert")
15
+ parser.add_argument("output", type=Path, help="Destination file; the format is taken from its extension")
16
+ args = parser.parse_args()
17
+
18
+ try:
19
+ convert(args.input, args.output)
20
+ except ConversionError as error:
21
+ parser.exit(1, f"error: {error}\n")
22
+
23
+ print(f"Converted {args.input} -> {args.output}")
@@ -0,0 +1,90 @@
1
+ """Document conversion between Markdown, HTML, and PDF."""
2
+
3
+ from pathlib import Path
4
+
5
+ import html2text
6
+ import markdown
7
+ from markdown_pdf import MarkdownPdf, Section
8
+ from pypdf import PdfReader
9
+
10
+ FORMATS = ("md", "html", "pdf")
11
+
12
+ _HTML_HEAD = """<!DOCTYPE html>
13
+ <html>
14
+ <head>
15
+ <meta charset="utf-8">
16
+ <style>
17
+ body { font-family: -apple-system, sans-serif; line-height: 1.6; max-width: 800px; margin: 2rem auto; padding: 0 1rem; }
18
+ code { background: #f4f4f4; padding: 2px 4px; border-radius: 4px; }
19
+ pre { background: #f4f4f4; padding: 1rem; overflow-x: auto; }
20
+ table { border-collapse: collapse; width: 100%; }
21
+ th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
22
+ </style>
23
+ </head>
24
+ <body>
25
+ """
26
+
27
+ _HTML_TAIL = """
28
+ </body>
29
+ </html>
30
+ """
31
+
32
+
33
+ class ConversionError(Exception):
34
+ """Raised when a conversion cannot be performed."""
35
+
36
+
37
+ def _format_of(path):
38
+ fmt = path.suffix.lower().lstrip(".")
39
+ if fmt not in FORMATS:
40
+ raise ConversionError(f"Unsupported format {path.suffix!r}; expected one of {', '.join(FORMATS)}")
41
+ return fmt
42
+
43
+
44
+ def _read_md(path):
45
+ return path.read_text(encoding="utf-8")
46
+
47
+
48
+ def _read_html(path):
49
+ handler = html2text.HTML2Text()
50
+ handler.ignore_links = False
51
+ return handler.handle(path.read_text(encoding="utf-8"))
52
+
53
+
54
+ def _read_pdf(path):
55
+ pages = (page.extract_text() for page in PdfReader(path).pages)
56
+ return "\n\n".join(page for page in pages if page)
57
+
58
+
59
+ def _write_md(content, path):
60
+ path.write_text(content, encoding="utf-8")
61
+
62
+
63
+ def _write_html(content, path):
64
+ body = markdown.markdown(content, extensions=["tables", "fenced_code"])
65
+ path.write_text(_HTML_HEAD + body + _HTML_TAIL, encoding="utf-8")
66
+
67
+
68
+ def _write_pdf(content, path):
69
+ pdf = MarkdownPdf(toc_level=2)
70
+ pdf.add_section(Section(content))
71
+ pdf.save(str(path))
72
+
73
+
74
+ _READERS = {"md": _read_md, "html": _read_html, "pdf": _read_pdf}
75
+ _WRITERS = {"md": _write_md, "html": _write_html, "pdf": _write_pdf}
76
+
77
+
78
+ def convert(source, target):
79
+ """Convert ``source`` to ``target``, inferring both formats from file extensions.
80
+
81
+ Every conversion routes through Markdown as an intermediate representation, so
82
+ reading a PDF yields extracted plain text rather than structured markup.
83
+ """
84
+ source, target = Path(source), Path(target)
85
+ if not source.is_file():
86
+ raise ConversionError(f"Input file not found: {source}")
87
+
88
+ reader, writer = _READERS[_format_of(source)], _WRITERS[_format_of(target)]
89
+ writer(reader(source), target)
90
+ return target
@@ -0,0 +1,74 @@
1
+ Metadata-Version: 2.4
2
+ Name: multi_convert
3
+ Version: 0.1.0
4
+ Summary: A python package for converting multiple document formats
5
+ Home-page: https://github.com/tasteslikecobrachicken/multi_convert
6
+ Author: Cobra Chicken
7
+ Author-email: Cobra Chicken <tasteslikecobrachicken@gmail.com>
8
+ Project-URL: Homepage, https://github.com/tasteslikecobrachicken/multi_convert
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.10
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: markdown>=3.5
16
+ Requires-Dist: markdown-pdf>=1.4
17
+ Requires-Dist: html2text>=2024.2.26
18
+ Requires-Dist: pypdf>=4.0
19
+ Provides-Extra: test
20
+ Requires-Dist: pytest>=8; extra == "test"
21
+ Dynamic: author
22
+ Dynamic: home-page
23
+ Dynamic: license-file
24
+ Dynamic: requires-python
25
+
26
+ # multi_convert
27
+
28
+ Python package for converting document formats between Markdown, HTML, and PDF.
29
+
30
+ ## Installation
31
+
32
+ ```bash
33
+ pip install multi_convert
34
+ ```
35
+
36
+ Requires Python 3.10 or newer.
37
+
38
+ ## Usage
39
+
40
+ ### Library
41
+
42
+ ```python
43
+ from multi_convert import convert
44
+
45
+ convert("notes.md", "notes.pdf")
46
+ convert("page.html", "page.md")
47
+ ```
48
+
49
+ Both formats are inferred from the file extensions. `convert` returns the output
50
+ path and raises `ConversionError` if the input is missing or either extension is
51
+ not one of `.md`, `.html`, or `.pdf`.
52
+
53
+ ### Command line
54
+
55
+ ```bash
56
+ multi-convert notes.md notes.pdf
57
+ ```
58
+
59
+ ## Supported conversions
60
+
61
+ | From | To |
62
+ | --- | --- |
63
+ | Markdown | HTML, PDF |
64
+ | HTML | Markdown, PDF |
65
+ | PDF | Markdown, HTML |
66
+
67
+ Every conversion routes through Markdown as an intermediate representation.
68
+ Because PDF text extraction recovers plain text only, converting *from* PDF
69
+ loses headings, tables, and emphasis; the other five directions preserve
70
+ structure.
71
+
72
+ ## License
73
+
74
+ MIT
@@ -0,0 +1,16 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ setup.cfg
5
+ setup.py
6
+ src/multi_convert/__init__.py
7
+ src/multi_convert/cli.py
8
+ src/multi_convert/core.py
9
+ src/multi_convert.egg-info/PKG-INFO
10
+ src/multi_convert.egg-info/SOURCES.txt
11
+ src/multi_convert.egg-info/dependency_links.txt
12
+ src/multi_convert.egg-info/entry_points.txt
13
+ src/multi_convert.egg-info/requires.txt
14
+ src/multi_convert.egg-info/top_level.txt
15
+ tests/test_cli.py
16
+ tests/test_convert.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ multi-convert = multi_convert.cli:main
@@ -0,0 +1,7 @@
1
+ markdown>=3.5
2
+ markdown-pdf>=1.4
3
+ html2text>=2024.2.26
4
+ pypdf>=4.0
5
+
6
+ [test]
7
+ pytest>=8
@@ -0,0 +1 @@
1
+ multi_convert
@@ -0,0 +1,68 @@
1
+ import pytest
2
+
3
+ from multi_convert.cli import main
4
+
5
+
6
+ def run(monkeypatch, *args):
7
+ monkeypatch.setattr("sys.argv", ["multi-convert", *(str(a) for a in args)])
8
+ main()
9
+
10
+
11
+ class TestSuccess:
12
+ def test_converts_file(self, monkeypatch, capsys, md_file, tmp_path):
13
+ target = tmp_path / "out.html"
14
+ run(monkeypatch, md_file, target)
15
+
16
+ assert target.is_file()
17
+ assert "<h1>Title</h1>" in target.read_text(encoding="utf-8")
18
+
19
+ def test_reports_the_conversion(self, monkeypatch, capsys, md_file, tmp_path):
20
+ target = tmp_path / "out.html"
21
+ run(monkeypatch, md_file, target)
22
+ out = capsys.readouterr().out
23
+
24
+ assert str(md_file) in out
25
+ assert str(target) in out
26
+
27
+
28
+ class TestFailure:
29
+ def test_missing_input_exits_nonzero(self, monkeypatch, capsys, tmp_path):
30
+ with pytest.raises(SystemExit) as exc:
31
+ run(monkeypatch, tmp_path / "nope.md", tmp_path / "out.html")
32
+
33
+ assert exc.value.code == 1
34
+ assert "Input file not found" in capsys.readouterr().err
35
+
36
+ def test_unsupported_format_exits_nonzero(self, monkeypatch, capsys, md_file, tmp_path):
37
+ with pytest.raises(SystemExit) as exc:
38
+ run(monkeypatch, md_file, tmp_path / "out.docx")
39
+
40
+ assert exc.value.code == 1
41
+ assert "Unsupported format" in capsys.readouterr().err
42
+
43
+ def test_failure_prints_nothing_to_stdout(self, monkeypatch, capsys, md_file, tmp_path):
44
+ with pytest.raises(SystemExit):
45
+ run(monkeypatch, md_file, tmp_path / "out.docx")
46
+
47
+ assert capsys.readouterr().out == ""
48
+
49
+
50
+ class TestArguments:
51
+ def test_missing_output_argument_is_rejected(self, monkeypatch, capsys, md_file):
52
+ with pytest.raises(SystemExit) as exc:
53
+ run(monkeypatch, md_file)
54
+
55
+ assert exc.value.code == 2
56
+
57
+ def test_no_arguments_is_rejected(self, monkeypatch, capsys):
58
+ with pytest.raises(SystemExit) as exc:
59
+ run(monkeypatch)
60
+
61
+ assert exc.value.code == 2
62
+
63
+ def test_help_exits_zero(self, monkeypatch, capsys):
64
+ with pytest.raises(SystemExit) as exc:
65
+ run(monkeypatch, "--help")
66
+
67
+ assert exc.value.code == 0
68
+ assert "Markdown, HTML, and PDF" in capsys.readouterr().out
@@ -0,0 +1,158 @@
1
+ import pytest
2
+ from pypdf import PdfReader
3
+
4
+ from multi_convert import ConversionError, convert
5
+
6
+
7
+ def pdf_text(path):
8
+ return "\n".join(page.extract_text() or "" for page in PdfReader(path).pages)
9
+
10
+
11
+ class TestFromMarkdown:
12
+ def test_to_html_preserves_structure(self, md_file, tmp_path):
13
+ out = convert(md_file, tmp_path / "out.html")
14
+ html = out.read_text(encoding="utf-8")
15
+
16
+ assert "<h1>Title</h1>" in html
17
+ assert "<strong>bold</strong>" in html
18
+ assert '<a href="https://example.com">link</a>' in html
19
+ assert "<table>" in html and "<th>A</th>" in html
20
+ assert '<code class="language-python">' in html
21
+
22
+ def test_to_html_wraps_in_full_document(self, md_file, tmp_path):
23
+ html = convert(md_file, tmp_path / "out.html").read_text(encoding="utf-8")
24
+
25
+ assert html.startswith("<!DOCTYPE html>")
26
+ assert html.rstrip().endswith("</html>")
27
+ assert "<meta charset=\"utf-8\">" in html
28
+ assert "font-family" in html
29
+
30
+ def test_to_pdf_is_readable_and_keeps_text(self, md_file, tmp_path):
31
+ out = convert(md_file, tmp_path / "out.pdf")
32
+
33
+ assert out.read_bytes().startswith(b"%PDF-")
34
+ assert "Title" in pdf_text(out)
35
+
36
+
37
+ class TestFromHtml:
38
+ def test_to_markdown_preserves_structure(self, html_file, tmp_path):
39
+ md = convert(html_file, tmp_path / "out.md").read_text(encoding="utf-8")
40
+
41
+ assert "# Title" in md
42
+ assert "**bold**" in md
43
+ assert "(https://example.com)" in md
44
+ assert "first" in md and "second" in md
45
+
46
+ def test_to_markdown_strips_html_tags(self, html_file, tmp_path):
47
+ md = convert(html_file, tmp_path / "out.md").read_text(encoding="utf-8")
48
+
49
+ assert "<h1>" not in md
50
+ assert "<strong>" not in md
51
+
52
+ def test_to_pdf_is_readable_and_keeps_text(self, html_file, tmp_path):
53
+ out = convert(html_file, tmp_path / "out.pdf")
54
+
55
+ assert out.read_bytes().startswith(b"%PDF-")
56
+ assert "Title" in pdf_text(out)
57
+
58
+
59
+ class TestFromPdf:
60
+ def test_to_markdown_extracts_text(self, pdf_file, tmp_path):
61
+ md = convert(pdf_file, tmp_path / "out.md").read_text(encoding="utf-8")
62
+
63
+ assert "Title" in md
64
+ assert "plain paragraph text" in md
65
+
66
+ def test_to_html_wraps_extracted_text(self, pdf_file, tmp_path):
67
+ html = convert(pdf_file, tmp_path / "out.html").read_text(encoding="utf-8")
68
+
69
+ assert html.startswith("<!DOCTYPE html>")
70
+ assert "Title" in html
71
+
72
+ def test_extraction_is_lossy(self, pdf_file, tmp_path):
73
+ """PDF text extraction recovers no Markdown structure; see README."""
74
+ md = convert(pdf_file, tmp_path / "out.md").read_text(encoding="utf-8")
75
+
76
+ assert "# Title" not in md
77
+
78
+
79
+ class TestRoundTrip:
80
+ def test_markdown_survives_html_round_trip(self, md_file, tmp_path):
81
+ html = convert(md_file, tmp_path / "mid.html")
82
+ md = convert(html, tmp_path / "back.md").read_text(encoding="utf-8")
83
+
84
+ assert "# Title" in md
85
+ assert "**bold**" in md
86
+ assert "(https://example.com)" in md
87
+
88
+
89
+ class TestApi:
90
+ def test_returns_target_path(self, md_file, tmp_path):
91
+ target = tmp_path / "out.html"
92
+
93
+ assert convert(md_file, target) == target
94
+
95
+ def test_accepts_string_paths(self, md_file, tmp_path):
96
+ target = tmp_path / "out.html"
97
+ convert(str(md_file), str(target))
98
+
99
+ assert target.is_file()
100
+
101
+ def test_same_format_copies_content(self, md_file, tmp_path):
102
+ out = convert(md_file, tmp_path / "copy.md")
103
+
104
+ assert out.read_text(encoding="utf-8") == md_file.read_text(encoding="utf-8")
105
+
106
+ def test_overwrites_existing_target(self, md_file, tmp_path):
107
+ target = tmp_path / "out.html"
108
+ target.write_text("stale", encoding="utf-8")
109
+ convert(md_file, target)
110
+
111
+ assert "stale" not in target.read_text(encoding="utf-8")
112
+
113
+
114
+ class TestErrors:
115
+ def test_missing_input(self, tmp_path):
116
+ with pytest.raises(ConversionError, match="Input file not found"):
117
+ convert(tmp_path / "nope.md", tmp_path / "out.html")
118
+
119
+ def test_directory_as_input(self, tmp_path):
120
+ with pytest.raises(ConversionError, match="Input file not found"):
121
+ convert(tmp_path, tmp_path / "out.html")
122
+
123
+ def test_unsupported_source_extension(self, tmp_path):
124
+ source = tmp_path / "sample.docx"
125
+ source.write_text("x", encoding="utf-8")
126
+
127
+ with pytest.raises(ConversionError, match="Unsupported format '.docx'"):
128
+ convert(source, tmp_path / "out.html")
129
+
130
+ def test_unsupported_target_extension(self, md_file, tmp_path):
131
+ with pytest.raises(ConversionError, match="Unsupported format '.docx'"):
132
+ convert(md_file, tmp_path / "out.docx")
133
+
134
+ def test_extensionless_input(self, tmp_path):
135
+ source = tmp_path / "sample"
136
+ source.write_text("x", encoding="utf-8")
137
+
138
+ with pytest.raises(ConversionError, match="Unsupported format"):
139
+ convert(source, tmp_path / "out.html")
140
+
141
+ def test_extension_case_is_ignored(self, tmp_path):
142
+ source = tmp_path / "sample.MD"
143
+ source.write_text("# Title\n", encoding="utf-8")
144
+ out = convert(source, tmp_path / "out.HTML")
145
+
146
+ assert "<h1>Title</h1>" in out.read_text(encoding="utf-8")
147
+
148
+ def test_missing_input_checked_before_extensions(self, tmp_path):
149
+ """A nonexistent file reports the missing path, not its extension."""
150
+ with pytest.raises(ConversionError, match="Input file not found"):
151
+ convert(tmp_path / "nope.docx", tmp_path / "out.html")
152
+
153
+ def test_no_output_written_on_failure(self, md_file, tmp_path):
154
+ target = tmp_path / "out.docx"
155
+ with pytest.raises(ConversionError):
156
+ convert(md_file, target)
157
+
158
+ assert not target.exists()