Module: Markshi
- Defined in:
- lib/markshi.rb,
lib/markshi/version.rb
Constant Summary collapse
- VERSION =
"0.0.2"
Instance Method Summary collapse
- #decorate_boxes(text) ⇒ Object
- #highlight_code(text) ⇒ Object
- #layout(title, toc, text, template = 'default') ⇒ Object
- #markdownize(text) ⇒ Object
Instance Method Details
#decorate_boxes(text) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/markshi.rb', line 20 def decorate_boxes(text) boxes = %w[note quote caution tip] boxes = boxes.join '|' text.gsub(/<blockquote><p><strong>(#{boxes})<\/strong>/mi) do "<blockquote class=\"#{$1}\"><p>".downcase end end |
#highlight_code(text) ⇒ Object
14 15 16 17 18 |
# File 'lib/markshi.rb', line 14 def highlight_code(text) text.gsub(/<pre><code>(\[(\w+)\])?\n([^<]+)<\/code><\/pre>/m) do CodeRay.scan($3, $2).div(:css => :class).gsub('&', '&') end end |
#layout(title, toc, text, template = 'default') ⇒ Object
28 29 30 31 32 |
# File 'lib/markshi.rb', line 28 def layout(title, toc, text, template = 'default') templates_dir = File.('../../templates', __FILE__) template = ERB.new(File.read("#{templates_dir}/#{template}.erb.html")) template.result(binding) end |
#markdownize(text) ⇒ Object
9 10 11 12 |
# File 'lib/markshi.rb', line 9 def markdownize(text) rd = RDiscount.new(text, :smart, :generate_toc) [rd.toc_content, rd.to_html] end |