Merge pull request #2876 from lightpanda-io/content-type-makrdown

handle text/makrdown as plain text
This commit is contained in:
Karl Seguin
2026-07-03 22:46:48 +08:00
committed by GitHub
2 changed files with 8 additions and 2 deletions

View File

@@ -1398,7 +1398,7 @@ fn frameDataCallback(response: HttpClient.Response, data: []const u8) !void {
.arena = try self.getArena(.large, "Frame.navigate"),
} };
},
.application_json, .text_javascript, .text_css, .text_plain => {
.application_json, .text_javascript, .text_css, .text_plain, .text_markdown => {
var arr: std.ArrayList(u8) = .empty;
try arr.appendSlice(self.arena, "<html><head><meta charset=\"utf-8\"></head><body><pre>");
self._parse_state = .{ .text = arr };

View File

@@ -40,6 +40,7 @@ pub const ContentTypeEnum = enum {
text_javascript,
text_plain,
text_css,
text_markdown,
image_jpeg,
image_gif,
image_png,
@@ -55,6 +56,7 @@ pub const ContentType = union(ContentTypeEnum) {
text_javascript: void,
text_plain: void,
text_css: void,
text_markdown: void,
image_jpeg: void,
image_gif: void,
image_png: void,
@@ -72,6 +74,7 @@ pub fn contentTypeString(mime: *const Mime) []const u8 {
.text_html => "text/html",
.text_javascript => "application/javascript",
.text_plain => "text/plain",
.text_markdown => "text/markdown",
.text_css => "text/css",
.image_jpeg => "image/jpeg",
.image_png => "image/png",
@@ -342,7 +345,7 @@ pub fn isHTML(self: *const Mime) bool {
pub fn isText(mime: *const Mime) bool {
return switch (mime.content_type) {
.text_xml, .text_html, .text_javascript, .text_plain, .text_css => true,
.text_xml, .text_html, .text_javascript, .text_plain, .text_css, .text_markdown => true,
.application_json => true,
else => false,
};
@@ -359,6 +362,7 @@ fn parseContentType(value: []const u8) !struct { ContentType, usize } {
@"text/html",
@"text/css",
@"text/plain",
@"text/markdown",
@"text/javascript",
@"application/javascript",
@@ -377,6 +381,7 @@ fn parseContentType(value: []const u8) !struct { ContentType, usize } {
.@"text/javascript", .@"application/javascript", .@"application/x-javascript" => .{ .text_javascript = {} },
.@"text/plain" => .{ .text_plain = {} },
.@"text/css" => .{ .text_css = {} },
.@"text/markdown" => .{ .text_markdown = {} },
.@"image/jpeg" => .{ .image_jpeg = {} },
.@"image/png" => .{ .image_png = {} },
.@"image/gif" => .{ .image_gif = {} },
@@ -790,6 +795,7 @@ test "Mime: parse common" {
try expect(.{ .content_type = .{ .application_json = {} } }, "application/json");
try expect(.{ .content_type = .{ .text_css = {} } }, "text/css");
try expect(.{ .content_type = .{ .text_markdown = {} } }, "text/markdown");
try expect(.{ .content_type = .{ .image_jpeg = {} } }, "image/jpeg");
try expect(.{ .content_type = .{ .image_png = {} } }, "image/png");