Class: Makeup::Markup
- Inherits:
-
Object
- Object
- Makeup::Markup
- Defined in:
- lib/makeup/markup.rb
Class Method Summary collapse
Instance Method Summary collapse
- #highlight_code_blocks(path, markup) ⇒ Object
-
#initialize(options = {}) ⇒ Markup
constructor
A new instance of Markup.
- #render(path, content) ⇒ Object
- #sanitize(html) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Markup
Returns a new instance of Markup.
39 40 41 42 |
# File 'lib/makeup/markup.rb', line 39 def initialize( = {}) @markup_class_name = [:markup_class_name] || "prettyprint" @highlighter = [:highlighter] || NoopHighlighter.new end |
Class Method Details
.can_render?(path) ⇒ Boolean
61 62 63 |
# File 'lib/makeup/markup.rb', line 61 def self.can_render?(path) GitHub::Markup.can_render?(path) end |
.markups ⇒ Object
65 66 67 |
# File 'lib/makeup/markup.rb', line 65 def self.markups GitHub::Markup.markups end |
Instance Method Details
#highlight_code_blocks(path, markup) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/makeup/markup.rb', line 53 def highlight_code_blocks(path, markup) return markup unless path =~ /\.(md|mkdn?|mdwn|mdown|markdown)$/ CodeBlockParser.parse(markup) do |lexer, code| hb = @highlighter.highlight(path, code, { :lexer => lexer }) "<pre class=\"#{hb.lexer} #{@markup_class_name}\">#{hb.code}</pre>" end end |
#render(path, content) ⇒ Object
44 45 46 47 |
# File 'lib/makeup/markup.rb', line 44 def render(path, content) content = highlight_code_blocks(path, content) sanitize(GitHub::Markup.render(path, content)) end |
#sanitize(html) ⇒ Object
49 50 51 |
# File 'lib/makeup/markup.rb', line 49 def sanitize(html) Loofah.fragment(html).scrub!(:prune).to_s end |