Sha256: 82771db6f885c9102a69386f52cf83577fcb3c205d1a3b0162e2c74336008037

Contents?: true

Size: 1.2 KB

Versions: 1

Compression:

Stored size: 1.2 KB

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

  class JazzyCopyright < Redcarpet::Render::HTML
    def link(link, _title, content)
      %(<a class="link" href="#{link}" target="_blank" \
rel="external">#{content}</a>)
    end
  end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jazzy-0.2.4 lib/jazzy/jazzy_markdown.rb