Class: Makeup::Markup

Inherits:
Object
  • Object
show all
Defined in:
lib/makeup/markup.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Markup

Returns a new instance of Markup.



53
54
55
56
# File 'lib/makeup/markup.rb', line 53

def initialize(options = {})
  @markup_class_name = options[:markup_class_name] || "prettyprint"
  @highlighter = options[:highlighter] || NoopHighlighter.new
end

Class Method Details

.can_render?(path) ⇒ Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/makeup/markup.rb', line 75

def self.can_render?(path)
  GitHub::Markup.can_render?(path)
end

.markupsObject



79
80
81
# File 'lib/makeup/markup.rb', line 79

def self.markups
  GitHubMarkupAccessor.markups
end

Instance Method Details

#highlight_code_blocks(path, markup) ⇒ Object



67
68
69
70
71
72
73
# File 'lib/makeup/markup.rb', line 67

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



58
59
60
61
# File 'lib/makeup/markup.rb', line 58

def render(path, content)
  content = highlight_code_blocks(path, content)
  sanitize(GitHub::Markup.render(path, content))
end

#sanitize(html) ⇒ Object



63
64
65
# File 'lib/makeup/markup.rb', line 63

def sanitize(html)
  Loofah.fragment(html).scrub!(:prune).to_s
end