Module: Gitlab::Asciidoc

Defined in:
lib/gitlab/asciidoc.rb,
lib/gitlab/asciidoc/html5_converter.rb,
lib/gitlab/asciidoc/include_processor.rb,
lib/gitlab/asciidoc/mermaid_block_processor.rb,
lib/gitlab/asciidoc/syntax_highlighter/html_pipeline_adapter.rb

Overview

Parser/renderer for the AsciiDoc format that uses Asciidoctor and filters the resulting HTML through HTML pipeline filters.

Defined Under Namespace

Modules: SyntaxHighlighter Classes: Html5Converter, IncludeProcessor, MermaidBlockProcessor

Constant Summary collapse

MAX_INCLUDE_DEPTH =
5
MAX_INCLUDES =
32
DEFAULT_ADOC_ATTRS =
{
    'showtitle' => true,
    'sectanchors' => true,
    'idprefix' => 'user-content-',
    'idseparator' => '-',
    'env' => 'gitlab',
    'env-gitlab' => '',
    'source-highlighter' => 'gitlab-html-pipeline',
    'icons' => 'font',
    'outfilesuffix' => '.adoc',
    'max-include-depth' => MAX_INCLUDE_DEPTH
}.freeze

Class Method Summary collapse

Class Method Details

.path_attrs(path) ⇒ Object


29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/gitlab/asciidoc.rb', line 29

def self.path_attrs(path)
  return {} unless path

  {
    # Set an empty docname if the path is a directory
    'docname' => if path[-1] == ::File::SEPARATOR
                   ''
                 else
                   ::File.basename(path, '.*')
                 end
  }
end

.plantuml_setupObject


69
70
71
72
73
74
75
76
# File 'lib/gitlab/asciidoc.rb', line 69

def self.plantuml_setup
  Asciidoctor::PlantUml.configure do |conf|
    conf.url = Gitlab::CurrentSettings.plantuml_url
    conf.svg_enable = Gitlab::CurrentSettings.plantuml_enabled
    conf.png_enable = Gitlab::CurrentSettings.plantuml_enabled
    conf.txt_enable = false
  end
end

.render(input, context) ⇒ Object

Public: Converts the provided Asciidoc markup into HTML.

input - the source text in Asciidoc format context - :commit, :project, :ref, :requested_path


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/gitlab/asciidoc.rb', line 47

def self.render(input, context)
  extensions = proc do
    include_processor ::Gitlab::Asciidoc::IncludeProcessor.new(context)
    block ::Gitlab::Asciidoc::MermaidBlockProcessor
  end

  extra_attrs = path_attrs(context[:requested_path])
  asciidoc_opts = { safe: :secure,
                    backend: :gitlab_html5,
                    attributes: DEFAULT_ADOC_ATTRS.merge(extra_attrs),
                    extensions: extensions }

  context[:pipeline] = :ascii_doc
  context[:max_includes] = [MAX_INCLUDES, context[:max_includes]].compact.min

  plantuml_setup

  html = ::Asciidoctor.convert(input, asciidoc_opts)
  html = Banzai.render(html, context)
  html.html_safe
end