Add render context to markdown renderer

This commit is contained in:
Riyad Preukschas 2012-07-24 01:45:08 +02:00
parent 058b71edf3
commit e1b4e22e5c
2 changed files with 11 additions and 1 deletions

View file

@ -43,7 +43,7 @@ module ApplicationHelper
end
def markdown(text)
@__renderer ||= Redcarpet::Markdown.new(Redcarpet::Render::GitlabHTML.new(filter_html: true), {
@__renderer ||= Redcarpet::Markdown.new(Redcarpet::Render::GitlabHTML.new(self, filter_html: true), {
no_intra_emphasis: true,
tables: true,
fenced_code_blocks: true,

View file

@ -1,4 +1,14 @@
class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML
attr_reader :template
alias_method :h, :template
def initialize(template, options = {})
@template = template
@project = @template.instance_variable_get("@project")
super options
end
def block_code(code, language)
if Pygments::Lexer.find(language)
Pygments.highlight(code, :lexer => language, :options => {:encoding => 'utf-8'})