|
@@ -351,6 +351,42 @@ namespace Astralis {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Gets the outer HTML of this element (including the element itself)
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ public string outer_html {
|
|
|
|
|
+ owned get {
|
|
|
|
|
+ // Create a temporary document to serialize this node
|
|
|
|
|
+ var temp_doc = new Xml.Doc();
|
|
|
|
|
+ temp_doc.set_root_element(xml_node->copy(1));
|
|
|
|
|
+ string buffer;
|
|
|
|
|
+ temp_doc.dump_memory(out buffer);
|
|
|
|
|
+ // Strip XML declaration
|
|
|
|
|
+ if (buffer.has_prefix("<?xml")) {
|
|
|
|
|
+ int end = buffer.index_of("?>");
|
|
|
|
|
+ if (end >= 0) {
|
|
|
|
|
+ int start = end + 2;
|
|
|
|
|
+ while (start < buffer.length && buffer[start].isspace()) {
|
|
|
|
|
+ start++;
|
|
|
|
|
+ }
|
|
|
|
|
+ return buffer.substring(start);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return buffer ?? "";
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Creates an HttpResult from this node's outer HTML.
|
|
|
|
|
+ /// Useful for returning HTML fragments to HTMX requests.
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <param name="status">HTTP status code (defaults to OK)</param>
|
|
|
|
|
+ /// <returns>An HttpResult containing the node's HTML with Content-Type text/html</returns>
|
|
|
|
|
+ public HttpResult to_result(StatusCode status = StatusCode.OK) {
|
|
|
|
|
+ return new HttpStringResult(outer_html, status)
|
|
|
|
|
+ .set_header("Content-Type", "text/html; charset=UTF-8");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
internal MarkupDocument doc {
|
|
internal MarkupDocument doc {
|
|
|
get { return document; }
|
|
get { return document; }
|
|
|
}
|
|
}
|