WORK-077
ID:WORK-077Status:done

Extract Shared Media Image Unwrap Utility

Priority:highComplexity:simpleSource:SPEC-028
changeset-release/main View source

Criteria completion

No incremental history — criteria tracking started on Apr 19.

Branches 2
changeset-release/main current done
main doneclaude/file-naming-convention-LJdwR done
History 5
  1. f2b3512
    Content editedby Claude
    Add {ID}-{slug}.md filename convention + migrate filenames subcommand
  2. 59ded4a
    Content editedby Claude
    Implement SPEC-037 plan package hardening: all 7 work items
  3. f262d7b
    Content editedby Claude
    Backfill source attributes on all 123 work items
  4. bfa195e
    Content editedby Claude
    Mark WORK-076, WORK-077, WORK-078 as done
  5. 9aff526
    Created (done)by Claude
    Add work items WORK-076 through WORK-082 for SPEC-028

Summary

Media zones must unwrap Markdoc's <p><img/></p> to emit a bare <img> inside the media container. This logic exists inline in realm.ts and faction.ts (~15 lines each) and is missing from recipe.ts and playlist.ts. Extract it into a single shared utility and apply it everywhere.

Acceptance Criteria

  • New extractMediaImage() utility (or similar) exported from packages/runes/src/common.ts
  • Utility uses RenderableNodeCursor's .tag('img') traversal to unwrap paragraph-wrapped images
  • recipe.ts media zone updated to use the utility — <p><img/></p> no longer survives into output
  • playlist.ts media zone updated to use the utility
  • realm.ts and faction.ts inline unwrap code replaced with calls to the shared utility
  • Identity transform output for recipe and playlist now emits <div data-name="media"><img .../></div> (no <p> wrapper)
  • All existing tests pass (update snapshots if media zone output changes)

Approach

  1. Study the inline unwrap code in realm.ts/faction.ts and the cursor.tag('img').limit(1) pattern from pageSectionProperties
  2. Create a utility that takes transformed media nodes and returns an unwrapped img in a container div
  3. Apply to all four runes with media zones
  4. Update any test snapshots that captured the old <p><img/></p> structure

References

  • SPEC-028 (Standard 3a — Media Zones Must Unwrap Paragraph-Wrapped Images)
  • SPEC-028 (Standard 4 — Avoid Duplicated Transform Logic)