Enable markdown processing on line items

This commit is contained in:
Benjamin Beganović 2021-07-29 11:35:07 +02:00
parent 0904222eef
commit 5b8d685a52
3 changed files with 5 additions and 20 deletions

View File

@ -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 [];

View File

@ -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 ?? '');

View File

@ -91,31 +91,19 @@ trait PdfMakerUtilities
foreach ($children as $child) {
$contains_html = false;
if (isset($child['content'])) {
// Commented cause it keeps adding <br> 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:
// <my-tag></my-tag> => true
// <my-tag /> => true
// <my-tag> => 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');