feat(编辑能力): 统一文字编辑,完善排版保存
build.yaml / build (push) Successful in 43s

This commit is contained in:
xiaoqidun committed 2026-10-28 12:44:31 +08:00
1 parent e35533859c
commit 89a7ef04c7
23 files changed
+410 -114

No files matched your search

+35 -2
View File
@@ -397,6 +397,9 @@ func editorXMLAttributes(node *editorXML, allowed string) bool {
if attr.Name.Space == "xmlns" || attr.Name.Local == "xmlns" && attr.Name.Space == "" {
continue
}
if textLayoutAttribute(node.name, attr) {
continue
}
if attr.Name.Space != "" || !slices.Contains(strings.Fields(allowed), attr.Name.Local) {
return false
}
@@ -569,6 +572,15 @@ func editorXMLMergeNamespace(data []byte, node *editorXML, oldXML, newXML []byte
return nil, err
}
changes := make(map[string]string)
layoutValue := func(n *editorXML) string {
for _, attr := range n.attrs {
if attr.Name.Space == textLayoutNamespace && attr.Name.Local == "Layout" {
return attr.Value
}
}
return ""
}
layoutChanged := layoutValue(oldNode) != layoutValue(newNode)
if legacyClip {
changes["TransFlag"] = ""
}
@@ -578,7 +590,7 @@ func editorXMLMergeNamespace(data []byte, node *editorXML, oldXML, newXML []byte
}
}
contentChanged := !bytes.Equal(oldXML[oldNode.open:oldNode.close], newXML[newNode.open:newNode.close])
if len(changes) == 0 && !contentChanged && namespace == node.name.Space {
if len(changes) == 0 && !layoutChanged && !contentChanged && namespace == node.name.Space {
return bytes.Clone(data[node.start:node.end]), nil
}
d := xml.NewDecoder(bytes.NewReader(data[node.start:node.open]))
@@ -587,8 +599,29 @@ func editorXMLMergeNamespace(data []byte, node *editorXML, oldXML, newXML []byte
return nil, err
}
start := token.(xml.StartElement)
if layoutChanged {
value, found := layoutValue(newNode), false
attrs := start.Attr[:0]
for i, attr := range start.Attr {
resolved := node.attrs[i]
if resolved.Name.Space == textLayoutNamespace && resolved.Name.Local == "Layout" {
found = true
if value != "" {
attr.Value = value
attrs = append(attrs, attr)
}
continue
}
attrs = append(attrs, attr)
}
start.Attr = attrs
if !found && value != "" {
prefix := editorXMLNamespacePrefix(node, "ofdgo")
start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Space: "xmlns", Local: prefix}, Value: textLayoutNamespace}, xml.Attr{Name: xml.Name{Space: prefix, Local: "Layout"}, Value: value})
}
}
if legacyClip || namespace != node.name.Space {
start.Name.Space = editorXMLNamespacePrefix(node)
start.Name.Space = editorXMLNamespacePrefix(node, "ofd")
start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Space: "xmlns", Local: start.Name.Space}, Value: namespace})
}
var result bytes.Buffer