2015-05-12 19:07:48 -04:00
|
|
|
require 'asciidoctor'
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
# Parser/renderer for the AsciiDoc format that uses Asciidoctor and filters
|
|
|
|
# the resulting HTML through HTML pipeline filters.
|
|
|
|
module Asciidoc
|
|
|
|
|
|
|
|
DEFAULT_ADOC_ATTRS = [
|
|
|
|
'showtitle', 'idprefix=user-content-', 'idseparator=-', 'env=gitlab',
|
|
|
|
'env-gitlab', 'source-highlighter=html-pipeline'
|
|
|
|
].freeze
|
|
|
|
|
|
|
|
# Public: Converts the provided Asciidoc markup into HTML.
|
|
|
|
#
|
|
|
|
# input - the source text in Asciidoc format
|
|
|
|
# context - a Hash with the template context:
|
|
|
|
# :commit
|
|
|
|
# :project
|
|
|
|
# :project_wiki
|
|
|
|
# :requested_path
|
|
|
|
# :ref
|
|
|
|
# asciidoc_opts - a Hash of options to pass to the Asciidoctor converter
|
|
|
|
#
|
2015-10-14 14:18:49 -04:00
|
|
|
def self.render(input, context, asciidoc_opts = {})
|
|
|
|
asciidoc_opts.reverse_merge!(
|
2015-05-12 19:07:48 -04:00
|
|
|
safe: :secure,
|
2015-10-14 14:18:49 -04:00
|
|
|
backend: :html5,
|
2015-05-12 19:07:48 -04:00
|
|
|
attributes: []
|
|
|
|
)
|
|
|
|
asciidoc_opts[:attributes].unshift(*DEFAULT_ADOC_ATTRS)
|
|
|
|
|
|
|
|
html = ::Asciidoctor.convert(input, asciidoc_opts)
|
|
|
|
|
|
|
|
if context[:project]
|
2015-12-15 09:51:16 -05:00
|
|
|
html = Banzai.render(html, context.merge(pipeline: :asciidoc))
|
2015-05-12 19:07:48 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
html.html_safe
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|