diff options
author | Douwe Maan <douwe@gitlab.com> | 2015-12-15 15:51:16 +0100 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2015-12-15 15:51:16 +0100 |
commit | 7781bda9bd82997f4a03de4cf911b1156ceb2cde (patch) | |
tree | a632a12b295694232205e2190f784f9bb79235ee /lib/banzai/pipeline | |
parent | 9451db3819ae45734c4343e55a74d347cdacf70d (diff) | |
download | gitlab-ce-7781bda9bd82997f4a03de4cf911b1156ceb2cde.tar.gz |
Move Markdown/reference logic from Gitlab::Markdown to Banzai
Diffstat (limited to 'lib/banzai/pipeline')
-rw-r--r-- | lib/banzai/pipeline/asciidoc_pipeline.rb | 13 | ||||
-rw-r--r-- | lib/banzai/pipeline/atom_pipeline.rb | 14 | ||||
-rw-r--r-- | lib/banzai/pipeline/base_pipeline.rb | 30 | ||||
-rw-r--r-- | lib/banzai/pipeline/combined_pipeline.rb | 27 | ||||
-rw-r--r-- | lib/banzai/pipeline/description_pipeline.rb | 14 | ||||
-rw-r--r-- | lib/banzai/pipeline/email_pipeline.rb | 13 | ||||
-rw-r--r-- | lib/banzai/pipeline/full_pipeline.rb | 9 | ||||
-rw-r--r-- | lib/banzai/pipeline/gfm_pipeline.rb | 41 | ||||
-rw-r--r-- | lib/banzai/pipeline/note_pipeline.rb | 14 | ||||
-rw-r--r-- | lib/banzai/pipeline/plain_markdown_pipeline.rb | 13 | ||||
-rw-r--r-- | lib/banzai/pipeline/post_process_pipeline.rb | 20 | ||||
-rw-r--r-- | lib/banzai/pipeline/reference_extraction_pipeline.rb | 13 | ||||
-rw-r--r-- | lib/banzai/pipeline/single_line_pipeline.rb | 9 |
13 files changed, 230 insertions, 0 deletions
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/banzai/pipeline/combined_pipeline.rb b/lib/banzai/pipeline/combined_pipeline.rb new file mode 100644 index 00000000000..f3bf1809d18 --- /dev/null +++ b/lib/banzai/pipeline/combined_pipeline.rb @@ -0,0 +1,27 @@ +require 'banzai' + +module Banzai + module Pipeline + module CombinedPipeline + def self.new(*pipelines) + Class.new(BasePipeline) do + const_set :PIPELINES, pipelines + + def self.pipelines + self::PIPELINES + end + + def self.filters + pipelines.flat_map(&:filters) + end + + def self.transform_context(context) + pipelines.reduce(context) do |context, pipeline| + pipeline.transform_context(context) + end + end + end + end + end + end +end diff --git a/lib/banzai/pipeline/description_pipeline.rb b/lib/banzai/pipeline/description_pipeline.rb new file mode 100644 index 00000000000..94c2cb165a5 --- /dev/null +++ b/lib/banzai/pipeline/description_pipeline.rb @@ -0,0 +1,14 @@ +require 'banzai' + +module Banzai + module Pipeline + class DescriptionPipeline < FullPipeline + def self.transform_context(context) + super(context).merge( + # SanitizationFilter + inline_sanitization: true + ) + end + end + end +end diff --git a/lib/banzai/pipeline/email_pipeline.rb b/lib/banzai/pipeline/email_pipeline.rb new file mode 100644 index 00000000000..14356145a35 --- /dev/null +++ b/lib/banzai/pipeline/email_pipeline.rb @@ -0,0 +1,13 @@ +require 'banzai' + +module Banzai + module Pipeline + class EmailPipeline < FullPipeline + def self.transform_context(context) + super(context).merge( + only_path: false + ) + end + end + end +end diff --git a/lib/banzai/pipeline/full_pipeline.rb b/lib/banzai/pipeline/full_pipeline.rb new file mode 100644 index 00000000000..72395a5d50e --- /dev/null +++ b/lib/banzai/pipeline/full_pipeline.rb @@ -0,0 +1,9 @@ +require 'banzai' + +module Banzai + module Pipeline + class FullPipeline < CombinedPipeline.new(PlainMarkdownPipeline, GfmPipeline) + + end + end +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/banzai/pipeline/note_pipeline.rb b/lib/banzai/pipeline/note_pipeline.rb new file mode 100644 index 00000000000..89335143852 --- /dev/null +++ b/lib/banzai/pipeline/note_pipeline.rb @@ -0,0 +1,14 @@ +require 'banzai' + +module Banzai + module Pipeline + class NotePipeline < FullPipeline + def self.transform_context(context) + super(context).merge( + # TableOfContentsFilter + no_header_anchors: true + ) + end + end + end +end 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 |