💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows
Python agentsaiai-agentsembeddingsinformation-retrievallanguage-modellarge-language-modelsllmnlppythonragretrieval-augmented-generationsearchsearch-enginesemantic-searchsentence-embeddingstransformerstxtaivector-databasevector-search
Keep the paragraphs of a blockquote on separate lines in HTMLToMarkdown
RavSinghChandan4a60ff1288f9
diff --git a/src/python/txtai/pipeline/data/htmltomd.py b/src/python/txtai/pipeline/data/htmltomd.pyindex 7f09025e..b4ffb664 100644--- a/src/python/txtai/pipeline/data/htmltomd.py+++ b/src/python/txtai/pipeline/data/htmltomd.py@@ -253,7 +253,17 @@ class HTMLToMarkdown(Pipeline):block as markdown"""- text = "\n".join(f"> {x}" for x in node.text.strip().split("\n"))+ # Start each paragraph on its own line, even when the HTML has no whitespace between them+ text, newline = "", False+ for child in node.children:+ if child.name or child.text.strip():+ if (child.name in ("p", "div") or newline) and text and not text.endswith("\n"):+ text += "\n"+ newline = child.name in ("p", "div")++ text += child.text++ text = "\n".join(f"> {x}" for x in text.strip().split("\n"))return f"{text}\n\n" if self.paragraphs else f"{text}\n"def items(self, node, article):diff --git a/test/python/testpipeline/testdata/testtextractor.py b/test/python/testpipeline/testdata/testtextractor.pyindex 440f33de..96e8a4be 100644--- a/test/python/testpipeline/testdata/testtextractor.py+++ b/test/python/testpipeline/testdata/testtextractor.py@@ -108,6 +108,8 @@ class TestTextractor(unittest.TestCase):# Blockquotesself.assertMarkdown("<blockquote>This is a test</blockquote>", "> This is a test")+ self.assertMarkdown("<blockquote><p>Test1</p><p>Test2</p></blockquote>", "> Test1\n> Test2")+ self.assertMarkdown("<blockquote>Test1<p>Test2</p>Test3</blockquote>", "> Test1\n> Test2\n> Test3")# Listsself.assertMarkdown("<ul><li>Test1</li><li>Test2</li></ul>", "- Test1\n- Test2")