From 3f5d7c7e1c9a8b5ba53996e8a8f2f4881929b2ea Mon Sep 17 00:00:00 2001 From: Guillaume Grossetie Date: Fri, 14 Jun 2019 07:53:08 +0000 Subject: Add basic support for AsciiDoc include directive See http://asciidoctor.org/docs/user-manual/#include-directive --- lib/gitlab/asciidoc.rb | 54 ++++++++++++++++++++------------------------------ 1 file changed, 22 insertions(+), 32 deletions(-) (limited to 'lib/gitlab/asciidoc.rb') 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 - - %(#{node.content}) - end - - def inline_quoted(node) - return super unless node.type.to_sym == :latexmath - - %(#{node.text}) - end - - private - - def id_attribute(node) - node.id ? %( id="#{node.id}") : nil - end - end end end -- cgit v1.2.1