kxxt / obsidian-advanced-paste

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

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

Open YousufSSyed opened 7 months ago

YousufSSyed commented 7 months ago

(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.

kxxt commented 7 months ago

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.

YousufSSyed commented 7 months ago

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

kxxt commented 7 months ago

@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.