x/markup_tag/mod.ts

Render markup tag easily
Latest
function sanitize
import { sanitize } from "https://deno.land/x/markup_tag@0.3.0/mod.ts?s=sanitize";

Sanitize &, <, > and " in string.

Parameters

optional
str
[src]

(optional)

optional
unnamed 1: Record<string, boolean>
[src]

(optional)

Returns

string[src]

sanitized string

Use SanitizeOption like { amp: false } to ignore sanitizing.

Examples:

import { sanitize } from "https://deno.land/x/markup_tag/mod.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts"

// common usage
assertEquals(
sanitize(`<img src="https://www.example.com?width=10&height=10">`),
"&lt;img src=&quot;https://www.example.com?width=10&amp;height=10&quot;&gt;",
);

// ignore sanitizing specific characters
assertEquals(sanitize("<br>", { lt: false, gt: false }), "<br>");