require 'redcarpet' require 'cgi' require 'magic_reveal/version' module MagicReveal class SlideRenderer < Redcarpet::Render::HTML include Redcarpet::Render::SmartyPants attr_accessor :has_shown_slides def initialize super(no_styles: true) end def self.markdown_renderer Redcarpet::Markdown.new( self.new, :space_after_headers => true, :filter_html => true, :fenced_code_blocks => true, :no_intra_emphasis => true, ) end def doc_header @has_shown_slides = false "" end def doc_footer has_shown_slides ? '' : '' end def header(text, header_level) output = [] if has_shown_slides output << "" else @has_shown_slides = true end output << "
" output << "#{text}" output.join("\n") end def prepare_code(code) if code =~ %r{\A\s*@@source\s*=\s*(.*)\s*\Z} File.read($1) else code end end def block_code(code, language) output = [] if language output << "
"
      else
        output << "
"
      end
      output << ""

      output << CGI::escapeHTML(prepare_code code)
      output << ""
      output << "
" output.join("") end end end