Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Footnotes don't accept pasted content #16

Open
bjhess opened this issue Dec 18, 2024 · 6 comments
Open

Footnotes don't accept pasted content #16

bjhess opened this issue Dec 18, 2024 · 6 comments
Assignees

Comments

@bjhess
Copy link

bjhess commented Dec 18, 2024

I've found that you cannot paste (cmd-v or right-click paste) into the footnotes area. This seems like a very common use case.

Buttondown:

CleanShot 2024-12-18 at 11 40 51

As I was testing it this started working fine in Buttondown and Pika. So I tried a different browser and it was working there. Then I went to delete what I was writing, tried one more time and pasting wasn't working in either browser again. Something intermittent?

Do you see similar behavior?

Copy link

linear bot commented Dec 18, 2024

@jmduke
Copy link
Member

jmduke commented Dec 19, 2024

@mary-ext mind taking a look here?

@bjhess
Copy link
Author

bjhess commented Dec 19, 2024

(FYI, I have seen it work and not work intermittently. Haven't been able to hone in on why pasting is working in the rare moments that it does work.)

@bjhess
Copy link
Author

bjhess commented Dec 19, 2024

Here's my suspicion. I think it's the Tiptap YouTube extension interfering–I suspect you also have it installed on Buttondown? If I disable that extension I don't seem to have any problems pasting content.

I will also dig in and see if there's a way around it as we don't want to remove that extension…

@bjhess
Copy link
Author

bjhess commented Dec 19, 2024

Okay, here's how I conditionally bypassed the YouTube extension when in ol.footnotes by recreating and extending its existing paste handler. AI helped write this so it certainly could be improved. I could not figure out a way to lookup the root REGEX from the YouTube extension. Obviously that would be preferred.

import { nodePasteRule } from '@tiptap/core'
import Youtube from '@tiptap/extension-youtube'

export default Youtube.extend({
  addPasteRules() {
    if (!this.options.addPasteHandler) {
      return []
    }

    const youtubeRegex = Youtube.options.youtubeRegex

    return [
      nodePasteRule({
        find: /^((?:https?:)?\/\/)?((?:www|m|music)\.)?((?:youtube\.com|youtu.be|youtube-nocookie\.com))(\/(?:[\w-]+\?v=|embed\/|v\/)?)([\w-]+)(\S+)?$/g,
        type: this.type,
        getAttributes: match => {
          // Check if we're inside a footnotes section by looking at parent nodes
          const selection = this.editor.state.selection
          const $pos = selection.$from
          let isInFootnotes = false
          
          // Walk up the document tree to check for footnotes
          for (let depth = $pos.depth; depth > 0; depth--) {
            const node = $pos.node(depth)
            if (node.attrs.class && node.attrs.class.includes('footnotes')) {
              isInFootnotes = true
              break
            }
          }

          if (isInFootnotes) {
            return false
          }
          
          return { src: match.input }
        },
      }),
    ]
  },
})

@mary-ext
Copy link
Member

mary-ext commented Dec 20, 2024

Hmm, we're not using Tiptap's YouTube extension on Buttondown, but I'll definitely see if there's anything we can do from this end.

@mary-ext mary-ext self-assigned this Dec 20, 2024
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

No branches or pull requests

3 participants