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(/_$/, '') "' \ "#{text}\n" end SPECIAL_LIST_TYPES = %w(Attention Author Authors Bug Complexity Copyright Date Experiment Important Invariant Note Parameter Postcondition Precondition Remark Requires Returns See SeeAlso Since TODO Throws Version Warning).freeze # rubocop:disable RegexpLiteral SPECIAL_LIST_TYPE_REGEX = %r{ \A\s* # optional leading spaces (

\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 # rubocop:enable RegexpLiteral ELIDED_LI_TOKEN = '7wNVzLB0OYPL2eGlPKu8q4vITltqh0Y6DPZf659TPMAeYh49o'.freeze def list_item(text, _list_type) return ELIDED_LI_TOKEN if text =~ SPECIAL_LIST_TYPE_REGEX str = '

  • ' str << text.strip str << "
  • \n" end def list(text, list_type) elided = text.gsub!(ELIDED_LI_TOKEN, '') return if text =~ /\A\s*\Z/ && elided str = "\n" str << (list_type == :ordered ? "
      \n" : "
    \n" : "\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) %(#{content}) end end def self.copyright_markdown @copyright_markdown ||= Redcarpet::Markdown.new( JazzyCopyright, JazzyHTML::OPTIONS, ) end end