summaryrefslogtreecommitdiff
path: root/lib/banzai/filter/jira_import/adf_to_commonmark_filter.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/banzai/filter/jira_import/adf_to_commonmark_filter.rb')
-rw-r--r--lib/banzai/filter/jira_import/adf_to_commonmark_filter.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/banzai/filter/jira_import/adf_to_commonmark_filter.rb b/lib/banzai/filter/jira_import/adf_to_commonmark_filter.rb
new file mode 100644
index 00000000000..3db2244d641
--- /dev/null
+++ b/lib/banzai/filter/jira_import/adf_to_commonmark_filter.rb
@@ -0,0 +1,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