Skip to content

AI turns documents or topics into real, native PowerPoint decks—with native shapes, transitions and animations, data-backed charts and tables on demand, audio narration from speaker notes, and support for your own .pptx templates. · by Hugo He

fix(web-to-md): a Markdown file that shows HTML in a code fence stays Markdown

hugohe36a92c1fd8e88
diff --git a/skills/ppt-master/scripts/source_to_md/web_to_md.py b/skills/ppt-master/scripts/source_to_md/web_to_md.py
index a63b9409..39349556 100644
--- a/skills/ppt-master/scripts/source_to_md/web_to_md.py
+++ b/skills/ppt-master/scripts/source_to_md/web_to_md.py
@@ -1261,14 +1261,16 @@ def is_plain_text_document(url: str, body: str) -> bool:
A raw file such as ``.../CHANGELOG.md`` on raw.githubusercontent.com is
already Markdown; running it through the HTML extractor loses the file or
- fails on a missing body. The URL suffix decides, guarded by the absence of
- an HTML document tag near the top of the body.
+ fails on a missing body. The URL suffix decides, unless the body itself
+ opens as an HTML document.
"""
path = urlparse(url).path.lower()
if not path.endswith(PLAIN_TEXT_SUFFIXES):
return False
- head = body[:4096].lower()
- return "<html" not in head and "<body" not in head and "<!doctype html" not in head
+ # An HTML page starts as one; a README whose code fence shows "<body>" or
+ # "<html>" further down is still Markdown.
+ start = body[:4096].lstrip("\ufeff \t\r\n").lower()
+ return not start.startswith(("<!doctype html", "<html", "<head", "<body"))
def _save_plain_text_document(
diff --git a/skills/ppt-master/scripts/tests/test_source_to_md_content_loss_web.py b/skills/ppt-master/scripts/tests/test_source_to_md_content_loss_web.py
index 73b3403b..60aecf29 100644
--- a/skills/ppt-master/scripts/tests/test_source_to_md_content_loss_web.py
+++ b/skills/ppt-master/scripts/tests/test_source_to_md_content_loss_web.py
@@ -98,3 +98,16 @@ class WebContentLossTests(unittest.TestCase):
self.assertIn('DENSE_BODY', md)
md = self._convert('<main><article><p>' + 'NESTED_BODY ' * 40 + '</p></article></main>')
self.assertEqual(md.count('NESTED_BODY'), 40)
+
+
+class PlainTextDetectionTests(unittest.TestCase):
+ URL = "https://raw.githubusercontent.com/example/repo/main/README.md"
+
+ def test_markdown_showing_html_in_a_code_fence_stays_markdown(self) -> None:
+ body = "# HTML guide\n\nBefore\n\n```html\n<body>Example</body>\n```\n\nAfter\n"
+ self.assertTrue(web_to_md.is_plain_text_document(self.URL, body))
+
+ def test_html_page_at_a_markdown_url_is_html(self) -> None:
+ self.assertFalse(
+ web_to_md.is_plain_text_document(self.URL, "<!DOCTYPE html><html><body>x</body></html>")
+ )