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 CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- markdownizer (0.2.1)
4
+ markdownizer (0.3.0)
5
5
  activerecord (>= 3.0.3)
6
6
  coderay
7
7
  rdiscount
@@ -1,3 +1,3 @@
1
1
  module Markdownizer
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
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
- (caption || '') << CodeRay.scan(code, language).div({:css => :class}.merge(options))
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 = "<h5>" << $1.strip << "</h5>"
132
+ caption = $1.strip
123
133
  ''
124
134
  end
125
135
  [code.strip, options, caption]
@@ -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
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 0
9
- version: 0.3.0
8
+ - 1
9
+ version: 0.3.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Josep M. Bach