bep40 commited on
Commit
0b2c8ee
·
verified ·
1 Parent(s): f27c7e3

fix(html): remove malformed <a href= src=> tags from AI text

Browse files
Files changed (1) hide show
  1. ai_patch.py +4 -2
ai_patch.py CHANGED
@@ -66,11 +66,13 @@ def _postprocess_ai_text(text, max_units=20):
66
  text = _clean(text)
67
  if not text:
68
  return text
69
- # Remove any remaining HTML artifacts like <a href='...'>, <img src=...> even if partially corrupted
 
 
70
  text = re.sub(r'<a\s+[^>]*>', '', text, flags=re.I)
71
  text = re.sub(r'<img\s+[^>]*>', '', text, flags=re.I)
72
- text = re.sub(r'</a>', '', text, flags=re.I)
73
  text = re.sub(r'<[^>]+>', '', text) # Any remaining HTML tags
 
74
  drop_prefixes = (
75
  "dưới đây", "sau đây", "bài viết", "tôi sẽ", "mình sẽ",
76
  "tóm tắt bài", "tiêu đề:", "sapo:", "nội dung:", "kết luận:"
 
66
  text = _clean(text)
67
  if not text:
68
  return text
69
+ # Remove malformed HTML with both href and src attributes (e.g., <a href="..." src="...">)
70
+ text = re.sub(r'<a[^>]*href\s*=\s*"[^"]*"[^>]*\s*src\s*=\s*"[^"]*"[^>]*>', '', text, flags=re.I)
71
+ # Remove any remaining HTML artifacts like <a href='...'>, <img src=...>, <a ...>
72
  text = re.sub(r'<a\s+[^>]*>', '', text, flags=re.I)
73
  text = re.sub(r'<img\s+[^>]*>', '', text, flags=re.I)
 
74
  text = re.sub(r'<[^>]+>', '', text) # Any remaining HTML tags
75
+ text = re.sub(r'</a>', '', text, flags=re.I)
76
  drop_prefixes = (
77
  "dưới đây", "sau đây", "bài viết", "tôi sẽ", "mình sẽ",
78
  "tóm tắt bài", "tiêu đề:", "sapo:", "nội dung:", "kết luận:"