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 +1 -1
- data/lib/markdownizer/version.rb +1 -1
- data/lib/markdownizer.rb +9 -6
- data/spec/markdownizer_spec.rb +2 -4
- metadata +3 -3
data/Gemfile.lock
CHANGED
data/lib/markdownizer/version.rb
CHANGED
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
|
-
|
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
|
data/spec/markdownizer_spec.rb
CHANGED
@@ -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
|
|