Sha256: 8b3ec8f4b8ee48eac98931df258cdd25fbbb9783e254ffe8ee2edf893461a92e

Contents?: true

Size: 947 Bytes

Versions: 6

Compression:

Stored size: 947 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: true,
    }.freeze
  end

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
jazzy-0.0.20 lib/jazzy/jazzy_markdown.rb
jazzy-0.0.19 lib/jazzy/jazzy_markdown.rb
jazzy-0.0.18 lib/jazzy/jazzy_markdown.rb
jazzy-0.0.17 lib/jazzy/jazzy_markdown.rb
jazzy-0.0.16 lib/jazzy/jazzy_markdown.rb
jazzy-0.0.15 lib/jazzy/jazzy_markdown.rb