notable README.md
24 kB · 573 lines
Markdown
at main

notable #

Parse and convert reMarkable tablet .rm files: version 6 (software ≥ 3), and the older versions 5 and 3 (software 2.x and 1.x), which are read as the version 6 pages they convert to.

notable ships as three things:

  • lib/ — a library for reading, editing and writing .rm files at the block/tree level (the parsing and rendering part runs in browsers too, see In the browser), plus a Node.js client for the reMarkable cloud
  • bin/notable — a CLI tool for converting .rm files to Markdown, SVG, and PDF, and for listing, downloading, uploading, organising and mirroring the documents in your reMarkable cloud account (see reMarkable cloud)
  • Notable, a desktop app — the cloud as a library you can browse and organise, a notebook editor that writes strokes in the tablet's own format, a PDF editor on pdf.js, and a mirror to a folder on disk (see The desktop app)

Installation #

npm install @robin.berjon/notable

Or globally to use the CLI:

npm install -g @robin.berjon/notable

CLI Usage #

Conversion is the default command (notable convert …, or just notable …):

notable [options] [input...]

Options:
  -f, --from <FORMAT>   Format to convert from (default: guess from filename)
  -t, --to <FORMAT>     Format to convert to (default: guess from filename)
  -o, --output <FILE>   Output filename (default: stdout)
  -v, --verbose         Increase verbosity
  -V, --version         Show version
  -h, --help            Show help

The cloud commands (login, ls, get, put, sync, …) are described under reMarkable cloud.

Available FORMAT values: rm, markdown, svg, pdf, blocks, blocks-data.

Examples #

Convert a .rm file to Markdown (printed to stdout):

notable -t markdown note.rm

Convert a .rm file to SVG, writing to a file:

notable -t svg -o note.svg note.rm

Guess the output format from the file extension:

notable note.rm -o note.pdf

Convert a Markdown file to a .rm file:

notable -t rm note.md -o note.rm

Bring a page from an older tablet (version 3 or 5) up to version 6:

notable old-page.rm -o page.rm

Dump the internal block structure of a .rm file:

notable -t blocks note.rm
notable -t blocks-data note.rm   # omit point/byte data

Format notes #

Format Read Write Notes
rm ✓ ✓ reMarkable binary file; versions 3, 5 and 6 are read, version 6 is written
markdown ✓ ✓ Text + highlighted passages
svg — ✓ Vector rendering of strokes
pdf — ✓ Pure JS, no external tools; multiple inputs become pages
blocks — — Debug dump (JSON)
blocks-data — — Debug dump without point data

Library API #

import {
  readBlocks, writeBlocks, readTree,
  simpleTextDocument,
  rmToMarkdown, rmToSvg, rmToPdf, rmsToPdf,
} from '@robin.berjon/notable';

Converters #

The CLI's converters are part of the library:

import { readFileSync, writeFileSync } from 'node:fs';
import { rmToMarkdown, rmToSvg, rmsToPdf } from '@robin.berjon/notable';

const page = readFileSync('page.rm');
const markdown = rmToMarkdown(page);   // string
const svg = rmToSvg(page);             // string

// one PDF page per .rm buffer, all pure JS
const pdf = rmsToPdf([page1, page2, page3]);  // Buffer
writeFileSync('notebook.pdf', pdf);

rmToPdf(data) is the single-page shorthand; treesToPdf(trees) and treeToSvg(tree) accept already-parsed scene trees if you need to read the data once and export it several ways.

Reading blocks #

import { readFileSync } from 'node:fs';
import { readBlocks } from '@robin.berjon/notable';

const data = readFileSync('note.rm');
for (const block of readBlocks(data)) {
  console.log(block.constructor.name);
}

readBlocks(buffer) accepts a Buffer and returns a generator of Block objects.

Older pages (versions 3 and 5) #

Pages written by tablet software before 3.0 are in a simpler format: layers of strokes of points, with no ids. readBlocks and readTree look at the header and take such a page in as the version 6 blocks that say the same thing, so the exporters, the scene tree and PageEditor work on it as they do on any page, and writeBlocks(readBlocks(old)) is the page in version 6. Any other version fails with Unsupported .rm file version N.

import { rmVersion, readTree, readLegacyLines, legacyPagePlacement } from '@robin.berjon/notable';

