Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

feat(pdf-export): refactor markdown field export

as-op8dd5d27ccde5
diff --git a/app/models/work_package/pdf_export/markdown.rb b/app/models/work_package/pdf_export/markdown.rb
index 086fbb84df5..6e94a97a1fd 100644
--- a/app/models/work_package/pdf_export/markdown.rb
+++ b/app/models/work_package/pdf_export/markdown.rb
@@ -28,23 +28,16 @@
module WorkPackage::PDFExport::Markdown
- def write_markdown!(work_package, markdown, label)
- return if markdown.blank?
-
- # TODO: move page break threshold const to style settings and implement conditional break with height measuring
- write_optional_page_break(100)
- write_label! label
+ def write_markdown!(work_package, markdown)
write_content! work_package, markdown
end
- def write_label!(label)
- with_margin(label_margins_style) do
- pdf.formatted_text([label_style.merge({ text: label })])
- end
- end
+ private
def write_content!(work_package, markdown)
configure_markup work_package
+ #CommonMarker.render_doc(content, CM_PARSE_OPTIONS, CM_EXTENSIONS)
+
markup = format_text(markdown, object: work_package, format: :html)
.gsub('class="op-uc-image"', 'style="width:100"') # TODO: this is a workaround image formatting
pdf.markup markup
@@ -87,15 +80,6 @@ module WorkPackage::PDFExport::Markdown
heading6: markup_h6_style }
end
- def label_margins_style
- { margin_top: 8, margin_bottom: 4 }
- end
-
- def label_style
- { size: 11, styles: [:bold] }
- end
-
-
def markup_h1_style
{ size: 10, styles: [:bold] }
end
diff --git a/app/models/work_package/pdf_export/markdown_field.rb b/app/models/work_package/pdf_export/markdown_field.rb
new file mode 100644
index 00000000000..42ac7421690
--- /dev/null
+++ b/app/models/work_package/pdf_export/markdown_field.rb
@@ -0,0 +1,57 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2023 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+module WorkPackage::PDFExport::MarkdownField
+ include WorkPackage::PDFExport::Markdown
+
+ def write_markdown_field!(work_package, markdown, label)
+ return if markdown.blank?
+
+ # TODO: move page break threshold const to style settings and implement conditional break with height measuring
+ write_optional_page_break(100)
+ write_label! label
+ write_markdown! work_package, markdown
+ end
+
+ private
+
+ def write_label!(label)
+ with_margin(label_margins_style) do
+ pdf.formatted_text([label_style.merge({ text: label })])
+ end
+ end
+
+ def label_margins_style
+ { margin_top: 8, margin_bottom: 4 }
+ end
+
+ def label_style
+ { size: 11, styles: [:bold] }
+ end
+
+end
diff --git a/app/models/work_package/pdf_export/work_package_detail.rb b/app/models/work_package/pdf_export/work_package_detail.rb
index a2da0516c9a..e2d9bb2ad5c 100644
--- a/app/models/work_package/pdf_export/work_package_detail.rb
+++ b/app/models/work_package/pdf_export/work_package_detail.rb
@@ -27,7 +27,7 @@
#++
module WorkPackage::PDFExport::WorkPackageDetail
- include WorkPackage::PDFExport::Markdown
+ include WorkPackage::PDFExport::MarkdownField
def write_work_packages_details!(work_packages, id_wp_meta_map)
work_packages.each do |work_package|
@@ -110,14 +110,14 @@ module WorkPackage::PDFExport::WorkPackageDetail
end
def write_description!(work_package)
- write_markdown!(work_package, work_package.description, WorkPackage.human_attribute_name(:description))
+ write_markdown_field!(work_package, work_package.description, WorkPackage.human_attribute_name(:description))
end
def write_custom_fields!(work_package)
work_package.custom_field_values
.select { |cv| cv.custom_field.formattable? }
.each do |custom_value|
- write_markdown!(work_package, custom_value.value, custom_value.custom_field.name)
+ write_markdown_field!(work_package, custom_value.value, custom_value.custom_field.name)
end
end