markdownizer 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- markdownizer (0.2.0)
4
+ markdownizer (0.2.1)
5
5
  activerecord (>= 3.0.3)
6
6
  coderay
7
7
  rdiscount
@@ -1,3 +1,3 @@
1
1
  module Markdownizer
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/markdownizer.rb CHANGED
@@ -101,7 +101,10 @@ module Markdownizer
101
101
  #
102
102
  def coderay(text, options = {})
103
103
  text.gsub(%r[\{% code (\w+?) %\}(.+?)\{% endcode %\}]m) do
104
- code, language = $2, $1
104
+ options.delete(:highlight_lines)
105
+ options.delete(:caption)
106
+
107
+ code, language = $2.strip, $1.strip
105
108
 
106
109
  code, options, caption = extract_caption_from(code, options)
107
110
  code, options = extract_highlights_from(code, options)
@@ -115,22 +118,22 @@ module Markdownizer
115
118
  def extract_caption_from(code, options)
116
119
  caption = nil
117
120
  code.gsub!(%r[\{% caption '([\w\s]+)' %\}]) do
118
- options.merge!({:caption => $1}) if $1
119
- caption = "<h5>" << $1 << "</h5>"
121
+ options.merge!({:caption => $1.strip}) if $1
122
+ caption = "<h5>" << $1.strip << "</h5>"
120
123
  ''
121
124
  end
122
- [code, options, caption]
125
+ [code.strip, options, caption]
123
126
  end
124
127
 
125
128
  # FIXME: Find a safer way to eval code, MY LORD
126
129
  def extract_highlights_from(code, options)
127
130
  code.gsub!(%r[\{% highlight (.+) %\}]) do
128
- enumerable = eval($1)
131
+ enumerable = eval($1.strip)
129
132
  enumerable = (Enumerable === enumerable)? enumerable : nil
130
133
  options.merge!({:highlight_lines => enumerable}) if enumerable
131
134
  ''
132
135
  end
133
- [code, options]
136
+ [code.strip, options]
134
137
  end
135
138
 
136
139
  end
@@ -64,11 +64,9 @@ describe Markdownizer do
64
64
  it 'calls CodeRay to parse the code inside {% highlight ruby %} blocks' do
65
65
  scanned_code, html_code = double(:scanned_code), double(:html_code)
66
66
 
67
- CodeRay.should_receive(:scan).with("""
68
- def function(*args)
67
+ CodeRay.should_receive(:scan).with("""def function(*args)
69
68
  puts 'result'
70
- end
71
- """, 'ruby').and_return scanned_code
69
+ end""", 'ruby').and_return scanned_code
72
70
 
73
71
  scanned_code.should_receive(:div).with(:css => :class, :my => :option).and_return 'parsed code'
74
72
 
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 2
8
- - 1
9
- version: 0.2.1
7
+ - 3
8
+ - 0
9
+ version: 0.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Josep M. Bach