# #34 M6: Illustrations travel with it (S6.2) — inline rewrite > **Date:** 2026-11-01 > **Type:** issue > **Reference:** [git.babylondreams.de/AlexKucera/museion#34](https://git.babylondreams.de/AlexKucera/museion/issues/34) ## Goal Ink-sketch PNGs in a Post's `assets/` upload to Micro.blog via the Micropub media endpoint and travel with the piece, with alt text — G12: the author judges style, the mentor never assesses images. AC floor: a photo without alt text never ships. ## What Was Done - `Museion/MicropubMedia.swift` (new) — `nonisolated extension Micropub`: `illustrations(in:)` parses `![alt](assets/…)` refs (one shared single-line-alt regex), `rewritingIllustrations(_:uploaded:)` builds the wire body, `mimeType(forDestination:)` (the endpoint's exact formats), `makeConfigRequest` (q=config), `makeMediaUploadRequest`/`uploadMedia` (multipart `file` POST, per-request boundary, sanitized Content-Disposition filename; Location → body url → trust-gated decode). - `Museion/Micropub.swift` — `micropubSendDraft` routes through the private `uploadIllustrations` rail: alt floor → pre-flight (mime gate, symlink-resolved path containment, one payload per FILE) → q=config → one upload per file → refs rewritten in place; `makeDraftRequest`/`sendDraft` back to the exact #33 shape (no photos param, no photo property keys). - `MuseionTests/MicropubMediaTests.swift` (new) + `MicropubModelTests.swift` — 15 pins: parse/rewrite (position, alt verbatim, quoted-title drop, angle form, boundaries, multi-line agreement), mime matrix, multipart bytes, decode gates, three-hop order, whitespace-alt floor, symlink refusal, duplicate-destination upload-once, no-photo-keys-ever, no-illustration single request. - Live dogfood (alexanderkucera.com, 2026-11-01): upload + attach worked; the shipped photo-PROPERTY transport rendered the image at the BOTTOM of the post — position lost. Fixed by swapping to inline URL rewriting (refs keep their place, alt rides the markdown). - Finish-audit (3 fresh-context reviewers): 7 findings fixed — markdown injection via upload URL (angle-form destination), symlinked-asset exfiltration (resolvingSymlinksInPath containment), duplicate-ref double upload (per-file payloads), whitespace-alt pin gap (#6 class), rewrite boundary pins, mime matrix completion, regex recompile (`static let`). All four behavior guards flip-verified in one batch cycle (4 pins failed on their own guards, restored, green). - Ticket #141 published (drop-image-onto-editor ingest UX, blocked by #34) after a design discussion — alt type-over placeholder, slugged filenames, saved-posts-only, prose-only. ## Decisions & Rationale | Decision | Rationale | |----------|-----------| | INLINE URL rewrite, no `photo`/`mp-photo-alt` property | Live dogfood proved the property renders wherever the theme decides (bottom); inline refs preserve position, alt rides the markdown, and sending both would double-render. Net code smaller than the property shape. | | Angle form `![alt]()` when the URL carries `()<> ` chars | `trustworthyURL` was built for line-bounded frontmatter; a `)` in a plain-paren destination closes the image early and smuggles a live attacker link. Angle form caps worst case at broken rendering. | | One payload per FILE (duplicate refs share it) | Header+footer refs to one asset uploaded twice and orphaned the first URL; iterating the deduped payload list is shorter than the per-ref loop it replaced. | | Symlink-resolved containment | Lexical `standardizedFileURL` prefix passes a symlinked `assets/` — the bytes would upload off-machine under the writer's token. Matches the cards/learnings symlink posture. | | Floor at the rail only (chokepoint guard deleted) | With no photos param, a parsed body ref is the ONLY way an image ships and every send routes through the rail — a second guard defended nothing (#6's rule applied honestly, not reflexively). | | Regex stays NSRegularExpression (`static let`) | The Regex-literal conversion rewrites a coordinate system three reviewers' probes verified correct; the free hoist kills the only real cost (recompile per access). | | #141 own ticket, not a #34 rider | Ingest UX is new surface beyond #34's ACs; #34 closes clean. | ## Gotchas & Fixes | Problem | Root Cause | Fix | |---------|------------|-----| | Published image rendered at post bottom, not where placed | Ref stripped from wire body; image attached as a `photo` property, which the theme renders wherever it wants | Rewrite refs in place with uploaded URLs (the flagged interpretation choice, settled by dogfood) | | Build error "Unprintable ASCII character" | A patch inserted a literal TAB byte inside a Swift string literal instead of the `\t` escape | Byte-exact Python replace (patch-tool fuzzy matching can't be trusted with invisible bytes) | | `mark` lint violation from a comment | A test comment line began `// MARKDOWN` — the rule matches `// MARK`-prefixed lines loosely | Reworded the comment | | `large_tuple` violation | Per-file payload list as a 3-tuple | Private `Payload` struct inside the rail | | Restore-after-flip aborted mid-script | Restore tuple ordered `(old='', new=…)` — empty old_string asserts against 15k matches | Insert-before-anchor restore with `count==1` anchors, re-verified markers | | UI smoke test red for ~30 min (61s activation timeout) | #134-class window-server state (app itself proven to launch and stay alive; failure survived isolation + testmanagerd restart) | Nothing — cleared on its own before the final verification run (546/546) | ## Files Changed | File | Change Summary | |------|---------------| | `Museion/MicropubMedia.swift` | NEW — parse/rewrite/mime/config/multipart media surface | | `Museion/Micropub.swift` | Illustration rail in `micropubSendDraft`; draft request back to #33 shape | | `MuseionTests/MicropubMediaTests.swift` | NEW — 11 media-surface pins | | `MuseionTests/MicropubModelTests.swift` | +6 #34 model pins incl. floor, symlink, duplicate | | `Museion/AGENTS.md`, `MuseionTests/AGENTS.md` | DOX: the inline-rewrite contract + pin inventory | | `AGENTS.md` (root) | GitNexus stats line + session-log window | ## Verification - Full suite **546 executed / 546 passed / 0 failed** (xcodebuild macOS, xcresult-counted) — 529 baseline + 17 net new - Flip cycle: all four audit guards disabled in one batch → exactly the four pins failed → restored → green - swiftformat 0 dirty; swiftlint clean on all touched files - GitNexus detect-changes (intended Micropub family + docs only) + analyze re-run ## Open Items & Next Steps - [ ] One live re-publish of an illustrated piece (Send Again → Publish) to see the inline position on the real blog — then close #34 - [ ] #34's AC1 wording says "attaches as photo" — mechanism is now inline; amend or accept on close - [ ] #141 (drop image onto prose editor) unblocks when #34 closes — filename slugging must keep the space-free destination contract - [ ] v2 candidates (declined): upload dedup via q=source on re-send, HEIC conversion, host-allowlist for trustworthyURL --- *Log written by write-log skill*