feat(spellcheck): underline possible mistakes in transcriptions (#53, part 1) #58

Merged
jfro merged 12 commits from feat/53-spellcheck into main 2026-10-27 13:11:21 +00:00
Owner

Part of #53: spelling and grammar underlines in a page's transcription. Marks on the handwriting follow in a stacked PR (feat/53-ink-marks).

What it does

  • Settings → OCR: a LanguageTool server and language (en-US by default) with a Test button. LANGUAGETOOL_URL wins over the setting; a URL typed in the UI can't reach private or reserved networks (Backups.Network), only the env var can.
  • Check spelling in the transcription header (when a server is set up, not on backup pages): checks the page in the background, lists each possible mistake with its word, message and up to 3 suggestions, and underlines them in the text with the CSS Custom Highlight API (red for spelling, blue for grammar). Pressing it again hides them; an edit or a page change drops them.
  • Checked once per transcription + text + language (spellcheck_results); text with no words is never sent.
  • One shared word list (Spellcheck.Words), whitespace-delimited and trimmed of edge punctuation, so 10:30, e.g. and and/or are one word each, as they are one word of ink. The OCR's guesses (teh [?]), [illegible], struck text, code, links, list markers and symbol runs aren't checked.
  • The JS hook lines up the checked text with the rendered text without whitespace; if they differ it underlines nothing (and warns in the console) rather than the wrong words.
  • Backups.Network now also refuses ::/96, 2001::/32 (Teredo) and 2002::/16 (6to4). Armstrong's SSRF audit test is in as test/rm_analyzer/spellcheck_ssrf_test.exs.
  • Logger diagnostics on every LanguageTool call (status, language, length, duration).
  • Docs: docs/spellcheck.md, README.

Checked

  • mix precommit: 947 pass.
  • A real run against LanguageTool 6.8 in Docker, in Chromium at 1280px and 390x844: 3 spelling + 2 grammar hits underlined on the right words; teh [?], 10:30, e.g. and & left alone; hiding clears the underlines.

Migrations

20261027120000 (spellcheck settings), 20261027130000 (spellcheck results).

Part of #53: spelling and grammar underlines in a page's transcription. Marks on the handwriting follow in a stacked PR (feat/53-ink-marks). ## What it does - **Settings → OCR**: a LanguageTool server and language (en-US by default) with a Test button. `LANGUAGETOOL_URL` wins over the setting; a URL typed in the UI can't reach private or reserved networks (`Backups.Network`), only the env var can. - **Check spelling** in the transcription header (when a server is set up, not on backup pages): checks the page in the background, lists each possible mistake with its word, message and up to 3 suggestions, and underlines them in the text with the CSS Custom Highlight API (red for spelling, blue for grammar). Pressing it again hides them; an edit or a page change drops them. - Checked once per transcription + text + language (`spellcheck_results`); text with no words is never sent. - One shared word list (`Spellcheck.Words`), whitespace-delimited and trimmed of edge punctuation, so 10:30, e.g. and and/or are one word each, as they are one word of ink. The OCR's guesses (`teh [?]`), `[illegible]`, struck text, code, links, list markers and symbol runs aren't checked. - The JS hook lines up the checked text with the rendered text without whitespace; if they differ it underlines nothing (and warns in the console) rather than the wrong words. - `Backups.Network` now also refuses `::/96`, `2001::/32` (Teredo) and `2002::/16` (6to4). Armstrong's SSRF audit test is in as `test/rm_analyzer/spellcheck_ssrf_test.exs`. - Logger diagnostics on every LanguageTool call (status, language, length, duration). - Docs: `docs/spellcheck.md`, README. ## Checked - `mix precommit`: 947 pass. - A real run against LanguageTool 6.8 in Docker, in Chromium at 1280px and 390x844: 3 spelling + 2 grammar hits underlined on the right words; `teh [?]`, `10:30`, `e.g.` and `&` left alone; hiding clears the underlines. ## Migrations `20261027120000` (spellcheck settings), `20261027130000` (spellcheck results).
Spellcheck.Words.read/1 walks the Markdown (MDEx) to the text the checker
and the browser see, and its tokens with UTF-16 offsets: words, the OCR's
guesses and [illegible], struck words, code, link addresses, and markers
for list bullets, numbers and checkboxes, so word_index means the same
thing for the underlines and the ink marks. Ignored ranges keep hits off
everything but plain words.

Refs #53
Spellcheck.LanguageTool.check/3 posts a text to a LanguageTool server's
/v2/check and normalises its hits (offsets in UTF-16, kind spelling or
grammar, up to 5 replacements; style suggestions left out). Each call is
logged with the host, language, length, status, duration and hit count.
The test fixture is a real LanguageTool 6.8 answer.

Refs #53
Armstrong's review: 10:30, e.g., and/or are one ink box each, so they're
one token, trimmed of edge punctuation; a run with no letter or digit is
a :symbol token (ink, not checked).
Spellcheck.check_page/2 sends a transcription's plain text (Words) to the
user's LanguageTool, keeps the hits on checked words with the word
indexes they cover, and stores the result (spellcheck_results), so the
same text and language is never sent twice. Another user's transcription
is refused; text with no words isn't sent.
feat(spellcheck): underline possible mistakes in a page's transcription
All checks were successful
CI / test (pull_request) Successful in 1m25s
e953dd1c07
"Check spelling" checks the page on demand and lists its hits; the Spelling
hook underlines them with the CSS Highlight API, only when the rendered text
lines up with the text checked. Closes the UI part of #53.
jfro added this to the v1.6.0 milestone 2026-10-27 02:37:37 +00:00
Author
Owner

Browser check by me (Chromium, real LanguageTool 6.8):

Desktop 1280px:
desktop

Phone 390x844:
phone

Nye still does the QA pass.

Browser check by me (Chromium, real LanguageTool 6.8): Desktop 1280px: ![desktop](https://git.knope.dev/attachments/5e3c2b47-5af2-44ab-a2ee-df4750735fad) Phone 390x844: ![phone](https://git.knope.dev/attachments/bbc91e88-24b4-4e7d-bd63-b0533139e5b8) Nye still does the QA pass.
keep/1 inserts through a changeset with the foreign keys, so a transcription
deleted while LanguageTool answers returns {:error, "that page is gone"} and
logs the ids. The cache hash includes Words.version/0, dropped hits are
counted at debug, and a non-200 body is logged by its first line only.
Adds Armstrong's audit test (F4).
style: format the spellcheck audit test
Some checks failed
CI / test (pull_request) Failing after 1m25s
9b6b833b84
test: leave the live LanguageTool test out unless asked (--include live_lt)
All checks were successful
CI / test (pull_request) Successful in 1m25s
609948c460
Words.inline compared a link's url against "mailto:" <> url (backwards)
and missed www. autolinks (url "http://" <> literal), so both were
checked as words. A comma straight after **bold** or a link was its own
token although it's one word of ink. Words.version goes to 2.
Also documents mix test --include live_lt.
jfro merged commit f8f70ba23a into main 2026-10-27 13:11:21 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
jfro/rm-analyzer!58
No description provided.