Skip to content

docx-grader: annotated page images, feasibility prototype (AI-Assisted) - #390

Open
bh0fer wants to merge 18 commits into
feature/docx-grader-rawfrom
feature/docx-grader-annotations
Open

bh0fer wants to merge 18 commits into
feature/docx-grader-rawfrom
feature/docx-grader-annotations

Conversation

@bh0fer

@bh0fer bh0fer commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Part 4 for #385, stacked on #388 (← #387 ← #386). It evaluates whether annotated page images of the original can be generated for the checks picked in the docx-spec, using the Excalidraw markup convention of @tdev/excalidoc, and ships a working prototype.

Result: feasible, with two manual steps

Word documents have no layout of their own, so the page images need a layout engine. Word or LibreOffice don't run in the CLI, and JS docx renderers are not exact. The prototype therefore takes the original exported as PDF from Word (one click for the teacher, pixel-exact):

yarn workspace @hfr/docx-grader annotate docs/word/original.docx --pdf docs/word/original.pdf

For every page it writes:

  • original-annotated-<n>.webp.excalidraw: the page is the background image (PNG, TDEV-BACKGROUND-IMAGE / TDEV-BACKGROUND--FILE, built by the new pure helper backgroundImageScene in excalidoc, which createExcalidrawMarkup now uses too). The labels, arrows and frames are ordinary, editable elements in Excalidraw's «Normal» font. The scene exports at scale 4 with a padding of 4 (exportPadding is now part of excalidoc's CustomData).
  • original-annotated-<n>.webp: a fixed placeholder (blurred page, "open in the image editor, check and save"). The teacher opens each image in the image-markup editor, checks the labels and saves; the editor's WebP export replaces the placeholder. There is no CLI-rendered preview, so there is no second renderer of the layout and no sharp.

How it works:

  1. pdf.js renders the pages and gives the text positions; pdfjs-dist and canvas are already in yarn.lock through react-pdf.
  2. Each check's anchors are located by comparing letters and digits only, so ligatures, hyphenation and line breaks don't matter.
  3. Occurrences of repeated text (e.g. TOC or list-of-figures entries before their heading or caption) are counted in the docx model.
  4. Headers and footers are recognized by Word's PDF tags (Artifact), and searched only for header/footer checks. Untagged PDFs fall back to the margins of the first section.
  5. Labels go to a column right of the page, one arrow per place and page; several checks on the same place share a label. Labels are built from each check's expectation (shared with its title), without the anchor text.
  6. Arrows run through the right margin to the end of the line, so they cross no text; text that doesn't end its line (character formats, columns) is framed.
  7. Items without a place on the page are listed in orange above the first page.

Grading changes in this PR

These change what students see and are not part of the annotation prototype:

  • Image width is checked exactly (±0.05 cm for rounding) instead of ±0.3 cm: the width must be typed in Word's width field; an image resized by dragging now fails.
  • Quoted text uses "" instead of «» in titles and messages (quote()); «» are kept for names of styles. Check ids derive from titles, so regenerating a spec changes the ids of section checks (e.g. -cc5c6d → -e4af02); no spec on main is affected yet.

Verified

  • 65 package tests (full suite 925), typecheck, prettier.
  • The real @excalidraw/excalidraw (bundled from this repo, in headless Chromium) restored and exported the generated scenes (checked before the placeholder change; the scene format has since gained the typed element fields index, startBinding, endBinding, lastCommittedPoint).
  • Real Word PDF exports from the issue (ex01, 1 page; Week2, 11 pages): headers, footers, headings, captions and character formats are located correctly.
  • README example: assets/ex01-what-is-programming-annotated-1.webp.excalidraw, generated from the Word PDF in assets/, and next to it the image editor's export (.webp).

Open / not verified

  • Mac Word's PDF export (different engine, maybe untagged) was not tried.
  • Frames and arrows for character formats use equal character widths, so they can be off by a few characters.
  • Reading order of multi-column sections, text boxes, floating shapes and tables. A wrong order means "label in the list above page 1", not a wrong arrow.
  • Without Word's tags, only the first section's margins separate headers and footers from the body.
  • PDFs without embedded fonts: rendering in Node without standardFontDataUrl was not tested.
  • Labels are correct but can be wordy; they are meant to be shortened in the editor.
  • The page image is stored as PNG inside the .excalidraw (about 550 KB per page for the example), which grows the repository.
  • canvas is an optional dependency: yarn install doesn't fail without it, and the CLI explains what's missing.

Decisions

  • No CLI preview: a placeholder until the scene is saved in the editor (manual step).
  • A PDF export from Word is the required input; no LibreOffice conversion.

🤖 Generated with Claude Code

lebalz and others added 2 commits November 18, 2026 23:03
annotate renders each page of the original's PDF export and writes an
image with labels for the spec's checks, plus an editable Excalidraw
scene with the page as TDEV-BACKGROUND--FILE (#385).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- excalidoc's backgroundImageScene builds the scene for both the markup
  editor and the annotate CLI
- leave header and footer bands out when locating body text
- canvas is an optional dependency, loaded only by the annotate CLI

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bolt-new-by-stackblitz

Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@lebalz
lebalz added this pull request to stack #389 November 18, 2026 22:11
@netlify

netlify Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for teaching-dev ready!

Name Link
🔨 Latest commit 8cd528b
🔍 Latest deploy log https://app.netlify.com/projects/teaching-dev/deploys/6afedfbe85b77f9376b28fd5
😎 Deploy Preview https://deploy-preview-390--teaching-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bh0fer
bh0fer requested a review from a team November 18, 2026 22:16
lebalz and others added 15 commits November 18, 2026 23:23
General notes are an orange list at the top left of the first page.
sharp encodes webp and is an optional dependency like canvas.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Notes without a place on the page use font size 20. Labels name the
paragraph style only once, e.g. «Überschrift 1». «» is kept for styles.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Students set the width in the size field, so dragged sizes should fail.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ut them

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ing titles

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… the editor, drop sharp

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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