support markdown in upload notes

This commit is contained in:
E. S. 2024-03-15 18:36:31 +00:00
parent ebeb5f096c
commit 6f42528428
2 changed files with 9 additions and 3 deletions

View File

@ -117,7 +117,8 @@ class MyParsedown extends ParsedownExtended {
url: $image_url,
direct_url: $image->getDirectUrl(),
note: $this->lang !== null && $this->lang == PostLanguage::Russian ? $image->noteRu : $image->noteEn
note: markup::markdownToHtml($this->lang !== null && $this->lang == PostLanguage::Russian ? $image->noteRu : $image->noteEn,
no_paragraph: true)
);
return $result;

View File

@ -7,9 +7,14 @@ class markup {
public static function markdownToHtml(string $md,
bool $use_image_previews = true,
?PostLanguage $lang = null): string {
?PostLanguage $lang = null,
bool $no_paragraph = false): string {
$pd = new MyParsedown(useImagePreviews: $use_image_previews, lang: $lang);
return $pd->text($md);
$html = $pd->text($md);
if ($no_paragraph) {
$html = preg_replace('/<p>(.*?)<\/p>/', '$1', $html);
}
return $html;
}
public static function toc(string $md): string {