CommonMarker+Rouge

Gem Travis Code Climate Code Climate

A CommonMarker wrapper with syntax highlight support by Rouge.

IMPORTANT

commonmarker-rouge currently works only with renderer in :UNSAFE mode. Don't forget to set :UNSAFE manually if you're overwriting the renderer mode.

If you know how to fix this behavior please comment in Issue #5

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, [: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.