2012-04-17 21:02:21 +00:00
|
|
|
class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML
|
2012-07-23 23:45:08 +00:00
|
|
|
|
|
|
|
attr_reader :template
|
|
|
|
alias_method :h, :template
|
|
|
|
|
|
|
|
def initialize(template, options = {})
|
|
|
|
@template = template
|
|
|
|
@project = @template.instance_variable_get("@project")
|
2013-10-08 11:02:30 +00:00
|
|
|
@ref = @template.instance_variable_get("@ref")
|
2013-10-10 12:29:16 +00:00
|
|
|
@request_path = @template.instance_variable_get("@path")
|
2012-07-23 23:45:08 +00:00
|
|
|
super options
|
|
|
|
end
|
|
|
|
|
2012-04-17 21:02:21 +00:00
|
|
|
def block_code(code, language)
|
2012-11-09 23:55:56 +00:00
|
|
|
options = { options: {encoding: 'utf-8'} }
|
2013-06-09 19:30:20 +00:00
|
|
|
lexer = Pygments::Lexer.find(language) # language can be an alias
|
2013-07-07 17:00:07 +00:00
|
|
|
options.merge!(lexer: lexer.aliases[0].downcase) if lexer # downcase is required
|
2012-11-09 23:55:56 +00:00
|
|
|
|
2012-12-22 12:18:40 +00: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 11:01:15 +00:00
|
|
|
<<-HTML
|
2012-12-22 12:18:40 +00:00
|
|
|
|
|
|
|
<div class="#{h.user_color_scheme_class}">#{Pygments.highlight(code, options)}</div>
|
|
|
|
|
2012-12-22 11:01:15 +00:00
|
|
|
HTML
|
2012-04-17 21:02:21 +00:00
|
|
|
end
|
2012-08-02 00:29:15 +00:00
|
|
|
|
2013-01-16 21:37:39 +00:00
|
|
|
def link(link, title, content)
|
|
|
|
h.link_to_gfm(content, link, title: title)
|
|
|
|
end
|
|
|
|
|
2013-10-08 10:24:50 +00:00
|
|
|
def preprocess(full_document)
|
2013-10-11 19:41:33 +00:00
|
|
|
if @project
|
|
|
|
h.create_relative_links(full_document, @project.path_with_namespace, @ref, @request_path, is_wiki?)
|
|
|
|
else
|
|
|
|
full_document
|
|
|
|
end
|
2013-10-08 10:24:50 +00:00
|
|
|
end
|
|
|
|
|
2012-08-02 00:29:15 +00:00
|
|
|
def postprocess(full_document)
|
|
|
|
h.gfm(full_document)
|
|
|
|
end
|
2013-10-08 12:21:01 +00:00
|
|
|
|
|
|
|
def is_wiki?
|
|
|
|
@template.instance_variable_get("@wiki")
|
|
|
|
end
|
2012-06-08 08:23:31 +00:00
|
|
|
end
|