# 04 — File Formats Six formats. HTML is the interoperability workhorse; BM JSON is our lossless round-trip format; CSV is for spreadsheets; Markdown is share/export-only; and since v1.1.0 two browser files are read directly — Chrome's profile `Bookmarks` file and Firefox's JSON backup. | Format | Import | Export | Lossless | Purpose | |---|---|---|---|---| | Netscape HTML | ✔ | ✔ | structure+dates | Universal browser exchange (Chrome, Edge, Brave, Firefox, Safari, Vivaldi, Opera all read/write it) | | BM JSON v1 | ✔ | ✔ | ✔ | Backups, round-trip, safety backup before Replace | | Chrome `Bookmarks` (§2a) | ✔ | ✖ | structure+dates | The profile file itself — the copy left when the browser no longer starts; keeps Other and Mobile | | Firefox JSON backup (§2b) | ✔ | ✖ | structure+dates | `bookmarks-YYYY-MM-DD.json` from Library → Backup…; keeps Mobile, which Firefox's HTML export drops | | CSV (RFC 4180) | ✔ | ✔ | flattened | Spreadsheet review/editing | | Markdown | ✖ | ✔ | — | Human-readable sharing (blog posts, Discord, README) | **Sniffing** (`detect-format.ts`, called only through `parse-file.ts`'s `parseBookmarkFile`) reads content and never the extension — Chrome's file has none — after stripping a BOM: 1. Text whose first non-blank character is `{` or `[` is JSON. It is parsed **exactly once** and routed by shape: `format: "bookmarkmagic"` → BM JSON; an object `roots` holding `bookmark_bar`, `other` or `synced` → Chrome; `type: "text/x-moz-place-container"` (or `root: "placesRoot"`) with a `children` array → Firefox. Valid JSON matching none → `NOT_BM_JSON` (meaning, since v1.1.0, "JSON, but no bookmark file we know"); invalid JSON → `MALFORMED_JSON`. JSON is tested first so a title quoting the doctype can never make a JSON file look like HTML. 2. `
``` Export rules: 4-space indent per depth (matches Chrome), attributes only when values exist, one **root marker** on each folder that stands for a browser root (below), HTML-escape `& < > "` in titles and hrefs — **and `\r` as ` `**. The last one is not a markup hazard but a round-trip one: the HTML tokenizer normalizes CR and CRLF to LF during input-stream preprocessing, so an unescaped `\r` in a title comes back as `\n`. A numeric reference survives, because character references are decoded after that normalization. `\r` reaches us from BM JSON and from quoted CSV fields, so this is reachable, not theoretical. **Root markers** (since v1.1.0). Our own export and the Replace safety backup write the browser roots as top-level folders; without a marker, re-importing them nested a folder named "Other bookmarks" *inside* Other Bookmarks, one more level on every restore (`03 §1`). Exactly one attribute per folder, the toolbar winning: | Root | Attribute | Who reads it | |---|---|---| | Bookmarks Bar | `PERSONAL_TOOLBAR_FOLDER="true"` | every browser | | Other Bookmarks | `UNFILED_BOOKMARKS_FOLDER="true"` | Firefox (its own exporter writes it), and us | | Mobile Bookmarks | `MOBILE_BOOKMARKS_FOLDER="true"` | us — importers ignore attributes they do not know | | Bookmarks Menu (Firefox) | *none* — its contents are written **loose at the top level** | every browser, the way Firefox's own exporter writes it (since v1.3.0) | The Bookmarks Menu has no attribute of its own in Firefox's format: Firefox exports the menu's entries as the file's top level and imports loose top-level entries back into the menu. A BM JSON `root: "menu"` folder (§2) is therefore written to HTML by unwrapping it — its children appear at the top level, before the marked roots — and reading that file in Firefox puts them back where they were (`03 §1`). Chromium has no menu root, so in Chrome or Edge those entries land in Other Bookmarks, as they do from Firefox's own export. The other way round, Chrome's own export writes Other's and Mobile's contents loose (§1.2), so in Firefox they land in the Bookmarks Menu, exactly as Firefox's own import places them; our exports mark both roots and land where they came from. ### 1.2 Parse tolerance (import) Must accept, with a warning where noted: - Missing `` / stray `
` (normal for the format). - `