Class: Banzai::Filter::MarkdownEngines::CommonMark

Inherits:
Object
  • Object
show all
Defined in:
lib/banzai/filter/markdown_engines/common_mark.rb

Constant Summary collapse

EXTENSIONS =
[
  :autolink,      # provides support for automatically converting URLs to anchor tags.
  :strikethrough, # provides support for strikethroughs.
  :table,         # provides support for tables.
  :tagfilter      # strips out several "unsafe" HTML tags from being used: https://github.github.com/gfm/#disallowed-raw-html-extension-
].freeze
PARSE_OPTIONS =
[
  :FOOTNOTES,                  # parse footnotes.
  :STRIKETHROUGH_DOUBLE_TILDE, # parse strikethroughs by double tildes (as redcarpet does).
  :VALIDATE_UTF8               # replace illegal sequences with the replacement character U+FFFD.
].freeze
RENDER_OPTIONS =

The `:GITHUB_PRE_LANG` option is not used intentionally because it renders a fence block with language as `<pre lang=“LANG”>some code\n</pre>` while GitLab's syntax is `<pre><code lang=“LANG”>some coden</code></pre>`. If in the future the syntax is about to be made GitHub-compatible, please, add `:GITHUB_PRE_LANG` render option below and remove `code_block` method from `lib/banzai/renderer/common_mark/html.rb`.

[
  # as of commonmarker 0.18.0, we need to use :UNSAFE to get the same as the original :DEFAULT
  # https://github.com/gjtorikian/commonmarker/pull/81
  :UNSAFE
].freeze
RENDER_OPTIONS_SOURCEPOS =
RENDER_OPTIONS + [
  :SOURCEPOS # enable embedding of source position information
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ CommonMark

Returns a new instance of CommonMark.


41
42
43
44
# File 'lib/banzai/filter/markdown_engines/common_mark.rb', line 41

def initialize(context)
  @context  = context
  @renderer = Banzai::Renderer::CommonMark::HTML.new(options: render_options)
end

Instance Method Details

#render(text) ⇒ Object


46
47
48
49
50
# File 'lib/banzai/filter/markdown_engines/common_mark.rb', line 46

def render(text)
  doc = CommonMarker.render_doc(text, PARSE_OPTIONS, EXTENSIONS)

  @renderer.render(doc)
end