2018-10-22 03:00:50 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-05-12 19:07:48 -04:00
|
|
|
require 'asciidoctor'
|
2019-06-14 03:53:08 -04:00
|
|
|
require 'asciidoctor-plantuml'
|
|
|
|
require 'asciidoctor/extensions'
|
|
|
|
require 'gitlab/asciidoc/html5_converter'
|
2015-05-12 19:07:48 -04:00
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
# Parser/renderer for the AsciiDoc format that uses Asciidoctor and filters
|
|
|
|
# the resulting HTML through HTML pipeline filters.
|
|
|
|
module Asciidoc
|
2019-06-14 03:53:08 -04:00
|
|
|
MAX_INCLUDE_DEPTH = 5
|
|
|
|
DEFAULT_ADOC_ATTRS = {
|
|
|
|
'showtitle' => true,
|
|
|
|
'idprefix' => 'user-content-',
|
|
|
|
'idseparator' => '-',
|
|
|
|
'env' => 'gitlab',
|
|
|
|
'env-gitlab' => '',
|
|
|
|
'source-highlighter' => 'html-pipeline',
|
|
|
|
'icons' => 'font',
|
|
|
|
'outfilesuffix' => '.adoc',
|
|
|
|
'max-include-depth' => MAX_INCLUDE_DEPTH
|
|
|
|
}.freeze
|
2015-05-12 19:07:48 -04:00
|
|
|
|
|
|
|
# Public: Converts the provided Asciidoc markup into HTML.
|
|
|
|
#
|
|
|
|
# input - the source text in Asciidoc format
|
2019-06-14 03:53:08 -04:00
|
|
|
# context - :commit, :project, :ref, :requested_path
|
2015-05-12 19:07:48 -04:00
|
|
|
#
|
2017-05-02 10:52:19 -04:00
|
|
|
def self.render(input, context)
|
2019-06-14 03:53:08 -04:00
|
|
|
extensions = proc do
|
|
|
|
include_processor ::Gitlab::Asciidoc::IncludeProcessor.new(context)
|
|
|
|
end
|
|
|
|
|
2017-04-24 06:21:10 -04:00
|
|
|
asciidoc_opts = { safe: :secure,
|
|
|
|
backend: :gitlab_html5,
|
2019-06-14 03:53:08 -04:00
|
|
|
attributes: DEFAULT_ADOC_ATTRS,
|
|
|
|
extensions: extensions }
|
2015-05-12 19:07:48 -04:00
|
|
|
|
2017-05-09 08:14:24 -04:00
|
|
|
context[:pipeline] = :ascii_doc
|
2017-05-02 10:52:19 -04:00
|
|
|
|
2016-11-28 12:41:29 -05:00
|
|
|
plantuml_setup
|
|
|
|
|
2015-05-12 19:07:48 -04:00
|
|
|
html = ::Asciidoctor.convert(input, asciidoc_opts)
|
2017-05-02 10:52:19 -04:00
|
|
|
html = Banzai.render(html, context)
|
2015-05-12 19:07:48 -04:00
|
|
|
html.html_safe
|
|
|
|
end
|
2016-12-08 19:15:08 -05:00
|
|
|
|
2016-11-28 12:41:29 -05:00
|
|
|
def self.plantuml_setup
|
|
|
|
Asciidoctor::PlantUml.configure do |conf|
|
2018-02-02 13:39:55 -05:00
|
|
|
conf.url = Gitlab::CurrentSettings.plantuml_url
|
|
|
|
conf.svg_enable = Gitlab::CurrentSettings.plantuml_enabled
|
|
|
|
conf.png_enable = Gitlab::CurrentSettings.plantuml_enabled
|
2016-11-28 12:41:29 -05:00
|
|
|
conf.txt_enable = false
|
|
|
|
end
|
|
|
|
end
|
2016-12-08 19:15:08 -05:00
|
|
|
end
|
|
|
|
end
|