From 81d4c8d23bc7b69615574209c8615854c75a5ec1 Mon Sep 17 00:00:00 2001 From: Vincent Chan Date: Mon, 15 Aug 2022 12:51:32 +0800 Subject: [PATCH] feat: blockquote --- .../lib/src/infra/html_converter.dart | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/infra/html_converter.dart b/frontend/app_flowy/packages/flowy_editor/lib/src/infra/html_converter.dart index 0f8578b5c7..5963d5955d 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/infra/html_converter.dart +++ b/frontend/app_flowy/packages/flowy_editor/lib/src/infra/html_converter.dart @@ -24,6 +24,7 @@ const String tagDel = "del"; const String tagStrong = "strong"; const String tagSpan = "span"; const String tagCode = "code"; +const String tagBlockQuote = "blockquote"; extension on Color { String toRgbaString() { @@ -70,6 +71,8 @@ class HTMLToNodesConverter { } else { result.add(_handleRichText(child)); } + } else if (child.localName == tagBlockQuote) { + result.addAll(_handleBlockQuote(child)); } else { result.addAll(_handleElement(child)); } @@ -83,6 +86,18 @@ class HTMLToNodesConverter { return result; } + List _handleBlockQuote(html.Element element) { + final result = []; + + for (final child in element.nodes.toList()) { + if (child is html.Element) { + result.addAll(_handleElement(child, {"subtype": "quote"})); + } + } + + return result; + } + List _handleBTag(html.Element element) { final childNodes = element.nodes; return _handleContainer(childNodes); @@ -527,6 +542,8 @@ class NodesToHTMLConverter { } else if (heading == StyleKey.h3) { tagName = tagH3; } + } else if (subType == StyleKey.quote) { + tagName = tagBlockQuote; } for (final op in delta) { @@ -567,10 +584,19 @@ class NodesToHTMLConverter { } } - if (tagName != tagParagraph && + if (tagName == tagBlockQuote) { + final p = html.Element.tag(tagParagraph); + for (final node in childNodes) { + p.append(node); + } + final blockQuote = html.Element.tag(tagName); + blockQuote.append(p); + return blockQuote; + } else if (tagName != tagParagraph && tagName != tagH1 && tagName != tagH2 && - tagName != tagH3) { + tagName != tagH3 && + tagName != tagBlockQuote) { final p = html.Element.tag(tagParagraph); for (final node in childNodes) { p.append(node);