Use html parser instead of regex to clean composer input

Before sending input to the LLM, we clean the composer input to
remove html tags. We relied on regex that we not complete enough and
could be bypassed easily. So let's use the html parser available in
Dart instead.

I also added some tests.
This commit is contained in:
Théo Poizat
2025-12-15 08:22:16 +01:00
committed by Dat H. Pham
parent f77580ed44
commit a9cfe86a59
2 changed files with 39 additions and 8 deletions
+16
View File
@@ -816,4 +816,20 @@ void main() {
);
});
});
group('StringConvert.convertHtmlContentToTextContent', () {
test('should preserve line breaks between paragraphs', () {
const htmlContent = '<p>First paragraph</p><p>Second paragraph</p><p>Third paragraph</p>';
final result = StringConvert.convertHtmlContentToTextContent(htmlContent);
expect(result, 'First paragraph\nSecond paragraph\nThird paragraph');
});
test('should preserve line breaks for br', () {
const htmlContent = '<p>First paragraph</p><div><br></div><p>Second paragraph</p>';
final result = StringConvert.convertHtmlContentToTextContent(htmlContent);
expect(result, 'First paragraph\n\nSecond paragraph');
});
});
}