CommonMarker wrapper with Rouge as syntax highlighter
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
bin
lib/commonmarker
spec
.gitignore
.rspec
.travis.yml
Gemfile
LICENSE.md
README.md
Rakefile
commonmarker-rouge.gemspec

README.md

CommonMarker+Rouge

Gem Travis Code Climate Code Climate Gemnasium

A CommonMarker wrapper with syntax highlight support by Rouge.

Installation

Add these lines to your application's Gemfile:

gem 'commonmarker-rouge'

Usage

# use default CommonMarker class and Rouge::Formatters::HTML formatter
CommonMarker::Rouge.render_html(content)

# get CommonMarker parsed AST
CommonMarker::Rouge.render_doc(content)

# pass options to CommonMarker
CommonMarker::Rouge.render_html(content, [:SAFE, :SOURCEPOS])

# use custom CommonMarker wrapper (must provide compatible render_doc)
CommonMarker::Rouge.render_html(content, cmark_class: CommonMarkerWrapper)

# use custom Rouge formatter by class
CommonMarker::Rouge.render_html(content, formatter_class: Rouge::Formatters::HTMLLinewise)
# or by instance
CommonMarker::Rouge.render_html(content, formatter: Rouge::Formatters::HTMLTable.new(
  Rouge::Formatters::HTML.new
))

# pass some options to Rouge
CommonMarker::Rouge.render_html(content, options: { css_class: 'custom-class' })
# or
CommonMarker::Rouge.render_html(content, formatter: Rouge::Formatters::HTMLTable.new(
  Rouge::Formatters::HTML.new, code_class: 'rouge-code'
))

License

The gem is available as open source under the terms of the MIT License.