Merge pull request #6360 from beganovich/v5-601-commonmark

(v5) Markdown support on line items
This commit is contained in:
Benjamin Beganović 2021-07-29 12:56:25 +02:00 committed by GitHub
commit d1ad3bcb26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 87 additions and 23 deletions

View File

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

View File

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

View File

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

View File

@ -20,7 +20,7 @@
p { p {
margin: 0; margin: 0;
padding: 0; padding: 0;
page-break-after: always; /* page-break-after: always; */
} }
.header-wrapper { .header-wrapper {
@ -242,6 +242,14 @@
display: none display: none
} }
} }
/** Markdown-specific styles. **/
#product-table h3,
#task-table h3,
#delivery-note-table h3 {
font-size: 1rem;
margin-bottom: 0;
}
</style> </style>
<table> <table>

View File

@ -235,6 +235,14 @@
#footer { #footer {
margin-top: 30px; margin-top: 30px;
} }
/** Markdown-specific styles. **/
#product-table h3,
#task-table h3,
#delivery-note-table h3 {
font-size: 1rem;
margin-bottom: 0;
}
</style> </style>
<div id="header"></div> <div id="header"></div>

View File

@ -193,6 +193,14 @@
#footer { #footer {
margin-top: 30px; margin-top: 30px;
} }
/** Markdown-specific styles. **/
#product-table h3,
#task-table h3,
#delivery-note-table h3 {
font-size: 1rem;
margin-bottom: 0;
}
</style> </style>
<div id="header"></div> <div id="header"></div>

View File

@ -195,6 +195,14 @@
#footer { #footer {
margin-top: 30px; margin-top: 30px;
} }
/** Markdown-specific styles. **/
#product-table h3,
#task-table h3,
#delivery-note-table h3 {
font-size: 1rem;
margin-bottom: 0;
}
</style> </style>
<div id="header"></div> <div id="header"></div>

View File

@ -193,6 +193,14 @@
#footer { #footer {
margin-top: 30px; margin-top: 30px;
} }
/** Markdown-specific styles. **/
#product-table h3,
#task-table h3,
#delivery-note-table h3 {
font-size: 1rem;
margin-bottom: 0;
}
</style> </style>
<div id="header"></div> <div id="header"></div>

View File

@ -204,6 +204,14 @@
#footer { #footer {
margin-top: 30px; margin-top: 30px;
} }
/** Markdown-specific styles. **/
#product-table h3,
#task-table h3,
#delivery-note-table h3 {
font-size: 1rem;
margin-bottom: 0;
}
</style> </style>
<div id="header"></div> <div id="header"></div>

View File

@ -22,7 +22,7 @@
p { p {
margin: 0; margin: 0;
padding: 0; padding: 0;
page-break-after: always; /* page-break-after: always; */
} }
.header-container { .header-container {
@ -261,6 +261,14 @@
display: none display: none
} }
} }
/** Markdown-specific styles. **/
#product-table h3,
#task-table h3,
#delivery-note-table h3 {
font-size: 1rem;
margin-bottom: 0;
}
</style> </style>
<table> <table>

View File

@ -171,6 +171,14 @@
[data-ref="totals_table-outstanding"] { [data-ref="totals_table-outstanding"] {
color: var(--primary-color) color: var(--primary-color)
} }
/** Markdown-specific styles. **/
#product-table h3,
#task-table h3,
#delivery-note-table h3 {
font-size: 1rem;
margin-bottom: 0;
}
</style> </style>
<div id="header"></div> <div id="header"></div>

View File

@ -240,8 +240,15 @@
#footer { #footer {
margin-top: 1rem; margin-top: 1rem;
} }
</style>
/** Markdown-specific styles. **/
#product-table h3,
#task-table h3,
#delivery-note-table h3 {
font-size: 1rem;
margin-bottom: 0;
}
</style>
<div id="header"> <div id="header">
<div style="background-color: #00968B"><!-- 1 --></div> <div style="background-color: #00968B"><!-- 1 --></div>

View File

@ -226,6 +226,14 @@
#footer { #footer {
margin-top: 30px; margin-top: 30px;
} }
/** Markdown-specific styles. **/
#product-table h3,
#task-table h3,
#delivery-note-table h3 {
font-size: 1rem;
margin-bottom: 0;
}
</style> </style>
<div id="header"></div> <div id="header"></div>