diff --git a/app/Services/PdfMaker/Design.php b/app/Services/PdfMaker/Design.php index 7d41c6aeb12e..7ca40090c583 100644 --- a/app/Services/PdfMaker/Design.php +++ b/app/Services/PdfMaker/Design.php @@ -347,7 +347,7 @@ class Design extends BaseDesign $items = $this->transformLineItems($this->entity->line_items, $type); - // $this->processMarkdownOnLineItems($items); + $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 feeba76772ff..1869849f29f7 100644 --- a/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php +++ b/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php @@ -333,9 +333,6 @@ document.addEventListener('DOMContentLoaded', function() { 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 ?? ''); diff --git a/app/Services/PdfMaker/PdfMakerUtilities.php b/app/Services/PdfMaker/PdfMakerUtilities.php index ae18d5fb3eb3..8ce5622896cf 100644 --- a/app/Services/PdfMaker/PdfMakerUtilities.php +++ b/app/Services/PdfMaker/PdfMakerUtilities.php @@ -91,31 +91,19 @@ trait PdfMakerUtilities foreach ($children as $child) { $contains_html = false; - if (isset($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: - // => true - // => true - // => false - if (isset($child['content'])) { if (isset($child['is_empty']) && $child['is_empty'] === true) { continue; } - $contains_html = preg_match("/\/[a-z]*>/i", $child['content'], $m) != 0; + $contains_html = preg_match('#(?<=<)\w+(?=[^<]*?>)#', $child['content'], $m) != 0; } if ($contains_html) { - // If the element contains the HTML, we gonna display it as is. DOMDocument, is going to - // encode it for us, preventing any errors on the backend due processing stage. + // If the element contains the HTML, we gonna display it as is. Backend is going to + // encode it for us, preventing any errors on the processing stage. // Later, we decode this using Javascript so it looks like it's normal HTML being injected. - // To get all elements that need frontend decoding, we use 'data-ref' property. + // To get all elements that need frontend decoding, we use 'data-state' property. $_child = $this->document->createElement($child['element'], ''); $_child->setAttribute('data-state', 'encoded-html');