GnoxNahte / obsidian-auto-embed

Obsidian plugin to embed websites using simple markdown instead of iframe
MIT License
18 stars 0 forks source link

Bug Report: Conflict with Paste mode plugin #16

Closed ksdavidc closed 6 days ago

ksdavidc commented 1 week ago

What happened?

(cross posted at https://github.com/jglev/obsidian-paste-mode/issues/35#issue-2597852935)

conflict with paste mode plugin.

see attached vault. paste mode.zip

If you paste a link like https://www.youtube.com/watch?v=FQboGAF3fOg you will get the "embed" popup.

If enable paste mode, and try to paste, no popup appears.

If you disable paste mode and IMPORTANT reload the vault, popup returns.

Sample Markdown

https://www.youtube.com/watch?v=FQboGAF3fOg

Errors

none

Obsidian Version

Version 1.7.4 (Installer 1.6.5)

Plugin Version

latest

OS

MacOS

GnoxNahte commented 6 days ago

Hi, thanks for the report!

I'm not sure how to solve it properly though.

However, if you are ok with modifying the paste-mode plugin and the paste-mode plugin not modifying any links, Here's a quick workaround:

  1. Go to Settings -> Community plugins ->Installed plugins, click on the folder icon
  2. Go to "obsidian-paste-to-current-indentation" -> Open "main.js", open in a text editor
  3. Select lines 4336-4339
    // Line 4336-4339
      this.app.workspace.on("editor-paste", (evt, editor) => __async(this, null, function* () {
        if (evt.defaultPrevented) {
          return;
        }
  4. Replace with this
    this.app.workspace.on("editor-paste", (evt, editor) => __async(this, null, function* () {
        var _a;
        if (evt.defaultPrevented) {
          return;
        }
        {
          let isURL = function(str) {
            if (str.startsWith("app://")) {
              return false;
            }
            try {
              new URL(str);
              return true;
            } catch (e) {
              return false;
            }
          }, isLinkToImage = function(url) {
            return /\.(jpg|jpeg|png|webp|avif|gif)$/.test(url);
          };
          const clipboardData = (_a = evt.clipboardData) == null ? void 0 : _a.getData("text/plain");
          if (!(!clipboardData || clipboardData === "" || !isURL(clipboardData) || isLinkToImage(clipboardData)))
            return;
        }

    A quick explanation of the code: It just checks if the pasted text is an URL. If it is a URL, return out of the paste event function.

The other plugin looks like it isn't maintained so I don't think you have to worry about any updates that will overwrite the code.

Let me work if it works for you!

ksdavidc commented 6 days ago

Thanks, I appreciate it. I'll try your fix, but am using your plugin quite a bit more, so that's my priority. The last update on the other was about a year and half, but you never know :-) Thanks.