# Single File Notebook export format implemented in userspace

**URL:** <https://talk.observablehq.com/t/single-file-notebook-export-format-implemented-in-userspace/10013>\
**Category:** Show and tell\
**Created:** [November 16, 2024, 10:31am UTC](https://talk.observablehq.com/t/single-file-notebook-export-format-implemented-in-userspace/10013 "2024-11-16T10:31:28Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomlarkworthy](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/tomlarkworthy/32/5940_2.png) [@tomlarkworthy](https://talk.observablehq.com/u/tomlarkworthy)\
**Post date:** [November 16, 2024, 10:31am UTC](https://talk.observablehq.com/t/single-file-notebook-export-format-implemented-in-userspace/10013/1 "2024-11-16T10:31:28Z")

</div>

A userspace notebook exporter that serializes notebooks into a single HTML file. Works from file://, syncs to S3, stays unminified for easy editing, works offline, and is editable with a text editor and is recursively self-sustaining. LFG!!!

[![](https://canada1.discourse-cdn.com/flex030/uploads/observablehq/original/2X/7/79dcedc13bfe586020c41931398e93bc74a1e021.jpeg "Export Observable notebooks as single self-sustainable offline files.") ](https://www.youtube.com/watch?v=wx93r1pY_6Y)

> **[Exporter: A Single File Notebook Serializer](https://observablehq.com/@tomlarkworthy/exporter)**
>
> Serialize literate computational notebooks with their dependancies into single files. Double click to open locally. No server required, works in a \`file://\` context for simplicity. File-first representation. The Observable Runtime and common builtins...

---

<div class="post-metadata">

**Author:** ![cvn](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/cvn/32/7340_2.png) [@cvn](https://talk.observablehq.com/u/cvn)\
**Post date:** [November 17, 2024, 7:55am UTC](https://talk.observablehq.com/t/single-file-notebook-export-format-implemented-in-userspace/10013/2 "2024-11-17T07:55:17Z")

</div>

This worked well with a complex, media-heavy notebook of mine. It’s nice to have an archive of that project. I might not have made one without this existing. Thank you!

---

<div class="post-metadata">

**Author:** ![aaronkyle](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/aaronkyle/32/8106_2.png) [@aaronkyle](https://talk.observablehq.com/u/aaronkyle)\
**Post date:** [December 2, 2024, 3:20pm UTC](https://talk.observablehq.com/t/single-file-notebook-export-format-implemented-in-userspace/10013/3 "2024-12-02T15:20:51Z")

</div>

Hi Tom. Thank you for this tool! I noticed that some HTML fragments that I had in a table acquire an observablehq root (and resulting ‘file not found’ when I click them). Is this a parameter you can set in this manner:

```auto
viewof parameters = Inputs.bind(
  exporter(),
  localStorageView(`exporter-https://observablehq.com/d/f0fa398a5407d813`, {
    json: true,
    defaultValue: exporter().value
  })
)

```

… Also, if I don’t wish to import the exporter in a notebook (as that would be rendered along with the notebook), where in your code would I configure this? I see the exporter function with a placeholder to the notebook URL and a blank value – is that it?

```auto
createShowable(
              Inputs.text({
                value: "",
                placeholder: "https://observablehq.com/@tomlarkworthy/exporter"
              })

```

---

<div class="post-metadata">

**Author:** ![tomlarkworthy](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/tomlarkworthy/32/5940_2.png) [@tomlarkworthy](https://talk.observablehq.com/u/tomlarkworthy)\
**Post date:** [December 2, 2024, 6:50pm UTC](https://talk.observablehq.com/t/single-file-notebook-export-format-implemented-in-userspace/10013/4 "2024-12-02T18:50:48Z")

</div>

I don’t understand the first question. I would need a link. Feel free to DM. I was jsut messing around with that notebook so possible I broke it.

If you don’t want the exporter to be included in the notebook, then use the export from notebook URL so your exporter is in a different notebook than the one being exported. I guess the notebook would need to be in an unindexed but public URL though.

To avoid you having to keep rekeying in the export settings, like the notebookURL, you could instantiate a notebook exporter, then set it parameters programatically. I think you found the component that you need to set, but you don’t have to do it in source, as its built out of a view which supports back-writing.

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/observablehq/original/2X/7/7fd3232306294b8941edb6925666af52c58588c3.png)

EDIT:

thinking about it I jsut added the notebook\_url as a top level parameter to make it simpler to adjust

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/observablehq/original/2X/8/8678b370b7990305fb89b1aaf15aeb135689bc33.png)

---

<div class="post-metadata">

**Author:** ![aaronkyle](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/aaronkyle/32/8106_2.png) [@aaronkyle](https://talk.observablehq.com/u/aaronkyle)\
**Post date:** [December 2, 2024, 10:28pm UTC](https://talk.observablehq.com/t/single-file-notebook-export-format-implemented-in-userspace/10013/5 "2024-12-02T22:28:48Z")

</div>

I appreciate your time and help, Tom.

For the first question, in the compiled output, there’s a top-level setting that is  
`<base href="https://observablehq.com"></base>`

The result of having this code included is that the HTML links I had in my notebook would resolve to  
[https://observablehq.com](https://observablehq.com) + (so, for example, [https://observablehq.com/003t0000111sut.html](https://observablehq.com/003t0000111sut.html)). Therefore, if a user clicked the link (which is hard-coded in the data I was using), they’d land at a non-existing Observable notebook.

If I change that setting to, e.g. [https://myhostdomain.com/](https://myhostdomain.com/) , then my links start working. So I was trying to figure out where in the exporter I could change this value.

---

<div class="post-metadata">

**Author:** ![tomlarkworthy](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/tomlarkworthy/32/5940_2.png) [@tomlarkworthy](https://talk.observablehq.com/u/tomlarkworthy)\
**Post date:** [December 3, 2024, 5:58am UTC](https://talk.observablehq.com/t/single-file-notebook-export-format-implemented-in-userspace/10013/6 "2024-12-03T05:58:02Z")

</div>

yeah so there are lots of no-brainer degrees of freedom that need adding as configurables. The `<base>` is something that should be configurable, and I would push that up into the options like I did for “notebook\_url”. I don’t think stuff like that needs a UI.

the notebook\_url is actually also plumbed into the `<title>` so you can follow that to see how to get options into the export process. Note in the export template the title is customized with `${title}`. We should switch the hardcoded base href with `${base}`, but default to `https://observablehq.com`

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/observablehq/original/2X/2/2d3fdb17f308d2b6941e5cdb36cc93e59080548c.png)

With forking forking properly its quite easy to experiment try things out, I would be happy to add suggestions but also I will add that option too if its not easy.

---

<div class="post-metadata">

**Author:** ![tomlarkworthy](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/tomlarkworthy/32/5940_2.png) [@tomlarkworthy](https://talk.observablehq.com/u/tomlarkworthy)\
**Post date:** [March 5, 2025, 9:20am UTC](https://talk.observablehq.com/t/single-file-notebook-export-format-implemented-in-userspace/10013/7 "2025-03-05T09:20:46Z")

</div>

The export now remembers the hash URL, which can simplify passing a small amount of view state between exports. I like the hash URL because it can be manipulated by the user, its brutalist.

[![](https://canada1.discourse-cdn.com/flex030/uploads/observablehq/original/2X/6/601481f5019fa8fb7cdd87f0f854dc0ab5a612e9.jpeg "Exporter preserves hash URL now") ](https://www.youtube.com/watch?v=QWas_gmRObA)

Under the hood the hash URL is stored as a local fileAttachment [Local FileAttachments / Tom Larkworthy | Observable](https://observablehq.com/@tomlarkworthy/fileattachments). As fileAttachments survive export, so does this state, so it can be restored on `file://` load.

So this is all implemented in userspace without any special consideration in the serialised file representation.

Being able to programatically persist state in file attachments is a game changer for long lived work. For large amounts of data you want to pass between exports, using a mutable fileAttachment is better, as hash URL is limited to 2kb so its a scarce resource, but with fileAttachments you can store unbounded amounts of binary data between exports

---

<div class="post-metadata">

**Author:** ![tomlarkworthy](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/tomlarkworthy/32/5940_2.png) [@tomlarkworthy](https://talk.observablehq.com/u/tomlarkworthy)\
**Post date:** [November 1, 2025, 8:44pm UTC](https://talk.observablehq.com/t/single-file-notebook-export-format-implemented-in-userspace/10013/8 "2025-11-01T20:44:07Z")

</div>

**Exporter 2!**

> **[Exporter 2: Single File Serializer](https://observablehq.com/@tomlarkworthy/exporter-2)**
>
> video explainer Serialize literate computational notebooks with their dependancies into single files. Double click to open locally. No server required, works in a \`file://\` context for simplicity. File-first representation. The Observable Runtime and...

Exporter 2 is now based on `es-module-shims` which is better than the previous importmap approach because it enables bringing in network loaded modules dynamically. It also leads to a simpler and faster implementation and unblocks more advanced local-first workflows for CSS and WASM and Typescript while still being in a single file. I hit some limits with importmaps with what can be done after the page was loaded in userspace. This is all fixed with the new export format.

The stdlib is setup by a distinct userspace bootloader module allowing userspace customisation (different duckdb client? Notebook 2.0 stdlib?) and multiple mains. This is loosens the previous coupling between the serialisation format and Observable 1.0 runtime, although I only have a working toolchain for Observable 1.0 cell model.

Looks have improved a _ton_ by reusing NotebookKit’s themes.

This is the refined version of exporter now I have thought about what is needed for an evolvable base.

---

<div class="post-metadata">

**Author:** ![stschiff](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/stschiff/32/9112_2.png) [@stschiff](https://talk.observablehq.com/u/stschiff)\
**Post date:** [January 17, 2026, 11:59am UTC](https://talk.observablehq.com/t/single-file-notebook-export-format-implemented-in-userspace/10013/9 "2026-01-17T11:59:25Z")

</div>

Very cool. I would love to have such an option for notebook kit. Would make it super easy to create reports and share as stand-alone HTML files.
