2024-04-04 23:31:46 +00:00
|
|
|
<div align="center">
|
2024-04-04 23:10:35 +00:00
|
|
|
|
|
|
|
<img src="./3dicons-co-icon.png" height="60px">
|
|
|
|
|
2024-04-04 21:39:27 +00:00
|
|
|
# Swarnam
|
2022-04-15 18:13:31 +00:00
|
|
|
|
2024-04-10 15:27:24 +00:00
|
|
|
A no-frills web playground plugin for Obsidian. Inspired by [MDN playgrounds](https://developer.mozilla.org/en-US/docs/Web/CSS/grid).
|
2024-04-04 23:11:46 +00:00
|
|
|
|
|
|
|
<small>(icon credit: [3dicons](https://3dicons.co))</small>
|
2024-04-04 23:31:46 +00:00
|
|
|
</div>
|
2022-04-15 18:13:31 +00:00
|
|
|
|
2024-04-04 23:49:51 +00:00
|
|
|
## Demo
|
|
|
|
|
|
|
|
https://github.com/runofthemillgeek/swarnam-obsidian/assets/2759499/333424b3-2f82-4c1e-9e50-68c837227433
|
|
|
|
|
2024-04-04 21:39:27 +00:00
|
|
|
## Usage
|
2022-04-15 18:13:31 +00:00
|
|
|
|
2024-04-04 21:39:27 +00:00
|
|
|
Install the extension from Obsidian community plugins list (you need to enable this first from
|
2024-04-04 22:03:36 +00:00
|
|
|
Settings), enable the plugin and then restart Obsidian.
|
2022-04-15 18:13:31 +00:00
|
|
|
|
2024-04-04 21:39:27 +00:00
|
|
|
To create a new Swarnam block, you need to open a block code snippet and give it the `swarnam` tag
|
|
|
|
like so:
|
2022-04-15 18:13:31 +00:00
|
|
|
|
2024-04-04 23:43:02 +00:00
|
|
|
```swarnam
|
|
|
|
<h1>Hello, world</h1>
|
|
|
|
```
|
2022-04-15 18:13:31 +00:00
|
|
|
|
2024-04-04 21:39:27 +00:00
|
|
|
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.
|
2022-04-15 18:13:31 +00:00
|
|
|
|
2024-04-04 21:39:27 +00:00
|
|
|
You can also add CSS and JS by separating them with `---*---` like so:
|
2022-04-15 18:13:31 +00:00
|
|
|
|
2024-04-04 23:43:02 +00:00
|
|
|
```swarnam
|
|
|
|
<h1 id="h1">Hello world</h1>
|
2022-04-15 18:13:31 +00:00
|
|
|
|
2024-04-04 23:43:02 +00:00
|
|
|
---*---
|
2022-04-15 18:13:31 +00:00
|
|
|
|
2024-04-04 23:43:02 +00:00
|
|
|
h1 {
|
|
|
|
font-family: "Manjari";
|
|
|
|
color: red;
|
|
|
|
animation: rainbow 5s ease infinite forwards;
|
|
|
|
}
|
2022-04-15 18:13:31 +00:00
|
|
|
|
2024-04-04 23:43:02 +00:00
|
|
|
@keyframes rainbow {
|
|
|
|
0% { filter: hue-rotate(0); }
|
|
|
|
100% { filter: hue-rotate(360deg); }
|
|
|
|
}
|
2022-12-05 20:49:16 +00:00
|
|
|
|
2024-04-04 23:43:02 +00:00
|
|
|
---*---
|
2022-12-05 20:49:16 +00:00
|
|
|
|
2024-04-04 23:43:02 +00:00
|
|
|
let i = 0;
|
2022-12-05 20:55:39 +00:00
|
|
|
|
2024-04-04 23:43:02 +00:00
|
|
|
setInterval(() => {
|
|
|
|
h1.textContent = `${["Hello", "Hola", "നമസ്കാരം"][i++ % 3]} Obsidian!`;
|
|
|
|
}, 1500)
|
|
|
|
```
|
2022-12-05 20:49:16 +00:00
|
|
|
|
2024-04-04 21:39:27 +00:00
|
|
|
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.
|
2022-04-15 18:13:31 +00:00
|
|
|
|
2024-04-04 21:39:27 +00:00
|
|
|
## How does it work
|
2022-04-15 18:13:31 +00:00
|
|
|
|
2024-04-04 21:39:27 +00:00
|
|
|
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.
|
2024-04-04 23:15:36 +00:00
|
|
|
|
|
|
|
## 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).
|