Architecture

How Tangle reconstructs a table from a screenshot

Paste a screenshot of a spreadsheet into Tangle and you get back an actual Markdown table — columns aligned, headers intact — not a wall of OCR’d text with the spacing guessed wrong. Apple Vision, the on-device OCR engine behind it, doesn’t give you that for free. It gives you a flat list of text observations, each with a bounding box and nothing else. Whether those boxes form a table, two columns of unrelated text, or just a paragraph is entirely on the caller to figure out.

Rows first, then columns

The reconstruction works in two passes over the bounding boxes. First, Y-clustering: group text observations into rows based on vertical position, since a real row’s cells all sit at roughly the same height regardless of how many columns the table has. Second, column anchors via largest-gap analysis: look at the horizontal positions across all the detected rows and find the gaps between them — the largest, most consistent gaps mark where one column ends and the next begins. Each cell then gets assigned to the column slot it falls into, and the result renders straight to a Markdown table.

The harder problem: knowing when not to do this

A table detector that fires on anything resembling columns is worse than no detector — two-column body text, a list with a trailing date, a caption under an image, all have “stuff with gaps in it” if you squint. Tangle guards against false positives with a few concrete thresholds:

  • Max cell width 40% of the image width — a real table cell doesn’t span nearly the whole row.
  • Row-gap consistency — the coefficient of variation across row gaps has to stay under 0.55, so a loose, irregular layout doesn’t get mistaken for a grid.
  • Two-column layouts get an extra check — cells have to average five words or fewer, specifically to tell an actual two-column table apart from ordinary newspaper-style text columns, which also produce two roughly-aligned blocks of text but aren’t a table at all.

None of these are exotic machine learning — they’re straightforward geometric heuristics tuned against real screenshots until the false-positive rate on plain text dropped to zero without losing real tables.

A smaller trick that reuses the same data: bold detection

The same bounding boxes are also how Tangle figures out what text was bold in the original image, which OCR doesn’t report directly either. Each text region gets cropped to a small grayscale bitmap, and Tangle computes the dark/light pixel density, normalized so it works for both light-on-dark and dark-on-light text. Anything with a density more than 50% above the document’s median gets flagged as bold and wrapped in **asterisks** in the output — in table cells and body paragraphs alike, though headings are exempt since they’re already visually distinct without it.

All of this — table reconstruction, bold detection, the OCR itself — runs locally through Apple Vision. Nothing in a screenshot you paste into Tangle ever leaves the Mac. Tangle is open source, if you want to see the actual bounding-box math: github.com/danielecostarella/tangle.