rmVersion(data);                       // 3, 5 or 6; null when it is not a .rm file
const tree = readTree(data);           // the same tree whatever the version
const raw = readLegacyLines(data);     // { version, layers: [{ strokes: [{ pen, color, size, startingLength, points }] }] }

What the conversion does:

  • Coordinates. An old page counts x from the left edge of the 1404 by 1872 screen; the tree counts it from the middle, as version 6 does, so 702 is taken off. y is unchanged.
  • Points. Speed, direction, width and pressure are floats in an old page (direction in radians, pressure from 0 to 1, width in pixels) and become the integers version 6 keeps (width and speed in quarter pixels, direction and pressure from 0 to 255).
  • Pens and colours kept their numbers, with one exception: an old highlighter stroke says black and means yellow (the highlighter had no colour to choose), so it becomes PenColor.YELLOW. The grey highlighter of late software 2 says grey and stays grey. A pen's size (1.875, 2, 2.125 for thin, medium, thick) becomes the thickness scale 1, 2, 3.
  • Eraser and erase-area strokes are dropped: they record where the eraser went, and the tablet had already cut the erased ink out of the strokes under them. readTree(data, { erasers: true }) keeps them.
  • Ids are made the way the tablet makes them for a new page, the same ones every time for the same bytes. Strokes are attributed to a nil author UUID unless you pass { authorUuid }.

