0.2.4 • Published 2 years ago

jsml-parser v0.2.4

Weekly downloads
-
License
UNLICENSED
Repository
github
Last release
2 years ago

JSML

JSON that represents HTML JavaScript object notation that represents hypertext Markup Language

See demonstration on GitHub.

createElement()

in browsers

<script src="https://cdn.jsdelivr.net/npm/jsml-parser@0.2/createElement.js"></script>
<script>
    const jsml =
    {p: {
        class: "myClass myClass2",
        style: "margin: .5em 0; padding: 0.5em;",
        $: [
            "JSML means ",
            {a: {
                href: "https://www.json.org/",
                text: "JSON",
                onClick: () => console.log("with listener support")
            }},
            " that represents ",
            {em: "HTML"}
        ]
    }};

    const elem = JSML.createElement(jsml);
    document.body.append(elem, elem.outerHTML);
</script>

For ideas of this format and concept of even shorter implementation, see context.

in node.js

Use jsdom to create an object which emulates HTMLDocument.

npm install jsml-parser jsdom
const {JSDOM} = require("jsdom");
const JSML = require("jsml-parser");

const dom = new JSDOM("");
const elem = JSML.createElement(
    {p: "Hello world"},
    dom.window.document
);

toHTML()

Note: For toHTML(), assigning event listener by function is not fully implemented yet.

in browsers

<script src="https://cdn.jsdelivr.net/npm/jsml-parser@0.2/toHTML.js"></script>
<script>
console.log(JSML.toHTML({p: "test"}));
</script>

in node.js

You don't need other packages to run toHTML().

npm install jsml-parser
const JSML = require("jsml-parser");
console.log(JSML.toHTML({p: "test"}));

See also

0.2.4

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.2

2 years ago

0.1.0

2 years ago

1.0.0

6 years ago