Permalink
Browse files

Markdownizer 0.3.0

  • Loading branch information...
txus committed Feb 7, 2011
1 parent 2255852 commit 0abbf48e553deff174ff0529af65870d92cd500c
Showing with 13 additions and 12 deletions.
  1. +1 −1 Gemfile.lock
  2. +9 −6 lib/markdownizer.rb
  3. +1 −1 lib/markdownizer/version.rb
  4. +2 −4 spec/markdownizer_spec.rb
View
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- markdownizer (0.2.0)
+ markdownizer (0.2.1)
activerecord (>= 3.0.3)
coderay
rdiscount
View
@@ -101,7 +101,10 @@ def markdown(text)
#
def coderay(text, options = {})
text.gsub(%r[\{% code (\w+?) %\}(.+?)\{% endcode %\}]m) do
- code, language = $2, $1
+ options.delete(:highlight_lines)
+ options.delete(:caption)
+
+ code, language = $2.strip, $1.strip
code, options, caption = extract_caption_from(code, options)
code, options = extract_highlights_from(code, options)
@@ -115,22 +118,22 @@ def coderay(text, options = {})
def extract_caption_from(code, options)
caption = nil
code.gsub!(%r[\{% caption '([\w\s]+)' %\}]) do
- options.merge!({:caption => $1}) if $1
- caption = "<h5>" << $1 << "</h5>"
+ options.merge!({:caption => $1.strip}) if $1
+ caption = "<h5>" << $1.strip << "</h5>"
''
end
- [code, options, caption]
+ [code.strip, options, caption]
end
# FIXME: Find a safer way to eval code, MY LORD
def extract_highlights_from(code, options)
code.gsub!(%r[\{% highlight (.+) %\}]) do
- enumerable = eval($1)
+ enumerable = eval($1.strip)
enumerable = (Enumerable === enumerable)? enumerable : nil
options.merge!({:highlight_lines => enumerable}) if enumerable
''
end
- [code, options]
+ [code.strip, options]
end
end
@@ -1,3 +1,3 @@
module Markdownizer
- VERSION = "0.2.1"
+ VERSION = "0.3.0"
end
@@ -64,11 +64,9 @@ def function(*args)
it 'calls CodeRay to parse the code inside {% highlight ruby %} blocks' do
scanned_code, html_code = double(:scanned_code), double(:html_code)
- CodeRay.should_receive(:scan).with("""
- def function(*args)
+ CodeRay.should_receive(:scan).with("""def function(*args)
puts 'result'
- end
- """, 'ruby').and_return scanned_code
+ end""", 'ruby').and_return scanned_code
scanned_code.should_receive(:div).with(:css => :class, :my => :option).and_return 'parsed code'

0 comments on commit 0abbf48

Please sign in to comment.