obsidian-advanced-paste icon indicating copy to clipboard operation
obsidian-advanced-paste copied to clipboard

Can you expose Obsidian's built-in paste functionality as a function?

Open YousufSSyed opened this issue 2 years ago • 3 comments

(To be clear, Obsidian's paste system, not the plugin's default one)

I'd like to run pasted content through Obsidian's system for turning it into markdown, before processing it in a transform.

YousufSSyed avatar Dec 24 '23 05:12 YousufSSyed

Obsidian's paste system

Obsidian itself doesn't expose any paste related APIs, that's why this plugin uses a lots of hacks to hook it.

There is a clipboard manager in editor object, but that's not a part of obsidian's public API. You can probably use it since the editor object is exposed to custom transforms.

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

I'd like to run pasted content through Obsidian's system for turning it into markdown

As for turning html into markdown. Obsidian uses turndown as well. The turndown utility provided to the custom transform does the same job.

kxxt avatar Dec 24 '23 11:12 kxxt

@kxxt How could I run pasted content through it and get back the result?

YousufSSyed avatar Dec 24 '23 16:12 YousufSSyed

@kxxt How could I run pasted content through it and get back the result?

I am assuming you are asking about the clipboardManager. The simple answer is no. The clipboardManager handles the paste directly without giving back the result.

Here's the prototype of the clipboardManager if you are interested in it:

image


For running pasted content through turndown, check the first example under this section.

kxxt avatar Dec 25 '23 02:12 kxxt