Guest User

Untitled

a guest
Sep 20th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. require 'rubygems'
  3. require 'redcarpet'
  4. require 'pygments.rb'
  5.  
  6. class HTMLwithPygments < Redcarpet::Render::HTML
  7. def block_code(code, language)
  8. Pygments.highlight(code, :lexer => language.to_sym, :options => {
  9. :encoding => 'utf-8'
  10. })
  11. end
  12. end
  13.  
  14. def from_markdown(text)
  15. markdown = Redcarpet::Markdown.new(HTMLwithPygments,
  16. :fenced_code_blocks => true,
  17. :no_intra_emphasis => true,
  18. :autolink => true,
  19. :strikethrough => true,
  20. :lax_html_blocks => true,
  21. :superscript => true,
  22. :hard_wrap => false,
  23. :tables => true,
  24. :xhtml => false)
  25.  
  26. text.gsub!(/\{\{( *)?"(.*?)"\}\}/, '\1\2')
  27. text.gsub!(/^\{% highlight (.+?) ?%\}(.*?)^\{% endhighlight %\}/m) do |match|
  28. Pygments.highlight($2, :lexer => $1, :options => {:encoding => 'utf-8'})
  29. end
  30.  
  31. markdown.render(text)
  32. end
  33.  
  34. puts from_markdown(ARGF.read)
Add Comment
Please, Sign In to add comment