[DRAFT] Procrastinating writing
For a while now, I've been wanting to write more..
But, at least at my current skill level, writing is quite hard. But, you know what's not hard? Programming. So instead of writing, I've been spending time "making writing easier", because obviously the implementation details of my tools are what's holding me back.
Adding features to this blog
For this blog, I write basic markdown and use markdown2 to convert it to HTML. This works pretty well, but:
- It's not extendable from a user perspective
- While looking at how to extend it, I read it's code and got nightmares
What's someone to do, if they can't have a custom {embed} or {aside} block, write HTML manually? Absolutely not.
How about defining a grammar for the (objectively correct) subset of Markdown that I use?
Once I had a grammar, I could use lark to parse the text to an AST.
The initial AST does not communicate meaning though, as it looks something like
To make this more amenable to emit HTML later, first we need to perform a tree-rewriting step, which is just pattern matching on certain sequences and organizing them into a more semantic hierarchy
once the elements are grouped in semantic blocks, emitting HTML is trivial:
and now, I can also pass callbacks for some events:
h1 -> add id & anchor
Rendering diagrams
For diagrams, I use diagrams.net (nee draw.io). This is a nice tool, with a Linux client and everything!
The problem? Exporting a handful of diagrams from drawio "native" files to svg requires starting the full editor, taking 5-10 seconds.
I looked at these ".drawio" files, and... it's just XML, why can't it be faster?
I spent a few days writing a renderer for these files, which outputs straight svg.
Notes on weird format stuff, arrow rendering algo (unclear), text formatting (3 ways) and measuring bounding boxes