sailorfe

2025 Sept 4 – Markdown in Meow

I'm a big fan of Charm even though Go is a sexy mystery to me, and the first app of theirs I ever used was Glow. That was back when I still used the Obsidian GUI and didn't know just how much of my life would revolve around Markdown, or how anal I would become about my custom colorschemes. In fact, I don't think I've ever once used a popular prebuilt scheme like Catppuccin or Rose Pine. I developed the earliest versions of Moon Queen when I still used macOS... but with WezTerm, somehow?

Configurable as Glow is, I kept trying and failing to get into Glamour to try and port one of my colorschemes to the Charm ecosystem. There's a perfectly friendly tutorial and everything. However, I have such a fine-tuned and partially automated rice setup that adding one more thing with hardcoded colors is a pain. So I fell off using Glow for the good last year and change, just reading my Markdown files in nvim normal mode.

And then a cat moved into my house and somehow managed to walk across my 40% keyboard and hit some variation of d, c, or i while I practiced guitar off a lead sheet I saved as Markdown. So ironically, an easy solution to my problem would have simply been to cat chords_*.md, but then I remembered Glow and decided to tackle a Python take on its most basic function in an afternoon.

So I ended up with Meow, basically a Markdown cat using Rich and Pygments.

I've been using Rich for the last month of building Ephem to color planetary glyphs according to Hellenistic sect and entire placements by their sign's mode or element, all through the Text class's stylize() method, which is wonderfully easy for someone like me who's spent a fair bit of time staring at Bash ANSI escape sequences.

The biggest headache I ran into is probably more beef with Markdown. I use YAML frontmatter on my Markdown notes and for static sites like this one. One thing I despise about Markdown--probably the only thing I despise about Markdown--is the two syntaxes for headings that I really think most people don't know about and you would the misfortune to learn only if you fence in your YAML with ---'s. I tried all sorts of things with Pygments, like trying to detect YAML:

is_yaml = (lang in ("yaml", "yml")) or code.startswith("---")
if is_yaml:
    continue

But again, this didn't work because MarkdownIt interprets --- as a heading no matter what. My YAML blocks kept getting their newlines stripped and basically appearing as one long string at the top of all my documents. Then I finally ran Glow side by side and saw... they just skip YAML entirely. So the solution was creating this function:

def strip_yaml_frontmatter(text: str) -> str:
    if text.startswith("---"):
        parts = text.split("---", 2)
        if len(parts) >= 3:
            return parts[2].lstrip("\n")
    return text

which looks for all instances of --- + xyz + --- and strips it regardless of whether the contents are YAML or not. Could this backfire for someone who uses those as <hr>'s? Yes. I'll... get to that before I formally ship v1, but right now I have a testing version you can try that works well enough.