Skip to content

Commit

Permalink
Resize SVGs, allow list of images in preamble
Browse files Browse the repository at this point in the history
  • Loading branch information
plexus committed Jun 15, 2013
1 parent a4998ca commit 324243d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
16 changes: 15 additions & 1 deletion bin/mdpress
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/impress_renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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>"
Expand Down

0 comments on commit 324243d

Please sign in to comment.