changed name to print_md

This commit is contained in:
Ian Griffin 2025-11-12 20:25:57 +08:00
parent 5f3175379b
commit 9bd513a3a3
4 changed files with 37 additions and 2 deletions

2
.gitignore vendored
View File

@ -1,2 +1,4 @@
build
*.egg-info
*/__pycache__
__pycache__

View File

@ -4,7 +4,10 @@
#
# You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
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:
"""Commandline 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()

View File

@ -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 installtime
@ -21,3 +21,6 @@ dependencies = [
"termcolor>=3.1.0",
"pygments>=2.12",
]
[project.scripts]
print_md = "print_md:main"