Class: Redcarpet::Render::VelvetRope
- Inherits:
-
HTML
- Object
- HTML
- Redcarpet::Render::VelvetRope
- Defined in:
- lib/velvet_rope.rb
Instance Method Summary collapse
- #emoji_template(name) ⇒ Object
-
#initialize(extensions = {}) ⇒ VelvetRope
constructor
A new instance of VelvetRope.
- #postprocess(document) ⇒ Object
Constructor Details
#initialize(extensions = {}) ⇒ VelvetRope
Returns a new instance of VelvetRope.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/velvet_rope.rb', line 9 def initialize(extensions={}) @extensions ||= {} @extensions[:highlight_syntax] = extensions.delete(:highlight_syntax) || false @extensions[:emoji] = extensions.delete(:emoji) || false # This is ugly, but is a workaround for Redcarpet not handling `super` # as it is a wrapper for the implementation written in C if @extensions[:highlight_syntax] self.class.send(:define_method, :block_code) do |code, language| if Pygments::Lexer.find_by_alias(language) Pygments.highlight(code, :lexer => language) else Pygments.highlight(code) end end end # `super` however DOES work in this intializer... super(extensions) end |
Instance Method Details
#emoji_template(name) ⇒ Object
43 44 45 |
# File 'lib/velvet_rope.rb', line 43 def emoji_template(name) '<img alt="' + name + '" src="' + "/images/emoji/#{name}.png" + '" style="vertical-align:middle" width="20" height="20" />' end |
#postprocess(document) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/velvet_rope.rb', line 30 def postprocess(document) if @extensions[:emoji] document.gsub!(/:([a-z0-9\+\-_]+):/) do |match| if Emoji.names.include?($1) emoji_template($1) else match end end end document end |