2012-04-17 23:02:21 +02:00
|
|
|
class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML
|
2012-07-24 01:45:08 +02:00
|
|
|
|
|
|
|
attr_reader :template
|
|
|
|
alias_method :h, :template
|
|
|
|
|
|
|
|
def initialize(template, options = {})
|
|
|
|
@template = template
|
|
|
|
@project = @template.instance_variable_get("@project")
|
|
|
|
super options
|
|
|
|
end
|
|
|
|
|
2012-04-17 23:02:21 +02:00
|
|
|
def block_code(code, language)
|
2012-11-10 00:55:56 +01:00
|
|
|
options = { options: {encoding: 'utf-8'} }
|
2012-12-22 12:01:15 +01:00
|
|
|
options.merge!(lexer: language.downcase) if Pygments::Lexer.find(language)
|
2012-11-10 00:55:56 +01:00
|
|
|
|
2012-12-22 13:18:40 +01:00
|
|
|
# New lines are placed to fix an rendering issue
|
|
|
|
# with code wrapped inside <h1> tag for next case:
|
|
|
|
#
|
|
|
|
# # Title kinda h1
|
|
|
|
#
|
|
|
|
# ruby code here
|
|
|
|
#
|
2012-12-22 12:01:15 +01:00
|
|
|
<<-HTML
|
2012-12-22 13:18:40 +01:00
|
|
|
|
|
|
|
<div class="#{h.user_color_scheme_class}">#{Pygments.highlight(code, options)}</div>
|
|
|
|
|
2012-12-22 12:01:15 +01:00
|
|
|
HTML
|
2012-04-17 23:02:21 +02:00
|
|
|
end
|
2012-08-02 02:29:15 +02:00
|
|
|
|
2013-01-16 22:37:39 +01:00
|
|
|
def link(link, title, content)
|
|
|
|
h.link_to_gfm(content, link, title: title)
|
|
|
|
end
|
|
|
|
|
2012-08-02 02:29:15 +02:00
|
|
|
def postprocess(full_document)
|
|
|
|
h.gfm(full_document)
|
|
|
|
end
|
2012-06-08 10:23:31 +02:00
|
|
|
end
|