Class: OrbitalFields::Markdown::HTMLwithPygments
- Inherits:
-
Redcarpet::Render::HTML
- Object
- Redcarpet::Render::HTML
- OrbitalFields::Markdown::HTMLwithPygments
- Defined in:
- lib/orbital_fields/markdown.rb
Instance Method Summary collapse
Instance Method Details
#block_code(code, language) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/orbital_fields/markdown.rb', line 51 def block_code(code, language) input_name = language.to_s input_name = input_name.slice(0..19)+"..."+input_name.slice(-1..-20) if input_name.length > 40 language = language.match(/\.([^\.]*)$/i)[1].downcase if language =~ /\.([^\.]*)$/i language = "rhtml" if language == "erb" lexer = Pygments::Lexer.find_by_alias(language) lexer_name = lexer.name.downcase unless lexer.nil? lexer_name ||= "text" lexer ||= Pygments::Lexer.find_by_alias(lexer_name) <<-EOS <div class="code_block"> <div class="code_header"> #{CGI.escapeHTML(input_name)} rendered as #{CGI.escapeHTML(lexer.name)} #{clippy(code)} </div> #{Pygments.highlight(code, lexer: lexer_name)} </div> EOS end |
#clippy(text) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/orbital_fields/markdown.rb', line 71 def clippy(text) id = "clippy_#{rand(10000000)}" <<-EOS <div id="#{id}" class="clippy"> <span style="display:none;visibility:hidden" class="clippy_code">#{CGI.escapeHTML(text)}</span> <span class="clippy_label"></span> <object type="application/x-shockwave-flash" data="/assets/orbital_fields/clippy.swf" width="14" height="14" id="#{id}_flash"> <param name="movie" value="/assets/orbital_fields/clippy.swf" /> <param name="allowScriptAccess" value="always" /> <param name="quality" value="high" /> <param name="scale" value="noscale" /> <param name="FlashVars" value="target=#{CGI.escape('#' + id)}" /> <param name="bgcolor" value="#E0E0E0" /> </object> </div> EOS end |