Sha256: f43b5c5c8b3118bc2c1a31fa7077f0efde6cf889b761138329dca7f6ccfd2c2b

Contents?: true

Size: 1.03 KB

Versions: 8

Compression:

Stored size: 1.03 KB

Contents

module Troy
  class Markdown
    # Create a new Redcarpet renderer, that prepares the code block
    # to use Prisme.js syntax.
    #
    module PrismJs
      def block_code(code, language)
        %[<pre class="language-#{language}"><code>#{CGI.escapeHTML(code)}</code></pre>]
      end
    end

    # Create a new Redcarpet renderer, that prepares the code block
    # to use Prisme.js syntax.
    #
    module Rouge
      include ::Rouge::Plugins::Redcarpet
    end

    class Renderer < Redcarpet::Render::HTML
      include Redcarpet::Render::HTMLAbbreviations
      include Redcarpet::Render::SmartyPants
      include Rouge
    end

    # Set the Markdown markup that must be rendered.
    #
    attr_reader :markup

    def initialize(markup)
      @markup = markup
    end

    def renderer
      @renderer ||= Redcarpet::Markdown.new(Renderer, {
        autolink: true,
        space_after_headers: true,
        fenced_code_blocks: true,
        footnotes: true
      })
    end

    def to_html
      renderer.render(markup)
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
troy-0.0.35 lib/troy/markdown.rb
troy-0.0.34 lib/troy/markdown.rb
troy-0.0.33 lib/troy/markdown.rb
troy-0.0.32 lib/troy/markdown.rb
troy-0.0.31 lib/troy/markdown.rb
troy-0.0.30 lib/troy/markdown.rb
troy-0.0.29 lib/troy/markdown.rb
troy-0.0.28 lib/troy/markdown.rb