Sha256: 1a9060d2047b794e3a40b018546c2b1008268931f6ff8ace279b9bcef7539d37

Contents?: true

Size: 968 Bytes

Versions: 5

Compression:

Stored size: 968 Bytes

Contents

require 'redcarpet'
require 'rouge'
require 'rouge/plugins/redcarpet'

module Jazzy
  class JazzyHTML < Redcarpet::Render::HTML
    include Redcarpet::Render::SmartyPants
    include Rouge::Plugins::Redcarpet

    def paragraph(text)
      "<p class=\"para\">#{text}</p>"
    end

    def header(text, header_level)
      text_slug = text.gsub(/[^a-zA-Z0-9]+/, '_')
        .downcase
        .sub(/^_/, '')
        .sub(/_$/, '')

      "<a href='##{text_slug}' class='anchor' aria-hidden=true>" \
        '<span class="header-anchor"></span>' \
      '</a>' \
      "<h#{header_level} id='#{text_slug}'>#{text}</h#{header_level}>\n"
    end

    OPTIONS = {
      autolink: true,
      fenced_code_blocks: true,
      no_intra_emphasis: true,
      quote: true,
      strikethrough: true,
      space_after_headers: false,
      tables: true,
    }.freeze
  end

  def self.markdown
    @markdown ||= Redcarpet::Markdown.new(JazzyHTML,  JazzyHTML::OPTIONS)
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
jazzy-0.1.4 lib/jazzy/jazzy_markdown.rb
jazzy-0.1.3 lib/jazzy/jazzy_markdown.rb
jazzy-0.1.2 lib/jazzy/jazzy_markdown.rb
jazzy-0.1.1 lib/jazzy/jazzy_markdown.rb
jazzy-0.1.0 lib/jazzy/jazzy_markdown.rb