summaryrefslogtreecommitdiff
path: root/lib/banzai/filter/markdown_engines/redcarpet.rb
blob: ac99941fefaba6b11995be964dd2f821403c4523 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# `Redcarpet` markdown engine for GitLab's Banzai markdown filter.
# This module is used in Banzai::Filter::MarkdownFilter.
# Used gem is `redcarpet` which is a ruby library for markdown processing.
# Homepage: https://github.com/vmg/redcarpet

module Banzai
  module Filter
    module MarkdownEngines
      class Redcarpet
        OPTIONS = {
          fenced_code_blocks:  true,
          footnotes:           true,
          lax_spacing:         true,
          no_intra_emphasis:   true,
          space_after_headers: true,
          strikethrough:       true,
          superscript:         true,
          tables:              true
        }.freeze

        def initialize
          html_renderer = Banzai::Renderer::Redcarpet::HTML.new
          @renderer = ::Redcarpet::Markdown.new(html_renderer, OPTIONS)
        end

        def render(text)
          @renderer.render(text)
        end
      end
    end
  end
end