diff --git a/htdocs/core/lib/parsemd.lib.php b/htdocs/core/lib/parsemd.lib.php
index 89e0936611f..284ea81e6d3 100644
--- a/htdocs/core/lib/parsemd.lib.php
+++ b/htdocs/core/lib/parsemd.lib.php
@@ -31,6 +31,14 @@
*/
function dolMd2Html($content, $parser = 'parsedown', $replaceimagepath = null)
{
+ // Replace a HTML string with a Markdown syntax
+ $content = preg_replace('/([^<]+)<\/a>/', '[\2](\1)', $content);
+ //$content = preg_replace('/([^<]+)<\/a>/', '[\3](\1){:target="\2"}', $content);
+ $content = preg_replace('/([^<]+)<\/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;
diff --git a/htdocs/core/modules/DolibarrModules.class.php b/htdocs/core/modules/DolibarrModules.class.php
index e98b00b658b..6f9136798ed 100644
--- a/htdocs/core/modules/DolibarrModules.class.php
+++ b/htdocs/core/modules/DolibarrModules.class.php
@@ -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>/', '[\2](\1)', $content);
- //$content = preg_replace('/([^<]+)<\/a>/', '[\3](\1){:target="\2"}', $content);
- $content = preg_replace('/([^<]+)<\/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);