Sha256: 9d16e39335081216da3efc948d8cf078037f899a87c2806ddf4c106592a71ecb

Contents?: true

Size: 1.23 KB

Versions: 3

Compression:

Stored size: 1.23 KB

Contents

require 'redcarpet'

module RevealCK
  module Markdown
    # This class defines what "Slide Markdown" is.
    class SlideMarkdown < Redcarpet::Render::HTML
      HR = '<hr>'
      HR_NEWLINE = "<hr>\n"

      HTML_SLIDE_START = '<section>'
      HTML_SLIDE_END = '</section>'
      HTML_SLIDE_DIVIDER = "#{HTML_SLIDE_END}\n#{HTML_SLIDE_START}"

      MARKDOWN_SLIDE_DIVIDER = '---'
      MARKDOWN_SLIDE_DIVIDER_REGEX = /^---$/
      MARKDOWN_SLIDE_DIVIDER_WITH_NEWLINES = "\n---\n"

      def preprocess(doc)
        doc.gsub(MARKDOWN_SLIDE_DIVIDER_REGEX,
                 MARKDOWN_SLIDE_DIVIDER_WITH_NEWLINES)
      end

      def postprocess(doc)
        doc = doc[HR.size, doc.size - 1] if doc.start_with?(HR)

        if doc.end_with?(HR_NEWLINE)
          doc = doc[0, doc.size - 1 - HR_NEWLINE.size]
        end
        doc = doc.gsub(HR, HTML_SLIDE_DIVIDER)
        "#{HTML_SLIDE_START}\n#{doc}\n#{HTML_SLIDE_END}"
      end

      def block_code(code, language)
        if language.nil?
          "<pre><code>#{code}</code></pre>"
        elsif language == 'notes' || language == 'note'
          "<aside class='notes'>#{code}</aside>"
        else
          "<pre><code class=\"#{language}\">#{code}</code></pre>"
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
reveal-ck-0.5.1 lib/reveal-ck/markdown/slide_markdown.rb
reveal-ck-0.5.0 lib/reveal-ck/markdown/slide_markdown.rb
reveal-ck-0.4.2 lib/reveal-ck/markdown/slide_markdown.rb