mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Enable markdown processing on line items
This commit is contained in:
parent
0904222eef
commit
5b8d685a52
@ -347,7 +347,7 @@ class Design extends BaseDesign
|
|||||||
|
|
||||||
$items = $this->transformLineItems($this->entity->line_items, $type);
|
$items = $this->transformLineItems($this->entity->line_items, $type);
|
||||||
|
|
||||||
// $this->processMarkdownOnLineItems($items);
|
$this->processMarkdownOnLineItems($items);
|
||||||
|
|
||||||
if (count($items) == 0) {
|
if (count($items) == 0) {
|
||||||
return [];
|
return [];
|
||||||
|
@ -333,9 +333,6 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
|
|
||||||
public function processMarkdownOnLineItems(array &$items)
|
public function processMarkdownOnLineItems(array &$items)
|
||||||
{
|
{
|
||||||
// Use setting to determinate if parsing should be done.
|
|
||||||
// 'parse_markdown_on_pdfs'
|
|
||||||
|
|
||||||
foreach ($items as $key => $item) {
|
foreach ($items as $key => $item) {
|
||||||
foreach ($item as $variable => $value) {
|
foreach ($item as $variable => $value) {
|
||||||
$item[$variable] = DesignHelpers::parseMarkdownToHtml($value ?? '');
|
$item[$variable] = DesignHelpers::parseMarkdownToHtml($value ?? '');
|
||||||
|
@ -91,31 +91,19 @@ trait PdfMakerUtilities
|
|||||||
foreach ($children as $child) {
|
foreach ($children as $child) {
|
||||||
$contains_html = false;
|
$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['content'])) {
|
||||||
if (isset($child['is_empty']) && $child['is_empty'] === true) {
|
if (isset($child['is_empty']) && $child['is_empty'] === true) {
|
||||||
continue;
|
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 ($contains_html) {
|
||||||
// If the element contains the HTML, we gonna display it as is. DOMDocument, is going to
|
// 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 backend due processing stage.
|
// 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.
|
// 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 = $this->document->createElement($child['element'], '');
|
||||||
$_child->setAttribute('data-state', 'encoded-html');
|
$_child->setAttribute('data-state', 'encoded-html');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user