mvdkwast / obsidian-copy-as-html

Obsidian plugin: copy document as HTML, including images
MIT License
48 stars 11 forks source link

Expose some simple api functions #12

Closed MeepTech closed 1 year ago

MeepTech commented 1 year ago

Adding minimal plugin api

Changes:

Added Functions

Params:

Return:

Promise\: A promise for an html element with the result of the markdown as html

Convert Markdown

Convert a raw markdown string to an html element.

Note: This may cause tabs to open and close temporatily in the background, this is nessicary to render the items property without using the current view.

Params:

Return:

Promise\: A promise for an html element with the result of the markdown as html

Credits

mvdkwast commented 1 year ago

Hi @MeepTech,

Thanks for your contribution. The idea of having an API for rendering markdown to HTML is great. I've regular questions about this on Discord, and I've seen several similar implementations in other plugins, so this would probably be useful. Ideally this functionality would be exposed directly by Obsidian (have some option to do a complete render with the MarkdownRenderer).

Where I have my doubts is about tying other plugins to this one directly. Maybe it would be better if we made this code available as an npm package ?

I'm also curious about your use-case for these APIs. Can you tell me more ?

MeepTech commented 1 year ago

Hello back @mvdkwast, and thanks for the timely response!

1.

Where I have my doubts is about tying other plugins to this one directly. Maybe it would be better if we made this code available as an npm package ?

I think I agree with you here, though I'm not too familiar with how to do this myself. Can you recommend any articles or offer any assistance here for how I'd look into modifying this change into an npm package?

2.

I'm also curious about your use-case for these APIs. Can you tell me more ?

Sure thing! My current personal use case is for testing other plugins in obsidian easily and viewing the results in a collective note. I use your plugin to convert sections of a document into html and then get the inner text to help make comparisons of results easy and to ignore styling in results providing false error positives.

I am also using the exposed apis in my collective meta-scry plugin here that covers a lot of ways to de-compile and re-compile your notes into data (mostly a personal project): https://github.com/Meep-Tech/obsidian-metadata-scry-plugin

I can also think of other use cases, such as providing previews for RESTful endpoint access to notes and for serialization of dataviewjs queries into html.

mvdkwast commented 1 year ago

All very interesting use-cases !

About converting this to a package, I never did this myself, so I would have to do some research. The approach would be basically to move all the rendering code to this package, and make this plugin and yours use the lib. I'll try to find some time this week to see how this can work.

MeepTech commented 1 year ago

@mvdkwast I think i've found out how to publish plugins as a lib. I'll look into it sometime this week some more.

mvdkwast commented 1 year ago

Hi @MeepTech, closing this PR as it's been a while and it seems that I won't be able to find any time soon to work on this.