markdownizer 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile.lock +1 -1
- data/lib/markdownizer/version.rb +1 -1
- data/lib/markdownizer.rb +12 -2
- data/spec/markdownizer_spec.rb +3 -0
- metadata +2 -2
data/Gemfile.lock
CHANGED
data/lib/markdownizer/version.rb
CHANGED
data/lib/markdownizer.rb
CHANGED
@@ -91,6 +91,9 @@ module Markdownizer
|
|
91
91
|
# ruby %}` until `{% endcode %}` and replaces it with appropriate classes for
|
92
92
|
# code highlighting. It can take many languages aside from Ruby.
|
93
93
|
#
|
94
|
+
# With a hash of options you can specify `:line_numbers` (`:table` or `:inline`),
|
95
|
+
# and the class of the enclosing div with `:enclosing_class`.
|
96
|
+
#
|
94
97
|
# It also parses a couple of special idioms:
|
95
98
|
#
|
96
99
|
# * {% caption 'my caption' %} introduces an h5 before the code and passes
|
@@ -104,12 +107,19 @@ module Markdownizer
|
|
104
107
|
options.delete(:highlight_lines)
|
105
108
|
options.delete(:caption)
|
106
109
|
|
110
|
+
enclosing_class = options[:enclosing_class] || 'markdownizer_code'
|
111
|
+
|
107
112
|
code, language = $2.strip, $1.strip
|
108
113
|
|
109
114
|
code, options, caption = extract_caption_from(code, options)
|
110
115
|
code, options = extract_highlights_from(code, options)
|
111
116
|
|
112
|
-
|
117
|
+
html_caption = caption ? '<h5>' << caption << '</h5>' : nil
|
118
|
+
|
119
|
+
"<div class=\"#{enclosing_class}#{caption ? "\" caption=\"#{caption}" : ''}\">" <<
|
120
|
+
(html_caption || '') <<
|
121
|
+
CodeRay.scan(code, language).div({:css => :class}.merge(options)) <<
|
122
|
+
"</div>"
|
113
123
|
end
|
114
124
|
end
|
115
125
|
|
@@ -119,7 +129,7 @@ module Markdownizer
|
|
119
129
|
caption = nil
|
120
130
|
code.gsub!(%r[\{% caption '([\w\s]+)' %\}]) do
|
121
131
|
options.merge!({:caption => $1.strip}) if $1
|
122
|
-
caption =
|
132
|
+
caption = $1.strip
|
123
133
|
''
|
124
134
|
end
|
125
135
|
[code.strip, options, caption]
|
data/spec/markdownizer_spec.rb
CHANGED
@@ -96,6 +96,9 @@ describe Markdownizer do
|
|
96
96
|
|
97
97
|
subject.coderay(text_with_range_highlights)
|
98
98
|
end
|
99
|
+
it 'encloses everything in a nice class' do
|
100
|
+
subject.coderay(text_with_caption).should match(/div class=\"markdownizer_code\" caption=\"This will become an h5\"/)
|
101
|
+
end
|
99
102
|
end
|
100
103
|
|
101
104
|
describe Markdownizer::DSL do
|