From 9bd513a3a3b6d9e7cb8a9cd6a492c42a6243a3bb Mon Sep 17 00:00:00 2001 From: Ian Griffin Date: Wed, 12 Nov 2025 20:25:57 +0800 Subject: [PATCH] changed name to print_md --- .gitignore | 2 ++ {term_color_md => print_md}/__init__.py | 30 ++++++++++++++++++ pyproject.toml | 7 ++-- .../__pycache__/__init__.cpython-311.pyc | Bin 4429 -> 0 bytes 4 files changed, 37 insertions(+), 2 deletions(-) rename {term_color_md => print_md}/__init__.py (81%) delete mode 100644 term_color_md/__pycache__/__init__.cpython-311.pyc diff --git a/.gitignore b/.gitignore index 59d5265..e905b88 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ build *.egg-info +*/__pycache__ +__pycache__ diff --git a/term_color_md/__init__.py b/print_md/__init__.py similarity index 81% rename from term_color_md/__init__.py rename to print_md/__init__.py index 87740f8..7144d96 100644 --- a/term_color_md/__init__.py +++ b/print_md/__init__.py @@ -4,7 +4,10 @@ # # You should have received a copy of the GNU General Public License along with this program. If not, see . +import argparse import re +import sys + from termcolor import colored from pygments import highlight from pygments.lexers import get_lexer_by_name, TextLexer @@ -100,3 +103,30 @@ def render(text): return formatted_text + +def main() -> None: + """Command‑line entry point. + + The CLI accepts one or more file paths, reads each file, renders it via + :func:`render`, and prints the result to stdout. Files that cannot be + opened will emit an error on ``stderr`` but the program continues + processing subsequent files. + """ + + parser = argparse.ArgumentParser( + description="Render markdown files to the terminal with ANSI color." # pragma: no cover - trivial description + ) + parser.add_argument("files", nargs="+", help="Markdown files to render") + args = parser.parse_args() + + for path in args.files: + try: + with open(path, "r", encoding="utf-8") as f: + content = f.read() + # Render and print + sys.stdout.write(render(content)) + except Exception as exc: # pragma: no cover - error handling + sys.stderr.write(f"Error reading {path}: {exc}\n") + +if __name__ == "__main__": # pragma: no cover - used only when executed as script + main() diff --git a/pyproject.toml b/pyproject.toml index b1d31b7..f93963f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,9 +11,9 @@ build-backend = "setuptools.build_meta" # 2. Project metadata (replaces the `setup()` call) # ------------------------------------------------------------------ [project] -name = "term_color_md" +name = "print_md" version = "0.1" -description = "simple utilities to render markdon on the terminal" +description = "simple utilities to print markdown on the terminal colorfully" requires-python = ">=3.9" # Dependencies that your package needs at install‑time @@ -21,3 +21,6 @@ dependencies = [ "termcolor>=3.1.0", "pygments>=2.12", ] + +[project.scripts] +print_md = "print_md:main" diff --git a/term_color_md/__pycache__/__init__.cpython-311.pyc b/term_color_md/__pycache__/__init__.cpython-311.pyc deleted file mode 100644 index 670c63466e44bc3c517f66f3da62cb35ffeded31..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4429 zcmcgvUrZZE8lSb-|5zJCFu@Qo1{1(0g(gR%HsoK^q{@+CNa0N50LCyIW3skkcil9; zwd99BxDitQmIUP#x2p2zl83yUlvX{JoKCvDoU|Kll9IMLw`!Mk(o=8WHdpmwlVrs{xohv%C0e*O~jK?X5TyeKTNTS zD9_XEEV1D&{;{I35q+O6o3Q5sD5A=X=_YErTWQV`kjNUKA!~#nOU6LfBoN0z!7%y9 ztXVJ@pSNEbqqk5jN37D11!%m9#@?-rXRioGuAjGTD$SE+8IpqeCbDw3Vkv78EbLCf zQbb5zOwgpaoh6e7>^(GRjTphwG_(}WFOCC1*gDcGSlJH*lC9;PoB9H>bkC~yDCywQ zPAMmS1hO{1uH1v>unIQ5ezUIEy@^)nE?y-qWvc{(P?d22pkITfhk_B|Hx;R}=JUTO zTDsU0VCe_6R+Z>IuM2H@UG{CHX@6d$EbINuQi6fsRqjKmC|Ct4Xpb50IrJEyC4-&k7?%2UEKoUjupaLG44}QO zKOyFAv>TxNHMARH(`#t&g3Yg?-2y!?(?-b6Tae!q4CpRs4XWV7jB$E;I#V+>!3B_j z%I=AaJ^mv# z#_02TGo%ldDmi;8np`IitL95I!=x^*6GFyl6TBJUxv7ajWU_lAFcA<3amT=7K2%LHHkDpL zfQST#=kcx&^v$IbbYDE0jP)(B^L^<0qx;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