summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-12-15 15:51:16 +0100
committerDouwe Maan <douwe@gitlab.com>2015-12-15 15:51:16 +0100
commit7781bda9bd82997f4a03de4cf911b1156ceb2cde (patch)
treea632a12b295694232205e2190f784f9bb79235ee
parent9451db3819ae45734c4343e55a74d347cdacf70d (diff)
downloadgitlab-ce-7781bda9bd82997f4a03de4cf911b1156ceb2cde.tar.gz
Move Markdown/reference logic from Gitlab::Markdown to Banzai
-rw-r--r--app/helpers/gitlab_markdown_helper.rb6
-rw-r--r--app/helpers/issues_helper.rb2
-rw-r--r--app/helpers/labels_helper.rb2
-rw-r--r--app/models/concerns/mentionable.rb16
-rw-r--r--app/models/concerns/participable.rb29
-rw-r--r--app/models/issue.rb2
-rw-r--r--app/models/note.rb4
-rw-r--r--lib/banzai.rb13
-rw-r--r--lib/banzai/cross_project_reference.rb22
-rw-r--r--lib/banzai/filter.rb10
-rw-r--r--lib/banzai/filter/abstract_reference_filter.rb (renamed from lib/gitlab/markdown/abstract_reference_filter.rb)6
-rw-r--r--lib/banzai/filter/autolink_filter.rb (renamed from lib/gitlab/markdown/filter/autolink_filter.rb)6
-rw-r--r--lib/banzai/filter/commit_range_reference_filter.rb (renamed from lib/gitlab/markdown/filter/commit_range_reference_filter.rb)6
-rw-r--r--lib/banzai/filter/commit_reference_filter.rb (renamed from lib/gitlab/markdown/filter/commit_reference_filter.rb)6
-rw-r--r--lib/banzai/filter/emoji_filter.rb (renamed from lib/gitlab/markdown/filter/emoji_filter.rb)6
-rw-r--r--lib/banzai/filter/external_issue_reference_filter.rb (renamed from lib/gitlab/markdown/filter/external_issue_reference_filter.rb)6
-rw-r--r--lib/banzai/filter/external_link_filter.rb (renamed from lib/gitlab/markdown/filter/external_link_filter.rb)6
-rw-r--r--lib/banzai/filter/issue_reference_filter.rb (renamed from lib/gitlab/markdown/filter/issue_reference_filter.rb)6
-rw-r--r--lib/banzai/filter/label_reference_filter.rb (renamed from lib/gitlab/markdown/filter/label_reference_filter.rb)6
-rw-r--r--lib/banzai/filter/markdown_filter.rb (renamed from lib/gitlab/markdown/filter/markdown_filter.rb)11
-rw-r--r--lib/banzai/filter/merge_request_reference_filter.rb (renamed from lib/gitlab/markdown/filter/merge_request_reference_filter.rb)6
-rw-r--r--lib/banzai/filter/redactor_filter.rb (renamed from lib/gitlab/markdown/filter/redactor_filter.rb)8
-rw-r--r--lib/banzai/filter/reference_filter.rb (renamed from lib/gitlab/markdown/reference_filter.rb)27
-rw-r--r--lib/banzai/filter/reference_gatherer_filter.rb (renamed from lib/gitlab/markdown/filter/reference_gatherer_filter.rb)13
-rw-r--r--lib/banzai/filter/relative_link_filter.rb (renamed from lib/gitlab/markdown/filter/relative_link_filter.rb)6
-rw-r--r--lib/banzai/filter/sanitization_filter.rb (renamed from lib/gitlab/markdown/filter/sanitization_filter.rb)6
-rw-r--r--lib/banzai/filter/snippet_reference_filter.rb (renamed from lib/gitlab/markdown/filter/snippet_reference_filter.rb)6
-rw-r--r--lib/banzai/filter/syntax_highlight_filter.rb (renamed from lib/gitlab/markdown/filter/syntax_highlight_filter.rb)6
-rw-r--r--lib/banzai/filter/table_of_contents_filter.rb (renamed from lib/gitlab/markdown/filter/table_of_contents_filter.rb)6
-rw-r--r--lib/banzai/filter/task_list_filter.rb (renamed from lib/gitlab/markdown/filter/task_list_filter.rb)6
-rw-r--r--lib/banzai/filter/upload_link_filter.rb (renamed from lib/gitlab/markdown/filter/upload_link_filter.rb)6
-rw-r--r--lib/banzai/filter/user_reference_filter.rb (renamed from lib/gitlab/markdown/filter/user_reference_filter.rb)6
-rw-r--r--lib/banzai/lazy_reference.rb27
-rw-r--r--lib/banzai/pipeline.rb10
-rw-r--r--lib/banzai/pipeline/asciidoc_pipeline.rb13
-rw-r--r--lib/banzai/pipeline/atom_pipeline.rb14
-rw-r--r--lib/banzai/pipeline/base_pipeline.rb30
-rw-r--r--lib/banzai/pipeline/combined_pipeline.rb (renamed from lib/gitlab/markdown/combined_pipeline.rb)8
-rw-r--r--lib/banzai/pipeline/description_pipeline.rb (renamed from lib/gitlab/markdown/pipeline/description_pipeline.rb)8
-rw-r--r--lib/banzai/pipeline/email_pipeline.rb (renamed from lib/gitlab/markdown/pipeline/email_pipeline.rb)8
-rw-r--r--lib/banzai/pipeline/full_pipeline.rb (renamed from lib/gitlab/markdown/pipeline/full_pipeline.rb)6
-rw-r--r--lib/banzai/pipeline/gfm_pipeline.rb41
-rw-r--r--lib/banzai/pipeline/note_pipeline.rb (renamed from lib/gitlab/markdown/pipeline/note_pipeline.rb)8
-rw-r--r--lib/banzai/pipeline/plain_markdown_pipeline.rb13
-rw-r--r--lib/banzai/pipeline/post_process_pipeline.rb20
-rw-r--r--lib/banzai/pipeline/reference_extraction_pipeline.rb13
-rw-r--r--lib/banzai/pipeline/single_line_pipeline.rb9
-rw-r--r--lib/banzai/reference_extractor.rb55
-rw-r--r--lib/banzai/renderer.rb76
-rw-r--r--lib/gitlab/asciidoc.rb2
-rw-r--r--lib/gitlab/markdown.rb115
-rw-r--r--lib/gitlab/markdown/cross_project_reference.rb24
-rw-r--r--lib/gitlab/markdown/pipeline.rb4
-rw-r--r--lib/gitlab/markdown/pipeline/asciidoc_pipeline.rb13
-rw-r--r--lib/gitlab/markdown/pipeline/atom_pipeline.rb14
-rw-r--r--lib/gitlab/markdown/pipeline/gfm_pipeline.rb41
-rw-r--r--lib/gitlab/markdown/pipeline/plain_markdown_pipeline.rb13
-rw-r--r--lib/gitlab/markdown/pipeline/post_process_pipeline.rb20
-rw-r--r--lib/gitlab/markdown/pipeline/reference_extraction_pipeline.rb13
-rw-r--r--lib/gitlab/markdown/pipeline/single_line_pipeline.rb9
-rw-r--r--lib/gitlab/reference_extractor.rb53
-rw-r--r--spec/benchmarks/lib/gitlab/markdown/reference_filter_spec.rb2
-rw-r--r--spec/lib/banzai/cross_project_reference_spec.rb (renamed from spec/lib/gitlab/markdown/cross_project_reference_spec.rb)2
-rw-r--r--spec/lib/banzai/filter/autolink_filter_spec.rb (renamed from spec/lib/gitlab/markdown/filter/autolink_filter_spec.rb)2
-rw-r--r--spec/lib/banzai/filter/commit_range_reference_filter_spec.rb (renamed from spec/lib/gitlab/markdown/filter/commit_range_reference_filter_spec.rb)2
-rw-r--r--spec/lib/banzai/filter/commit_reference_filter_spec.rb (renamed from spec/lib/gitlab/markdown/filter/commit_reference_filter_spec.rb)2
-rw-r--r--spec/lib/banzai/filter/emoji_filter_spec.rb (renamed from spec/lib/gitlab/markdown/filter/emoji_filter_spec.rb)2
-rw-r--r--spec/lib/banzai/filter/external_issue_reference_filter_spec.rb (renamed from spec/lib/gitlab/markdown/filter/external_issue_reference_filter_spec.rb)2
-rw-r--r--spec/lib/banzai/filter/external_link_filter_spec.rb (renamed from spec/lib/gitlab/markdown/filter/external_link_filter_spec.rb)2
-rw-r--r--spec/lib/banzai/filter/issue_reference_filter_spec.rb (renamed from spec/lib/gitlab/markdown/filter/issue_reference_filter_spec.rb)2
-rw-r--r--spec/lib/banzai/filter/label_reference_filter_spec.rb (renamed from spec/lib/gitlab/markdown/filter/label_reference_filter_spec.rb)2
-rw-r--r--spec/lib/banzai/filter/merge_request_reference_filter_spec.rb (renamed from spec/lib/gitlab/markdown/filter/merge_request_reference_filter_spec.rb)2
-rw-r--r--spec/lib/banzai/filter/redactor_filter_spec.rb (renamed from spec/lib/gitlab/markdown/filter/redactor_filter_spec.rb)2
-rw-r--r--spec/lib/banzai/filter/reference_gatherer_filter_spec.rb (renamed from spec/lib/gitlab/markdown/filter/reference_gatherer_filter_spec.rb)2
-rw-r--r--spec/lib/banzai/filter/relative_link_filter_spec.rb (renamed from spec/lib/gitlab/markdown/filter/relative_link_filter_spec.rb)2
-rw-r--r--spec/lib/banzai/filter/sanitization_filter_spec.rb (renamed from spec/lib/gitlab/markdown/filter/sanitization_filter_spec.rb)2
-rw-r--r--spec/lib/banzai/filter/snippet_reference_filter_spec.rb (renamed from spec/lib/gitlab/markdown/filter/snippet_reference_filter_spec.rb)2
-rw-r--r--spec/lib/banzai/filter/syntax_highlight_filter_spec.rb (renamed from spec/lib/gitlab/markdown/filter/syntax_highlight_filter_spec.rb)2
-rw-r--r--spec/lib/banzai/filter/table_of_contents_filter_spec.rb (renamed from spec/lib/gitlab/markdown/filter/table_of_contents_filter_spec.rb)2
-rw-r--r--spec/lib/banzai/filter/task_list_filter_spec.rb (renamed from spec/lib/gitlab/markdown/filter/task_list_filter_spec.rb)2
-rw-r--r--spec/lib/banzai/filter/upload_link_filter_spec.rb (renamed from spec/lib/gitlab/markdown/filter/upload_link_filter_spec.rb)2
-rw-r--r--spec/lib/banzai/filter/user_reference_filter_spec.rb (renamed from spec/lib/gitlab/markdown/filter/user_reference_filter_spec.rb)2
-rw-r--r--spec/lib/gitlab/asciidoc_spec.rb2
-rw-r--r--spec/support/filter_spec_helper.rb36
84 files changed, 542 insertions, 491 deletions
diff --git a/app/helpers/gitlab_markdown_helper.rb b/app/helpers/gitlab_markdown_helper.rb
index 5004e02ea0b..a0cf3dc0843 100644
--- a/app/helpers/gitlab_markdown_helper.rb
+++ b/app/helpers/gitlab_markdown_helper.rb
@@ -20,7 +20,7 @@ module GitlabMarkdownHelper
end
user = current_user if defined?(current_user)
- gfm_body = Gitlab::Markdown.render(escaped_body, project: @project, current_user: user, pipeline: :single_line)
+ gfm_body = Banzai.render(escaped_body, project: @project, current_user: user, pipeline: :single_line)
fragment = Nokogiri::HTML::DocumentFragment.parse(gfm_body)
if fragment.children.size == 1 && fragment.children[0].name == 'a'
@@ -50,7 +50,7 @@ module GitlabMarkdownHelper
context[:project] ||= @project
- html = Gitlab::Markdown.render(text, context)
+ html = Banzai.render(text, context)
context.merge!(
current_user: (current_user if defined?(current_user)),
@@ -61,7 +61,7 @@ module GitlabMarkdownHelper
ref: @ref
)
- Gitlab::Markdown.post_process(html, context)
+ Banzai.post_process(html, context)
end
def asciidoc(text)
diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb
index e66b9c628c7..21149a15b69 100644
--- a/app/helpers/issues_helper.rb
+++ b/app/helpers/issues_helper.rb
@@ -121,6 +121,6 @@ module IssuesHelper
end
end
- # Required for Gitlab::Markdown::IssueReferenceFilter
+ # Required for Banzai::IssueReferenceFilter
module_function :url_for_issue
end
diff --git a/app/helpers/labels_helper.rb b/app/helpers/labels_helper.rb
index 795fb439f25..97e8baa179a 100644
--- a/app/helpers/labels_helper.rb
+++ b/app/helpers/labels_helper.rb
@@ -107,6 +107,6 @@ module LabelsHelper
options_from_collection_for_select(grouped_labels, 'name', 'title', params[:label_name])
end
- # Required for Gitlab::Markdown::LabelReferenceFilter
+ # Required for Banzai::LabelReferenceFilter
module_function :render_colored_label, :text_color_for_bg, :escape_once
end
diff --git a/app/models/concerns/mentionable.rb b/app/models/concerns/mentionable.rb
index d2ea9ab7313..d4e3099453d 100644
--- a/app/models/concerns/mentionable.rb
+++ b/app/models/concerns/mentionable.rb
@@ -23,7 +23,7 @@ module Mentionable
included do
if self < Participable
- participant ->(current_user) { mentioned_users(current_user, load_lazy_references: false) }
+ participant ->(current_user) { mentioned_users(current_user) }
end
end
@@ -43,9 +43,9 @@ module Mentionable
self
end
- def all_references(current_user = self.author, text = nil, load_lazy_references: true)
- ext = Gitlab::ReferenceExtractor.new(self.project, current_user, load_lazy_references: load_lazy_references)
-
+ def all_references(current_user = self.author, text = nil)
+ ext = Gitlab::ReferenceExtractor.new(self.project, current_user)
+
if text
ext.analyze(text)
else
@@ -59,13 +59,13 @@ module Mentionable
ext
end
- def mentioned_users(current_user = nil, load_lazy_references: true)
- all_references(current_user, load_lazy_references: load_lazy_references).users
+ def mentioned_users(current_user = nil)
+ all_references(current_user).users
end
# Extract GFM references to other Mentionables from this Mentionable. Always excludes its #local_reference.
- def referenced_mentionables(current_user = self.author, text = nil, load_lazy_references: true)
- refs = all_references(current_user, text, load_lazy_references: load_lazy_references)
+ def referenced_mentionables(current_user = self.author, text = nil)
+ refs = all_references(current_user, text)
refs = (refs.issues + refs.merge_requests + refs.commits)
# We're using this method instead of Array diffing because that requires
diff --git a/app/models/concerns/participable.rb b/app/models/concerns/participable.rb
index 85367f89f4f..808d80b0530 100644
--- a/app/models/concerns/participable.rb
+++ b/app/models/concerns/participable.rb
@@ -38,20 +38,21 @@ module Participable
# Be aware that this method makes a lot of sql queries.
# Save result into variable if you are going to reuse it inside same request
def participants(current_user = self.author, load_lazy_references: true)
- participants = self.class.participant_attrs.flat_map do |attr|
- value =
- if attr.respond_to?(:call)
- instance_exec(current_user, &attr)
- else
- send(attr)
- end
+ participants =
+ Gitlab::ReferenceExtractor.lazily do
+ self.class.participant_attrs.flat_map do |attr|
+ value =
+ if attr.respond_to?(:call)
+ instance_exec(current_user, &attr)
+ else
+ send(attr)
+ end
- participants_for(value, current_user)
- end.compact.uniq
-
- if load_lazy_references
- participants = Gitlab::Markdown::ReferenceFilter::LazyReference.load(participants).uniq
+ participants_for(value, current_user)
+ end.compact.uniq
+ end
+ unless Gitlab::ReferenceExtractor.lazy?
participants.select! do |user|
user.can?(:read_project, project)
end
@@ -64,12 +65,12 @@ module Participable
def participants_for(value, current_user = nil)
case value
- when User, Gitlab::Markdown::ReferenceFilter::LazyReference
+ when User, Banzai::LazyReference
[value]
when Enumerable, ActiveRecord::Relation
value.flat_map { |v| participants_for(v, current_user) }
when Participable
- value.participants(current_user, load_lazy_references: false)
+ value.participants(current_user)
end
end
end
diff --git a/app/models/issue.rb b/app/models/issue.rb
index e04035b3af8..9f4f4923e58 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -88,7 +88,7 @@ class Issue < ActiveRecord::Base
note.all_references(load_lazy_references: false).merge_requests
end.uniq
- Gitlab::Markdown::ReferenceFilter::LazyReference.load(references).uniq.sort_by(&:iid)
+ Banzai::LazyReference.load(references).uniq.sort_by(&:iid)
end
# Reset issue events cache
diff --git a/app/models/note.rb b/app/models/note.rb
index 04053ccc61e..ea69ef65fcb 100644
--- a/app/models/note.rb
+++ b/app/models/note.rb
@@ -373,11 +373,11 @@ class Note < ActiveRecord::Base
end
def contains_emoji_only?
- note =~ /\A#{Gitlab::Markdown::EmojiFilter.emoji_pattern}\s?\Z/
+ note =~ /\A#{Banzai::EmojiFilter.emoji_pattern}\s?\Z/
end
def award_emoji_name
- original_name = note.match(Gitlab::Markdown::EmojiFilter.emoji_pattern)[1]
+ original_name = note.match(Banzai::EmojiFilter.emoji_pattern)[1]
AwardEmoji.normilize_emoji_name(original_name)
end
end
diff --git a/lib/banzai.rb b/lib/banzai.rb
new file mode 100644
index 00000000000..093382261ae
--- /dev/null
+++ b/lib/banzai.rb
@@ -0,0 +1,13 @@
+module Banzai
+ def self.render(text, context = {})
+ Renderer.render(text, context)
+ end
+
+ def self.render_result(text, context = {})
+ Renderer.render_result(text, context)
+ end
+
+ def self.post_process(html, context)
+ Renderer.post_process(html, context)
+ end
+end
diff --git a/lib/banzai/cross_project_reference.rb b/lib/banzai/cross_project_reference.rb
new file mode 100644
index 00000000000..ba2866e1efa
--- /dev/null
+++ b/lib/banzai/cross_project_reference.rb
@@ -0,0 +1,22 @@
+require 'banzai'
+
+module Banzai
+ # Common methods for ReferenceFilters that support an optional cross-project
+ # reference.
+ module CrossProjectReference
+ # Given a cross-project reference string, get the Project record
+ #
+ # Defaults to value of `context[:project]` if:
+ # * No reference is given OR
+ # * Reference given doesn't exist
+ #
+ # ref - String reference.
+ #
+ # Returns a Project, or nil if the reference can't be found
+ def project_from_ref(ref)
+ return context[:project] unless ref
+
+ Project.find_with_namespace(ref)
+ end
+ end
+end
diff --git a/lib/banzai/filter.rb b/lib/banzai/filter.rb
new file mode 100644
index 00000000000..fd4fe024252
--- /dev/null
+++ b/lib/banzai/filter.rb
@@ -0,0 +1,10 @@
+require 'active_support/core_ext/string/output_safety'
+require 'banzai'
+
+module Banzai
+ module Filter
+ def self.[](name)
+ const_get("#{name.to_s.camelize}Filter")
+ end
+ end
+end
diff --git a/lib/gitlab/markdown/abstract_reference_filter.rb b/lib/banzai/filter/abstract_reference_filter.rb
index 9488e980c08..bdaa4721b4b 100644
--- a/lib/gitlab/markdown/abstract_reference_filter.rb
+++ b/lib/banzai/filter/abstract_reference_filter.rb
@@ -1,7 +1,7 @@
-require 'gitlab/markdown'
+require 'banzai'
-module Gitlab
- module Markdown
+module Banzai
+ module Filter
# Issues, Merge Requests, Snippets, Commits and Commit Ranges share
# similar functionality in reference filtering.
class AbstractReferenceFilter < ReferenceFilter
diff --git a/lib/gitlab/markdown/filter/autolink_filter.rb b/lib/banzai/filter/autolink_filter.rb
index c37c3bc55bf..da4ee80c1b5 100644
--- a/lib/gitlab/markdown/filter/autolink_filter.rb
+++ b/lib/banzai/filter/autolink_filter.rb
@@ -1,9 +1,9 @@
-require 'gitlab/markdown'
+require 'banzai'
require 'html/pipeline/filter'
require 'uri'
-module Gitlab
- module Markdown
+module Banzai
+ module Filter
# HTML Filter for auto-linking URLs in HTML.
#
# Based on HTML::Pipeline::AutolinkFilter
diff --git a/lib/gitlab/markdown/filter/commit_range_reference_filter.rb b/lib/banzai/filter/commit_range_reference_filter.rb
index 36b3258ef76..e67cd45ab9b 100644
--- a/lib/gitlab/markdown/filter/commit_range_reference_filter.rb
+++ b/lib/banzai/filter/commit_range_reference_filter.rb
@@ -1,7 +1,7 @@
-require 'gitlab/markdown'
+require 'banzai'
-module Gitlab
- module Markdown
+module Banzai
+ module Filter
# HTML filter that replaces commit range references with links.
#
# This filter supports cross-project references.
diff --git a/lib/gitlab/markdown/filter/commit_reference_filter.rb b/lib/banzai/filter/commit_reference_filter.rb
index e3066a89b04..9e57608b483 100644
--- a/lib/gitlab/markdown/filter/commit_reference_filter.rb
+++ b/lib/banzai/filter/commit_reference_filter.rb
@@ -1,7 +1,7 @@
-require 'gitlab/markdown'
+require 'banzai'
-module Gitlab
- module Markdown
+module Banzai
+ module Filter
# HTML filter that replaces commit references with links.
#
# This filter supports cross-project references.
diff --git a/lib/gitlab/markdown/filter/emoji_filter.rb b/lib/banzai/filter/emoji_filter.rb
index da10e4d3760..86838e1483c 100644
--- a/lib/gitlab/markdown/filter/emoji_filter.rb
+++ b/lib/banzai/filter/emoji_filter.rb
@@ -1,10 +1,10 @@
require 'action_controller'
-require 'gitlab/markdown'
+require 'banzai'
require 'gitlab_emoji'
require 'html/pipeline/filter'
-module Gitlab
- module Markdown
+module Banzai
+ module Filter
# HTML filter that replaces :emoji: with images.
#
# Based on HTML::Pipeline::EmojiFilter
diff --git a/lib/gitlab/markdown/filter/external_issue_reference_filter.rb b/lib/banzai/filter/external_issue_reference_filter.rb
index 14bdf5521fc..f5737a7ac19 100644
--- a/lib/gitlab/markdown/filter/external_issue_reference_filter.rb
+++ b/lib/banzai/filter/external_issue_reference_filter.rb
@@ -1,7 +1,7 @@
-require 'gitlab/markdown'
+require 'banzai'
-module Gitlab
- module Markdown
+module Banzai
+ module Filter
# HTML filter that replaces external issue tracker references with links.
# References are ignored if the project doesn't use an external issue
# tracker.
diff --git a/lib/gitlab/markdown/filter/external_link_filter.rb b/lib/banzai/filter/external_link_filter.rb
index e09dfcb83c8..ac87b9820af 100644
--- a/lib/gitlab/markdown/filter/external_link_filter.rb
+++ b/lib/banzai/filter/external_link_filter.rb
@@ -1,8 +1,8 @@
-require 'gitlab/markdown'
+require 'banzai'
require 'html/pipeline/filter'
-module Gitlab
- module Markdown
+module Banzai
+ module Filter
# HTML Filter to add a `rel="nofollow"` attribute to external links
#
class ExternalLinkFilter < HTML::Pipeline::Filter
diff --git a/lib/gitlab/markdown/filter/issue_reference_filter.rb b/lib/banzai/filter/issue_reference_filter.rb
index 1ed69e2f431..51180cb901a 100644
--- a/lib/gitlab/markdown/filter/issue_reference_filter.rb
+++ b/lib/banzai/filter/issue_reference_filter.rb
@@ -1,7 +1,7 @@
-require 'gitlab/markdown'
+require 'banzai'
-module Gitlab
- module Markdown
+module Banzai
+ module Filter
# HTML filter that replaces issue references with links. References to
# issues that do not exist are ignored.
#
diff --git a/lib/gitlab/markdown/filter/label_reference_filter.rb b/lib/banzai/filter/label_reference_filter.rb
index a2026eecaeb..07bac2dd7fd 100644
--- a/lib/gitlab/markdown/filter/label_reference_filter.rb
+++ b/lib/banzai/filter/label_reference_filter.rb
@@ -1,7 +1,7 @@
-require 'gitlab/markdown'
+require 'banzai'
-module Gitlab
- module Markdown
+module Banzai
+ module Filter
# HTML filter that replaces label references with links.
class LabelReferenceFilter < ReferenceFilter
# Public: Find label references in text
diff --git a/lib/gitlab/markdown/filter/markdown_filter.rb b/lib/banzai/filter/markdown_filter.rb
index 921e2a0794e..0072bab1f99 100644
--- a/lib/gitlab/markdown/filter/markdown_filter.rb
+++ b/lib/banzai/filter/markdown_filter.rb
@@ -1,5 +1,8 @@
-module Gitlab
- module Markdown
+require 'banzai'
+require 'html/pipeline/filter'
+
+module Banzai
+ module Filter
class MarkdownFilter < HTML::Pipeline::TextFilter
def initialize(text, context = nil, result = nil)
super text, context, result
@@ -11,8 +14,8 @@ module Gitlab
html.rstrip!
html
end
-
- private
+
+ private
def self.redcarpet_options
# https://github.com/vmg/redcarpet#and-its-like-really-simple-to-use
diff --git a/lib/gitlab/markdown/filter/merge_request_reference_filter.rb b/lib/banzai/filter/merge_request_reference_filter.rb
index 2eb77c46da7..755b946a34b 100644
--- a/lib/gitlab/markdown/filter/merge_request_reference_filter.rb
+++ b/lib/banzai/filter/merge_request_reference_filter.rb
@@ -1,7 +1,7 @@
-require 'gitlab/markdown'
+require 'banzai'
-module Gitlab
- module Markdown
+module Banzai
+ module Filter
# HTML filter that replaces merge request references with links. References
# to merge requests that do not exist are ignored.
#
diff --git a/lib/gitlab/markdown/filter/redactor_filter.rb b/lib/banzai/filter/redactor_filter.rb
index 33ef7ce18b5..89e7a79789a 100644
--- a/lib/gitlab/markdown/filter/redactor_filter.rb
+++ b/lib/banzai/filter/redactor_filter.rb
@@ -1,8 +1,8 @@
-require 'gitlab/markdown'
+require 'banzai'
require 'html/pipeline/filter'
-module Gitlab
- module Markdown
+module Banzai
+ module Filter
# HTML filter that removes references to records that the current user does
# not have permission to view.
#
@@ -27,7 +27,7 @@ module Gitlab
def user_can_reference?(node)
if node.has_attribute?('data-reference-filter')
reference_type = node.attr('data-reference-filter')
- reference_filter = Gitlab::Markdown.const_get(reference_type)
+ reference_filter = Banzai::Filter.const_get(reference_type)
reference_filter.user_can_reference?(current_user, node, context)
else
diff --git a/lib/gitlab/markdown/reference_filter.rb b/lib/banzai/filter/reference_filter.rb
index 3b83b8bd8f8..33457a3f361 100644
--- a/lib/gitlab/markdown/reference_filter.rb
+++ b/lib/banzai/filter/reference_filter.rb
@@ -1,9 +1,9 @@
require 'active_support/core_ext/string/output_safety'
-require 'gitlab/markdown'
+require 'banzai'
require 'html/pipeline/filter'
-module Gitlab
- module Markdown
+module Banzai
+ module Filter
# Base class for GitLab Flavored Markdown reference filters.
#
# References within <pre>, <code>, <a>, and <style> elements are ignored.
@@ -12,27 +12,6 @@ module Gitlab
# :project (required) - Current project, ignored if reference is cross-project.
# :only_path - Generate path-only links.
class ReferenceFilter < HTML::Pipeline::Filter
- LazyReference = Struct.new(:klass, :ids) do
- def self.load(refs)
- lazy_references, values = refs.partition { |ref| ref.is_a?(self) }
-
- lazy_values = lazy_references.group_by(&:klass).flat_map do |klass, refs|
- ids = refs.flat_map(&:ids)
- klass.where(id: ids)
- end
-
- values + lazy_values
- end
-
- def load
- self.klass.where(id: self.ids)
- end
- end
-
- def self.[](name)
- Markdown.const_get("#{name.to_s.camelize}ReferenceFilter")
- end
-
def self.user_can_reference?(user, node, context)
if node.has_attribute?('data-project')
project_id = node.attr('data-project').to_i
diff --git a/lib/gitlab/markdown/filter/reference_gatherer_filter.rb b/lib/banzai/filter/reference_gatherer_filter.rb
index 62f241b4967..855f238ac1e 100644
--- a/lib/gitlab/markdown/filter/reference_gatherer_filter.rb
+++ b/lib/banzai/filter/reference_gatherer_filter.rb
@@ -1,8 +1,8 @@
-require 'gitlab/markdown'
+require 'banzai'
require 'html/pipeline/filter'
-module Gitlab
- module Markdown
+module Banzai
+ module Filter
# HTML filter that gathers all referenced records that the current user has
# permission to view.
#
@@ -20,7 +20,7 @@ module Gitlab
gather_references(node)
end
- load_lazy_references unless context[:load_lazy_references] == false
+ load_lazy_references unless ReferenceExtractor.lazy?
doc
end
@@ -31,7 +31,7 @@ module Gitlab
return unless node.has_attribute?('data-reference-filter')
reference_type = node.attr('data-reference-filter')
- reference_filter = Gitlab::Markdown.const_get(reference_type)
+ reference_filter = Banzai::Filter.const_get(reference_type)
return if context[:reference_filter] && reference_filter != context[:reference_filter]
@@ -47,11 +47,10 @@ module Gitlab
end
end
- # Will load all references of one type using one query.
def load_lazy_references
refs = result[:references]
refs.each do |type, values|
- refs[type] = ReferenceFilter::LazyReference.load(values)
+ refs[type] = ReferenceExtractor.lazily(values)
end
end
diff --git a/lib/gitlab/markdown/filter/relative_link_filter.rb b/lib/banzai/filter/relative_link_filter.rb
index 81f60120fcd..5a081125f21 100644
--- a/lib/gitlab/markdown/filter/relative_link_filter.rb
+++ b/lib/banzai/filter/relative_link_filter.rb
@@ -1,9 +1,9 @@
-require 'gitlab/markdown'
+require 'banzai'
require 'html/pipeline/filter'
require 'uri'
-module Gitlab
- module Markdown
+module Banzai
+ module Filter
# HTML filter that "fixes" relative links to files in a repository.
#
# Context options:
diff --git a/lib/gitlab/markdown/filter/sanitization_filter.rb b/lib/banzai/filter/sanitization_filter.rb
index cf153f30622..d03e3ae4b3c 100644
--- a/lib/gitlab/markdown/filter/sanitization_filter.rb
+++ b/lib/banzai/filter/sanitization_filter.rb
@@ -1,9 +1,9 @@
-require 'gitlab/markdown'
+require 'banzai'
require 'html/pipeline/filter'
require 'html/pipeline/sanitization_filter'
-module Gitlab
- module Markdown
+module Banzai
+ module Filter
# Sanitize HTML
#
# Extends HTML::Pipeline::SanitizationFilter with a custom whitelist.
diff --git a/lib/gitlab/markdown/filter/snippet_reference_filter.rb b/lib/banzai/filter/snippet_reference_filter.rb
index f7bd07c2a34..1ad5df96f85 100644
--- a/lib/gitlab/markdown/filter/snippet_reference_filter.rb
+++ b/lib/banzai/filter/snippet_reference_filter.rb
@@ -1,7 +1,7 @@
-require 'gitlab/markdown'
+require 'banzai'
-module Gitlab
- module Markdown
+module Banzai
+ module Filter
# HTML filter that replaces snippet references with links. References to
# snippets that do not exist are ignored.
#
diff --git a/lib/gitlab/markdown/filter/syntax_highlight_filter.rb b/lib/banzai/filter/syntax_highlight_filter.rb
index 8597e02f0de..c889cc1e97c 100644
--- a/lib/gitlab/markdown/filter/syntax_highlight_filter.rb
+++ b/lib/banzai/filter/syntax_highlight_filter.rb
@@ -1,9 +1,9 @@
-require 'gitlab/markdown'
+require 'banzai'
require 'html/pipeline/filter'
require 'rouge/plugins/redcarpet'
-module Gitlab
- module Markdown
+module Banzai
+ module Filter
# HTML Filter to highlight fenced code blocks
#
class SyntaxHighlightFilter < HTML::Pipeline::Filter
diff --git a/lib/gitlab/markdown/filter/table_of_contents_filter.rb b/lib/banzai/filter/table_of_contents_filter.rb
index bbb3bf7fc8b..92d130074dc 100644
--- a/lib/gitlab/markdown/filter/table_of_contents_filter.rb
+++ b/lib/banzai/filter/table_of_contents_filter.rb
@@ -1,8 +1,8 @@
-require 'gitlab/markdown'
+require 'banzai'
require 'html/pipeline/filter'
-module Gitlab
- module Markdown
+module Banzai
+ module Filter
# HTML filter that adds an anchor child element to all Headers in a
# document, so that they can be linked to.
#
diff --git a/lib/gitlab/markdown/filter/task_list_filter.rb b/lib/banzai/filter/task_list_filter.rb
index 2f133ae8500..bdf7c2ebdfc 100644
--- a/lib/gitlab/markdown/filter/task_list_filter.rb
+++ b/lib/banzai/filter/task_list_filter.rb
@@ -1,8 +1,8 @@
-require 'gitlab/markdown'
+require 'banzai'
require 'task_list/filter'
-module Gitlab
- module Markdown
+module Banzai
+ module Filter
# Work around a bug in the default TaskList::Filter that adds a `task-list`
# class to every list element, regardless of whether or not it contains a
# task list.
diff --git a/lib/gitlab/markdown/filter/upload_link_filter.rb b/lib/banzai/filter/upload_link_filter.rb
index fbada73ab86..1a1d0aad8ca 100644
--- a/lib/gitlab/markdown/filter/upload_link_filter.rb
+++ b/lib/banzai/filter/upload_link_filter.rb
@@ -1,9 +1,9 @@
-require 'gitlab/markdown'
+require 'banzai'
require 'html/pipeline/filter'
require 'uri'
-module Gitlab
- module Markdown
+module Banzai
+ module Filter
# HTML filter that "fixes" relative upload links to files.
# Context options:
# :project (required) - Current project
diff --git a/lib/gitlab/markdown/filter/user_reference_filter.rb b/lib/banzai/filter/user_reference_filter.rb
index 0a20d9c0347..67c24faf991 100644
--- a/lib/gitlab/markdown/filter/user_reference_filter.rb
+++ b/lib/banzai/filter/user_reference_filter.rb
@@ -1,7 +1,7 @@
-require 'gitlab/markdown'
+require 'banzai'
-module Gitlab
- module Markdown
+module Banzai
+ module Filter
# HTML filter that replaces user or group references with links.
#
# A special `@all` reference is also supported.
diff --git a/lib/banzai/lazy_reference.rb b/lib/banzai/lazy_reference.rb
new file mode 100644
index 00000000000..073ec5d9801
--- /dev/null
+++ b/lib/banzai/lazy_reference.rb
@@ -0,0 +1,27 @@
+require 'banzai'
+
+module Banzai
+ class LazyReference
+ def self.load(refs)
+ lazy_references, values = refs.partition { |ref| ref.is_a?(self) }
+
+ lazy_values = lazy_references.group_by(&:klass).flat_map do |klass, refs|
+ ids = refs.flat_map(&:ids)
+ klass.where(id: ids)
+ end
+
+ values + lazy_values
+ end
+
+ attr_reader :klass, :ids
+
+ def initialize(klass, ids)
+ @klass = klass
+ @ids = Array.wrap(ids).map(&:to_i)
+ end
+
+ def load
+ self.klass.where(id: self.ids)
+ end
+ end
+end
diff --git a/lib/banzai/pipeline.rb b/lib/banzai/pipeline.rb
new file mode 100644
index 00000000000..4e017809d9d
--- /dev/null
+++ b/lib/banzai/pipeline.rb
@@ -0,0 +1,10 @@
+require 'banzai'
+
+module Banzai
+ module Pipeline
+ def self.[](name)
+ name ||= :full
+ const_get("#{name.to_s.camelize}Pipeline")
+ end
+ end
+end
diff --git a/lib/banzai/pipeline/asciidoc_pipeline.rb b/lib/banzai/pipeline/asciidoc_pipeline.rb
new file mode 100644
index 00000000000..5e76a817be5
--- /dev/null
+++ b/lib/banzai/pipeline/asciidoc_pipeline.rb
@@ -0,0 +1,13 @@
+require 'banzai'
+
+module Banzai
+ module Pipeline
+ class AsciidocPipeline < BasePipeline
+ def self.filters
+ [
+ Filter::RelativeLinkFilter
+ ]
+ end
+ end
+ end
+end
diff --git a/lib/banzai/pipeline/atom_pipeline.rb b/lib/banzai/pipeline/atom_pipeline.rb
new file mode 100644
index 00000000000..957f352aec5
--- /dev/null
+++ b/lib/banzai/pipeline/atom_pipeline.rb
@@ -0,0 +1,14 @@
+require 'banzai'
+
+module Banzai
+ module Pipeline
+ class AtomPipeline < FullPipeline
+ def self.transform_context(context)
+ super(context).merge(
+ only_path: false,
+ xhtml: true
+ )
+ end
+ end
+ end
+end
diff --git a/lib/banzai/pipeline/base_pipeline.rb b/lib/banzai/pipeline/base_pipeline.rb
new file mode 100644
index 00000000000..cd30009e5c0
--- /dev/null
+++ b/lib/banzai/pipeline/base_pipeline.rb
@@ -0,0 +1,30 @@
+require 'banzai'
+require 'html/pipeline'
+
+module Banzai
+ module Pipeline
+ class BasePipeline
+ def self.filters
+ []
+ end
+
+ def self.transform_context(context)
+ context
+ end
+
+ def self.html_pipeline
+ @html_pipeline ||= HTML::Pipeline.new(filters)
+ end
+
+ class << self
+ %i(call to_document to_html).each do |meth|
+ define_method(meth) do |text, context|
+ context = transform_context(context)
+
+ html_pipeline.send(meth, text, context)
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/markdown/combined_pipeline.rb b/lib/banzai/pipeline/combined_pipeline.rb
index 6b08a5e9f72..f3bf1809d18 100644
--- a/lib/gitlab/markdown/combined_pipeline.rb
+++ b/lib/banzai/pipeline/combined_pipeline.rb
@@ -1,10 +1,10 @@
-require 'gitlab/markdown'
+require 'banzai'
-module Gitlab
- module Markdown
+module Banzai
+ module Pipeline
module CombinedPipeline
def self.new(*pipelines)
- Class.new(Pipeline) do
+ Class.new(BasePipeline) do
const_set :PIPELINES, pipelines
def self.pipelines
diff --git a/lib/gitlab/markdown/pipeline/description_pipeline.rb b/lib/banzai/pipeline/description_pipeline.rb
index 76f6948af8f..94c2cb165a5 100644
--- a/lib/gitlab/markdown/pipeline/description_pipeline.rb
+++ b/lib/banzai/pipeline/description_pipeline.rb
@@ -1,10 +1,10 @@
-require 'gitlab/markdown'
+require 'banzai'
-module Gitlab
- module Markdown
+module Banzai
+ module Pipeline
class DescriptionPipeline < FullPipeline
def self.transform_context(context)
- super(context).merge(
+ super(context).merge(
# SanitizationFilter
inline_sanitization: true
)
diff --git a/lib/gitlab/markdown/pipeline/email_pipeline.rb b/lib/banzai/pipeline/email_pipeline.rb
index b88cb790270..14356145a35 100644
--- a/lib/gitlab/markdown/pipeline/email_pipeline.rb
+++ b/lib/banzai/pipeline/email_pipeline.rb
@@ -1,10 +1,10 @@
-require 'gitlab/markdown'
+require 'banzai'
-module Gitlab
- module Markdown
+module Banzai
+ module Pipeline
class EmailPipeline < FullPipeline
def self.transform_context(context)
- super(context).merge(
+ super(context).merge(
only_path: false
)
end
diff --git a/lib/gitlab/markdown/pipeline/full_pipeline.rb b/lib/banzai/pipeline/full_pipeline.rb
index b3b7a3c27c0..72395a5d50e 100644
--- a/lib/gitlab/markdown/pipeline/full_pipeline.rb
+++ b/lib/banzai/pipeline/full_pipeline.rb
@@ -1,7 +1,7 @@
-require 'gitlab/markdown'
+require 'banzai'
-module Gitlab
- module Markdown
+module Banzai
+ module Pipeline
class FullPipeline < CombinedPipeline.new(PlainMarkdownPipeline, GfmPipeline)
end
diff --git a/lib/banzai/pipeline/gfm_pipeline.rb b/lib/banzai/pipeline/gfm_pipeline.rb
new file mode 100644
index 00000000000..38750b55ec7
--- /dev/null
+++ b/lib/banzai/pipeline/gfm_pipeline.rb
@@ -0,0 +1,41 @@
+require 'banzai'
+
+module Banzai
+ module Pipeline
+ class GfmPipeline < BasePipeline
+ def self.filters
+ @filters ||= [
+ Filter::SyntaxHighlightFilter,
+ Filter::SanitizationFilter,
+
+ Filter::UploadLinkFilter,
+ Filter::EmojiFilter,
+ Filter::TableOfContentsFilter,
+ Filter::AutolinkFilter,
+ Filter::ExternalLinkFilter,
+
+ Filter::UserReferenceFilter,
+ Filter::IssueReferenceFilter,
+ Filter::ExternalIssueReferenceFilter,
+ Filter::MergeRequestReferenceFilter,
+ Filter::SnippetReferenceFilter,
+ Filter::CommitRangeReferenceFilter,
+ Filter::CommitReferenceFilter,
+ Filter::LabelReferenceFilter,
+
+ Filter::TaskListFilter
+ ]
+ end
+
+ def self.transform_context(context)
+ context.merge(
+ only_path: true,
+
+ # EmojiFilter
+ asset_host: Gitlab::Application.config.asset_host,
+ asset_root: Gitlab.config.gitlab.base_url
+ )
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/markdown/pipeline/note_pipeline.rb b/lib/banzai/pipeline/note_pipeline.rb
index a8bf5f42d8e..89335143852 100644
--- a/lib/gitlab/markdown/pipeline/note_pipeline.rb
+++ b/lib/banzai/pipeline/note_pipeline.rb
@@ -1,10 +1,10 @@
-require 'gitlab/markdown'
+require 'banzai'
-module Gitlab
- module Markdown
+module Banzai
+ module Pipeline
class NotePipeline < FullPipeline
def self.transform_context(context)
- super(context).merge(
+ super(context).merge(
# TableOfContentsFilter
no_header_anchors: true
)
diff --git a/lib/banzai/pipeline/plain_markdown_pipeline.rb b/lib/banzai/pipeline/plain_markdown_pipeline.rb
new file mode 100644
index 00000000000..998fd75daa2
--- /dev/null
+++ b/lib/banzai/pipeline/plain_markdown_pipeline.rb
@@ -0,0 +1,13 @@
+require 'banzai'
+
+module Banzai
+ module Pipeline
+ class PlainMarkdownPipeline < BasePipeline
+ def self.filters
+ [
+ Filter::MarkdownFilter
+ ]
+ end
+ end
+ end
+end
diff --git a/lib/banzai/pipeline/post_process_pipeline.rb b/lib/banzai/pipeline/post_process_pipeline.rb
new file mode 100644
index 00000000000..148f24b6ce1
--- /dev/null
+++ b/lib/banzai/pipeline/post_process_pipeline.rb
@@ -0,0 +1,20 @@
+require 'banzai'
+
+module Banzai
+ module Pipeline
+ class PostProcessPipeline < BasePipeline
+ def self.filters
+ [
+ Filter::RelativeLinkFilter,
+ Filter::RedactorFilter
+ ]
+ end
+
+ def self.transform_context(context)
+ context.merge(
+ post_process: true
+ )
+ end
+ end
+ end
+end
diff --git a/lib/banzai/pipeline/reference_extraction_pipeline.rb b/lib/banzai/pipeline/reference_extraction_pipeline.rb
new file mode 100644
index 00000000000..4f9bc9fcccc
--- /dev/null
+++ b/lib/banzai/pipeline/reference_extraction_pipeline.rb
@@ -0,0 +1,13 @@
+require 'banzai'
+
+module Banzai
+ module Pipeline
+ class ReferenceExtractionPipeline < BasePipeline
+ def self.filters
+ [
+ Filter::ReferenceGathererFilter
+ ]
+ end
+ end
+ end
+end
diff --git a/lib/banzai/pipeline/single_line_pipeline.rb b/lib/banzai/pipeline/single_line_pipeline.rb
new file mode 100644
index 00000000000..6725c9039a9
--- /dev/null
+++ b/lib/banzai/pipeline/single_line_pipeline.rb
@@ -0,0 +1,9 @@
+require 'banzai'
+
+module Banzai
+ module Pipeline
+ class SingleLinePipeline < GfmPipeline
+
+ end
+ end
+end
diff --git a/lib/banzai/reference_extractor.rb b/lib/banzai/reference_extractor.rb
new file mode 100644
index 00000000000..8ae5b890953
--- /dev/null
+++ b/lib/banzai/reference_extractor.rb
@@ -0,0 +1,55 @@
+require 'banzai'
+
+module Banzai
+ # Extract possible GFM references from an arbitrary String for further processing.
+ class ReferenceExtractor
+ class << self
+ LAZY_KEY = :banzai_reference_extractor_lazy
+
+ def lazy?
+ Thread.current[LAZY_KEY]
+ end
+
+ def lazily(values = nil, &block)
+ return values || block.call if lazy?
+
+ begin
+ Thread.current[LAZY_KEY] = true
+
+ values ||= block.call
+
+ Banzai::LazyReference.load(values.uniq).uniq
+ ensure
+ Thread.current[LAZY_KEY] = false
+ end
+ end
+ end
+
+ def initialize
+ @texts = []
+ end
+
+ def analyze(text, context = {})
+ @texts << Renderer.render(text, context)
+ end
+
+ def references(type, context = {})
+ filter = Banzai::Filter["#{type}_reference"]
+
+ context.merge!(
+ pipeline: :reference_extraction,
+
+ # ReferenceGathererFilter
+ reference_filter: filter
+ )
+
+ self.class.lazily do
+ @texts.flat_map do |html|
+ text_context = context.dup
+ result = Renderer.render_result(html, text_context)
+ result[:references][type]
+ end.uniq
+ end
+ end
+ end
+end
diff --git a/lib/banzai/renderer.rb b/lib/banzai/renderer.rb
new file mode 100644
index 00000000000..891c0fd7749
--- /dev/null
+++ b/lib/banzai/renderer.rb
@@ -0,0 +1,76 @@
+module Banzai
+ module Renderer
+ # Convert a Markdown String into an HTML-safe String of HTML
+ #
+ # Note that while the returned HTML will have been sanitized of dangerous
+ # HTML, it may post a risk of information leakage if it's not also passed
+ # through `post_process`.
+ #
+ # Also note that the returned String is always HTML, not XHTML. Views
+ # requiring XHTML, such as Atom feeds, need to call `post_process` on the
+ # result, providing the appropriate `pipeline` option.
+ #
+ # markdown - Markdown String
+ # context - Hash of context options passed to our HTML Pipeline
+ #
+ # Returns an HTML-safe String
+ def self.render(text, context = {})
+ cache_key = context.delete(:cache_key)
+ cache_key = full_cache_key(cache_key, context[:pipeline])
+
+ if cache_key
+ Rails.cache.fetch(cache_key) do
+ cacheless_render(text, context)
+ end
+ else
+ cacheless_render(text, context)
+ end
+ end
+
+ def self.render_result(text, context = {})
+ Pipeline[context[:pipeline]].call(text, context)
+ end
+
+ # Perform post-processing on an HTML String
+ #
+ # This method is used to perform state-dependent changes to a String of
+ # HTML, such as removing references that the current user doesn't have
+ # permission to make (`RedactorFilter`).
+ #
+ # html - String to process
+ # context - Hash of options to customize output
+ # :pipeline - Symbol pipeline type
+ # :project - Project
+ # :user - User object
+ #
+ # Returns an HTML-safe String
+ def self.post_process(html, context)
+ context = Pipeline[context[:pipeline]].transform_context(context)
+
+ pipeline = Pipeline[:post_process]
+ if context[:xhtml]
+ pipeline.to_document(html, context).to_html(save_with: Nokogiri::XML::Node::SaveOptions::AS_XHTML)
+ else
+ pipeline.to_html(html, context)
+ end.html_safe
+ end
+
+ private
+
+ def self.cacheless_render(text, context = {})
+ result = render_result(text, context)
+
+ output = result[:output]
+ if output.respond_to?(:to_html)
+ output.to_html
+ else
+ output.to_s
+ end
+ end
+
+ def self.full_cache_key(cache_key, pipeline_name)
+ return unless cache_key
+ ["banzai", *cache_key, pipeline_name || :full]
+ end
+ end
+end
diff --git a/lib/gitlab/asciidoc.rb b/lib/gitlab/asciidoc.rb
index 330d3342dd1..b203b9d70e4 100644
--- a/lib/gitlab/asciidoc.rb
+++ b/lib/gitlab/asciidoc.rb
@@ -32,7 +32,7 @@ module Gitlab
html = ::Asciidoctor.convert(input, asciidoc_opts)
if context[:project]
- html = Gitlab::Markdown.render(html, context.merge(pipeline: :asciidoc))
+ html = Banzai.render(html, context.merge(pipeline: :asciidoc))
end
html.html_safe
diff --git a/lib/gitlab/markdown.rb b/lib/gitlab/markdown.rb
deleted file mode 100644
index f4e2cefca51..00000000000
--- a/lib/gitlab/markdown.rb
+++ /dev/null
@@ -1,115 +0,0 @@
-require 'html/pipeline'
-
-module Gitlab
- # Custom parser for GitLab-flavored Markdown
- #
- # See the files in `lib/gitlab/markdown/` for specific processing information.
- module Markdown
- # Convert a Markdown String into an HTML-safe String of HTML
- #
- # Note that while the returned HTML will have been sanitized of dangerous
- # HTML, it may post a risk of information leakage if it's not also passed
- # through `post_process`.
- #
- # Also note that the returned String is always HTML, not XHTML. Views
- # requiring XHTML, such as Atom feeds, need to call `post_process` on the
- # result, providing the appropriate `pipeline` option.
- #
- # markdown - Markdown String
- # context - Hash of context options passed to our HTML Pipeline
- #
- # Returns an HTML-safe String
- def self.render(text, context = {})
- cache_key = context.delete(:cache_key)
- cache_key = full_cache_key(cache_key, context[:pipeline])
-
- if cache_key
- Rails.cache.fetch(cache_key) do
- cacheless_render(text, context)
- end
- else
- cacheless_render(text, context)
- end
- end
-
- def self.render_result(text, context = {})
- Pipeline[context[:pipeline]].call(text, context)
- end
-
- # Perform post-processing on an HTML String
- #
- # This method is used to perform state-dependent changes to a String of
- # HTML, such as removing references that the current user doesn't have
- # permission to make (`RedactorFilter`).
- #
- # html - String to process
- # context - Hash of options to customize output
- # :pipeline - Symbol pipeline type
- # :project - Project
- # :user - User object
- #
- # Returns an HTML-safe String
- def self.post_process(html, context)
- context = Pipeline[context[:pipeline]].transform_context(context)
-
- pipeline = Pipeline[:post_process]
- if context[:xhtml]
- pipeline.to_document(html, context).to_html(save_with: Nokogiri::XML::Node::SaveOptions::AS_XHTML)
- else
- pipeline.to_html(html, context)
- end.html_safe
- end
-
- private
-
- def self.cacheless_render(text, context = {})
- result = render_result(text, context)
-
- output = result[:output]
- if output.respond_to?(:to_html)
- output.to_html
- else
- output.to_s
- end
- end
-
- def self.full_cache_key(cache_key, pipeline_name)
- return unless cache_key
- ["markdown", *cache_key, pipeline_name || :full]
- end
-
- # Provide autoload paths for filters to prevent a circular dependency error
- autoload :AutolinkFilter, 'gitlab/markdown/filter/autolink_filter'
- autoload :CommitRangeReferenceFilter, 'gitlab/markdown/filter/commit_range_reference_filter'
- autoload :CommitReferenceFilter, 'gitlab/markdown/filter/commit_reference_filter'
- autoload :EmojiFilter, 'gitlab/markdown/filter/emoji_filter'
- autoload :ExternalIssueReferenceFilter, 'gitlab/markdown/filter/external_issue_reference_filter'
- autoload :ExternalLinkFilter, 'gitlab/markdown/filter/external_link_filter'
- autoload :IssueReferenceFilter, 'gitlab/markdown/filter/issue_reference_filter'
- autoload :LabelReferenceFilter, 'gitlab/markdown/filter/label_reference_filter'
- autoload :MarkdownFilter, 'gitlab/markdown/filter/markdown_filter'
- autoload :MergeRequestReferenceFilter, 'gitlab/markdown/filter/merge_request_reference_filter'
- autoload :RedactorFilter, 'gitlab/markdown/filter/redactor_filter'
- autoload :ReferenceGathererFilter, 'gitlab/markdown/filter/reference_gatherer_filter'
- autoload :RelativeLinkFilter, 'gitlab/markdown/filter/relative_link_filter'
- autoload :SanitizationFilter, 'gitlab/markdown/filter/sanitization_filter'
- autoload :SnippetReferenceFilter, 'gitlab/markdown/filter/snippet_reference_filter'
- autoload :SyntaxHighlightFilter, 'gitlab/markdown/filter/syntax_highlight_filter'
- autoload :TableOfContentsFilter, 'gitlab/markdown/filter/table_of_contents_filter'
- autoload :TaskListFilter, 'gitlab/markdown/filter/task_list_filter'
- autoload :UserReferenceFilter, 'gitlab/markdown/filter/user_reference_filter'
- autoload :UploadLinkFilter, 'gitlab/markdown/filter/upload_link_filter'
-
- autoload :AsciidocPipeline, 'gitlab/markdown/pipeline/asciidoc_pipeline'
- autoload :AtomPipeline, 'gitlab/markdown/pipeline/atom_pipeline'
- autoload :DescriptionPipeline, 'gitlab/markdown/pipeline/description_pipeline'
- autoload :EmailPipeline, 'gitlab/markdown/pipeline/email_pipeline'
- autoload :FullPipeline, 'gitlab/markdown/pipeline/full_pipeline'
- autoload :GfmPipeline, 'gitlab/markdown/pipeline/gfm_pipeline'
- autoload :NotePipeline, 'gitlab/markdown/pipeline/note_pipeline'
- autoload :PlainMarkdownPipeline, 'gitlab/markdown/pipeline/plain_markdown_pipeline'
- autoload :PostProcessPipeline, 'gitlab/markdown/pipeline/post_process_pipeline'
- autoload :ReferenceExtractionPipeline, 'gitlab/markdown/pipeline/reference_extraction_pipeline'
- autoload :SingleLinePipeline, 'gitlab/markdown/pipeline/single_line_pipeline'
- end
-end
diff --git a/lib/gitlab/markdown/cross_project_reference.rb b/lib/gitlab/markdown/cross_project_reference.rb
deleted file mode 100644
index 6ab04a584b0..00000000000
--- a/lib/gitlab/markdown/cross_project_reference.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-require 'gitlab/markdown'
-
-module Gitlab
- module Markdown
- # Common methods for ReferenceFilters that support an optional cross-project
- # reference.
- module CrossProjectReference
- # Given a cross-project reference string, get the Project record
- #
- # Defaults to value of `context[:project]` if:
- # * No reference is given OR
- # * Reference given doesn't exist
- #
- # ref - String reference.
- #
- # Returns a Project, or nil if the reference can't be found
- def project_from_ref(ref)
- return context[:project] unless ref
-
- Project.find_with_namespace(ref)
- end
- end
- end
-end
diff --git a/lib/gitlab/markdown/pipeline.rb b/lib/gitlab/markdown/pipeline.rb
index d683756f95a..8f3f43c0e91 100644
--- a/lib/gitlab/markdown/pipeline.rb
+++ b/lib/gitlab/markdown/pipeline.rb
@@ -1,11 +1,11 @@
-require 'gitlab/markdown'
+require 'banzai'
module Gitlab
module Markdown
class Pipeline
def self.[](name)
name ||= :full
- Markdown.const_get("#{name.to_s.camelize}Pipeline")
+ const_get("#{name.to_s.camelize}Pipeline")
end
def self.filters
diff --git a/lib/gitlab/markdown/pipeline/asciidoc_pipeline.rb b/lib/gitlab/markdown/pipeline/asciidoc_pipeline.rb
deleted file mode 100644
index 6829b4acb95..00000000000
--- a/lib/gitlab/markdown/pipeline/asciidoc_pipeline.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-require 'gitlab/markdown'
-
-module Gitlab
- module Markdown
- class AsciidocPipeline < Pipeline
- def self.filters
- [
- Gitlab::Markdown::RelativeLinkFilter
- ]
- end
- end
- end
-end
diff --git a/lib/gitlab/markdown/pipeline/atom_pipeline.rb b/lib/gitlab/markdown/pipeline/atom_pipeline.rb
deleted file mode 100644
index e151f8f5e5a..00000000000
--- a/lib/gitlab/markdown/pipeline/atom_pipeline.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-require 'gitlab/markdown'
-
-module Gitlab
- module Markdown
- class AtomPipeline < FullPipeline
- def self.transform_context(context)
- super(context).merge(
- only_path: false,
- xhtml: true
- )
- end
- end
- end
-end
diff --git a/lib/gitlab/markdown/pipeline/gfm_pipeline.rb b/lib/gitlab/markdown/pipeline/gfm_pipeline.rb
deleted file mode 100644
index ca90bd75d77..00000000000
--- a/lib/gitlab/markdown/pipeline/gfm_pipeline.rb
+++ /dev/null
@@ -1,41 +0,0 @@
-require 'gitlab/markdown'
-
-module Gitlab
- module Markdown
- class GfmPipeline < Pipeline
- def self.filters
- @filters ||= [
- Gitlab::Markdown::SyntaxHighlightFilter,
- Gitlab::Markdown::SanitizationFilter,
-
- Gitlab::Markdown::UploadLinkFilter,
- Gitlab::Markdown::EmojiFilter,
- Gitlab::Markdown::TableOfContentsFilter,
- Gitlab::Markdown::AutolinkFilter,
- Gitlab::Markdown::ExternalLinkFilter,
-
- Gitlab::Markdown::UserReferenceFilter,
- Gitlab::Markdown::IssueReferenceFilter,
- Gitlab::Markdown::ExternalIssueReferenceFilter,
- Gitlab::Markdown::MergeRequestReferenceFilter,
- Gitlab::Markdown::SnippetReferenceFilter,
- Gitlab::Markdown::CommitRangeReferenceFilter,
- Gitlab::Markdown::CommitReferenceFilter,
- Gitlab::Markdown::LabelReferenceFilter,
-
- Gitlab::Markdown::TaskListFilter
- ]
- end
-
- def self.transform_context(context)
- context.merge(
- only_path: true,
-
- # EmojiFilter
- asset_host: Gitlab::Application.config.asset_host,
- asset_root: Gitlab.config.gitlab.base_url
- )
- end
- end
- end
-end
diff --git a/lib/gitlab/markdown/pipeline/plain_markdown_pipeline.rb b/lib/gitlab/markdown/pipeline/plain_markdown_pipeline.rb
deleted file mode 100644
index 0abb93f8a03..00000000000
--- a/lib/gitlab/markdown/pipeline/plain_markdown_pipeline.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-require 'gitlab/markdown'
-
-module Gitlab
- module Markdown
- class PlainMarkdownPipeline < Pipeline
- def self.filters
- [
- Gitlab::Markdown::MarkdownFilter
- ]
- end
- end
- end
-end
diff --git a/lib/gitlab/markdown/pipeline/post_process_pipeline.rb b/lib/gitlab/markdown/pipeline/post_process_pipeline.rb
deleted file mode 100644
index 60cc32f490e..00000000000
--- a/lib/gitlab/markdown/pipeline/post_process_pipeline.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-require 'gitlab/markdown'
-
-module Gitlab
- module Markdown
- class PostProcessPipeline < Pipeline
- def self.filters
- [
- Gitlab::Markdown::RelativeLinkFilter,
- Gitlab::Markdown::RedactorFilter
- ]
- end
-
- def self.transform_context(context)
- context.merge(
- post_process: true
- )
- end
- end
- end
-end
diff --git a/lib/gitlab/markdown/pipeline/reference_extraction_pipeline.rb b/lib/gitlab/markdown/pipeline/reference_extraction_pipeline.rb
deleted file mode 100644
index a89ab462bac..00000000000
--- a/lib/gitlab/markdown/pipeline/reference_extraction_pipeline.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-require 'gitlab/markdown'
-
-module Gitlab
- module Markdown
- class ReferenceExtractionPipeline < Pipeline
- def self.filters
- [
- Gitlab::Markdown::ReferenceGathererFilter
- ]
- end
- end
- end
-end
diff --git a/lib/gitlab/markdown/pipeline/single_line_pipeline.rb b/lib/gitlab/markdown/pipeline/single_line_pipeline.rb
deleted file mode 100644
index 2f24927b879..00000000000
--- a/lib/gitlab/markdown/pipeline/single_line_pipeline.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-require 'gitlab/markdown'
-
-module Gitlab
- module Markdown
- class SingleLinePipeline < GfmPipeline
-
- end
- end
-end
diff --git a/lib/gitlab/reference_extractor.rb b/lib/gitlab/reference_extractor.rb
index e83167fa7d7..42f7c26f3c4 100644
--- a/lib/gitlab/reference_extractor.rb
+++ b/lib/gitlab/reference_extractor.rb
@@ -1,62 +1,27 @@
-require 'gitlab/markdown'
+require 'banzai'
module Gitlab
# Extract possible GFM references from an arbitrary String for further processing.
- class ReferenceExtractor
- attr_accessor :project, :current_user, :load_lazy_references
+ class ReferenceExtractor < Banzai::ReferenceExtractor
+ attr_accessor :project, :current_user
- def initialize(project, current_user = nil, load_lazy_references: true)
+ def initialize(project, current_user = nil)
@project = project
@current_user = current_user
- @load_lazy_references = load_lazy_references
- @texts = []
@references = {}
+
+ super()
end
- def analyze(text, options = {})
- @texts << Gitlab::Markdown.render(text, options.merge(project: project))
+ def analyze(text, context = {})
+ super(text, context.merge(project: project))
end
%i(user label issue merge_request snippet commit commit_range).each do |type|
define_method("#{type}s") do
- @references[type] ||= pipeline_result(type)
+ @references[type] ||= references(type, project: project, current_user: current_user)
end
end
-
- private
-
- # Instantiate and call HTML::Pipeline with a single reference filter type,
- # returning the result
- #
- # filter_type - Symbol reference type (e.g., :commit, :issue, etc.)
- #
- # Returns the results Array for the requested filter type
- def pipeline_result(filter_type)
- filter = Gitlab::Markdown::ReferenceFilter[filter_type]
-
- context = {
- pipeline: :reference_extraction,
-
- project: project,
- current_user: current_user,
-
- # ReferenceGathererFilter
- load_lazy_references: false,
- reference_filter: filter
- }
-
- values = @texts.flat_map do |html|
- text_context = context.dup
- result = Gitlab::Markdown.render_result(html, text_context)
- result[:references][filter_type]
- end.uniq
-
- if @load_lazy_references
- values = Gitlab::Markdown::ReferenceFilter::LazyReference.load(values).uniq
- end
-
- values
- end
end
end
diff --git a/spec/benchmarks/lib/gitlab/markdown/reference_filter_spec.rb b/spec/benchmarks/lib/gitlab/markdown/reference_filter_spec.rb
index 34cd9f7e4eb..3855763b200 100644
--- a/spec/benchmarks/lib/gitlab/markdown/reference_filter_spec.rb
+++ b/spec/benchmarks/lib/gitlab/markdown/reference_filter_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe Gitlab::Markdown::ReferenceFilter, benchmark: true do
+describe Banzai::Filter::ReferenceFilter, benchmark: true do
let(:input) do
html = <<-EOF
<p>Hello @alice and @bob, how are you doing today?</p>
diff --git a/spec/lib/gitlab/markdown/cross_project_reference_spec.rb b/spec/lib/banzai/cross_project_reference_spec.rb
index f594fe4ccf6..81b9a513ce3 100644
--- a/spec/lib/gitlab/markdown/cross_project_reference_spec.rb
+++ b/spec/lib/banzai/cross_project_reference_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe Gitlab::Markdown::CrossProjectReference, lib: true do
+describe Banzai::CrossProjectReference, lib: true do
include described_class
describe '#project_from_ref' do
diff --git a/spec/lib/gitlab/markdown/filter/autolink_filter_spec.rb b/spec/lib/banzai/filter/autolink_filter_spec.rb
index a0844aee559..84c2ddf444e 100644
--- a/spec/lib/gitlab/markdown/filter/autolink_filter_spec.rb
+++ b/spec/lib/banzai/filter/autolink_filter_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe Gitlab::Markdown::AutolinkFilter, lib: true do
+describe Banzai::Filter::AutolinkFilter, lib: true do
include FilterSpecHelper
let(:link) { 'http://about.gitlab.com/' }
diff --git a/spec/lib/gitlab/markdown/filter/commit_range_reference_filter_spec.rb b/spec/lib/banzai/filter/commit_range_reference_filter_spec.rb
index 570c9767628..c2a8ad36c30 100644
--- a/spec/lib/gitlab/markdown/filter/commit_range_reference_filter_spec.rb
+++ b/spec/lib/banzai/filter/commit_range_reference_filter_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe Gitlab::Markdown::CommitRangeReferenceFilter, lib: true do
+describe Banzai::Filter::CommitRangeReferenceFilter, lib: true do
include FilterSpecHelper
let(:project) { create(:project, :public) }
diff --git a/spec/lib/gitlab/markdown/filter/commit_reference_filter_spec.rb b/spec/lib/banzai/filter/commit_reference_filter_spec.rb
index 76e7957bbb9..473534ba68a 100644
--- a/spec/lib/gitlab/markdown/filter/commit_reference_filter_spec.rb
+++ b/spec/lib/banzai/filter/commit_reference_filter_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe Gitlab::Markdown::CommitReferenceFilter, lib: true do
+describe Banzai::Filter::CommitReferenceFilter, lib: true do
include FilterSpecHelper
let(:project) { create(:project, :public) }
diff --git a/spec/lib/gitlab/markdown/filter/emoji_filter_spec.rb b/spec/lib/banzai/filter/emoji_filter_spec.rb
index ea9b81862cf..cf314058158 100644
--- a/spec/lib/gitlab/markdown/filter/emoji_filter_spec.rb
+++ b/spec/lib/banzai/filter/emoji_filter_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe Gitlab::Markdown::EmojiFilter, lib: true do
+describe Banzai::Filter::EmojiFilter, lib: true do
include FilterSpecHelper
before do
diff --git a/spec/lib/gitlab/markdown/filter/external_issue_reference_filter_spec.rb b/spec/lib/banzai/filter/external_issue_reference_filter_spec.rb
index d8420102648..953466679e4 100644
--- a/spec/lib/gitlab/markdown/filter/external_issue_reference_filter_spec.rb
+++ b/spec/lib/banzai/filter/external_issue_reference_filter_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe Gitlab::Markdown::ExternalIssueReferenceFilter, lib: true do
+describe Banzai::Filter::ExternalIssueReferenceFilter, lib: true do
include FilterSpecHelper
def helper
diff --git a/spec/lib/gitlab/markdown/filter/external_link_filter_spec.rb b/spec/lib/banzai/filter/external_link_filter_spec.rb
index e559f5741cc..e3a8e15330e 100644
--- a/spec/lib/gitlab/markdown/filter/external_link_filter_spec.rb
+++ b/spec/lib/banzai/filter/external_link_filter_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe Gitlab::Markdown::ExternalLinkFilter, lib: true do
+describe Banzai::Filter::ExternalLinkFilter, lib: true do
include FilterSpecHelper
it 'ignores elements without an href attribute' do
diff --git a/spec/lib/gitlab/markdown/filter/issue_reference_filter_spec.rb b/spec/lib/banzai/filter/issue_reference_filter_spec.rb
index 1aa5d44568e..5a0d3d577a8 100644
--- a/spec/lib/gitlab/markdown/filter/issue_reference_filter_spec.rb
+++ b/spec/lib/banzai/filter/issue_reference_filter_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe Gitlab::Markdown::IssueReferenceFilter, lib: true do
+describe Banzai::Filter::IssueReferenceFilter, lib: true do
include FilterSpecHelper
def helper
diff --git a/spec/lib/gitlab/markdown/filter/label_reference_filter_spec.rb b/spec/lib/banzai/filter/label_reference_filter_spec.rb
index 4fcbb329fe4..b46ccc47605 100644
--- a/spec/lib/gitlab/markdown/filter/label_reference_filter_spec.rb
+++ b/spec/lib/banzai/filter/label_reference_filter_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'
require 'html/pipeline'
-describe Gitlab::Markdown::LabelReferenceFilter, lib: true do
+describe Banzai::Filter::LabelReferenceFilter, lib: true do
include FilterSpecHelper
let(:project) { create(:empty_project, :public) }
diff --git a/spec/lib/gitlab/markdown/filter/merge_request_reference_filter_spec.rb b/spec/lib/banzai/filter/merge_request_reference_filter_spec.rb
index 589550e15c4..352710df307 100644
--- a/spec/lib/gitlab/markdown/filter/merge_request_reference_filter_spec.rb
+++ b/spec/lib/banzai/filter/merge_request_reference_filter_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe Gitlab::Markdown::MergeRequestReferenceFilter, lib: true do
+describe Banzai::Filter::MergeRequestReferenceFilter, lib: true do
include FilterSpecHelper
let(:project) { create(:project, :public) }
diff --git a/spec/lib/gitlab/markdown/filter/redactor_filter_spec.rb b/spec/lib/banzai/filter/redactor_filter_spec.rb
index 9e6ee9f0d61..e9bb388e361 100644
--- a/spec/lib/gitlab/markdown/filter/redactor_filter_spec.rb
+++ b/spec/lib/banzai/filter/redactor_filter_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe Gitlab::Markdown::RedactorFilter, lib: true do
+describe Banzai::Filter::RedactorFilter, lib: true do
include ActionView::Helpers::UrlHelper
include FilterSpecHelper
diff --git a/spec/lib/gitlab/markdown/filter/reference_gatherer_filter_spec.rb b/spec/lib/banzai/filter/reference_gatherer_filter_spec.rb
index abfb5ad5e49..c8b1dfdf944 100644
--- a/spec/lib/gitlab/markdown/filter/reference_gatherer_filter_spec.rb
+++ b/spec/lib/banzai/filter/reference_gatherer_filter_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe Gitlab::Markdown::ReferenceGathererFilter, lib: true do
+describe Banzai::Filter::ReferenceGathererFilter, lib: true do
include ActionView::Helpers::UrlHelper
include FilterSpecHelper
diff --git a/spec/lib/gitlab/markdown/filter/relative_link_filter_spec.rb b/spec/lib/banzai/filter/relative_link_filter_spec.rb
index e0f53e2a533..0b3e5ecbc9f 100644
--- a/spec/lib/gitlab/markdown/filter/relative_link_filter_spec.rb
+++ b/spec/lib/banzai/filter/relative_link_filter_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Gitlab::Markdown::RelativeLinkFilter, lib: true do
+describe Banzai::Filter::RelativeLinkFilter, lib: true do
def filter(doc, contexts = {})
contexts.reverse_merge!({
commit: project.commit,
diff --git a/spec/lib/gitlab/markdown/filter/sanitization_filter_spec.rb b/spec/lib/banzai/filter/sanitization_filter_spec.rb
index a5e5ee0e08a..760d60a4190 100644
--- a/spec/lib/gitlab/markdown/filter/sanitization_filter_spec.rb
+++ b/spec/lib/banzai/filter/sanitization_filter_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe Gitlab::Markdown::SanitizationFilter, lib: true do
+describe Banzai::Filter::SanitizationFilter, lib: true do
include FilterSpecHelper
describe 'default whitelist' do
diff --git a/spec/lib/gitlab/markdown/filter/snippet_reference_filter_spec.rb b/spec/lib/banzai/filter/snippet_reference_filter_spec.rb
index 51526b58597..26466fbb180 100644
--- a/spec/lib/gitlab/markdown/filter/snippet_reference_filter_spec.rb
+++ b/spec/lib/banzai/filter/snippet_reference_filter_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe Gitlab::Markdown::SnippetReferenceFilter, lib: true do
+describe Banzai::Filter::SnippetReferenceFilter, lib: true do
include FilterSpecHelper
let(:project) { create(:empty_project, :public) }
diff --git a/spec/lib/gitlab/markdown/filter/syntax_highlight_filter_spec.rb b/spec/lib/banzai/filter/syntax_highlight_filter_spec.rb
index 8b76048f3e3..407617f3307 100644
--- a/spec/lib/gitlab/markdown/filter/syntax_highlight_filter_spec.rb
+++ b/spec/lib/banzai/filter/syntax_highlight_filter_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe Gitlab::Markdown::SyntaxHighlightFilter, lib: true do
+describe Banzai::Filter::SyntaxHighlightFilter, lib: true do
include FilterSpecHelper
it 'highlights valid code blocks' do
diff --git a/spec/lib/gitlab/markdown/filter/table_of_contents_filter_spec.rb b/spec/lib/banzai/filter/table_of_contents_filter_spec.rb
index c8c79c41847..6a5d003e87f 100644
--- a/spec/lib/gitlab/markdown/filter/table_of_contents_filter_spec.rb
+++ b/spec/lib/banzai/filter/table_of_contents_filter_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Gitlab::Markdown::TableOfContentsFilter, lib: true do
+describe Banzai::Filter::TableOfContentsFilter, lib: true do
include FilterSpecHelper
def header(level, text)
diff --git a/spec/lib/gitlab/markdown/filter/task_list_filter_spec.rb b/spec/lib/banzai/filter/task_list_filter_spec.rb
index 1b1714ef882..f2e3a44478d 100644
--- a/spec/lib/gitlab/markdown/filter/task_list_filter_spec.rb
+++ b/spec/lib/banzai/filter/task_list_filter_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe Gitlab::Markdown::TaskListFilter, lib: true do
+describe Banzai::Filter::TaskListFilter, lib: true do
include FilterSpecHelper
it 'does not apply `task-list` class to non-task lists' do
diff --git a/spec/lib/gitlab/markdown/filter/upload_link_filter_spec.rb b/spec/lib/banzai/filter/upload_link_filter_spec.rb
index 38a007b5bee..3b073a90a95 100644
--- a/spec/lib/gitlab/markdown/filter/upload_link_filter_spec.rb
+++ b/spec/lib/banzai/filter/upload_link_filter_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Gitlab::Markdown::UploadLinkFilter, lib: true do
+describe Banzai::Filter::UploadLinkFilter, lib: true do
def filter(doc, contexts = {})
contexts.reverse_merge!({
project: project
diff --git a/spec/lib/gitlab/markdown/filter/user_reference_filter_spec.rb b/spec/lib/banzai/filter/user_reference_filter_spec.rb
index 277037cf68a..3534bf97784 100644
--- a/spec/lib/gitlab/markdown/filter/user_reference_filter_spec.rb
+++ b/spec/lib/banzai/filter/user_reference_filter_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe Gitlab::Markdown::UserReferenceFilter, lib: true do
+describe Banzai::Filter::UserReferenceFilter, lib: true do
include FilterSpecHelper
let(:project) { create(:empty_project, :public) }
diff --git a/spec/lib/gitlab/asciidoc_spec.rb b/spec/lib/gitlab/asciidoc_spec.rb
index 3a860899e18..6beb21c6d2b 100644
--- a/spec/lib/gitlab/asciidoc_spec.rb
+++ b/spec/lib/gitlab/asciidoc_spec.rb
@@ -50,7 +50,7 @@ module Gitlab
filtered_html = '<b>ASCII</b>'
allow(Asciidoctor).to receive(:convert).and_return(html)
- expect(Gitlab::Markdown).to receive(:render)
+ expect(Banzai).to receive(:render)
.with(html, context.merge(pipeline: :asciidoc))
.and_return(filtered_html)
diff --git a/spec/support/filter_spec_helper.rb b/spec/support/filter_spec_helper.rb
index 91e3bee13c1..d6e03cbef3d 100644
--- a/spec/support/filter_spec_helper.rb
+++ b/spec/support/filter_spec_helper.rb
@@ -1,4 +1,4 @@
-# Helper methods for Gitlab::Markdown filter specs
+# Helper methods for Banzai filter specs
#
# Must be included into specs manually
module FilterSpecHelper
@@ -10,49 +10,49 @@ module FilterSpecHelper
# if none is provided.
#
# html - HTML String to pass to the filter's `call` method.
- # contexts - Hash context for the filter. (default: {project: project})
+ # context - Hash context for the filter. (default: {project: project})
#
# Returns a Nokogiri::XML::DocumentFragment
- def filter(html, contexts = {})
+ def filter(html, context = {})
if defined?(project)
- contexts.reverse_merge!(project: project)
+ context.reverse_merge!(project: project)
end
- described_class.call(html, contexts)
+ described_class.call(html, context)
end
# Run text through HTML::Pipeline with the current filter and return the
# result Hash
#
# body - String text to run through the pipeline
- # contexts - Hash context for the filter. (default: {project: project})
+ # context - Hash context for the filter. (default: {project: project})
#
# Returns the Hash
- def pipeline_result(body, contexts = {})
- contexts.reverse_merge!(project: project) if defined?(project)
+ def pipeline_result(body, context = {})
+ context.reverse_merge!(project: project) if defined?(project)
- pipeline = HTML::Pipeline.new([described_class], contexts)
+ pipeline = HTML::Pipeline.new([described_class], context)
pipeline.call(body)
end
- def reference_pipeline(contexts = {})
- contexts.reverse_merge!(project: project) if defined?(project)
+ def reference_pipeline(context = {})
+ context.reverse_merge!(project: project) if defined?(project)
filters = [
- Gitlab::Markdown::AutolinkFilter,
+ Banzai::Filter::AutolinkFilter,
described_class,
- Gitlab::Markdown::ReferenceGathererFilter
+ Banzai::Filter::ReferenceGathererFilter
]
- HTML::Pipeline.new(filters, contexts)
+ HTML::Pipeline.new(filters, context)
end
- def reference_pipeline_result(body, contexts = {})
- reference_pipeline(contexts).call(body)
+ def reference_pipeline_result(body, context = {})
+ reference_pipeline(context).call(body)
end
- def reference_filter(html, contexts = {})
- reference_pipeline(contexts).to_document(html)
+ def reference_filter(html, context = {})
+ reference_pipeline(context).to_document(html)
end
# Modify a String reference to make it invalid