# Best way to output HTML from a Plug

**URL:** https://community.silverbullet.md/t/best-way-to-output-html-from-a-plug/2627
**Category:** Plug Development
**Created:** [July 18, 2025, 2:31pm UTC](https://community.silverbullet.md/t/best-way-to-output-html-from-a-plug/2627 "2025-07-18T14:31:58Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![dsolera](https://community.silverbullet.md/user_avatar/community.silverbullet.md/dsolera/32/1482_2.png) [@dsolera](https://community.silverbullet.md/u/dsolera)
#### Post date: [July 18, 2025, 2:31pm UTC](https://community.silverbullet.md/t/best-way-to-output-html-from-a-plug/2627/1 "2025-07-18T14:31:59Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![MrMugame](https://community.silverbullet.md/user_avatar/community.silverbullet.md/mrmugame/32/358_2.png) [@MrMugame](https://community.silverbullet.md/u/MrMugame)
#### Post date: [July 18, 2025, 2:53pm UTC](https://community.silverbullet.md/t/best-way-to-output-html-from-a-plug/2627/2 "2025-07-18T14:53:08Z")

</div>

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](https://github.com/MrMugame/silversearch), 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](https://github.com/silverbulletmd/silverbullet-katex/blob/main/katex.ts) 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.

---

<div class="post-metadata">

### Author: ![dsolera](https://community.silverbullet.md/user_avatar/community.silverbullet.md/dsolera/32/1482_2.png) [@dsolera](https://community.silverbullet.md/u/dsolera)
#### Post date: [July 18, 2025, 3:02pm UTC](https://community.silverbullet.md/t/best-way-to-output-html-from-a-plug/2627/3 "2025-07-18T15:02:31Z")

</div>

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.

BTW, just installed KaTeX plug!

---

<div class="post-metadata">

### Author: ![MrMugame](https://community.silverbullet.md/user_avatar/community.silverbullet.md/mrmugame/32/358_2.png) [@MrMugame](https://community.silverbullet.md/u/MrMugame)
#### Post date: [July 18, 2025, 4:46pm UTC](https://community.silverbullet.md/t/best-way-to-output-html-from-a-plug/2627/4 "2025-07-18T16:46:37Z")

</div>

For the panel apis there is a [global syscall function](https://github.com/MrMugame/silversearch/blob/dbd24076e2f0856ac9d2c8676da3b8a2fa38f41a/modal/global.d.ts#L4). Unsure about widgets, but I don’t think there is one.

---

<div class="post-metadata">

### Author: ![dsolera](https://community.silverbullet.md/user_avatar/community.silverbullet.md/dsolera/32/1482_2.png) [@dsolera](https://community.silverbullet.md/u/dsolera)
#### Post date: [July 21, 2025, 6:47am UTC](https://community.silverbullet.md/t/best-way-to-output-html-from-a-plug/2627/5 "2025-07-21T06:47:13Z")

</div>

So basically, using your approach, I’d be able to call globalThis.syscall(“space.doSomething”) from pure JavaScript?

---

<div class="post-metadata">

### Author: ![MrMugame](https://community.silverbullet.md/user_avatar/community.silverbullet.md/mrmugame/32/358_2.png) [@MrMugame](https://community.silverbullet.md/u/MrMugame)
#### Post date: [July 21, 2025, 9:24am UTC](https://community.silverbullet.md/t/best-way-to-output-html-from-a-plug/2627/6 "2025-07-21T09:24:44Z")

</div>

Yep, if you are in the right context (i.e. document editors, panels)
