diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-20 11:43:02 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-20 11:43:02 +0300 |
commit | d9ab72d6080f594d0b3cae15f14b3ef2c6c638cb (patch) | |
tree | 2341ef426af70ad1e289c38036737e04b0aa5007 /lib/banzai | |
parent | d6e514dd13db8947884cd58fe2a9c2a063400a9b (diff) |
Add latest changes from gitlab-org/gitlab@14-4-stable-eev14.4.0-rc42
Diffstat (limited to 'lib/banzai')
5 files changed, 17 insertions, 17 deletions
diff --git a/lib/banzai/filter/front_matter_filter.rb b/lib/banzai/filter/front_matter_filter.rb index 5900e762244..d47900b816a 100644 --- a/lib/banzai/filter/front_matter_filter.rb +++ b/lib/banzai/filter/front_matter_filter.rb @@ -9,7 +9,7 @@ module Banzai html.sub(Gitlab::FrontMatter::PATTERN) do |_match| lang = $~[:lang].presence || lang_mapping[$~[:delim]] - ["```#{lang}", $~[:front_matter], "```", "\n"].join("\n") + ["```#{lang}:frontmatter", $~[:front_matter], "```", "\n"].join("\n") end end end diff --git a/lib/banzai/filter/references/abstract_reference_filter.rb b/lib/banzai/filter/references/abstract_reference_filter.rb index 08014ccdcce..cae0a8b424a 100644 --- a/lib/banzai/filter/references/abstract_reference_filter.rb +++ b/lib/banzai/filter/references/abstract_reference_filter.rb @@ -11,7 +11,7 @@ module Banzai def initialize(doc, context = nil, result = nil) super - @reference_cache = ReferenceCache.new(self, context) + @reference_cache = ReferenceCache.new(self, context, result) end # REFERENCE_PLACEHOLDER is used for re-escaping HTML text except found diff --git a/lib/banzai/filter/references/milestone_reference_filter.rb b/lib/banzai/filter/references/milestone_reference_filter.rb index 94f7106d31e..609aaf885ba 100644 --- a/lib/banzai/filter/references/milestone_reference_filter.rb +++ b/lib/banzai/filter/references/milestone_reference_filter.rb @@ -5,8 +5,6 @@ module Banzai module References # HTML filter that replaces milestone references with links. class MilestoneReferenceFilter < AbstractReferenceFilter - include Gitlab::Utils::StrongMemoize - self.reference_type = :milestone self.object_class = Milestone @@ -63,21 +61,15 @@ module Banzai end def valid_context?(parent) - strong_memoize(:valid_context) do - group_context?(parent) || project_context?(parent) - end + group_context?(parent) || project_context?(parent) end def group_context?(parent) - strong_memoize(:group_context) do - parent.is_a?(Group) - end + parent.is_a?(Group) end def project_context?(parent) - strong_memoize(:project_context) do - parent.is_a?(Project) - end + parent.is_a?(Project) end def references_in(text, pattern = Milestone.reference_pattern) diff --git a/lib/banzai/filter/references/reference_cache.rb b/lib/banzai/filter/references/reference_cache.rb index b2d47aba2d6..259958f1598 100644 --- a/lib/banzai/filter/references/reference_cache.rb +++ b/lib/banzai/filter/references/reference_cache.rb @@ -7,9 +7,10 @@ module Banzai include Gitlab::Utils::StrongMemoize include RequestStoreReferenceCache - def initialize(filter, context) + def initialize(filter, context, result) @filter = filter @context = context + @result = result || {} end def load_reference_cache(nodes) @@ -166,7 +167,7 @@ module Banzai private - attr_accessor :filter, :context + attr_accessor :filter, :context, :result delegate :project, :group, :parent, :parent_type, to: :filter @@ -184,7 +185,11 @@ module Banzai end def prepare_doc_for_scan(doc) - html = doc.to_html + html = if Feature.enabled?(:reference_cache_memoization, project, default_enabled: :yaml) + result[:rendered_html] ||= doc.to_html + else + doc.to_html + end filter.requires_unescaping? ? unescape_html_entities(html) : html end diff --git a/lib/banzai/filter/syntax_highlight_filter.rb b/lib/banzai/filter/syntax_highlight_filter.rb index f1440c13d47..8d869cd63d3 100644 --- a/lib/banzai/filter/syntax_highlight_filter.rb +++ b/lib/banzai/filter/syntax_highlight_filter.rb @@ -28,6 +28,7 @@ module Banzai def highlight_node(node) css_classes = +'code highlight js-syntax-highlight' lang, lang_params = parse_lang_params(node.attr('lang')) + sourcepos = node.parent.attr('data-sourcepos') retried = false if use_rouge?(lang) @@ -55,7 +56,9 @@ module Banzai retry end - highlighted = %(<pre class="#{css_classes}" + sourcepos_attr = sourcepos ? "data-sourcepos=\"#{sourcepos}\"" : "" + + highlighted = %(<pre #{sourcepos_attr} class="#{css_classes}" lang="#{language}" #{lang_params} v-pre="true"><code>#{code}</code></pre>) |