gfm_pipeline.rb 1.87 KB
Newer Older
1
2
3
module Banzai
  module Pipeline
    class GfmPipeline < BasePipeline
Douwe Maan's avatar
Douwe Maan committed
4
      # These filters convert GitLab Flavored Markdown (GFM) to HTML.
5
      # The handlers defined in app/assets/javascripts/behaviors/markdown/copy_as_gfm.js
6
7
      # 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
8
      # app/assets/javascripts/behaviors/markdown/copy_as_gfm.js, in reverse order.
Douwe Maan's avatar
Douwe Maan committed
9
      # The GFM-to-HTML-to-GFM cycle is tested in spec/features/copy_as_gfm_spec.rb.
10
      def self.filters
11
        @filters ||= FilterArray[
Horacio Sanson's avatar
Horacio Sanson committed
12
          Filter::PlantumlFilter,
13
          Filter::SanitizationFilter,
14
          Filter::SyntaxHighlightFilter,
15

16
          Filter::MathFilter,
17
          Filter::ColorFilter,
18
          Filter::MermaidFilter,
19
          Filter::SpacedLinkFilter,
20
          Filter::VideoLinkFilter,
21
          Filter::ImageLazyLoadFilter,
22
          Filter::ImageLinkFilter,
23
24
25
26
27
          Filter::EmojiFilter,
          Filter::TableOfContentsFilter,
          Filter::AutolinkFilter,
          Filter::ExternalLinkFilter,

28
29
30
31
32
33
34
35
36
37
38
          *reference_filters,

          Filter::TaskListFilter,
          Filter::InlineDiffFilter,

          Filter::SetDirectionFilter
        ]
      end

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

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

55
        context
56
57
58
59
      end
    end
  end
end