Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion astrbot/core/knowledge_base/parsers/epub_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
r"^(?:\d{1,3}|[ivxlcdm]{1,8}|[*†‡§¶]|↩|↑|back|return|返回|回到正文)$", re.I
)
_FOOTNOTE_HREF_RE = re.compile(
r"(?:^#|[#/_-](?:fn|footnote|note|noteref|backlink|return|filepos)\b)", re.I
r"[#/_-](?:fn|footnote|note|noteref|backlink|return|filepos)\b", re.I
)
_DOTTED_TOC_RE = re.compile(r"^\s*.+?\.{2,}\s*(?:\d+|[ivxlcdm]+)\s*$", re.I)
_SEP_RE = re.compile(r"^\s*(?:[-=*_]){3,}\s*$")
Expand Down
12 changes: 11 additions & 1 deletion tests/test_epub_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import pytest

from astrbot.core.knowledge_base.parsers.epub_parser import EpubParser
from astrbot.core.knowledge_base.parsers.epub_parser import EpubParser, _strip_links
from astrbot.core.knowledge_base.parsers.markitdown_parser import MarkitdownParser
from astrbot.core.knowledge_base.parsers.util import select_parser

Expand Down Expand Up @@ -132,6 +132,7 @@ def _make_epub_bytes_with_generic_content() -> bytes:
<body>
<h1>First</h1>
Lead text
<p>页内链接:需要<a href="#backup">离线备份</a>才能继续。</p>
<p>Piura<a href="text00000.html#filepos0000045863">*5</a>, continued.</p>
<img src="Image00000.jpg" alt="" />
<div>Inside div</div>
Expand Down Expand Up @@ -209,6 +210,7 @@ async def test_epub_parser_preserves_generic_container_text():
assert "**Title:**" not in result.text
assert "# First" in result.text
assert "Lead text" in result.text
assert "页内链接:需要离线备份才能继续。" in result.text
assert r"Piura\*5, continued." in result.text
assert "filepos" not in result.text
assert r"[\*5]" not in result.text
Expand All @@ -218,3 +220,11 @@ async def test_epub_parser_preserves_generic_container_text():
assert "Inside div" in result.text
assert "Inside section" in result.text
assert "| Cell A | Cell B |" in result.text


@pytest.mark.parametrize(
"link",
["[1](#ref1)", "[footnote](#footnote-1)"],
)
def test_epub_link_cleanup_removes_footnotes(link):
assert _strip_links(f"Before {link} after") == "Before after"
Loading