require 'redcarpet'
require 'rouge'
require 'rouge/plugins/redcarpet'
module Jazzy
module Markdown
class JazzyHTML < Redcarpet::Render::HTML
include Redcarpet::Render::SmartyPants
include Rouge::Plugins::Redcarpet
def header(text, header_level)
text_slug = text.gsub(/[^\w]+/, '-')
.downcase
.sub(/^-/, '')
.sub(/-$/, '')
"
\s*)? # optional opening p tag # any one of our special list types (#{SPECIAL_LIST_TYPES.map(&Regexp.method(:escape)).join('|')}) [\s:] # followed by either a space or a colon }ix ELIDED_LI_TOKEN = '7wNVzLB0OYPL2eGlPKu8q4vITltqh0Y6DPZf659TPMAeYh49o'.freeze def list_item(text, _list_type) if text =~ SPECIAL_LIST_TYPE_REGEX type = Regexp.last_match(2) if UNIQUELY_HANDLED_CALLOUTS.include? type.downcase return ELIDED_LI_TOKEN end return render_aside(type, text.sub(/#{Regexp.escape(type)}:\s+/, '')) end str = '
#{type.underscore.humanize}
#{text}\s*)?)'.freeze
OUTRO_PAT = '(? #{body} ')
# call smartypants for pretty quotes etc.
postprocess(body)
end
end
def self.renderer
@renderer ||= JazzyDeclarationHTML.new
end
def self.markdown
@markdown ||= Redcarpet::Markdown.new(renderer, REDCARPET_OPTIONS)
end
def self.render(markdown_text)
renderer.reset
markdown.render(markdown_text)
end
def self.rendered_returns
renderer.returns
end
def self.rendered_parameters
renderer.parameters
end
class JazzyCopyright < Redcarpet::Render::HTML
def link(link, _title, content)
%(#{content})
end
end
def self.copyright_markdown
@copyright_markdown ||= Redcarpet::Markdown.new(
JazzyCopyright,
REDCARPET_OPTIONS,
)
end
def self.render_copyright(markdown_text)
copyright_markdown.render(markdown_text)
end
end
end