Skip to content

Commit

Permalink
fix(article): 修复专栏引用语句无法纳入 markdown 的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Nemo2011 committed Jul 6, 2022
1 parent 3d09e9c commit a6580da
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions bilibili_api/article.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ def parse(el: BeautifulSoup):

elif e.name == "span":
# 各种样式

if "style" in e.attrs:
style = e.attrs["style"]

Expand Down Expand Up @@ -208,12 +207,20 @@ def parse(el: BeautifulSoup):
node.color = ARTICLE_COLOR_MAP[color_text]

node.children = parse(e)
else:
if e.text != "":
#print(e.text.replace("\n", ""))
#print()
node = TextNode(e.text)
# print("Add a text node: ", e.text)
node_list.append(node)
node.children = parse(e)

elif e.name == "blockquote":
# 引用块
# print(e.text)
node = BlockquoteNode()
node_list.append(node)

node.children = parse(e)

elif e.name == "figure":
Expand Down Expand Up @@ -376,17 +383,17 @@ async def get_all(self):
API 调用返回结果。
"""
sess = get_session()
async with sess.get(f"https://www.bilibili.com/read/cv{self.cvid}") as resp:
html = await resp.text()
resp = await sess.get(f"https://www.bilibili.com/read/cv{self.cvid}")
html = resp.text

match = re.search("window\.__INITIAL_STATE__=(\{.+?\});", html, re.I)
match = re.search("window\.__INITIAL_STATE__=(\{.+?\});", html, re.I)

if not match:
raise ApiException("找不到信息")
if not match:
raise ApiException("找不到信息")

data = json.loads(match[1])
data = json.loads(match[1])

return data
return data

async def set_like(self, status: bool = True):
"""
Expand Down Expand Up @@ -481,9 +488,8 @@ def __init__(self):

def markdown(self):
t = "".join([node.markdown() for node in self.children])

# 填补空白行的 > 并加上标识符
t = "\n".join(["> " + line for line in t.split("\n")])
t = "\n".join(["> " + line for line in t.split("\n")]) + "\n\n"

return t

Expand Down

0 comments on commit a6580da

Please sign in to comment.