Fix dolMd2Html

This commit is contained in:
Laurent Destailleur
2023-04-30 15:13:04 +02:00
parent d40fe56cb4
commit a1b41a22db
2 changed files with 9 additions and 5 deletions

View File

@@ -31,6 +31,14 @@
*/
function dolMd2Html($content, $parser = 'parsedown', $replaceimagepath = null)
{
// Replace a HTML string with a Markdown syntax
$content = preg_replace('/<a href="([^"]+)">([^<]+)<\/a>/', '[\2](\1)', $content);
//$content = preg_replace('/<a href="([^"]+)" target="([^"]+)">([^<]+)<\/a>/', '[\3](\1){:target="\2"}', $content);
$content = preg_replace('/<a href="([^"]+)" target="([^"]+)">([^<]+)<\/a>/', '[\3](\1)', $content);
// Replace HTML coments
$content = preg_replace('/<!--.*-->/ms', '', $content); // We remove HTML comment that are not MD comment because they will be escaped and output when setSafeMode is set to true.
if (is_array($replaceimagepath)) {
foreach ($replaceimagepath as $key => $val) {
$keytoreplace = ']('.$key;

View File

@@ -683,11 +683,6 @@ class DolibarrModules // Can not be abstract, because we need to instantiate it
if ((float) DOL_VERSION >= 6.0) {
@include_once DOL_DOCUMENT_ROOT.'/core/lib/parsemd.lib.php';
// Replace a HTML string with a Markdown syntax
$content = preg_replace('/<a href="([^"]+)">([^<]+)<\/a>/', '[\2](\1)', $content);
//$content = preg_replace('/<a href="([^"]+)" target="([^"]+)">([^<]+)<\/a>/', '[\3](\1){:target="\2"}', $content);
$content = preg_replace('/<a href="([^"]+)" target="([^"]+)">([^<]+)<\/a>/', '[\3](\1)', $content);
$content = dolMd2Html(
$content,
'parsedown',
@@ -788,6 +783,7 @@ class DolibarrModules // Can not be abstract, because we need to instantiate it
if ((float) DOL_VERSION >= 6.0) {
@include_once DOL_DOCUMENT_ROOT.'/core/lib/parsemd.lib.php';
$content = dolMd2Html($content, 'parsedown', array('doc/'=>dol_buildpath(strtolower($this->name).'/doc/', 1)));
} else {
$content = nl2br($content);