diff --git a/lib/src/plugins/html/html_document_decoder.dart b/lib/src/plugins/html/html_document_decoder.dart index a78c81306..99a96537b 100644 --- a/lib/src/plugins/html/html_document_decoder.dart +++ b/lib/src/plugins/html/html_document_decoder.dart @@ -45,8 +45,18 @@ class DocumentHTMLDecoder extends Converter { if (domNode is dom.Element) { final localName = domNode.localName; if (HTMLTags.formattingElements.contains(localName)) { - final attributes = _parserFormattingElementAttributes(domNode); - delta.insert(domNode.text, attributes: attributes); + final style = domNode.attributes['style']; + + ///This is used for temporarily handling documents copied from Google Docs, + /// see [#6808](https://github.com/AppFlowy-IO/AppFlowy/issues/6808). + final isMeaninglessTag = + style == 'font-weight:normal;' && localName == HTMLTags.bold; + if (isMeaninglessTag && domNode.children.isNotEmpty) { + nodes.addAll(_parseElement(domNode.children)); + } else { + final attributes = _parserFormattingElementAttributes(domNode); + delta.insert(domNode.text, attributes: attributes); + } } else if (HTMLTags.specialElements.contains(localName)) { if (delta.isNotEmpty) { nodes.add(paragraphNode(delta: delta)); diff --git a/test/plugins/html/html_document_test.dart b/test/plugins/html/html_document_test.dart index fe10709f1..938825b11 100644 --- a/test/plugins/html/html_document_test.dart +++ b/test/plugins/html/html_document_test.dart @@ -322,4 +322,50 @@ void main() { expect(node.attributes[HeadingBlockKeys.level], i); } }); + + test('sample 12', () { + // Checkout conversion is too low: only 18% of users who click on “Book” checkout. + // Comparable funnels for hotel booking sites achieve ~30% (source). + const html = + '''

Checkout conversion is too low: only 18% of users who click on “Book” checkout.

Comparable funnels for hotel booking sites achieve ~30% (source).


'''; + final document = htmlToDocument(html); + + final node = document.nodeAtPath([0])!; + expect(node.type, ParagraphBlockKeys.type); + expect( + node.delta!.toPlainText(), + 'Checkout conversion is too low: only 18% of users who click on “Book” checkout.', + ); + + final node2 = document.nodeAtPath([1])!; + expect(node2.type, ParagraphBlockKeys.type); + final jsonList = node2.delta!.toJson(); + final cleanJson = jsonList.map((e) { + final map = e as Map; + map.removeWhere((k, v) => k != 'insert' && k != 'attributes'); + return map; + }).toList(); + expect( + cleanJson, + [ + { + 'insert': 'Comparable funnels for hotel booking sites achieve ~30% (', + 'attributes': {'font_color': '0xff000000'}, + }, + { + 'insert': 'source', + 'attributes': { + 'href': + 'https://docs.google.com/document/d/147-eAtY305IGAghvmQzn0NXUFlh2zQs50GbmBNlgnaA/edit?tab=t.0', + 'underline': true, + 'font_color': '0xff1155cc', + }, + }, + { + 'insert': ').', + 'attributes': {'font_color': '0xff000000'}, + } + ], + ); + }); }