diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-20 12:16:11 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-20 12:16:11 +0300 |
commit | edaa33dee2ff2f7ea3fac488d41558eb5f86d68c (patch) | |
tree | 11f143effbfeba52329fb7afbd05e6e2a3790241 /lib/banzai/filter/markdown_engines/common_mark.rb | |
parent | d8a5691316400a0f7ec4f83832698f1988eb27c1 (diff) |
Add latest changes from gitlab-org/gitlab@14-7-stable-eev14.7.0-rc42
Diffstat (limited to 'lib/banzai/filter/markdown_engines/common_mark.rb')
-rw-r--r-- | lib/banzai/filter/markdown_engines/common_mark.rb | 36 |
1 files changed, 4 insertions, 32 deletions
diff --git a/lib/banzai/filter/markdown_engines/common_mark.rb b/lib/banzai/filter/markdown_engines/common_mark.rb index dc94e3c925a..cf368e28beb 100644 --- a/lib/banzai/filter/markdown_engines/common_mark.rb +++ b/lib/banzai/filter/markdown_engines/common_mark.rb @@ -4,8 +4,8 @@ # This module is used in Banzai::Filter::MarkdownFilter. # Used gem is `commonmarker` which is a ruby wrapper for libcmark (CommonMark parser) # including GitHub's GFM extensions. +# We now utilize the renderer built in `C`, rather than the ruby based renderer. # Homepage: https://github.com/gjtorikian/commonmarker - module Banzai module Filter module MarkdownEngines @@ -22,57 +22,29 @@ module Banzai :VALIDATE_UTF8 # replace illegal sequences with the replacement character U+FFFD. ].freeze - RENDER_OPTIONS_C = [ + RENDER_OPTIONS = [ :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_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 # allow raw/custom HTML and unsafe links. - ].freeze - def initialize(context) @context = context - @renderer = Banzai::Renderer::CommonMark::HTML.new(options: render_options) if Feature.disabled?(:use_cmark_renderer, default_enabled: :yaml) end def render(text) - if Feature.enabled?(:use_cmark_renderer, default_enabled: :yaml) - CommonMarker.render_html(text, render_options, extensions) - else - doc = CommonMarker.render_doc(text, PARSE_OPTIONS, extensions) - - @renderer.render(doc) - end + CommonMarker.render_html(text, render_options, EXTENSIONS) end private - def extensions - if Feature.enabled?(:use_cmark_renderer, default_enabled: :yaml) - 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_no_sourcepos : render_options_sourcepos end def render_options_no_sourcepos - Feature.enabled?(:use_cmark_renderer, default_enabled: :yaml) ? RENDER_OPTIONS_C : RENDER_OPTIONS_RUBY + RENDER_OPTIONS end def render_options_sourcepos |