lib/govspeak.rb in govspeak-0.8.12 vs lib/govspeak.rb in govspeak-0.8.13
- old
+ new
@@ -7,11 +7,11 @@
class Document
@@extensions = []
attr_accessor :images
-
+
def self.to_html(source, options = {})
new(source, options).to_html
end
def initialize(source, options = {})
@@ -23,11 +23,11 @@
def kramdown_doc
@kramdown_doc ||= Kramdown::Document.new(preprocess(@source), @options)
end
private :kramdown_doc
-
+
def to_html
kramdown_doc.to_html
end
def to_text
@@ -44,11 +44,11 @@
instance_exec($1, &block)
}
end
source
end
-
+
def encode(text)
HTMLEntities.new.encode(text)
end
private :encode
@@ -70,12 +70,12 @@
def self.wrap_with_div(class_name, character, parser=Kramdown::Document)
extension(class_name, surrounded_by(character)) { |body|
content = parser ? parser.new("#{body.strip}\n").to_html : body.strip
%{<div class="#{class_name}">\n#{content}</div>\n}
}
- end
-
+ end
+
def insert_strong_inside_p(body, parser=Kramdown::Document)
parser.new(body.strip).to_html.sub(/^<p>(.*)<\/p>$/,"<p><strong>\\1</strong></p>")
end
extension('reverse') { |body|
@@ -105,20 +105,20 @@
}
extension('map_link', surrounded_by("((", "))")) { |body|
%{<div class="map"><iframe width="200" height="200" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="#{body.strip}&output=embed"></iframe><br /><small><a href="#{body.strip}">View Larger Map</a></small></div>}
}
-
+
extension('attached-image', /^!!([0-9]+)/) do |image_number|
image = images[image_number.to_i - 1]
if image
caption = image.caption rescue nil
render_image(image.url, image.alt_text, caption)
else
""
end
end
-
+
def render_image(url, alt_text, caption = nil)
lines = []
lines << '<figure class="image embedded">'
lines << %Q{ <div class="img"><img alt="#{encode(alt_text)}" src="#{encode(url)}" /></div>}
lines << %Q{ <figcaption>#{encode(caption.strip)}</figcaption>} if caption && !caption.strip.empty?