Sha256: 89ac0a28bfe8bf1fffed2fcd99b44a0090181f3c530c3b718defabad37806c86

Contents?: true

Size: 897 Bytes

Versions: 6

Compression:

Stored size: 897 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 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

6 entries across 6 versions & 1 rubygems

Version Path
jazzy-0.2.3 lib/jazzy/jazzy_markdown.rb
jazzy-0.2.2 lib/jazzy/jazzy_markdown.rb
jazzy-0.2.1 lib/jazzy/jazzy_markdown.rb
jazzy-0.2.0 lib/jazzy/jazzy_markdown.rb
jazzy-0.1.6 lib/jazzy/jazzy_markdown.rb
jazzy-0.1.5 lib/jazzy/jazzy_markdown.rb