gfm_pipeline.rb 1.9 KB
Newer Older
1 2
# frozen_string_literal: true

3 4 5
module Banzai
  module Pipeline
    class GfmPipeline < BasePipeline
Douwe Maan's avatar
Douwe Maan committed
6
      # These filters convert GitLab Flavored Markdown (GFM) to HTML.
7
      # The handlers defined in app/assets/javascripts/behaviors/markdown/copy_as_gfm.js
8 9
      # consequently convert that same HTML to GFM to be copied to the clipboard.
      # Every filter that generates HTML from GFM should have a handler in
10
      # app/assets/javascripts/behaviors/markdown/copy_as_gfm.js, in reverse order.
Douwe Maan's avatar
Douwe Maan committed
11
      # The GFM-to-HTML-to-GFM cycle is tested in spec/features/copy_as_gfm_spec.rb.
12
      def self.filters
13
        @filters ||= FilterArray[
14
          Filter::PlantumlFilter,
15
          Filter::SanitizationFilter,
16
          Filter::SyntaxHighlightFilter,
17

18
          Filter::MathFilter,
19
          Filter::ColorFilter,
blackst0ne's avatar
blackst0ne committed
20
          Filter::MermaidFilter,
21
          Filter::SpacedLinkFilter,
22
          Filter::VideoLinkFilter,
23
          Filter::ImageLazyLoadFilter,
24
          Filter::ImageLinkFilter,
25 26 27 28 29
          Filter::EmojiFilter,
          Filter::TableOfContentsFilter,
          Filter::AutolinkFilter,
          Filter::ExternalLinkFilter,

30 31 32 33 34 35 36 37 38 39 40
          *reference_filters,

          Filter::TaskListFilter,
          Filter::InlineDiffFilter,

          Filter::SetDirectionFilter
        ]
      end

      def self.reference_filters
        [
41
          Filter::UserReferenceFilter,
42
          Filter::ProjectReferenceFilter,
43 44 45 46 47 48 49
          Filter::IssueReferenceFilter,
          Filter::ExternalIssueReferenceFilter,
          Filter::MergeRequestReferenceFilter,
          Filter::SnippetReferenceFilter,
          Filter::CommitRangeReferenceFilter,
          Filter::CommitReferenceFilter,
          Filter::LabelReferenceFilter,
50
          Filter::MilestoneReferenceFilter
51 52 53 54
        ]
      end

      def self.transform_context(context)
55
        context[:only_path] = true unless context.key?(:only_path)
56

57
        context
58 59 60 61
      end
    end
  end
end