Turn any technical book PDF into a Claude Code skill — ready to study, reference, and use while you work.
Python agent-skillsai-agentsbook-to-skillcontext-engineeringdocument-processingedtechknowledge-baseknowledge-managementllmpdf-to-markdownragself-studystudy-tools
fix(html): decode entities once in the stdlib parser (#60)
Shubham Srivastavad09d44da64b8
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex b0eb785..32461b5 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -28,6 +28,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0- The dependency-free RTF fallback (used when `striprtf` is not installed) nowdecodes `\uN` unicode escapes — smart quotes, dashes, accented letters — insteadof dropping them and leaving only the ASCII fallback character.+- The stdlib HTML parser (the fallback for HTML files and EPUB extraction when+ BeautifulSoup is not installed) no longer decodes HTML entities twice, so+ double-encoded entities such as `&amp;` survive intact.## [1.2.0] — 2026-06-17diff --git a/book_to_skill/parsers/html.py b/book_to_skill/parsers/html.pyindex 72af1a1..f454363 100644--- a/book_to_skill/parsers/html.py+++ b/book_to_skill/parsers/html.py@@ -31,7 +31,10 @@ class _HTMLTextExtractor(html.parser.HTMLParser):self._parts.append(data)def get_text(self) -> str:- return html.unescape("".join(self._parts))+ # HTMLParser(convert_charrefs=True) already decoded entities in+ # handle_data; do NOT unescape again or double-encoded entities+ # (e.g. "&amp;") collapse incorrectly.+ return "".join(self._parts)def extract_html_content(raw_html: str) -> str:diff --git a/tests/test_book_to_skill.py b/tests/test_book_to_skill.pyindex 4303b69..e8cfdef 100644--- a/tests/test_book_to_skill.py+++ b/tests/test_book_to_skill.py@@ -1033,3 +1033,35 @@ class TestRtfUnicodeFallback:# Two adjacent \uN escapes, each with a \'XX hex fallback, decode cleanly.text = self._BS + "u8220" + self._BS + "'93Hi" + self._BS + "u8221" + self._BS + "'94"assert strip_rtf_fallback(text) == "“Hi”"+++class TestHtmlEntityDecoding:+ """The stdlib HTML parser decodes entities exactly once (not twice)."""++ def _text(self, fragment):+ # Feed a raw fragment (no block tags) through a fresh stdlib parser.+ from book_to_skill.parsers.html import _HTMLTextExtractor+ p = _HTMLTextExtractor()+ p.feed(fragment)+ return p.get_text()++ def test_double_encoded_ampersand(self):+ # The bug: this used to collapse to "&" (decoded twice).+ assert self._text("&amp;") == "&"++ def test_double_encoded_tag(self):+ assert self._text("&lt;tag&gt;") == "<tag>"++ def test_single_entities_still_decode(self):+ assert self._text("<b>") == "<b>"+ assert self._text("&") == "&"++ def test_numeric_and_named_entities(self):+ assert self._text("é") == "é" # decimal numeric+ assert self._text("é") == "é" # hex numeric+ assert self._text("©") == "©" # non-ASCII named entity+ assert self._text("hello") == "hello" # plain text++ def test_skip_tag_content_excluded(self):+ # Confirms the change didn't disturb skip-tag handling.+ assert self._text("<style>x{}</style>keep") == "keep"