{% include JB/setup %}
Spell is a kind of interpreter that runs on browser not on backend. So, technically it's the frontend interpreter. It can provide many benefits.
%html
, %table
). In other words, every spell can be used as display system as well.Helium Spell works like Helium Visualization.
/helium
page.Find a spell what you want to use in /helium
package and click Enable
button.
Spell works like an interpreter. Use the MAGIC
value to execute spell in a note. (you might need to refresh after enabling) For example, Use %echo
for the Echo Spell.
Making a new spell is similar to Helium Visualization#write-new-visualization.
package.json
Create a package.json in new directory for spell.
zeppelin-spell
as a dependency to create spell (zeppelin-spell)Here's an example
{ "name": "zeppelin-echo-spell", "description": "Zeppelin Echo Spell (example)", "version": "1.0.0", "main": "index", "author": "", "license": "Apache-2.0", "dependencies": { "zeppelin-spell": "*" }, "helium": { "icon" : "<i class='fa fa-repeat'></i>", "spell": { "magic": "%echo", "usage": "%echo <TEXT>" } } }
Here are some examples you can refer
Now, you need to write code to create spell which processing text.
import { SpellBase, SpellResult, DefaultDisplayType, } from 'zeppelin-spell'; export default class EchoSpell extends SpellBase { constructor() { /** pass magic to super class's constructor parameter */ super("%echo"); } interpret(paragraphText) { const processed = paragraphText + '!'; /** * should return `SpellResult` which including `data` and `type` * default type is `TEXT` if you don't specify. */ return new SpellResult(processed); } }
Here is another example. Let's say we want to create markdown spell. First of all, we should add a dependency for markdown in package.json
// package.json "dependencies": { "markdown": "0.5.0", "zeppelin-spell": "*" },
And here is spell code.
import { SpellBase, SpellResult, DefaultDisplayType, } from 'zeppelin-spell'; import md from 'markdown'; const markdown = md.markdown; export default class MarkdownSpell extends SpellBase { constructor() { super("%markdown"); } interpret(paragraphText) { const parsed = markdown.toHTML(paragraphText); /** * specify `DefaultDisplayType.HTML` since `parsed` will contain DOM * otherwise it will be rendered as `DefaultDisplayType.TEXT` (default) */ return new SpellResult(parsed, DefaultDisplayType.HTML); } }
You don‘t want to publish your package every time you make a change in your spell. Zeppelin provides local deploy. The only thing you need to do is creating a Helium Package file (JSON) for local deploy. It’s automatically created when you publish to npm repository but in local case, you should make it by yourself.
{ "type" : "SPELL", "name" : "zeppelin-echo-spell", "version": "1.0.0", "description" : "Return just what receive (example)", "artifact" : "./zeppelin-examples/zeppelin-example-spell-echo", "license" : "Apache-2.0", "spell": { "magic": "%echo", "usage": "%echo <TEXT>" } }
$ZEPPELIN_HOME/helium
).type
should be SPELL
artifact
should be same as your spell directory.cd zeppelin-web yarn run dev:helium
You can browse localhost:9000. Every time refresh your browser, Zeppelin will rebuild your spell and reload changes.