Giter VIP home page Giter VIP logo

swarnam-obsidian's Introduction

Swarnam

A no-frills web playground plugin for Obsidian. Inspired by MDN playgrounds.

Swarnam (സ്വർണം) means gold in Malayalam.
(icon credit: 3dicons)

Demo

swarnam-demo.mp4

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:

```swarnam
<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:

```swarnam
<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).

swarnam-obsidian's People

Contributors

lishid avatar runofthemillgeek avatar ericaxu avatar guopenghui avatar edo78 avatar fyears avatar chrisgrieser avatar aidenlx avatar reorx avatar tokuhirom avatar timrogers avatar tfthacker avatar phibr0 avatar taurelas avatar kostapc avatar joethei avatar inouetakuya avatar henrebotha avatar gitmurf avatar clemens-e avatar pozdneev avatar aleksey-rowan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.