Skip to content

Commit 7ce982e

Browse files
committed
Allow adding of classes, copy images to presentation dir
1 parent 44d48f6 commit 7ce982e

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

bin/mdpress

+5-3
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,11 @@ end
5454

5555
def render opts
5656
text, metadata = extract_metadata(readfile(FILENAME))
57+
5758
# ugly hack to get attributes for impress.js
5859
# TODO make this pretty
59-
lines = text.split("\n")
60-
lines.drop_while { |l| l =~ /^\s*$/ }
60+
lines = text.split("\n").reject{|l| l=~ /\A!!/ }
61+
lines.drop_while { |l| l =~ /^$/ }
6162

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

@@ -67,7 +68,7 @@ def render opts
6768
lines.each_with_index do |line, i|
6869
if line =~ /^=(.*)$/ && (i == 0 || lines[i-1] =~ /^(-\s*){3,}$/)
6970
line =~ /^=(.*)$/
70-
attrs[attrs.size-1] = defaults.dup.merge(Hash[$1.split(' ').map{|a| k,v=a.split('=') ; [k, eval(v)]}])
71+
attrs[attrs.size-1] = defaults.dup.merge(Hash[$1.split(' ').map{|a| k,v=a.split('=') ; [k, eval(v.to_s)]}])
7172
next
7273
elsif line =~ /^(-\s*){3,}$/
7374
attrs << defaults.dup
@@ -79,6 +80,7 @@ def render opts
7980

8081
# now use those attributes and render the file
8182
ImpressRenderer.new.tap do |mdpress|
83+
mdpress.dest = DIRNAME
8284
mdpress.init_with_attrs attrs, opts
8385
mdpress.author= metadata['author'] if metadata['author']
8486
mdpress.title= metadata['title'] if metadata['title']

lib/impress_renderer.rb

+12-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
require 'hexp/h'
44

55
class ImpressRenderer < Redcarpet::Render::HTML
6+
attr_accessor :dest
7+
68
@attrs = []
79
@current = 0
810
@author, @head, @title = nil
@@ -27,6 +29,7 @@ def title= title
2729
end
2830

2931
def render_attrs(hsh)
32+
"class='step #{hsh.delete('class')}' "+
3033
hsh.map do |k,v|
3134
if v =~ /([\+\-])(\d+)/
3235
@counters[k] ||= 0
@@ -46,7 +49,7 @@ def hrule
4649
# this is how we later inject attributes into pages. what an awful hack.
4750
@current += 1
4851
%{</div>
49-
<div class='step' #{render_attrs(@attrs[@current])}>
52+
<div #{render_attrs(@attrs[@current])}>
5053
}
5154
end
5255

@@ -72,6 +75,13 @@ def codespan code
7275
H[:code, {class: "inline prettyprint"}, code].to_html
7376
end
7477

78+
def image link, title, alt
79+
if File.exist?("images/#{link}")
80+
`cp images/#{link} #{dest}/#{link}`
81+
end
82+
H[:img, {src: link, alt: alt}, title].to_html
83+
end
84+
7585
def mathjax
7686
if @opts[:latex]
7787
%{
@@ -112,7 +122,7 @@ def doc_header
112122
<p>For the best experience please use the latest <b>Chrome</b>, <b>Safari</b> or <b>Firefox</b> browser.</p>
113123
</div>
114124
<div id="impress">
115-
<div class='step' #{render_attrs(@attrs[0])}>
125+
<div #{render_attrs(@attrs[0])}>
116126
}
117127
end
118128

0 commit comments

Comments
 (0)