Skip to content

Commit b7000cf

Browse files
committed
use outerHTML instead of XMLSerializer; fixes #44
1 parent 20911d6 commit b7000cf

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/vite/observable.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,10 @@ export type NotebookTransform = (
3939
) => Notebook | Promise<Notebook>;
4040

4141
export interface ObservableOptions {
42-
/** The global window, for the default parser and serializer implementations. */
43-
window?: Pick<typeof globalThis, "DOMParser" | "XMLSerializer">;
42+
/** The global window, for the default parser implementations. */
43+
window?: Pick<typeof globalThis, "DOMParser">;
4444
/** The parser implementation; defaults to `new window.DOMParser()`. */
4545
parser?: DOMParser;
46-
/** The serializer implementation; defaults to `new window.XMLSerializer()`. */
47-
serializer?: XMLSerializer;
4846
/** The path to the page template; defaults to the default template. */
4947
template?: string;
5048
/** An optional function which transforms the template HTML for the current page. */
@@ -56,7 +54,6 @@ export interface ObservableOptions {
5654
export function observable({
5755
window = new JSDOM().window,
5856
parser = new window.DOMParser(),
59-
serializer = new window.XMLSerializer(),
6057
template = fileURLToPath(import.meta.resolve("../templates/default.html")),
6158
transformTemplate = (template) => template,
6259
transformNotebook = (notebook) => notebook
@@ -125,10 +122,11 @@ export function observable({
125122
// Don’t error if assets are missing (matching Vite’s behavior).
126123
filterMissingAssets(assets, dirname(context.filename));
127124

128-
const output = serializer.serializeToString(document);
125+
const output = document.documentElement.outerHTML;
129126
const i = output.indexOf("</body>");
130127
if (!(i >= 0)) throw new Error("body not found");
131128
return (
129+
`<!doctype html>` +
132130
output.slice(0, i) +
133131
`<style type="text/css">
134132
@import url("observable:styles/theme-${notebook.theme}.css");

0 commit comments

Comments
 (0)