md2star 2.0.0__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.
md2star/__init__.py ADDED
@@ -0,0 +1,42 @@
1
+ """md2star — Markdown → DOCX/PPTX/PDF bridge built on Pandoc.
2
+
3
+ Module summary
4
+ --------------
5
+ Public package surface for md2star. Re-exports the preprocessor entry
6
+ points so consumers can import them either from the top-level package
7
+ or from the ``md2star.preprocessing`` submodule.
8
+
9
+ Usage
10
+ -----
11
+ >>> from md2star import preprocess_markdown
12
+ >>> out = preprocess_markdown("# Hello\\n", base_dir=".")
13
+ >>> print(out.splitlines()[0]) # '# Hello'
14
+ # Hello
15
+
16
+ Author
17
+ ------
18
+ [Warith HARCHAOUI](https://linkedin.com/in/warith-harchaoui)
19
+ """
20
+
21
+ from __future__ import annotations
22
+
23
+ __version__: str = "2.0.0"
24
+
25
+ from .preprocessing import (
26
+ DEFAULT_ALT_TEXT_MODEL,
27
+ DEFAULT_LINT_MODEL,
28
+ fill_empty_alt_text,
29
+ is_ollama_installed,
30
+ preprocess_markdown,
31
+ render_mermaid_local,
32
+ )
33
+
34
+ __all__ = [
35
+ "__version__",
36
+ "preprocess_markdown",
37
+ "render_mermaid_local",
38
+ "fill_empty_alt_text",
39
+ "is_ollama_installed",
40
+ "DEFAULT_LINT_MODEL",
41
+ "DEFAULT_ALT_TEXT_MODEL",
42
+ ]
md2star/__main__.py ADDED
@@ -0,0 +1,31 @@
1
+ """Allow ``python -m md2star`` as an alternative to the ``md2star`` console script.
2
+
3
+ Module summary
4
+ --------------
5
+ Thin shim that forwards ``python -m md2star`` invocations to
6
+ :func:`md2star.cli.main`. Python convention: every importable
7
+ package that exposes a CLI should be runnable via ``-m``, so users
8
+ who bypass the installed entry point (debugging, sandboxed Pythons,
9
+ `pipx run --spec md2star md2star` style invocations) still get the
10
+ same behaviour.
11
+
12
+ Usage
13
+ -----
14
+ >>> # From the shell:
15
+ >>> # python -m md2star --help
16
+ >>> # python -m md2star docx report.md
17
+ >>> # is equivalent to the installed `md2star` entry point.
18
+
19
+ Author
20
+ ------
21
+ [Warith HARCHAOUI](https://linkedin.com/in/warith-harchaoui/)
22
+ """
23
+
24
+ from __future__ import annotations
25
+
26
+ import sys
27
+
28
+ from .cli import main
29
+
30
+ if __name__ == "__main__":
31
+ sys.exit(main())
md2star/cache.py ADDED
@@ -0,0 +1,93 @@
1
+ """Per-user cache directory for md2star image/mermaid artifacts.
2
+
3
+ Module summary
4
+ --------------
5
+ Historically, downscaled images, downloaded remote images, and rendered
6
+ mermaid PNGs all landed next to the user's source Markdown, cluttering
7
+ working directories with hidden dotfiles (``.remote_*``, ``*_max1600.*``,
8
+ ``*_cell.*``, ``.mermaid_*``). This module centralises every artifact under
9
+ ``$XDG_CACHE_HOME/md2star/`` (with platform fallbacks) so the user's source
10
+ trees stay clean and the cache can be wiped with a single
11
+ ``md2star clear-cache``.
12
+
13
+ Cache layout::
14
+
15
+ $XDG_CACHE_HOME/md2star/
16
+ ├── remote/ # downloaded http(s):// images, keyed by URL MD5
17
+ ├── resized/ # downscaled rasters, keyed by source-path + size MD5
18
+ ├── cell/ # cell-fitted images, keyed by source-path MD5
19
+ └── mermaid/ # rendered mermaid PNGs + resolved config JSON
20
+
21
+ The hash-keyed filenames make collisions across users impossible — two
22
+ different source files with the same basename do not stomp each other.
23
+
24
+ Usage
25
+ -----
26
+ >>> from md2star.cache import cache_dir, clear_cache
27
+ >>> p = cache_dir("remote")
28
+ >>> print(p.name) # 'remote'
29
+ remote
30
+ >>> freed = clear_cache()
31
+ >>> print(freed >= 0) # True
32
+ True
33
+
34
+ Author
35
+ ------
36
+ [Warith HARCHAOUI](https://linkedin.com/in/warith-harchaoui/)
37
+ """
38
+
39
+ from __future__ import annotations
40
+
41
+ import os
42
+ import shutil
43
+ import sys
44
+ from pathlib import Path
45
+
46
+ _APP_NAME = "md2star"
47
+
48
+
49
+ def _platform_cache_root() -> Path:
50
+ """Return the per-user cache root using each platform's convention.
51
+
52
+ * Linux/BSD: ``$XDG_CACHE_HOME`` (default ``~/.cache``).
53
+ * macOS: ``~/Library/Caches`` (Apple's documented per-user cache dir).
54
+ * Windows: ``%LOCALAPPDATA%`` (default ``~\\AppData\\Local``).
55
+ """
56
+ xdg = os.environ.get("XDG_CACHE_HOME")
57
+ if xdg:
58
+ return Path(xdg)
59
+
60
+ if sys.platform == "darwin":
61
+ return Path.home() / "Library" / "Caches"
62
+ if sys.platform == "win32":
63
+ local = os.environ.get("LOCALAPPDATA")
64
+ if local:
65
+ return Path(local)
66
+ return Path.home() / "AppData" / "Local"
67
+ return Path.home() / ".cache"
68
+
69
+
70
+ def cache_dir(subdir: str | None = None) -> Path:
71
+ """Return the md2star cache dir (or a subdirectory of it), creating it.
72
+
73
+ Honors ``MD2STAR_CACHE_DIR`` for testing / opt-out (e.g. a tempdir in CI).
74
+ """
75
+ override = os.environ.get("MD2STAR_CACHE_DIR")
76
+ root = Path(override) if override else (_platform_cache_root() / _APP_NAME)
77
+ target = root / subdir if subdir else root
78
+ target.mkdir(parents=True, exist_ok=True)
79
+ return target
80
+
81
+
82
+ def clear_cache() -> int:
83
+ """Remove the entire md2star cache directory. Returns bytes freed (approx)."""
84
+ root = cache_dir()
85
+ total = 0
86
+ for dirpath, _dirnames, filenames in os.walk(root):
87
+ for name in filenames:
88
+ try:
89
+ total += os.path.getsize(os.path.join(dirpath, name))
90
+ except OSError:
91
+ pass
92
+ shutil.rmtree(root, ignore_errors=True)
93
+ return total