jsml-parser

0.2.4 • Public • Published

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

/jsml-parser/

    Package Sidebar

    Install

    npm i jsml-parser

    Weekly Downloads

    7

    Version

    0.2.4

    License

    UNLICENSED

    Unpacked Size

    30.6 kB

    Total Files

    8

    Last publish

    Collaborators

    • kong0107