Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Markdownizer 0.3.1

  • Loading branch information...
commit 56704015e913868ceb7dba7645b4069614ebe9b3 1 parent 0abbf48
@txus txus authored
View
2  Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- markdownizer (0.2.1)
+ markdownizer (0.3.0)
activerecord (>= 3.0.3)
coderay
rdiscount
View
14 lib/markdownizer.rb
@@ -91,6 +91,9 @@ def markdown(text)
# ruby %}` until `{% endcode %}` and replaces it with appropriate classes for
# code highlighting. It can take many languages aside from Ruby.
#
+ # With a hash of options you can specify `:line_numbers` (`:table` or `:inline`),
+ # and the class of the enclosing div with `:enclosing_class`.
+ #
# It also parses a couple of special idioms:
#
# * {% caption 'my caption' %} introduces an h5 before the code and passes
@@ -104,12 +107,19 @@ def coderay(text, options = {})
options.delete(:highlight_lines)
options.delete(:caption)
+ enclosing_class = options[:enclosing_class] || 'markdownizer_code'
+
code, language = $2.strip, $1.strip
code, options, caption = extract_caption_from(code, options)
code, options = extract_highlights_from(code, options)
- (caption || '') << CodeRay.scan(code, language).div({:css => :class}.merge(options))
+ html_caption = caption ? '<h5>' << caption << '</h5>' : nil
+
+ "<div class=\"#{enclosing_class}#{caption ? "\" caption=\"#{caption}" : ''}\">" <<
+ (html_caption || '') <<
+ CodeRay.scan(code, language).div({:css => :class}.merge(options)) <<
+ "</div>"
end
end
@@ -119,7 +129,7 @@ def extract_caption_from(code, options)
caption = nil
code.gsub!(%r[\{% caption '([\w\s]+)' %\}]) do
options.merge!({:caption => $1.strip}) if $1
- caption = "<h5>" << $1.strip << "</h5>"
+ caption = $1.strip
''
end
[code.strip, options, caption]
View
2  lib/markdownizer/version.rb
@@ -1,3 +1,3 @@
module Markdownizer
- VERSION = "0.3.0"
+ VERSION = "0.3.1"
end
View
3  spec/markdownizer_spec.rb
@@ -96,6 +96,9 @@ def function(*args)
subject.coderay(text_with_range_highlights)
end
+ it 'encloses everything in a nice class' do
+ subject.coderay(text_with_caption).should match(/div class=\"markdownizer_code\" caption=\"This will become an h5\"/)
+ end
end
describe Markdownizer::DSL do
Please sign in to comment.
Something went wrong with that request. Please try again.