From 44549aaff394779e6548d56dc3f67367f6475d38 Mon Sep 17 00:00:00 2001 From: Tris Forster Date: Thu, 29 Jan 2026 09:37:15 +1100 Subject: [PATCH] Added basic rendering support and some cleanup --- README.md | 9 +++++++++ pyn/commands.py | 23 ++++++++++++++++++++++- pyn/todo.py | 4 ++++ pyproject.toml | 1 + 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e69de29..9a774d8 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,9 @@ +# PyN + +CLI tool for manipulating text notes + +### Git support + +If the notes directory is under git control then modifications will be auto staged. + +You can then execute the `pyn sync` command to pull and push from the upstream server. diff --git a/pyn/commands.py b/pyn/commands.py index eadfd50..bd191be 100644 --- a/pyn/commands.py +++ b/pyn/commands.py @@ -67,7 +67,7 @@ def cmd_list_notes(config: Config, notebook: str, pretty: bool) -> None: for filename in notes.get_file_list(config, notebook): if pretty: e = notes.file_entry(config, filename) - print(f"{e.notebook:>20s}: {e.filename}") + print(f"\033[32m{e.notebook:>20s}\033[0m: {e.filename}") else: print(filename) @@ -106,6 +106,27 @@ show_note.add_argument("title", help="note title", nargs="?") show_note.add_argument("--notebook", "-n", help="limit to this notebook") show_note.set_defaults(func=cmd_show_note) +def cmd_render_note(config, title, notebook: str) -> None: + filename = notes.search_filenames(config, title, notebook) + import markdown + import tempfile + import subprocess + import time + + with open(filename, "r", encoding="utf-8") as input_file: + text = input_file.read() + html = markdown.markdown(text) + + with tempfile.NamedTemporaryFile(suffix=".html", delete=True) as f: + f.write(html.encode('utf-8')) + subprocess.run(['firefox', '--new-tab', f"file://{f.name}"]) + time.sleep(1) + +render_note = group.add_parser("render") +render_note.add_argument("title", help="note title", nargs="?") +render_note.add_argument("--notebook", "-n", help="limit to this notebook") +render_note.set_defaults(func=cmd_render_note) + ### Git diff --git a/pyn/todo.py b/pyn/todo.py index c595cca..8b0ba94 100644 --- a/pyn/todo.py +++ b/pyn/todo.py @@ -4,6 +4,10 @@ from pyn.commands import group as parent_group from shutil import get_terminal_size import sys +LIST_CHAR = "-" +COMPLETE_CHAR = "x" +PENDING_PATTERN = r"^[+\-\*]\s+\[ \]" +COMPLETED_PATTERN = r"^[+\-\*]\s+\[" + COMPLETE_CHAR + r"\]" p = parent_group.add_parser("todo", help="manipulate todo items") group = p.add_subparsers() diff --git a/pyproject.toml b/pyproject.toml index bfeadba..abecf9a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,6 +8,7 @@ authors = [ readme = "README.md" requires-python = ">=3.13" dependencies = [ + "markdown (>=3.10.1,<4.0.0)" ] [project.scripts]