Преглед изворни кода

Merge branch 'feature/snapshot' into test

qinchaoyue пре 1 месец
родитељ
комит
9b808fab3d

+ 2 - 1
src/Hotline.Share/Dtos/Article/BulletinDto.cs

@@ -560,10 +560,11 @@ namespace Hotline.Share.Dtos.Article
         /// </summary>
         public string Title { get; set; }
 
+        private string content;
         /// <summary>
         /// 内容
         /// </summary>
-        public string Content { get; set; }
+        public string Content { get { return content.RemoveHtmlTags(); } set { content = value; } }
 
         public DateTime CreationTime { get; set; }
     }

+ 13 - 0
src/Hotline.Share/Tools/StringExtensions.cs

@@ -109,4 +109,17 @@ public static class StringExtensions
         }
         return string.Empty;
     }
+
+    /// <summary>
+    /// 移除字符串中的所有 HTML 标签
+    /// </summary>
+    /// <param name="input">包含 HTML 的字符串</param>
+    /// <returns>去除 HTML 标签后的字符串</returns>
+    public static string RemoveHtmlTags(this string input)
+    {
+        if (string.IsNullOrWhiteSpace(input))
+            return string.Empty;
+
+        return Regex.Replace(input, "<.*?>", string.Empty);
+    }
 }