Arsh Shah

Day 5: Redline, every word that changed between two versions of a contract

Lab · · Demo

The version that comes back is never quite the version you sent. Usually the changes are fine. Sometimes a "not" is gone.

Redline takes two versions of the same text, before and after, and marks every word that changed. Strikethrough for what got cut, underline for what got added. Under that you get a table, one row per change, with a few words on each side so you can find it.

Some rows get flagged, because they're the ones I'd read first:

The flags are regexes, simple text patterns that look for those words. They don't read the clause. An unflagged change can still be the one that costs you, and the page says so. Read every row.

Under the hood it's a Myers diff, a standard way to find the smallest set of edits that turns one text into the other. Git, the tool most programmers use to track code changes, uses it by default on lines. Redline runs it on words. It runs in your browser, and nothing gets sent anywhere. If two versions are so different they'd need more than 3,000 word-level edits, it tells you to go one section at a time instead of eating your memory.

['a "not", "no", or exception', /\b(not|no|never|none|nor|without|except|unless|notwithstanding|neither)\b|n't\b/i],

It's 79 lines of JavaScript for the logic and 46 lines of HTML for the page, about 9 KB in all. I threw 200 random edit sets at it, and it rebuilt both versions exactly every time. A made-up 400-clause contract (about 24,000 characters) with four changes diffed in about 10 milliseconds in Node, which runs JavaScript outside the browser.

Hit "Load a made-up example" to see it on a fake license clause. The territory, the term, the payment window, exclusivity and a "may not assign" all change. Seven changes, seven flags.

Thing that broke: the context column came out blank. Every unchanged word and every space was its own chunk, so "the words around this change" was a single space. Had to glue the unchanged runs together before grabbing context.

Thing that surprised me: contract number style. "two (2)" to "five (5)" is one edit to a person and two rows here. I left it.