Module: Mumukit::ContentType::Markdown
- Extended by:
- BaseContentType
- Defined in:
- lib/mumukit/content_type/markdown.rb
Defined Under Namespace
Classes: HTML, OneLinerHTML
Constant Summary
collapse
- @@markdown =
new_markdown HTML
- @@one_liner_markdown =
new_markdown OneLinerHTML
Class Method Summary
collapse
as_json, format_exception, to_html, to_s
Class Method Details
.code(code) ⇒ Object
37
38
39
|
# File 'lib/mumukit/content_type/markdown.rb', line 37
def self.code(code)
"\n```\n#{code}\n```\n\n"
end
|
.enumerate(items) ⇒ Object
69
70
71
|
# File 'lib/mumukit/content_type/markdown.rb', line 69
def self.enumerate(items)
items.map { |it| "* #{it}" }.join("\n")
end
|
.highlighted_code(language, code) ⇒ Object
41
42
43
|
# File 'lib/mumukit/content_type/markdown.rb', line 41
def self.highlighted_code(language, code)
"```#{language}\n#{(code.ends_with? "\n") ? code : "#{code}\n"}```"
end
|
.htmlize(content, options) ⇒ Object
57
58
59
|
# File 'lib/mumukit/content_type/markdown.rb', line 57
def self.htmlize(content, options)
render_replacing_mu_logo(content, renderer_for(options)) if content
end
|
.inline_code(code) ⇒ Object
45
46
47
|
# File 'lib/mumukit/content_type/markdown.rb', line 45
def self.inline_code(code)
"`#{code}`"
end
|
.name ⇒ Object
65
66
67
|
# File 'lib/mumukit/content_type/markdown.rb', line 65
def self.name
'markdown'
end
|
.new_markdown(renderer) ⇒ Object
26
27
28
|
# File 'lib/mumukit/content_type/markdown.rb', line 26
def self.new_markdown(renderer)
Redcarpet::Markdown.new(renderer, autolink: true, fenced_code_blocks: true, no_intra_emphasis: true, tables: true)
end
|
.render_replacing_mu_logo(content, renderer) ⇒ Object
49
50
51
52
53
54
55
|
# File 'lib/mumukit/content_type/markdown.rb', line 49
def self.render_replacing_mu_logo(content, renderer)
mumuki_logo = '<i class="text-primary da da-mumuki"></i>'
renderer
.render(content)
.gsub('<span class="err">ム</span>', mumuki_logo)
.gsub('ム', mumuki_logo)
end
|
.renderer_for(options) ⇒ Object
61
62
63
|
# File 'lib/mumukit/content_type/markdown.rb', line 61
def self.renderer_for(options)
options[:one_liner] ? @@one_liner_markdown : @@markdown
end
|
.title(title) ⇒ Object
33
34
35
|
# File 'lib/mumukit/content_type/markdown.rb', line 33
def self.title(title)
"**#{title}**"
end
|