Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-11-18 16:16:36 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-11-18 16:16:36 +0300
commit311b0269b4eb9839fa63f80c8d7a58f32b8138a0 (patch)
tree07e7870bca8aed6d61fdcc810731c50d2c40af47 /lib/banzai/filter/markdown_engines/common_mark.rb
parent27909cef6c4170ed9205afa7426b8d3de47cbb0c (diff)
Add latest changes from gitlab-org/gitlab@14-5-stable-eev14.5.0-rc42
Diffstat (limited to 'lib/banzai/filter/markdown_engines/common_mark.rb')
-rw-r--r--lib/banzai/filter/markdown_engines/common_mark.rb52
1 files changed, 39 insertions, 13 deletions
diff --git a/lib/banzai/filter/markdown_engines/common_mark.rb b/lib/banzai/filter/markdown_engines/common_mark.rb
index 7be52fc497f..a25ebedf029 100644
--- a/lib/banzai/filter/markdown_engines/common_mark.rb
+++ b/lib/banzai/filter/markdown_engines/common_mark.rb
@@ -13,8 +13,7 @@ module Banzai
EXTENSIONS = [
:autolink, # provides support for automatically converting URLs to anchor tags.
:strikethrough, # provides support for strikethroughs.
- :table, # provides support for tables.
- :tagfilter # strips out several "unsafe" HTML tags from being used: https://github.github.com/gfm/#disallowed-raw-html-extension-
+ :table # provides support for tables.
].freeze
PARSE_OPTIONS = [
@@ -23,36 +22,63 @@ module Banzai
:VALIDATE_UTF8 # replace illegal sequences with the replacement character U+FFFD.
].freeze
+ RENDER_OPTIONS_C = [
+ :GITHUB_PRE_LANG, # use GitHub-style <pre lang> for fenced code blocks.
+ :FOOTNOTES, # render footnotes.
+ :FULL_INFO_STRING, # include full info strings of code blocks in separate attribute.
+ :UNSAFE # allow raw/custom HTML and unsafe links.
+ ].freeze
+
# The `:GITHUB_PRE_LANG` option is not used intentionally because
# it renders a fence block with language as `<pre lang="LANG"><code>some code\n</code></pre>`
# while GitLab's syntax is `<pre><code lang="LANG">some code\n</code></pre>`.
# If in the future the syntax is about to be made GitHub-compatible, please, add `:GITHUB_PRE_LANG` render option below
# and remove `code_block` method from `lib/banzai/renderer/common_mark/html.rb`.
- RENDER_OPTIONS = [
+ RENDER_OPTIONS_RUBY = [
# as of commonmarker 0.18.0, we need to use :UNSAFE to get the same as the original :DEFAULT
# https://github.com/gjtorikian/commonmarker/pull/81
- :UNSAFE
- ].freeze
-
- RENDER_OPTIONS_SOURCEPOS = RENDER_OPTIONS + [
- :SOURCEPOS # enable embedding of source position information
+ :UNSAFE # allow raw/custom HTML and unsafe links.
].freeze
def initialize(context)
- @context = context
- @renderer = Banzai::Renderer::CommonMark::HTML.new(options: render_options)
+ @context = context
+ @renderer = Banzai::Renderer::CommonMark::HTML.new(options: render_options) if Feature.disabled?(:use_cmark_renderer)
end
def render(text)
- doc = CommonMarker.render_doc(text, PARSE_OPTIONS, EXTENSIONS)
+ if Feature.enabled?(:use_cmark_renderer)
+ CommonMarker.render_html(text, render_options, extensions)
+ else
+ doc = CommonMarker.render_doc(text, PARSE_OPTIONS, extensions)
- @renderer.render(doc)
+ @renderer.render(doc)
+ end
end
private
+ def extensions
+ if Feature.enabled?(:use_cmark_renderer)
+ EXTENSIONS
+ else
+ EXTENSIONS + [
+ :tagfilter # strips out several "unsafe" HTML tags from being used: https://github.github.com/gfm/#disallowed-raw-html-extension-
+ ].freeze
+ end
+ end
+
def render_options
- @context[:no_sourcepos] ? RENDER_OPTIONS : RENDER_OPTIONS_SOURCEPOS
+ @context[:no_sourcepos] ? render_options_no_sourcepos : render_options_sourcepos
+ end
+
+ def render_options_no_sourcepos
+ Feature.enabled?(:use_cmark_renderer) ? RENDER_OPTIONS_C : RENDER_OPTIONS_RUBY
+ end
+
+ def render_options_sourcepos
+ render_options_no_sourcepos + [
+ :SOURCEPOS # enable embedding of source position information
+ ].freeze
end
end
end