Added basic rendering support and some cleanup

This commit is contained in:
Tris Forster 2026-01-29 09:37:15 +11:00
parent e9cc2cc3d0
commit 44549aaff3
4 changed files with 36 additions and 1 deletions

View File

@ -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.

View File

@ -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

View File

@ -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()

View File

@ -8,6 +8,7 @@ authors = [
readme = "README.md"
requires-python = ">=3.13"
dependencies = [
"markdown (>=3.10.1,<4.0.0)"
]
[project.scripts]