In recent years, Markdown has become the lingua franca of plain-text files on the web. If you're a developer, you have read — and maybe even written — hundreds of Markdown documents over the course of your career.
GitHub repositories use README files written in Markdown. Stack Overflow and Reddit use it to format posts. Technical documentation, blog posts, and entire books are written in Markdown. And it's not just for humans either! AI tools such as Claude Code and Cursor use Markdown documents to improve the effectiveness of AI agents. This article you are reading is — you guessed it — written in Markdown!
Ruby on Rails, of course, has its own tooling around Markdown, and in this post, we'll build a Markdown editor using Rails.
Markdown in Ruby on Rails
Rails 8.1 brings Markdown as content type, as well as a new rich text editor with Markdown support. And if you can't or don't want to use Rails defaults, there are always gems, such as Marksmith.
But what does it actually take to build a GitHub-like Markdown editor? Something simple that supports editing Markdown text and previewing the result. Something like this:
Let's find out!
Markdown and Markdown Flavors
Before we start with the implementation, let's talk about the Markdown language itself. First, it's essential to understand that there is no single, definitive Markdown language. When Markdown was conceived in 2004, its original description left quite some room for interpretation. As a result, a plethora of Markdown dialects — or flavors — sprang into existence, each of them supporting different features and slightly different syntaxes.
The flavor you might be most familiar with is GitHub Flavored Markdown, or GFM in short. It is based on CommonMark, an attempt to create a formal, unified specification for Markdown, which was created in 2014. The CommonMark specification has been widely adopted, but even so, several different Markdown flavors remain common today.
... continue reading