What is the simplest and most performant way to generate HTML from a Plug (calling a function)? The most important part is that the HTML must respond to events, so it must also include event handlers calling some code that in turns calls SilverBullet’s APIs.
I see that HTMLElement and related DOM entities are not immediately available, at least with the Deno settings provided in the Plug template. Also, SilverBullet’s DOM API is not available for import, apparently.
Depends on the usage. Do you want to dynamically create it, or just provide “static” content?
The context you are working in is a WebWorker in which most DOM APIs are not available to my knowledge. SBs dom api is super minimal and purely written in lua (I think the implementation is only a few dozen lines long) - So yes it’s also not available.
If you want to serve html for a panel modal then I’d recommend you look at my plug, which has a rather complex build system, but in return is very powerful (e.g. I can use svelte as a framework). This approach doesn’t really allow building the html on the fly, all the “customization” is handled by the html itself.
The other approach is … just building it on the fly using string concatenation. Yeah … Sometimes that’s very feasible like the katex plug for example.
I’m talking about the html for panels/document editors here. I haven’t tried it with functions returning stuff for luawidgets, but I don’t think script tags are sanatized so it should work fine.
Thanks for the information.
I started with string manipulation, but then it got complex because I need to invoke SB APIs like space.deleteDocument() and I couldn’t find a way to bridge HTML → JS runtime → SB APIs.