@@ -29,6 +29,7 @@ const c = @cImport({
2929});
3030
3131const mimalloc = @import ("mimalloc.zig" );
32+ const normalizeWhitespace = @import ("html/document.zig" ).normalizeWhitespace ;
3233
3334// init initializes netsurf lib.
3435// init starts a mimalloc heap arena for the netsurf session. The caller must
@@ -2152,12 +2153,12 @@ fn parserErr(err: HubbubErr) ParserError!void {
21522153
21532154// documentHTMLParseFromStr parses the given HTML string.
21542155// The caller is responsible for closing the document.
2155- pub fn documentHTMLParseFromStr (str : []const u8 ) ! * DocumentHTML {
2156+ pub fn documentHTMLParseFromStr (arena : std.mem.Allocator , str : []const u8 ) ! * DocumentHTML {
21562157 var fbs = std .io .fixedBufferStream (str );
2157- return try documentHTMLParse (fbs .reader (), "UTF-8" );
2158+ return try documentHTMLParse (arena , fbs .reader (), "UTF-8" );
21582159}
21592160
2160- pub fn documentHTMLParse (reader : anytype , enc : ? [:0 ]const u8 ) ! * DocumentHTML {
2161+ pub fn documentHTMLParse (arena : std.mem.Allocator , reader : anytype , enc : ? [:0 ]const u8 ) ! * DocumentHTML {
21612162 var parser : ? * c.dom_hubbub_parser = undefined ;
21622163 var doc : ? * c.dom_document = undefined ;
21632164 var err : c.hubbub_error = undefined ;
@@ -2169,7 +2170,11 @@ pub fn documentHTMLParse(reader: anytype, enc: ?[:0]const u8) !*DocumentHTML {
21692170
21702171 try parseData (parser .? , reader );
21712172
2172- return @as (* DocumentHTML , @ptrCast (doc .? ));
2173+ const html_doc : * DocumentHTML = @ptrCast (doc .? );
2174+ const old_title = try documentHTMLGetTitle (html_doc );
2175+ const normalized = try normalizeWhitespace (arena , old_title );
2176+ try documentHTMLSetTitle (html_doc , normalized );
2177+ return html_doc ;
21732178}
21742179
21752180pub fn documentParseFragmentFromStr (self : * Document , str : []const u8 ) ! * DocumentFragment {
0 commit comments