opensourceprojects.dev

A broadsheet for software that doesn't ask for your email

The first step of rendering markup on GitHub, now a gem
GitHub RepoViews3

Project Description

View on GitHub

GitHub's Markup Gem: The First Step Before Your README Becomes HTML

You've probably written a README, a wiki page, or a docs file in Markdown, Textile, or reStructuredText and watched GitHub turn it into clean, rendered HTML. But have you ever wondered what actually happens between your raw text and the page you see? The github-markup gem is the first step of that journey, and it's open source.

What It Does

github-markup is a Ruby library that selects an underlying library to convert raw markup into HTML. That's it—it's the first step of a pipeline that every markup file in a repository goes through before it's rendered on GitHub.com.

The full pipeline looks like this: github-markup picks a parser for your file's format and converts it to HTML. Then the HTML is sanitized (aggressively removing things like script tags, inline styles, and class or id attributes). Syntax highlighting runs on code blocks via github/linguist. Other filters add emoji, task lists, named anchors, CDN caching for images, and autolinking. Finally, the result is rendered on GitHub.com.

The important caveat: only the first step is covered by this gem. The rest happens on GitHub.com. In particular, markup does no sanitization itself—it expects whatever pipeline consumes the HTML to handle that.

The gem supports a solid range of formats, each with its own dependency. Markdown (.markdown, .mdown, .mkdn, .md) uses CommonMarker. Textile uses RedCloth. RDoc, Org, Creole, MediaWiki, reStructuredText (via Python's docutils), AsciiDoc (via Asciidoctor), and POD round out the list.

Why It's Cool

It's honest about its scope. The README is upfront that this is one piece of a larger system, not a magic rendering solution. That kind of clarity is refreshing—you know exactly what you're getting and what you're responsible for.

  • One interface, many formats. Instead of wiring up a different parser for every markup language, you call GitHub::Markup.render and let it figure out the rest. That's a practical abstraction if you're building anything that handles user-supplied markup.
  • The dependency model is transparent. Each format lists exactly what you need to install. You don't pull in every parser—just the ones you actually use. There's even a script/bootstrap to fetch them all if you want the full set.
  • Markdown version flexibility. Markdown rendering supports CommonMarker 0.x and 2.x, and you keep the installed version's parser option behavior. Extensions follow the installed parser, so 2.x-only extensions stay unavailable on 0.x. It's a small detail, but it matters if you're pinning versions in production.
  • It's the actual code behind GitHub. This isn't a reimplementation or a clone—it's the library GitHub uses as the entry point for rendering markup across the platform. That's a meaningful endorsement of its design.

The convenience form is a nice touch, too. If you already know the format, GitHub::Markup.render_s lets you skip the filename-based detection and pass the markup type directly.

How to Try It

Getting started is a single gem install:

gem install github-markup

Or, if you're working from a checkout, run bundle install from the repository directory.

Then render something. The basic form takes a filename and a string:

require 'github/markup'

GitHub::Markup.render('README.markdown', "* One
* Two")

A more realistic version reads the file and passes its contents:

require 'github/markup'

GitHub::Markup.render(file, File.read(file))

And if you want to skip format detection:

require 'github/markup'

GitHub::Markup.render_s(GitHub::Markups::MARKUP_MARKDOWN, "* One
* Two")

For local development, the README walks you through a Python virtual environment, activating it, and running ./bootstrap from the script directory. You can set COMMONMARKER_VERSION to override the development bundle's default ~> 2.8.2 requirement.

The repository is at github.com/github/markup, and the contributing guidelines are worth reading before you file an issue.

Final Thoughts

github-markup is a focused tool for a specific job: turning raw markup into HTML using the right parser for the format. It's best suited for Ruby developers building pipelines that handle multiple markup languages, or anyone curious about how GitHub's rendering actually works under the hood. Just remember that sanitization and the rest of the pipeline are on you—this gem hands off HTML and trusts you to handle it safely. If you're building something that consumes user markup, that's a responsibility worth taking seriously, and this library gives you a clean starting point.


Follow @githubprojects for more developer tools and open source projects.

Back to Projects
Project ID: markupLast updated: November 4, 2026 at 02:51 AM