class MarkdownString
Public Class Methods
backquotes(text)
click to toggle source
Return markdown backquotes from text
Example¶ ↑
MarkdownString.backquotes "hoge\nhige\nhage\n"
result
>hoge >hige >hage
# File lib/markdown/backquotes.rb, line 16 def self.backquotes(text) return '>' if text.nil? return text unless text.is_a?(String) return '>' if text.empty? text.split("\n").reduce([]) do |ret, elm| ret << ">#{elm} " ret end.join("\n") + "\n" end
bold(text)
click to toggle source
Return markdown bold from text
Example¶ ↑
case list
MarkdownString.bold("hoge") # '**hoge**' MarkdownString.bold("") # '****' MarkdownString.bold(nil) # '****'
# File lib/markdown/bold.rb, line 14 def self.bold(text) return '****' if text.nil? return text unless text.is_a?(String) return '****' if text.empty? "**#{text}**" end
code(text)
click to toggle source
codes(text, lang = nil)
click to toggle source
Return markdown codes from text
Example¶ ↑
MarkdownString.codes("class Hoge\n def hoge\n 'hoge'\n end\nend\n")
result
~~~ruby class Hoge def hoge 'hoge' end end ~~~
# File lib/markdown/codes.rb, line 20 def self.codes(text, lang = nil) lang = '' if lang.nil? text = '' if text.nil? return text unless text.is_a?(String) "~~~#{lang}\n#{text}\n~~~\n" end
hr()
click to toggle source
italic(text)
click to toggle source
Return markdown italic from text
Example¶ ↑
case list
MarkdownString.italic(%w{a b c})
resitalict
* a * b * c
case not list
MarkdownString.italic("test") # => "test"
case nil list
MarkdownString.italic([nil, nil])
resitalict
* *
case empty list
MarkdownString.italic([]) # => ""
# File lib/markdown/italic.rb, line 35 def self.italic(text) return '**' if text.nil? return text unless text.is_a?(String) return '**' if text.empty? "*#{text}*" end
link(label, url)
click to toggle source
Return markdown link from label and url
Example¶ ↑
case list
MarkdownString.link 'label', 'http://hogehogehoge.com'
result
'[label](http://hogehogehoge.com)'
# File lib/markdown/link.rb, line 16 def self.link(label, url) label = '' if label.nil? url = '' if url.nil? return label unless label.is_a?(String) return url unless url.is_a?(String) "[#{label}](#{url})" end
ol(list)
click to toggle source
Return markdown ol from text
Example¶ ↑
case list
MarkdownString.ol(%w{a b c})
resolt
1. a 1. b 1. c
case not list
MarkdownString.ol("test") # => "test"
case nil list
MarkdownString.ol([nil, nil])
resolt
1. 1.
case empty list
MarkdownString.ol([]) # => ""
# File lib/markdown/ol.rb, line 35 def self.ol(list) return list unless list.is_a?(Array) return '' if list.empty? list.reduce([]) do |ret, elm| elm = '' if elm.nil? ret << "1. #{elm}" ret end.join("\n") + "\n" end
ul(list)
click to toggle source
Return markdown ul from text
Example¶ ↑
case list
MarkdownString.ul(%w{a b c})
result
* a * b * c
case not list
MarkdownString.ul("test") # => "test"
case nil list
MarkdownString.ul([nil, nil])
result
* *
case empty list
MarkdownString.ul([]) # => ""
# File lib/markdown/ul.rb, line 35 def self.ul(list) return list unless list.is_a?(Array) return '' if list.empty? list.reduce([]) do |ret, elm| elm = '' if elm.nil? ret << "* #{elm}" ret end.join("\n") + "\n" end
Private Class Methods
heading(text, level)
click to toggle source
# File lib/markdown/heading.rb, line 27 def self.heading(text, level) return '#' * level + ' ' if text.nil? return '#' * level + ' ' if text.respond_to?(:empty) && text.empty? '#' * level + " #{text}" end