Sha256: c02478670443faa174545ac767cb80eb7f56d5a4c69471403b633bc21802e2c0

Contents?: true

Size: 1.24 KB

Versions: 9

Compression:

Stored size: 1.24 KB

Contents

require 'rouge'
require 'redcarpet'
require 'rouge/plugins/redcarpet'

module Mumukit::ContentType::Markdown
  extend Mumukit::ContentType::BaseContentType

  class HTML < Mumukit::ContentType::Emoji::Render
    include Rouge::Plugins::Redcarpet

    def table(header, body)
      "<table class=\"table\"><thead>\n#{header}</thead><tbody>\n#{body}</tbody></table>\n"
    end

    def link(link, title, content)
      "<a title=\"#{title}\" href=\"#{link}\" target=\"_blank\">#{content}</a>"
    end
  end

  @@markdown = Redcarpet::Markdown.new(HTML, autolink: true, fenced_code_blocks: true, no_intra_emphasis: true, tables: true)

  def self.title(title)
    "**#{title}**"
  end

  def self.code(code)
    "\n```\n#{code}\n```\n\n"
  end

  def self.highlighted_code(language, code)
    "```#{language}\n#{(code.ends_with? "\n") ? code : "#{code}\n"}```"
  end

  def self.inline_code(code)
    "`#{code}`"
  end

  def self.replace_mu_logo(content)
    mumuki_logo = '<i class="text-primary da da-mumuki"></i>'
    @@markdown
        .render(content)
        .gsub('<span class="err">ム</span>', mumuki_logo)
        .gsub('ム', mumuki_logo)
  end

  def self.htmlize(content)
    replace_mu_logo(content) if content
  end

  def self.name
    'markdown'
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
mumukit-content-type-1.8.1 lib/mumukit/content_type/markdown.rb
mumukit-content-type-1.8.0 lib/mumukit/content_type/markdown.rb
mumukit-content-type-1.7.0 lib/mumukit/content_type/markdown.rb
mumukit-content-type-1.6.1 lib/mumukit/content_type/markdown.rb
mumukit-content-type-1.6.0 lib/mumukit/content_type/markdown.rb
mumukit-content-type-1.5.1 lib/mumukit/content_type/markdown.rb
mumukit-content-type-1.5.0 lib/mumukit/content_type/markdown.rb
mumukit-content-type-1.4.1 lib/mumukit/content_type/markdown.rb
mumukit-content-type-1.4.0 lib/mumukit/content_type/markdown.rb