Parcourir la source

feat(markup): add get_attributes method and simplify inner_html serialization

Add get_attributes() method to expose all element attributes as a read-only dictionary. Refactor inner_html property to use html wrapper element instead of div, eliminating the need for manual tag stripping in the getter.
Billy Barrow il y a 1 semaine
Parent
commit
0dca6b0600
1 fichiers modifiés avec 19 ajouts et 16 suppressions
  1. 19 16
      src/Markup/MarkupNode.vala

+ 19 - 16
src/Markup/MarkupNode.vala

@@ -57,6 +57,21 @@ namespace Astralis {
             document.update(this);
         }
 
+        /// <summary>
+        /// Gets all attributes of this element as a read-only dictionary
+        /// </summary>
+        public ReadOnlyAssociative<string, string> get_attributes() {
+            var result = new Dictionary<string, string>();
+            for (var prop = xml_node->properties; prop != null; prop = prop->next) {
+                var name = prop->name;
+                var value = xml_node->get_prop(name);
+                if (name != null && value != null) {
+                    result.set(name, value);
+                }
+            }
+            return result;
+        }
+
         /// <summary>
         /// Gets the id attribute of this element
         /// </summary>
@@ -507,8 +522,7 @@ namespace Astralis {
                     Html.ParserOption.NOBLANKS |
                     Html.ParserOption.NONET);
                 
-                string wrapped = "<div>" + value + "</div>";
-                char[] buffer = wrapped.to_utf8();
+                char[] buffer = value.to_utf8();
                 var temp_doc = Html.Doc.read_memory(buffer, buffer.length, "", "utf-8", options);
                 if (temp_doc == null) {
                     return;
@@ -532,7 +546,7 @@ namespace Astralis {
             owned get {
                 // Use Html.Doc to serialize the children properly
                 var temp_doc = new Html.Doc();
-                Xml.Node* wrapper = temp_doc.new_node(null, "div");
+                Xml.Node* wrapper = temp_doc.new_node(null, "html");
                 temp_doc.set_root_element(wrapper);
                 
                 // Copy children to the wrapper
@@ -545,19 +559,8 @@ namespace Astralis {
                 string buffer;
                 int len;
                 temp_doc.dump_memory(out buffer, out len);
-                
-                // Extract just the inner content (between <div> and </div>)
-                // The HTML serializer outputs proper HTML without XML declaration
-                string result = buffer ?? "";
-                
-                // Strip the wrapper div tags
-                if (result.has_prefix("<div>")) {
-                    result = result.substring(5);
-                }
-                if (result.has_suffix("</div>")) {
-                    result = result.substring(0, result.length - 6);
-                }
-                
+
+                string result = buffer ?? "";                
                 return result;
             }
         }