A no-frills web playground plugin for Obsidian.
Go to file
2024-04-05 04:59:19 +05:30
.github/workflows ci: add release action 2024-04-05 04:59:19 +05:30
.editorconfig use LF instead of CRLF (#28) 2022-04-15 14:13:31 -04:00
.eslintignore fix .eslintignore (#48) 2023-01-19 10:06:51 -05:00
.eslintrc add version bump script (#10) 2022-01-22 16:13:50 -05:00
.gitignore Update .gitignore (#25) 2022-01-28 10:34:53 -05:00
.npmrc add version bump script (#10) 2022-01-22 16:13:50 -05:00
3dicons-co-icon.png doc: add logo icon 2024-04-05 04:40:35 +05:30
esbuild.config.mjs Upgrade esbuild to v0.17.x (#47) 2023-01-25 13:49:50 -05:00
LICENSE.md chore: add license 2024-04-05 04:45:36 +05:30
main.ts refactor: move styles out 2024-04-05 03:33:36 +05:30
manifest.json refactor: move styles out 2024-04-05 03:33:36 +05:30
package-lock.json feat: implement MVP version of Swarnam 2024-04-05 03:09:27 +05:30
package.json Upgrade esbuild to v0.17.x (#47) 2023-01-25 13:49:50 -05:00
README.md chore: add license 2024-04-05 04:45:36 +05:30
styles.css refactor: move styles out 2024-04-05 03:33:36 +05:30
tsconfig.json Upgrade dependencies, add strictNullChecks. 2022-06-24 15:41:39 -04:00
version-bump.mjs add version bump script (#10) 2022-01-22 16:13:50 -05:00
versions.json Update for 0.15 2022-08-09 13:38:50 -04:00

Swarnam

A no-frills web playground plugin for Obsidian.

(icon credit: 3dicons)

Usage

Install the extension from Obsidian community plugins list (you need to enable this first from Settings), enable the plugin and then restart Obsidian.

To create a new Swarnam block, you need to open a block code snippet and give it the swarnam tag like so:

<h1>Hello, world</h1>

When you preview this, it'll show the source and render the HTML side-by-side. You can hover on the top-right and click the </> icon to edit the snippet to make some changes.

You can also add CSS and JS by separating them with ---*--- like so:

<h1 id="h1">Hello world</h1>

---*---

h1 {
  font-family: "Manjari";
  color: red;
  animation: rainbow 5s ease infinite forwards;
}

@keyframes rainbow {
  0% { filter: hue-rotate(0); }
  100% { filter: hue-rotate(360deg); }
}

---*---

let i = 0;

setInterval(() => {	
	h1.textContent = `${["Hello", "Hola", "നമസ്കാരം"][i++ % 3]} Obsidian!`;
}, 1500)

This'll render the three snippets on the left side and show the preview of a web page that has all these 3 blocks injected.

How does it work

We split the code block snippet into 3 parts and form an HTML document string by injecting the CSS and JS pieces into <style> and <script> tags. Once we have the final HTML document, we convert this into Base64 and create a data URI. Finally, an <iframe> element is created and the data URI is given as the src. Data URIs of mime type text/html and base64 enoding can be rendered by most browsers including the Chromium renderer Obsidian is built on top of. There are no additional build steps involved and thus, this is not a full-blown replacement for something like Sandpack.

Contributing

Spot any issue? Have a feature request or idea? Feel free to create a new issue in GitHub to discuss. (Pretty please do this before you spend your precious time on a PR that might not make into this repo).