浏览代码

Merge pull request #1373 from LucasXu0/fix_checkbox_copy

fix: copy link and code style
Lucas.Xu 2 年之前
父节点
当前提交
ea46272b49
共有 1 个文件被更改,包括 20 次插入5 次删除
  1. 20 5
      frontend/app_flowy/packages/appflowy_editor/lib/src/infra/html_converter.dart

+ 20 - 5
frontend/app_flowy/packages/appflowy_editor/lib/src/infra/html_converter.dart

@@ -241,6 +241,8 @@ class HTMLToNodesConverter {
     } else if (element.localName == HTMLTag.del) {
       delta.insert(element.text,
           attributes: {BuiltInAttributeKey.strikethrough: true});
+    } else if (element.localName == HTMLTag.code) {
+      delta.insert(element.text, attributes: {BuiltInAttributeKey.code: true});
     } else {
       delta.insert(element.text);
     }
@@ -276,11 +278,13 @@ class HTMLToNodesConverter {
       }
     }
 
-    final textNode = TextNode(delta: delta, attributes: attributes);
-    if (isCheckbox) {
-      textNode.attributes["subtype"] = BuiltInAttributeKey.checkbox;
-      textNode.attributes["checkbox"] = checked;
-    }
+    final textNode = TextNode(delta: delta, attributes: {
+      if (attributes != null) ...attributes,
+      if (isCheckbox) ...{
+        BuiltInAttributeKey.subtype: BuiltInAttributeKey.checkbox,
+        BuiltInAttributeKey.checkbox: checked,
+      }
+    });
     return textNode;
   }
 
@@ -557,6 +561,17 @@ class NodesToHTMLConverter {
             final strong = html.Element.tag(HTMLTag.del);
             strong.append(html.Text(op.text));
             childNodes.add(strong);
+          } else if (attributes.length == 1 &&
+              attributes[BuiltInAttributeKey.code] == true) {
+            final code = html.Element.tag(HTMLTag.code);
+            code.append(html.Text(op.text));
+            childNodes.add(code);
+          } else if (attributes.length == 1 &&
+              attributes[BuiltInAttributeKey.href] != null) {
+            final anchor = html.Element.tag(HTMLTag.anchor);
+            anchor.attributes["href"] = attributes[BuiltInAttributeKey.href];
+            anchor.append(html.Text(op.text));
+            childNodes.add(anchor);
           } else {
             final span = html.Element.tag(HTMLTag.span);
             final cssString = _attributesToCssStyle(attributes);