Class: MarkdownString
- Defined in:
- lib/markdown/hr.rb,
lib/markdown/ol.rb,
lib/markdown/ul.rb,
lib/markdown/bold.rb,
lib/markdown/italic.rb,
lib/markdown/heading.rb
Class Method Summary collapse
-
.bold(text) ⇒ Object
Return markdown bold from text.
-
.hr ⇒ Object
Return markdown hr.
-
.italic(text) ⇒ Object
Return markdown italic from text.
-
.ol(list) ⇒ Object
Return markdown ol from text.
-
.ul(list) ⇒ Object
Return markdown ul from text.
Class Method Details
.bold(text) ⇒ Object
Return markdown bold from text
Example
case list
MarkdownString.bold("hoge") # '**hoge**'
MarkdownString.bold("") # '****'
MarkdownString.bold(nil) # '****'
14 15 16 17 18 19 |
# 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 |
.hr ⇒ Object
Return markdown hr
Example
case list
MarkdownString.hr # => '---'
12 13 14 |
# File 'lib/markdown/hr.rb', line 12 def self.hr '---' end |
.italic(text) ⇒ Object
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([]) # => ""
35 36 37 38 39 40 |
# 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 |
.ol(list) ⇒ Object
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([]) # => ""
35 36 37 38 39 40 41 42 43 |
# 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) ⇒ Object
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([]) # => ""
35 36 37 38 39 40 41 42 43 |
# 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 |