diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
commit | a09983ae35713f5a2bbb100981116d31ce99826e (patch) | |
tree | 2ee2af7bd104d57086db360a7e6d8c9d5d43667a /lib/banzai/filter/jira_import/adf_to_commonmark_filter.rb | |
parent | 18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff) |
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
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.rb | 24 |
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 |