Class: Forem::Formatters::Redcarpet
- Inherits:
-
Object
- Object
- Forem::Formatters::Redcarpet
- Defined in:
- lib/forem/formatters/redcarpet.rb
Class Method Summary collapse
- .blockquote(text) ⇒ Object
- .format(text) ⇒ Object
-
.sanitize(text) ⇒ Object
This postpones the sanitization until after the rendered has rendered all the text.
- .syntax_highlight(html) ⇒ Object
Class Method Details
.blockquote(text) ⇒ Object
14 15 16 17 18 |
# File 'lib/forem/formatters/redcarpet.rb', line 14 def self.blockquote(text) text.split("\n").map do |line| "> " + line end.join("\n") end |
.format(text) ⇒ Object
8 9 10 11 12 |
# File 'lib/forem/formatters/redcarpet.rb', line 8 def self.format(text) = [:hard_wrap, :filter_html, :autolink, :no_intraemphasis, :fenced_code, :gh_blockcode] renderer = ::Redcarpet::Markdown.new(::Redcarpet::Render::HTML, :fenced_code_blocks => true) syntax_highlight(Forem::Sanitizer.sanitize(renderer.render(text))).html_safe end |
.sanitize(text) ⇒ Object
This postpones the sanitization until after the rendered has rendered all the text.
29 30 31 |
# File 'lib/forem/formatters/redcarpet.rb', line 29 def self.sanitize(text) text end |
.syntax_highlight(html) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/forem/formatters/redcarpet.rb', line 20 def self.syntax_highlight(html) doc = Nokogiri::HTML::DocumentFragment.parse(html.to_s) doc.css("pre code[@class]").each do |code| code.replace Pygments.highlight(code.text.rstrip, :lexer => code[:class], :class => "forem_highlight") end doc.to_s end |