Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: all the text pasted from google doc will be applied inline link #993

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions lib/src/plugins/html/html_document_decoder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,18 @@ class DocumentHTMLDecoder extends Converter<String, Document> {
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));
Expand Down
46 changes: 46 additions & 0 deletions test/plugins/html/html_document_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
'''<meta charset='utf-8'><meta charset="utf-8"><b style="font-weight:normal;" id="docs-internal-guid-30b67c3b-7fff-e5ec-0b19-376448d34980"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span style="font-size:11pt;font-family:Arial,sans-serif;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre;white-space:pre-wrap;">Checkout conversion is too low: only 18% of users who click on &ldquo;Book&rdquo; checkout.</span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span style="font-size:11pt;font-family:Arial,sans-serif;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre;white-space:pre-wrap;">Comparable funnels for hotel booking sites achieve ~30% (</span><a href="https://docs.google.com/document/d/147-eAtY305IGAghvmQzn0NXUFlh2zQs50GbmBNlgnaA/edit?tab=t.0" style="text-decoration:none;"><span style="font-size:11pt;font-family:Arial,sans-serif;color:#1155cc;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:underline;-webkit-text-decoration-skip:none;text-decoration-skip-ink:none;vertical-align:baseline;white-space:pre;white-space:pre-wrap;">source</span></a><span style="font-size:11pt;font-family:Arial,sans-serif;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre;white-space:pre-wrap;">).</span></p></b><br class="Apple-interchange-newline">''';
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'},
}
],
);
});
}
Loading