Welcome to mirror list, hosted at ThFree Co, Russian Federation.

adf_to_commonmark_filter.rb « jira_import « filter « banzai « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3db2244d6419125a07342a0de2526d4027f2cc91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# frozen_string_literal: true

module Banzai
  module Filter
    module JiraImport
      # Uses Kramdown to convert from the Atlassian Document Format (json)
      # into CommonMark
      # @see https://developer.atlassian.com/cloud/jira/platform/apis/document/structure/
      class AdfToCommonmarkFilter < HTML::Pipeline::TextFilter
        def initialize(text, context = nil, result = nil)
          super(text, context, result)
        end

        def call
          Kramdown::Document.new(@text, input: 'AtlassianDocumentFormat', html_tables: true).to_commonmark
        rescue ::Kramdown::Error => e
          # If we get an error, then just return the original text so at
          # least the user knows something went wrong
          "#{e.message}\n\n#{@text}"
        end
      end
    end
  end
end