kxxt / obsidian-advanced-paste

Advanced pasting functionality for obsidian
MIT License
42 stars 2 forks source link

Is it possible to use the default pasting behavior or Turndown in a cusotm transform? #17

Closed YousufSSyed closed 8 months ago

YousufSSyed commented 8 months ago

I want to extend the default pasting behavior instead of outright replacing it in my custom transforms. And ideally without importing all of TurndownJS into my script (if that's possible, I haven't quite looked at it).

kxxt commented 8 months ago

The default paste contains some dirty hacks and uses obsidian's private APIs. It can't serve as a stable API so I won't expose it to custom transforms.

https://github.com/kxxt/obsidian-advanced-paste/blob/cfb04918298f14ffa7f04aefa49beaef9a2e8a76/src/main.ts#L220-L284

But if your goal is to extend the default pasting behavior, you can fork this repo and modify it directly.

YousufSSyed commented 8 months ago

Can you still expose it and add a disclaimer that it "contains some dirty hacks and uses obsidian's private APIs" and that it can change at any time without notice?

I'd still like to use it even if that's the case, maybe other users too. I want to extend whatever the default pasting behavior is with this plugin.

YousufSSyed commented 8 months ago

Either way, how could I use Turndown without including my own copy of it?

kxxt commented 8 months ago

Either way, how could I use Turndown without including my own copy of it?

It's documented in the README: https://github.com/kxxt/obsidian-advanced-paste#advanced-utilities

YousufSSyed commented 8 months ago

Can you still expose it and add a disclaimer that it "contains some dirty hacks and uses obsidian's private APIs" and that it can change at any time without notice? I'd still like to use it even if that's the case, maybe other users too. I want to extend whatever the default pasting behavior is with this plugin.

kxxt commented 8 months ago

Can you still expose it and add a disclaimer that it "contains some dirty hacks and uses obsidian's private APIs" and that it can change at any time without notice?

I'd still like to use it even if that's the case, maybe other users too. I want to extend whatever the default pasting behavior is with this plugin.

And because of the above reason, the default pasting is tightly coupled to the Plugin class itself. Exposing it through a sane API will be difficult. It even uses a different clipboard API which takes ClipboardEvent instead of ClipboardItem.

YousufSSyed commented 8 months ago

@kxxt How hard would it be to make a function that could be called one from a custom transform which uses the plugin's default pasting behavior? Wouldn't it be a wrapper or whatnot? I haven't looked at the source code but I don't think it would be that hard, unless it is.

kxxt commented 8 months ago

@kxxt How hard would it be to make a function that could be called one from a custom transform which uses the plugin's default pasting behavior? Wouldn't it be a wrapper or whatnot? I haven't looked at the source code but I don't think it would be that hard, unless it is.

It's not exposing the function directly is hard. It's exposing it through a sane API is hard. If you really want it you should fork this repo and modify it directly.

YousufSSyed commented 8 months ago

@kxxt Alright, thanks for answering though.