Skip to content

Commit

Permalink
Merge pull request #132 from NekoAria/2.0
Browse files Browse the repository at this point in the history
修正标签处理中 `bbcode` 的处理逻辑,补上对 `url` 标签的处理;修正 `<a> 标签处理` 的逻辑
  • Loading branch information
Quan authored Jun 5, 2021
2 parents dd5207f + 6c28c88 commit 5f9e360
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/plugins/ELF_RSS2/RSS/rss_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from io import BytesIO
from pathlib import Path
from typing import Dict, Any
from html import unescape as html_unescape

import emoji
import feedparser
Expand Down Expand Up @@ -659,13 +660,22 @@ async def handle_html_tag(html) -> str:
rss_str = re.sub(
r"(\[url=.+?])?\[img].+?\[/img](\[/url])?", "", rss_str, flags=re.I
)
rss_str = re.sub(r"\[align=.+?]|\[/align]", "", rss_str, flags=re.I)
rss_str = re.sub(r"\[backcolor=.+?]|\[/backcolor]", "", rss_str, flags=re.I)
rss_str = re.sub(r"\[color=.+?]|\[/color]", "", rss_str, flags=re.I)
rss_str = re.sub(r"\[font=.+?]|\[/font]", "", rss_str, flags=re.I)
rss_str = re.sub(r"\[size=.+?]|\[/size]", "", rss_str, flags=re.I)
rss_str = re.sub(r"\[table=.+?]|\[/table]", "", rss_str, flags=re.I)
rss_str = re.sub(r"\[/?(b|u|tr|td)]", "", rss_str, flags=re.I)
bbcode_tags = [
"align",
"backcolor",
"color",
"font",
"size",
"table",
"url",
"b",
"u",
"tr",
"td",
]
for i in bbcode_tags:
rss_str = re.sub(rf"\[{i}=.+?]", "", rss_str, flags=re.I)
rss_str = re.sub(rf"\[/?{i}]", "", rss_str, flags=re.I)

# 去掉结尾被截断的信息
rss_str = re.sub(
Expand Down Expand Up @@ -699,8 +709,8 @@ async def handle_html_tag(html) -> str:

# <a> 标签处理
for a in new_html("a").items():
a_str = re.search(r"<a.+?</a>", str(a))[0]
if str(a.text()) != a.attr("href"):
a_str = re.search(r"<a.+?</a>", html_unescape(str(a)))[0]
if a.text() and str(a.text()) != a.attr("href"):
rss_str = rss_str.replace(a_str, f" {a.text()}: {a.attr('href')}\n")
else:
rss_str = rss_str.replace(a_str, f" {a.attr('href')}\n")
Expand Down

0 comments on commit 5f9e360

Please sign in to comment.