Skip to content
Permalink
Browse files
Resize SVGs, allow list of images in preamble
  • Loading branch information
plexus committed Jun 15, 2013
1 parent a4998ca commit 324243d0cbe700ce1a03eb6d54ca8e38ded85c8e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
@@ -62,13 +62,27 @@ def render opts

defaults = metadata['defaults'] || {}

metadata.fetch('images', []).each do |img|
if File.exist?("images/#{img}")
`cp images/#{img} #{DIRNAME}/#{img}`
end
end

attrs = [defaults.dup]

new_lines = []
lines.each_with_index do |line, i|
if line =~ /^=(.*)$/ && (i == 0 || lines[i-1] =~ /^(-\s*){3,}$/)
line =~ /^=(.*)$/
attrs[attrs.size-1] = defaults.dup.merge(Hash[$1.split(' ').map{|a| k,v=a.split('=') ; [k, eval(v.to_s)]}])
attr_pairs=[]
$1.split(' ').each do |str|
if str =~ /=/
attr_pairs << str
else
attr_pairs.last << ' ' << str
end
end
attrs[attrs.size-1] = defaults.dup.merge(Hash[attr_pairs.map{|a| k,v=a.split('=') ; [k, eval(v.to_s)]}])
next
elsif line =~ /^(-\s*){3,}$/
attrs << defaults.dup
@@ -59,7 +59,7 @@ def block_code code, lang
file << code
file.close
"<div class='dot-wrap'>" +
(Nokogiri(`dot #{file.path} -Tsvg`)/'svg').tap{|svg| svg.search('polygon').first.remove}.to_html +
(Nokogiri(`dot #{file.path} -Tsvg`)/'svg').first.tap{|svg| svg.search('polygon').first.remove; svg['width']='600px' ; svg.attributes['height'].remove }.to_html +
"</div>"
elsif lang == 'notes'
"<div class='notes' style='display:none;'>#{code}</div>"

0 comments on commit 324243d

Please sign in to comment.