Class: SyntaxhighlighterPreProcessor
- Inherits:
-
Object
- Object
- SyntaxhighlighterPreProcessor
- Defined in:
- lib/smartgen_syntaxhighlighter/pre_processor.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ SyntaxhighlighterPreProcessor
constructor
A new instance of SyntaxhighlighterPreProcessor.
- #process(body, metadata = {}) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ SyntaxhighlighterPreProcessor
Returns a new instance of SyntaxhighlighterPreProcessor.
4 5 6 7 |
# File 'lib/smartgen_syntaxhighlighter/pre_processor.rb', line 4 def initialize(opts={}) @enclose_with_tag = opts.delete(:enclose_with_tag) = merge_with_defaults(opts) end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
2 3 4 |
# File 'lib/smartgen_syntaxhighlighter/pre_processor.rb', line 2 def end |
Instance Method Details
#process(body, metadata = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/smartgen_syntaxhighlighter/pre_processor.rb', line 9 def process(body, ={}) body.gsub(%r{<(ruby|js|javascript|shell|bash|html|xml|as3|plain)>(.*?)</\1>}m) do |match| escaped_code = ERB::Util.h($2) [:brush] = case $1 when 'ruby', 'plain', 'as3', 'shell', 'bash', 'xml' $1 when 'js', 'javascript' 'js; html-script: true' when 'html' 'xml' # html is understood, but there are .xml rules in the CSS else 'plain' end %{#{enclose_start_tag}<pre class="#{to_class_attribute}">#{escaped_code}</pre>#{enclose_end_tag}} end end |