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

3 4 5
module Banzai
  module Pipeline
    class GfmPipeline < BasePipeline
6 7 8 9 10
      # These filters transform GitLab Flavored Markdown (GFM) to HTML.
      # The nodes and marks referenced in app/assets/javascripts/behaviors/markdown/editor_extensions.js
      # consequently transform that same HTML to GFM to be copied to the clipboard.
      # Every filter that generates HTML from GFM should have a node or mark in
      # app/assets/javascripts/behaviors/markdown/editor_extensions.js.
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 16 17 18

          # Must always be before the SanitizationFilter to prevent XSS attacks
          Filter::SpacedLinkFilter,

19
          Filter::SanitizationFilter,
20
          Filter::SyntaxHighlightFilter,
21

22
          Filter::MathFilter,
23
          Filter::ColorFilter,
blackst0ne's avatar
blackst0ne committed
24
          Filter::MermaidFilter,
25
          Filter::VideoLinkFilter,
26
          Filter::ImageLazyLoadFilter,
27
          Filter::ImageLinkFilter,
28 29 30 31
          Filter::EmojiFilter,
          Filter::TableOfContentsFilter,
          Filter::AutolinkFilter,
          Filter::ExternalLinkFilter,
32
          Filter::SuggestionFilter,
33
          Filter::FootnoteFilter,
34

35 36 37 38 39 40 41 42 43 44 45
          *reference_filters,

          Filter::TaskListFilter,
          Filter::InlineDiffFilter,

          Filter::SetDirectionFilter
        ]
      end

      def self.reference_filters
        [
46
          Filter::UserReferenceFilter,
47
          Filter::ProjectReferenceFilter,
48 49 50 51 52 53 54
          Filter::IssueReferenceFilter,
          Filter::ExternalIssueReferenceFilter,
          Filter::MergeRequestReferenceFilter,
          Filter::SnippetReferenceFilter,
          Filter::CommitRangeReferenceFilter,
          Filter::CommitReferenceFilter,
          Filter::LabelReferenceFilter,
55
          Filter::MilestoneReferenceFilter
56 57 58 59
        ]
      end

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

62
        context
63 64 65 66
      end
    end
  end
end