Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

feat: handle text-decoration for text styles

Vincent Chan61aaa20113a1
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 96c001a318..cc7fd949ae 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
@@ -159,10 +159,8 @@ class HTMLToNodesConverter {
}
final textDecorationStr = cssMap["text-decoration"];
- if (textDecorationStr == "line-through") {
- attrs[StyleKey.strikethrough] = true;
- } else if (textDecorationStr == "underline") {
- attrs[StyleKey.underline] = true;
+ if (textDecorationStr != null) {
+ _assignTextDecorations(attrs, textDecorationStr);
}
final backgroundColorStr = cssMap["background-color"];
@@ -179,6 +177,17 @@ class HTMLToNodesConverter {
return attrs.isEmpty ? null : attrs;
}
+ _assignTextDecorations(Attributes attrs, String decorationStr) {
+ final decorations = decorationStr.split(" ");
+ for (final d in decorations) {
+ if (d == "line-through") {
+ attrs[StyleKey.strikethrough] = true;
+ } else if (d == "underline") {
+ attrs[StyleKey.underline] = true;
+ }
+ }
+ }
+
/// Try to parse the `rgba(red, greed, blue, alpha)`
/// from the string.
Color? _tryParseCssColorString(String? colorString) {
@@ -424,6 +433,18 @@ class NodesToHTMLConverter {
checked: textNode.attributes["checkbox"] == true);
}
+ String _textDecorationsFromAttributes(Attributes attributes) {
+ var textDecoration = <String>[];
+ if (attributes[StyleKey.strikethrough] == true) {
+ textDecoration.add("line-through");
+ }
+ if (attributes[StyleKey.underline] == true) {
+ textDecoration.add("underline");
+ }
+
+ return textDecoration.join(" ");
+ }
+
String _attributesToCssStyle(Map<String, dynamic> attributes) {
final cssMap = <String, String>{};
if (attributes[StyleKey.backgroundColor] != null) {
@@ -441,12 +462,12 @@ class NodesToHTMLConverter {
if (attributes[StyleKey.bold] == true) {
cssMap["font-weight"] = "bold";
}
- if (attributes[StyleKey.strikethrough] == true) {
- cssMap["text-decoration"] = "line-through";
- }
- if (attributes[StyleKey.underline] == true) {
- cssMap["text-decoration"] = "underline";
+
+ final textDecoration = _textDecorationsFromAttributes(attributes);
+ if (textDecoration.isNotEmpty) {
+ cssMap["text-decoration"] = textDecoration;
}
+
if (attributes[StyleKey.italic] == true) {
cssMap["font-style"] = "italic";
}