Эх сурвалжийг харах

fix(markup): strip xml declaration from html output

Remove XML declaration (<?xml version="1.0"?>) from to_html() and
to_html_formatted() output. The declaration is unnecessary for HTML5
and can cause rendering issues in some browsers.
Billy Barrow 1 долоо хоног өмнө
parent
commit
d2c6c220ed

+ 18 - 2
src/Markup/MarkupDocument.vala

@@ -250,7 +250,7 @@ namespace Astralis {
         public string to_html() {
             string buffer;
             doc->dump_memory(out buffer);
-            return buffer;
+            return strip_xml_declaration(buffer);
         }
 
         /// <summary>
@@ -260,7 +260,23 @@ namespace Astralis {
             string buffer;
             int len;
             doc->dump_memory_format(out buffer, out len, true);
-            return buffer;
+            return strip_xml_declaration(buffer);
+        }
+
+        private string strip_xml_declaration(string html) {
+            // Remove XML declaration if present (e.g., <?xml version="1.0"?>)
+            if (html.has_prefix("<?xml")) {
+                int end = html.index_of("?>");
+                if (end >= 0) {
+                    // Skip the declaration and any following whitespace/newline
+                    int start = end + 2;
+                    while (start < html.length && html[start].isspace()) {
+                        start++;
+                    }
+                    return html.substring(start);
+                }
+            }
+            return html;
         }
 
         /// <summary>