Skip to content

Commit

Permalink
Merge pull request #9 from thefrontside/cl/add-doctype
Browse files Browse the repository at this point in the history
✨ Add <!doctype html> to html serialization
  • Loading branch information
cowboyd authored Sep 6, 2024
2 parents 7f34b14 + 5b8223d commit 5c2a1be
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/middleware/serialize-html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import type { HASTHtmlNode } from "../types.ts";
import { toHtml } from "npm:hast-util-to-html@9.0.0";

export function serializeHtml(node: HASTHtmlNode): Response {
return new Response(toHtml(node), {
let doctype = { type: "doctype" } as const;

return new Response(toHtml([doctype, node]), {
headers: {
"Content-Type": "text/html; charset=utf-8;",
},
Expand Down
4 changes: 2 additions & 2 deletions test/revolution.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ describe("revolution", () => {

expect(response.status).toEqual(200);
expect(yield* response.text()).toEqual(
"<html><body>Hello World</body></html>",
"<!doctype html><html><body>Hello World</body></html>",
);
});

Expand Down Expand Up @@ -204,7 +204,7 @@ describe("revolution", () => {
let response = yield* fetch(`http://${hostname}:${port}`, { signal });

expect(yield* response.text()).toEqual(
"<html><body><div>Banner</div>Hello World</body></html>",
"<!doctype html><html><body><div>Banner</div>Hello World</body></html>",
);
});
});

0 comments on commit 5c2a1be

Please sign in to comment.