changed name to print_md
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,2 +1,4 @@
|
||||
build
|
||||
*.egg-info
|
||||
*/__pycache__
|
||||
__pycache__
|
||||
|
||||
@@ -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:
|
||||
"""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()
|
||||
@@ -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"
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user