Skip to content

Expose keywords/links/pageId/orientation/recognitionStatus to OCR plugins - #146

Merged
philips merged 2 commits into
mainfrom
ocr-plugin-context-fields-issue-145
Jul 29, 2026
Merged

Expose keywords/links/pageId/orientation/recognitionStatus to OCR plugins#146
philips merged 2 commits into
mainfrom
ocr-plugin-context-fields-issue-145

Conversation

@philips-clanker

Copy link
Copy Markdown
Collaborator

Summary

Implements the field additions discussed in #145 (a follow-up from #144's prototype, which found the registerPageTextProcessor hook couldn't reproduce PR #122/#123's native keyword-star/link handling from outside the plugin).

Extends PageTextProcessorContext with:

  • keywords: string[] - this page's starred keywords, raw OCR'd text, deduplicated
  • links: ILink[] - this page's own internal links, same-file anchors already resolved
  • pageId: string - this page's own PAGEID
  • orientation: string - this page's orientation as recorded in the .note file
  • recognitionStatus: RecognitionStatuses - whether recognition ran/completed on this page, distinguishing that from text being merely empty

keywords/links are grouped per page using the same "first 4 characters of the sn.keywords/sn.links Record key = 1-indexed page" convention supernote-typescript's _parseLinks already documents (more reliable than IKeyword.KEYWORDPAGE, which can be '0'/invalid).

Titles were considered and dropped from this pass - ITitle has no decoded text (only TITLERECT + a bitmap), so producing title text would need correlating that rectangle against page.recognitionElements' word-level boxes, which is new logic, not just wiring through an existing field. Left for a follow-up once that's designed.

Stacked on supernote-typescript#38, which exports RecognitionStatuses from that library's index (needed so recognitionStatus can be typed as the real enum rather than a bare string) - this PR's submodule pointer currently points at that branch, not main. Rebase the pointer once #38 merges.

Test plan

  • npm run build (both submodule and plugin) - clean
  • npx tsc --noEmit - clean
  • npx eslint src/main.ts - 0 errors
  • npx vitest run - 95 passed
  • Manually verified collectPageKeywords/collectPageLinks against a real device-created fixture (supernote-typescript/tests/input/nomad-3.26.40-link-tag-3p.note) - keywords landed on the correct page (3), links resolved to the correct target pages (2), pageId/orientation/recognitionStatus all populated as expected
  • Manual test in Obsidian: a companion plugin registering a processor and logging ctx.keywords/ctx.links/ctx.pageId/ctx.orientation/ctx.recognitionStatus against a real note with starred keywords and internal links

…gins

Extends PageTextProcessorContext (registerPageTextProcessor's hook, see
ocr-plugins.md) with per-page fields an external companion plugin has
had no way to see until now: starred keywords, internal links, PAGEID,
orientation, and recognition status. Previously the hook only exposed
a flat OCR-text string and rasterized image bytes, which was enough to
reproduce the OCR-text-pattern half of #123 but not #122's genuine
keyword-star/link handling - see the discussion on #145.

sn.keywords/sn.links are grouped per page using the same
first-4-characters-of-the-Record-key convention supernote-typescript's
_parseLinks documents (more reliable than IKeyword.KEYWORDPAGE, which
can be '0'/invalid). Verified against a real device-created fixture
(supernote-typescript/tests/input/nomad-3.26.40-link-tag-3p.note).

Titles were considered too (same "device-native structured signal"
category as keywords/links) but dropped from this pass: ITitle has no
decoded text, only a bounding box + bitmap, so getting title text needs
correlating that box against page.recognitionElements' word boxes -
real new logic, not just wiring through an existing field.

Bumps the supernote-typescript submodule pointer to a branch (not yet
merged) that exports RecognitionStatuses from its index, needed to
type the new recognitionStatus field as that enum rather than a bare
string - see supernote-typescript#38.
Now that #38 (export RecognitionStatuses) merged to main, point at
that rather than the feature branch it landed via.
@philips
philips merged commit f662900 into main Jul 29, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants