Browse Source

过滤空的<p>

visuddhinanda 2 weeks ago
parent
commit
aafe5c0cc2
1 changed files with 4 additions and 0 deletions
  1. 4 0
      api-v13/app/Tools/Markdown.php

+ 4 - 0
api-v13/app/Tools/Markdown.php

@@ -31,6 +31,10 @@ class Markdown
      */
     public static function replaceSinglePWithSpan(string $html): string
     {
+        // 先过滤掉只含空白/全角空格的 <p>
+        $html = preg_replace('/<p\b[^>]*>[\s ]*<\/p>/u', '', $html);
+        $html = trim($html);
+
         preg_match_all('/<p\b[^>]*>.*?<\/p>/is', $html, $matches);
 
         if (count($matches[0]) === 1) {