@Arkshine 向我提供了这个解决方案,它会在图片前添加一个空行:
add_filter('wp_discourse_excerpt', [$this, 'wp_discourse_excerpt'], 10, 1);
/**
* 在任何 <img> 标签上方添加空行。
* 目的是避免 Discourse 无法显示下载的图片的 Markdown。
*
* @param $post_content
*
* @return string
*/
public function wp_discourse_excerpt($post_content)
{
$post_content = preg_replace('/(<img\s)/i', "\n\n$1", $post_content);
$post_content = preg_replace('/[\n]{3,}/', "\n\n", $post_content);
return $post_content;
}