Markdown for C, for Ruby

This is a MD4C binding for Ruby. It can parse Markdown documents based on the CommonMark and with some extensions, including the GitHub Flavored Markdown. It can also convert Markdown documents into HTML.

Project links: Codeberg, RubyGems.org

Installation

This gem requires the MD4C C library.

Install the gem and add to the application's Gemfile by executing:

bundle add md4c

If bundler is not being used to manage dependencies, install the gem by executing:

gem install md4c

Usage

The parser uses the callback approach:

require 'md4c'
parser = MD4C::Parser.new

parser.on_enter_block do |block|
  # do something with block
end

parser.parse(source)

There are also on_leave_block, on_enter_span, on_leave_span, and on_text methods.

The Parser's initialize method takes options for extensions. For example,

parser = MD4C::Parser.new(permissive_atx_headers: true)
# [...]
parser.parse(<<~END_MARKDOWN)
#this is now header
END_MARKDOWN

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome.

License

Copyright (C) 2026 gemmaro

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.