allmarkdown 0.0.1__py3-none-any.whl

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,18 @@
1
+ """allmarkdown - a standalone library that converts docx / pdf / xlsx / xls / txt to Markdown."""
2
+
3
+ from importlib.metadata import PackageNotFoundError, version as _version
4
+
5
+ from . import formats # noqa: F401 triggers format-module registration
6
+ from .core import SUPPORTED_EXTENSIONS, convert_all, convert_to_md
7
+
8
+ try:
9
+ __version__ = _version("allmarkdown")
10
+ except PackageNotFoundError:
11
+ __version__ = "0.0.1"
12
+
13
+ __all__ = [
14
+ "SUPPORTED_EXTENSIONS",
15
+ "convert_to_md",
16
+ "convert_all",
17
+ "__version__",
18
+ ]
allmarkdown/cli.py ADDED
@@ -0,0 +1,61 @@
1
+ """allmarkdown command-line entry point."""
2
+
3
+ import argparse
4
+ import sys
5
+ from pathlib import Path
6
+
7
+ from .core import convert_all, convert_to_md
8
+
9
+
10
+ def main(argv=None) -> int:
11
+ parser = argparse.ArgumentParser(
12
+ prog="allmarkdown",
13
+ description="Convert docx / pdf / xlsx / xls / txt files to Markdown",
14
+ )
15
+ parser.add_argument("input", help="Input file or directory path")
16
+ parser.add_argument("-o", "--output-dir", help="Output directory; defaults to the source file's directory")
17
+ parser.add_argument("--add-toc", action="store_true", help="Generate a table of contents with GitHub anchors")
18
+ parser.add_argument("--keep-original-toc", action="store_true", help="Keep the original Word auto-generated TOC in docx")
19
+ parser.add_argument(
20
+ "--fill-merged-cells", choices=["none", "h", "v", "both"], default="v",
21
+ help="Merged-cell fill strategy: v=fill vertically + leave horizontal blank (default), h=fill horizontally + leave vertical blank, both=fill all, none=blank all",
22
+ )
23
+ parser.add_argument("--force", action="store_true", help="Force re-conversion, ignoring the cache")
24
+ args = parser.parse_args(argv)
25
+
26
+ input_path = Path(args.input)
27
+ if not input_path.exists():
28
+ parser.error(f"Path does not exist: {input_path}")
29
+
30
+ output_dir = Path(args.output_dir) if args.output_dir else None
31
+
32
+ if input_path.is_file():
33
+ md_path, _ = convert_to_md(
34
+ input_path,
35
+ output_dir=output_dir or input_path.parent,
36
+ add_toc=args.add_toc,
37
+ keep_original_toc=args.keep_original_toc,
38
+ fill_merged_cells=args.fill_merged_cells,
39
+ )
40
+ print(f"Converted: {md_path}")
41
+ return 0
42
+
43
+ results = convert_all(
44
+ input_path,
45
+ output_dir=output_dir or input_path,
46
+ force_reconvert=args.force,
47
+ add_toc=args.add_toc,
48
+ keep_original_toc=args.keep_original_toc,
49
+ fill_merged_cells=args.fill_merged_cells,
50
+ )
51
+ ok = sum(1 for r in results if not r["error"])
52
+ bad = sum(1 for r in results if r["error"])
53
+ print(f"Done: {ok} succeeded, {bad} failed")
54
+ for r in results:
55
+ if r["error"]:
56
+ print(f" ✗ {r['file_path']}: {r['error']}")
57
+ return 0 if bad == 0 else 1
58
+
59
+
60
+ if __name__ == "__main__":
61
+ sys.exit(main())