Minor optimization

main
Thibaut Girka 2019-05-17 11:14:09 +02:00 committed by ThibG
parent 56245a2a72
commit 9ca21e93cc
1 changed files with 31 additions and 27 deletions

View File

@ -70,33 +70,7 @@ class Formatter
end end
def format_markdown(html) def format_markdown(html)
extensions = { html = reformat(markdown_formatter.render(html))
autolink: true,
no_intra_emphasis: true,
fenced_code_blocks: true,
disable_indented_code_blocks: true,
strikethrough: true,
lax_spacing: true,
space_after_headers: true,
superscript: true,
underline: true,
highlight: true,
footnotes: false,
}
renderer = HTMLRenderer.new({
filter_html: false,
escape_html: false,
no_images: true,
no_styles: true,
safe_links_only: true,
hard_wrap: true,
link_attributes: { target: '_blank', rel: 'nofollow noopener' },
})
markdown = Redcarpet::Markdown.new(renderer, extensions)
html = reformat(markdown.render(html))
html.delete("\r").delete("\n") html.delete("\r").delete("\n")
end end
@ -160,6 +134,36 @@ class Formatter
private private
def markdown_formatter
return @markdown_formatter if defined?(@markdown_formatter)
extensions = {
autolink: true,
no_intra_emphasis: true,
fenced_code_blocks: true,
disable_indented_code_blocks: true,
strikethrough: true,
lax_spacing: true,
space_after_headers: true,
superscript: true,
underline: true,
highlight: true,
footnotes: false,
}
renderer = HTMLRenderer.new({
filter_html: false,
escape_html: false,
no_images: true,
no_styles: true,
safe_links_only: true,
hard_wrap: true,
link_attributes: { target: '_blank', rel: 'nofollow noopener' },
})
@markdown_formatter = Redcarpet::Markdown.new(renderer, extensions)
end
def html_entities def html_entities
@html_entities ||= HTMLEntities.new @html_entities ||= HTMLEntities.new
end end