HTML escape/unescape inspired by html and html template literal inspired by lit-html
.
Escape five html entities: <, >, &, ' and ".
import { escape } from "https://deno.land/x/html_escape/escape.ts";
console.log(escape(`"Fran & Freddie's Diner" <tasty@example.com>`));
// "Fran & Freddie's Diner" <tasty@example.com>
Unescape html entities to characters.
import { unescape } from "https://deno.land/x/html_escape/unescape.ts";
console.log(unescape(""Fran & Freddie's Diner" <tasty@example.com>"));
// "Fran & Freddie's Diner" <tasty@example.com>
Template literal to safely embed values inside html fragments.
import { html } from "https://deno.land/x/html_escape/html.ts";
const list = ["one", "with", `"escaping"`];
function li(value: string) {
return html`<li>${value}</li>`;
}
const body = html`<ul>${list.map(li)}</ul>`;
console.log(body.toString());
// <ul><li>one</li><li>with</li><li>"escaping"</li></ul>