Sha256: b4c9d8e1e3db26771f1da6604e712ebbe7f98830f3f3e65ba8aaa7550562612b
Contents?: true
Size: 1.59 KB
Versions: 1
Compression:
Stored size: 1.59 KB
Contents
require 'redcarpet' require 'cgi' require 'magic_reveal/version' module MagicReveal # Custom renderer so the HTML is the right format for Reveal.js. 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( new, space_after_headers: true, filter_html: true, fenced_code_blocks: true, no_intra_emphasis: true ) end def doc_header @has_shown_slides = false "<!-- generated by magic_reveal v#{VERSION} on #{Time.now} -->" end def doc_footer has_shown_slides ? '</section>' : '' end def header(text, header_level, anchor = nil) [].tap do |output| output << '</section>' if has_shown_slides @has_shown_slides = true anchor_html = anchor ? " id=\"#{anchor}\"" : '' output << '<section>' output << "<h#{header_level}#{anchor_html}>#{text}</h#{header_level}>" end.join("\n") end def prepare_code(code) if code =~ /\A\s*@@source\s*=\s*(?<filename>.*)\s*\Z/ File.read Regexp.last_match[:filename] else code.sub(/\A\s*/, '').sub(/\s*\Z/, '') end end def block_code(code, language) [].tap do |output| output << (language ? "<pre class=\"#{language}\">" : '<pre>') output << '<code>' output << CGI.escapeHTML(prepare_code code) output << '</code>' output << '</pre>' end.join('') end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
magic_reveal-2.6.1.4 | lib/magic_reveal/slide_renderer.rb |