Module: Markita::Markdown::Image
- Defined in:
- lib/markita/markdown/image.rb
Overview
Module to isolate from Markdown
Constant Summary collapse
- RGX =
/^!\[([^\[\]]+)\]\(([^()]+)\)$/
Class Method Summary collapse
- .attributes(line) ⇒ Object
- .img_src(src, alt, att) ⇒ Object
- .size(alt) ⇒ Object
-
.style(alt) ⇒ Object
:reek:ControlParameter.
Class Method Details
.attributes(line) ⇒ Object
12 13 14 15 |
# File 'lib/markita/markdown/image.rb', line 12 def self.attributes(line) mdt = RGX.match(line) [mdt[1], *mdt[2].strip.split(/\s+/, 2)] if mdt end |
.img_src(src, alt, att) ⇒ Object
17 18 19 20 21 |
# File 'lib/markita/markdown/image.rb', line 17 def self.img_src(src, alt, att) style = Image.style(alt) size = Image.size(alt) %(<img src="#{src}"#{style}#{size}alt="#{alt.strip}"#{att.shift}>\n) end |
.size(alt) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/markita/markdown/image.rb', line 23 def self.size(alt) if (mdt = /(\d+)x(\d+)/.match(alt)) %(width="#{mdt[1]}" height="#{mdt[2]}" ) else '' end end |
.style(alt) ⇒ Object
:reek:ControlParameter
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/markita/markdown/image.rb', line 32 def self.style(alt) case alt when /^:.*:$/ %( style="display: block; margin-left: auto; margin-right: auto;" ) when /:$/ %( style="float:left;" ) when /^:/ %( style="float:right;" ) else ' ' end end |