From d701125bf124470d5b3047f70892f1c9757818cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Mon, 31 May 2021 14:08:24 +0200 Subject: [PATCH] Markdown parsing for line items --- app/Services/PdfMaker/Design.php | 2 ++ .../PdfMaker/Designs/Utilities/DesignHelpers.php | 14 ++++++++++++++ app/Services/PdfMaker/PdfMakerUtilities.php | 5 ++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/Services/PdfMaker/Design.php b/app/Services/PdfMaker/Design.php index f24aebd1d148..e5ac416f8897 100644 --- a/app/Services/PdfMaker/Design.php +++ b/app/Services/PdfMaker/Design.php @@ -346,6 +346,8 @@ class Design extends BaseDesign $items = $this->transformLineItems($this->entity->line_items, $type); + $this->processMarkdownOnLineItems($items); + if (count($items) == 0) { return []; } diff --git a/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php b/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php index b1f70f44f32f..40da9a3e7225 100644 --- a/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php +++ b/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php @@ -330,4 +330,18 @@ document.addEventListener('DOMContentLoaded', function() { return $converter->convertToHtml($markdown); } + + public function processMarkdownOnLineItems(array &$items) + { + // Use setting to determinate if parsing should be done. + // 'parse_markdown_on_pdfs' + + foreach ($items as $key => $item) { + foreach ($item as $variable => $value) { + $item[$variable] = DesignHelpers::parseMarkdownToHtml($value ?? ''); + } + + $items[$key] = $item; + } + } } diff --git a/app/Services/PdfMaker/PdfMakerUtilities.php b/app/Services/PdfMaker/PdfMakerUtilities.php index df84bddaab17..bc7df97a6136 100644 --- a/app/Services/PdfMaker/PdfMakerUtilities.php +++ b/app/Services/PdfMaker/PdfMakerUtilities.php @@ -92,7 +92,10 @@ trait PdfMakerUtilities $contains_html = false; if (isset($child['content'])) { - $child['content'] = nl2br($child['content']); + // Commented cause it keeps adding
at the end, if markdown parsing is turned on. + // Should update with 'parse_markdown_on_pdfs' setting. + + // $child['content'] = nl2br($child['content']); } // "/\/[a-z]*>/i" -> checks for HTML-like tags: