Copy Embed Code
pendingby Dustin Ho
Adds a 'Copy Embed Code' option to right-click context menu for images. Works in Live Preview and Reading Mode, including nested embeds.
Copy Embed Code
An Obsidian plugin that adds a "Copy Embed Code" option to the right-click context menu for images.
Features
- Works everywhere: Live Preview, Reading Mode, and nested embeds (transclusions)
- Local images: Copies wikilink format
![[filename.png]] - External images: Copies markdown format

The Problem
Obsidian's standard editor-menu API relies on cursor position, but clicking an image doesn't always move the cursor—especially when the image is inside an embed (transclusion), or nested multiple levels deep.
How It Works
Event Flow
- Right-click captured - A global
contextmenulistener (capture phase) detects the click - Image detection - Walks up the DOM tree from the click target to find any
<img>element - Menu injection - Adds "Copy Embed Code" via Obsidian's Menu API or DOM injection
- Copy action - Generates appropriate embed syntax and copies to clipboard
Handling Nested Embeds
The plugin uses DOM-based detection rather than cursor position:
Document
└── contextmenu listener (capture phase)
└── Walks up DOM tree from evt.target
└── Finds <img> regardless of nesting depth
This means an image 5 levels deep (blockquote → embed → callout → embed → image) works identically to a top-level image.
Dual Injection Strategy
| Context | Method |
|---|---|
| Edit mode | Hooks into Obsidian's editor-menu event |
| Reading mode / nested embeds | Injects directly into .menu DOM element |
Installation
Manual Installation
- Download
main.jsandmanifest.jsonfrom the releases - Create folder:
<vault>/.obsidian/plugins/copy-embed-url/ - Copy files into the folder
- Enable the plugin in Obsidian settings
From Source
npm install
npm run build
Usage
- Right-click any image in Obsidian
- Click "Copy Embed Code"
- Paste the embed code wherever needed
License
MIT
For plugin developers
Search results and similarity scores are powered by semantic analysis of your plugin's README. If your plugin isn't appearing for searches you'd expect, try updating your README to clearly describe your plugin's purpose, features, and use cases.