0.2.2
Render markup tag easily
Repository
Current version released
3 years ago
deno-markup-tag
Usage
Import
From deno.land/x:
import { tag } from "https://deno.land/x/markup_tag@0.2.2/mod.ts";
From nest.land:
import { tag } from "https://x.nest.land/markup-tag@0.2.2/mod.ts";
From GitHub:
import { tag } from "https://raw.githubusercontent.com/kawarimidoll/deno-markup-tag/0.2.2/mod.ts";
tag
Render markup tag.
// common usage
assertEquals(
tag("div", { id: "foo", class: "bar" }, "Hello world!"),
`<div id="foo" class="bar">Hello world!</div>`,
);
// void (no-close) tag
assertEquals(tag("meta", { charset: "utf-8" }), `<meta charset="utf-8">`);
// nested tags
assertEquals(
tag("ul", { class: "nav" }, tag("li", "first"), tag("li", "second")),
`<ul class="nav"><li>first</li><li>second</li></ul>`,
);
Character references
These constants are exported.
const NBSP = " ";
const LT = "<";
const GT = ">";
const AMP = "&";
const QUOT = """;
sanitize
Sanitize &
, <
, >
and "
in string.
// common usage
assertEquals(
sanitize(`<img src="https://www.example.com?width=10&height=10">`),
"<img src="https://www.example.com?width=10&height=10">",
);
// ignore sanitizing specific characters
assertEquals(sanitize("<br>", { lt: false, gt: false }), "<br>");