On an annotated PDF, an old page's ink sits over the PDF page scaled to fit the screen whole and set against its top left corner, where version 6 ink is in the page's own space (226 units per inch, x from the page's middle). legacyPagePlacement(width, height) takes the size of the page's CropBox in points and returns { scale, left, top }: screen units per point and where the page's corner is in the tree's coordinates.

Writing blocks #

import { writeBlocks } from '@robin.berjon/notable';

const buf = writeBlocks(blocks, { version: '3.2.2' });
// buf is a Buffer ready to write to a .rm file

The options object supports a version string to control which format features are emitted.

Reading the scene tree #

import { readTree } from '@robin.berjon/notable';

const tree = readTree(data);
// tree.root     — root Group containing layers
// tree.rootText — Text block (keyboard text), or null
// tree.sceneInfo

Walking strokes #

import { Line } from '@robin.berjon/notable';

for (const item of tree.walk()) {
  if (item instanceof Line) {
    console.log(`Stroke with ${item.points.length} points`);
  }
}

Creating a text document #

import { simpleTextDocument, writeBlocks } from '@robin.berjon/notable';

const buf = writeBlocks(simpleTextDocument('Hello reMarkable!'));

Block types #

Class Block type Description
AuthorIdsBlock 0x09 Maps author IDs to UUIDs
MigrationInfoBlock 0x00 Migration metadata
PageInfoBlock 0x0A Page statistics
SceneTreeBlock 0x01 Tree structure entry
TreeNodeBlock 0x02 Layer / group metadata
SceneGroupItemBlock 0x04 Group child reference
SceneLineItemBlock 0x05 Stroke (drawn line)
SceneGlyphItemBlock 0x03 Highlighted text range
SceneTextItemBlock 0x06 Text item in layer
SceneTombstoneItemBlock 0x08 Deleted item marker
RootTextBlock 0x07 Keyboard-entered text
SceneInfo 0x0D Canvas / paper info
UnreadableBlock — Unrecognised or corrupt block

Scene items #

import { PenColor, Pen, ParagraphStyle } from '@robin.berjon/notable';

// PenColor values: BLACK(0), GRAY(1), WHITE(2), YELLOW(3), GREEN(4),
//                 PINK(5), BLUE(6), RED(7), GRAY_OVERLAP(8), HIGHLIGHT(9), ...

// Pen values: BALLPOINT_1(2), BALLPOINT_2(15), FINELINER_1(4), FINELINER_2(17),
//             HIGHLIGHTER_1(5), HIGHLIGHTER_2(18), PENCIL_1(1), PENCIL_2(14), ...

// ParagraphStyle values: PLAIN(1), HEADING(2), BOLD(3), BULLET(4), BULLET2(5), ...

Text extraction #

import { readTree, TextDocument } from '@robin.berjon/notable';

const tree = readTree(data);
if (tree.rootText) {
  const doc = TextDocument.fromSceneItem(tree.rootText);
  for (const paragraph of doc.contents) {
    console.log(paragraph.style.value, paragraph.toString());
  }
}

CRDT sequence #

CrdtSequence is an ordered sequence backed by a topological sort of CRDT items:

import { CrdtSequence, CrdtSequenceItem, CrdtId } from '@robin.berjon/notable';

const seq = new CrdtSequence([
  new CrdtSequenceItem(new CrdtId(1, 1), new CrdtId(0, 0), new CrdtId(0, 0), 0, 'A'),
  new CrdtSequenceItem(new CrdtId(1, 2), new CrdtId(1, 1), new CrdtId(0, 0), 0, 'B'),
]);

seq.values(); // ['A', 'B']

SVG / PDF conversion notes #

SVG conversion renders strokes with pressure, speed, and direction data but text rendering is basic. If text boxes are present:

  • Multi-line text may render on a single line
  • Stroke positions relative to text may be approximate

PDF conversion is pure JS with no external dependencies. Passing several .rm files produces a single PDF with one page per input:

notable -t pdf -o notebook.pdf page1.rm page2.rm page3.rm

Typed text uses the standard base-14 PDF fonts (Helvetica/Times, WinAnsi encoding) when possible. When the text contains characters outside WinAnsi — Cyrillic, Greek, extended Latin — the bundled Noto Sans/Noto Serif fonts (the same families the reMarkable itself renders typed text with, see fonts/) are embedded automatically, with a ToUnicode CMap so text extraction and search keep working. CJK is not covered (the Noto CJK fonts are ~20 MB per face).

reMarkable cloud #

notable can talk to the reMarkable cloud — the same sync service the tablet and the official apps use — so you can pull notebooks down and convert them, push PDFs and notes up, reorganise folders, and keep a local mirror.

Logging in #

Open https://my.remarkable.com/device/browser/connect, copy the one-time code, and run:

notable login            # prompts for the code
notable login abcdefgh   # or pass it directly
notable whoami           # who you are, which hosts, and a connectivity check
notable logout

The code is exchanged for a long-lived device token, stored in ~/.config/notable/cloud.json (mode 0600). The short-lived user token the storage API wants is minted from it, and renewed, automatically. Tokens only ever go to reMarkable's own servers.

Paths #

Cloud commands take paths made of the names you see on the tablet: Folder/Sub/Document. A document's UUID works anywhere a path does. The trash is trash (trash/Old notes), and the root is / or an empty string. Names are matched exactly first, then case-insensitively; two items with the same name in the same folder make a path ambiguous — use the UUID then.

Commands #

Command What it does
ls [path] [-l] [-R] [--json] List a folder (folders end in /; -l adds type, date and UUID)
tree [path] Print the folder tree
info <path> [--json] Metadata, page count and files of a document
get <path...> [-o dir] Download a document's raw files in the tablet's own layout (<id>.metadata, <id>.content, <id>/<page>.rm, …)
get <path...> -t markdown|svg|pdf [-o dir|file] [--stdout] Download and convert instead (one file per document; SVG gets one file per page)
put <file...> [-d folder] [-n name] [-p] Upload: .pdf/.epub become documents, .rm pages and .md/.txt text become notebooks; -p combines the inputs into one multi-page notebook; the destination folder is created if missing
mkdir <path...> Create folders, with any missing parents
mv <path...> <folder> Move into a folder (/ for the root, trash for the trash)
rename <path> <name> Rename
rm <path...> Move to the trash
rm --purge <path...> Delete for good (folders recursively) — there is no undo
restore <path...> [-d folder] Move out of the trash
sync <dir> [-t formats] [--no-raw] [--trash] [--no-prune] [-n] Mirror the account into a directory, see below

Every command accepts --config <file>, --cache <dir> / --no-cache and -v (which traces the HTTP requests).

Mirroring with sync #

notable sync ~/remarkable -t markdown,pdf

produces, for every document, a directory of its raw files next to the converted copies:

~/remarkable/
  .notable-sync.json          what was synced, for the next incremental run
  Work/
    Meeting notes/            raw files (tablet layout)
    Meeting notes.md
    Meeting notes.pdf
  Quick sheets/
  Quick sheets.md

Only documents whose content changed are fetched again; renamed or moved documents are moved locally rather than re-downloaded; documents that disappeared from the cloud are removed locally (--no-prune keeps them). Trashed documents are skipped unless you pass --trash, which puts them under trash/. --no-raw keeps just the converted copies, -n shows what would happen without touching anything. Sync is one-way (cloud → disk).

Library #

import { RemarkableCloud } from '@robin.berjon/notable';

const cloud = RemarkableCloud.open();            // reads ~/.config/notable/cloud.json
if (!cloud.api.loggedIn) await cloud.api.login('abcdefgh');

await cloud.refresh();                           // fetch the document tree
for (const doc of cloud.tree.children()) console.log(doc.name + (doc.isFolder ? '/' : ''));

const notes = await cloud.docOf('Work/Meeting notes');
const pages = await cloud.pages(notes);          // [{ id, file, data: Buffer|null }]
const { data: markdown } = await cloud.export(notes, 'markdown');
await cloud.download(notes, './meeting-notes');  // raw files

const folder = await cloud.mkdir('Work/2026');
await cloud.upload('paper.pdf', { parent: folder, name: 'A paper' });
await cloud.uploadPages([rmPage1, rmPage2], { parent: 'Work', name: 'Two pages' });
await cloud.move('Work/A paper', 'Work/2026');
await cloud.rename('Work/2026/A paper', 'The paper');
await cloud.trash('Work/2026/The paper');
await cloud.restore('trash/The paper', 'Work');
await cloud.purge('Work/The paper');             // permanent

await cloud.sync('./remarkable', { formats: ['markdown'], onEvent: console.log });

RemarkableCloud.open(options) takes configPath, cacheDir (or null), config (an in-memory token object), fetch, log and concurrency. The lower layers are exported too: CloudApi (root/blob HTTP calls with token renewal and the blob cache), the index-file parser/serialiser and hashing rules in cloud.parseIndex / cloud.docIndex / cloud.rootIndex, and the .metadata / .content builders in cloud.newMetadata, cloud.notebookContent, cloud.fileContent.

Configuration #

What Default Override
credentials ~/.config/notable/cloud.json --config, NOTABLE_CONFIG, XDG_CONFIG_HOME
blob cache ~/.cache/notable/blobs/ --cache, --no-cache, NOTABLE_CACHE, XDG_CACHE_HOME
cloud hosts reMarkable's login --host <url> (saved), NOTABLE_CLOUD_HOST (one host for everything, e.g. a self-hosted rmfakecloud), or NOTABLE_AUTH_HOST + NOTABLE_SYNC_HOST

The cache is content-addressed (blobs never change once written), so it can be cleared at any time and only costs re-downloads.

How it works, and caveats #

The cloud is a content-addressed blob store with a single mutable pointer per account. The root points at an index listing every document (its UUID, hash, file count and size); each document is itself an index of its files, and every file is a blob named by its SHA-256. A document's hash is the SHA-256 of its files' hashes, the root's is the SHA-256 of its index text (schema 4). Writes upload the new blobs and indexes, then move the root pointer with the generation last read; if the tablet or another app moved it first, the server answers 412 and notable re-reads the tree, re-applies the change and retries. Every root write asks the cloud to broadcast the change so the tablet picks it up.

  • This is the unofficial API that rmapi, rmfakecloud and friends reverse engineered; reMarkable can change it at any time.
  • PDF/SVG export renders the ink and typed text only. For an annotated PDF or EPUB you get the annotations, not the underlying pages; download the raw files (get without -t) if you need the original.
  • Uploaded notebooks use the v6 page format and formatVersion: 2 content, so they need reMarkable software 3.x on the tablet (which is what .rm v6 needs anyway).
  • rm --purge removes the document from the root index. The cloud keeps the orphaned blobs around for a while; notable does not try to collect them.
  • .rmdoc bundles are not produced; get writes the same files unzipped.

In the browser #

@robin.berjon/notable/browser (lib/browser.js) is the part of the library that needs no Node: reading and writing blocks, the scene tree, the page renderer (pagePaint, lineSegments), the SVG and Markdown exporters, and the page editor below, for pages of any of the three versions. Bytes go in and out as Uint8Array (on Node they come back as Buffers, which are Uint8Arrays, so nothing changes there). The PDF exporter and the cloud client stay in the main entry.

Editing a page #

PageEditor holds a page's blocks and lets you add and erase strokes the way the tablet does: every stroke is a CRDT item in a layer's sequence, with an id made of an author index and a counter; erasing one leaves a tombstone, so copies of the page merge. The app's notebook editor is built on it, and it is what the cloud client's savePage, addPage and createNotebook write.

import { PageEditor, blankPage, makeLine, Pen, PenColor } from '@robin.berjon/notable/browser';

const page = PageEditor.parse(bytes);            // or PageEditor.blank({ authorUuid })
const author = page.authorIndex(myUuid);         // registered in the page if new
const key = page.addLine(makeLine({
  tool: Pen.FINELINER_2, color: PenColor.BLUE, thickness: 2,
  points: [{ x: -100, y: 300, pressure: 180, width: 8 }, { x: 20, y: 310, pressure: 200, width: 8 }],
}), { author });
page.strokes;                                    // [{ key, layer, line }]
page.removeStroke(key);                          // a tombstone; restoreStroke(key, line) undoes it
page.dropLine(key);                              // gone without trace (an undo of your own latest stroke)
const out = page.write();                        // bytes for `<page>.rm`

Coordinates are the tablet's: the page is 1404 wide (x from −702 to 702) and 1872 tall. A point's pressure (0–255), speed, direction (0–255, the tilt) and width (the pen's size at that point, about 8 for a medium pen) feed the pens' rendering formulas, so a stroke from a mouse looks right if you fill them in plausibly; app/src/ink.ts shows how the app does it.

The desktop app #

Notable is a mollusc app: mollusc.json at the root of the repository describes it, app/ holds the page (Lit, on supram, bundled by Vite) and the sidecar (app/sidecar/server.js), a small token-checked HTTP API around the cloud client that the page talks to. Credentials are the same cloud.json the CLI uses, so pairing once serves both.

npm install
npm run app          # mollusc dev .: Vite, the sidecar and the window, reloading on change
npm run app:build    # installers in out/ (macOS verified; Windows and Linux through the same config)

What it does:

  • Library. Folders, documents and the trash, as cards with the tablet's thumbnails or as a list; search; drag documents onto folders, the breadcrumb or the sidebar to move them; drop PDFs, EPUBs, .rm pages or text files on it to upload. Rename, move, trash, restore, delete for good.
  • Notebooks. Pages drawn from their .rm bytes, in the browser, with the common templates behind them. Draw with a mouse, trackpad or pen (pressure and tilt are kept) using the tablet's pens, colours and three widths; erase whole strokes; undo and redo; add and delete pages; change a page's template. Pages save themselves a few seconds after a change (⌘S saves now), along with a fresh thumbnail, and the tablet picks them up as its own. Strokes carry an author id made once per install, kept in app.json next to cloud.json.
  • PDFs. pdf.js's viewer with its editors turned on: highlight text, place text boxes, draw, add images; undo and redo; save writes the annotations into the PDF on the cloud. The handwriting the tablet keeps beside a PDF is drawn over the pages (toggle it with Tablet ink); it is shown, not edited, there.
  • Export and download. Any document to Markdown, SVG or PDF, or its raw files, to a place you pick.
  • Mirror. The sync command as a dialog: a folder, the formats to convert to, whether to keep raw files, include the trash, prune; a dry run to see what would happen; the log as it goes.
  • Account. Pair with a one-time code, see who you are paired as, disconnect.

Caveats, beyond the cloud ones above: the templates drawn behind a page are approximations of the common ones (the tablet draws the real ones); EPUBs open on their handwritten pages only, with no text behind them; and the overlay of tablet ink on a PDF assumes the tablet fitted the page to its width, which is what it does for the usual page sizes.

Running tests #

npm test             # unit tests, including the sidecar against the mock cloud
npm run e2e          # the desktop app itself: pairing, drawing, saving, a PDF; needs mollusc and a display
npm run typecheck    # the page's TypeScript

Tests cover binary round-trips of the test .rm files and the full test notebook, version 3 and 5 pages from a tablet, block serialisation, CRDT sequence ordering, text extraction, inline formatting, pen models, page editing (ids, authors, tombstones), and SVG/PDF export (including embedded-font PDFs). The cloud client, the CLI and the app's sidecar are exercised end to end against an in-process mock of the cloud (test/helpers/cloud-server.js) that applies the real service's validation rules: generation checks on the root pointer, CRC32C and SHA-256 checks on blobs, sorted schema-4 root indexes. npm run e2e drives the built app (through mollusc's smoke mode) against the same mock and checks what reached it; NOTABLE_E2E_SHOTS=<dir> makes it drop screenshots there.

Acknowledgements #

This is a JavaScript port of:

  • rmscene by Rick Lupton — the core .rm v6 parser
  • rmc — the CLI converter

The binary format was reverse-engineered with help from ddvk's reader.