summaryrefslogtreecommitdiff
path: root/lib/gitlab/asciidoc.rb
diff options
context:
space:
mode:
authorGuillaume Grossetie <g.grossetie@gmail.com>2019-06-14 07:53:08 +0000
committerJames Lopez <james@gitlab.com>2019-06-14 07:53:08 +0000
commit3f5d7c7e1c9a8b5ba53996e8a8f2f4881929b2ea (patch)
tree6b8c33c73a5391953e9da8c9d7b7f2c72295cf07 /lib/gitlab/asciidoc.rb
parentcd300323c8cc6744c46ef3f732c412226615abbf (diff)
downloadgitlab-ce-3f5d7c7e1c9a8b5ba53996e8a8f2f4881929b2ea.tar.gz
Add basic support for AsciiDoc include directive
See http://asciidoctor.org/docs/user-manual/#include-directive
Diffstat (limited to 'lib/gitlab/asciidoc.rb')
-rw-r--r--lib/gitlab/asciidoc.rb54
1 files changed, 22 insertions, 32 deletions
diff --git a/lib/gitlab/asciidoc.rb b/lib/gitlab/asciidoc.rb
index df8f0470063..7f8300a0c2f 100644
--- a/lib/gitlab/asciidoc.rb
+++ b/lib/gitlab/asciidoc.rb
@@ -1,27 +1,41 @@
# frozen_string_literal: true
require 'asciidoctor'
-require 'asciidoctor/converter/html5'
-require "asciidoctor-plantuml"
+require 'asciidoctor-plantuml'
+require 'asciidoctor/extensions'
+require 'gitlab/asciidoc/html5_converter'
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', 'icons=font',
- 'outfilesuffix=.adoc'
- ].freeze
+ 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
# Public: Converts the provided Asciidoc markup into HTML.
#
# input - the source text in Asciidoc format
+ # context - :commit, :project, :ref, :requested_path
#
def self.render(input, context)
+ extensions = proc do
+ include_processor ::Gitlab::Asciidoc::IncludeProcessor.new(context)
+ end
+
asciidoc_opts = { safe: :secure,
backend: :gitlab_html5,
- attributes: DEFAULT_ADOC_ATTRS }
+ attributes: DEFAULT_ADOC_ATTRS,
+ extensions: extensions }
context[:pipeline] = :ascii_doc
@@ -40,29 +54,5 @@ module Gitlab
conf.txt_enable = false
end
end
-
- class Html5Converter < Asciidoctor::Converter::Html5Converter
- extend Asciidoctor::Converter::Config
-
- register_for 'gitlab_html5'
-
- def stem(node)
- return super unless node.style.to_sym == :latexmath
-
- %(<pre#{id_attribute(node)} data-math-style="display"><code>#{node.content}</code></pre>)
- end
-
- def inline_quoted(node)
- return super unless node.type.to_sym == :latexmath
-
- %(<code#{id_attribute(node)} data-math-style="inline">#{node.text}</code>)
- end
-
- private
-
- def id_attribute(node)
- node.id ? %( id="#{node.id}") : nil
- end
- end
end
end