Module: Gitlab::Asciidoc

Defined in:
lib/gitlab/asciidoc.rb

Overview

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

Constant Summary collapse

DEFAULT_ADOC_ATTRS =
[
  'showtitle', 'idprefix=user-content-', 'idseparator=-', 'env=gitlab',
  'env-gitlab', 'source-highlighter=html-pipeline'
].freeze

Class Method Summary collapse

Class Method Details

.render(input, context, asciidoc_opts = {}) ⇒ Object

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


24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/gitlab/asciidoc.rb', line 24

def self.render(input, context, asciidoc_opts = {})
  asciidoc_opts.reverse_merge!(
    safe: :secure,
    backend: :html5,
    attributes: []
  )
  asciidoc_opts[:attributes].unshift(*DEFAULT_ADOC_ATTRS)

  html = ::Asciidoctor.convert(input, asciidoc_opts)

  html = Banzai.post_process(html, context)

  html.html_safe
end