A share card from a selection

Select a passage in the article. The card under it shows the passage, with its emphasis, in the largest type that fits. The card is an HTML figure styled with CSS and drawn by a canvas, so it can be saved, shared or copied as a PNG.

Commonplace books

A commonplace book is a notebook of passages copied out of other books. Readers have kept them for centuries, and the copying was the point: writing a sentence out by hand was a way to keep it.

John Locke published a method for indexing one, so that a passage copied years earlier could be found again by its subject. A quotation is only useful if it can be found.

Sharing a sentence from a web page is the same habit. The reader selects it and sends it to someone, usually as plain text and sometimes as a picture of the text.

Commonplace books
Show the code the figure, the quote, the fit and the export
  1. The card is a figure inside a canvas.
  2. The canvas on the page.
  3. The three styles are CSS: gradients, background-clip: text, text-wrap: balance, shadows.
  4. The selection as a quote, with emphasis kept and everything else flattened.
  5. The largest type that fits, measured with scrollHeight on the figure.
  6. Draw the figure at the size of the picture.
  7. Make the PNG.
  8. Save, share and copy.

How it works

The figure is a drawable child of a canvas with layoutsubtree, so the browser lays it out and styles it like any element, and scrollHeight on it reports whether the quote fits. The figure is 600 by 315 CSS pixels for the link preview size. The canvas bitmap is 1200 by 630, and drawElementImage(figure, 0, 0, 1200, 630) draws the figure at twice its layout size. canvas.toBlob() gives the PNG. The selected text is copied with Range.cloneContents(), keeping em, strong and code and flattening everything else.

Live checks

These start when you press the button. They build their own cards.

Findings

Measured in headless Chromium 157 on Linux with a software renderer, 2026-11-21.

Not verified: navigator.share() with a file and writing a PNG to the clipboard (the headless browser has neither a share sheet nor clipboard permission), and how the saved picture looks in a messaging app.