Skip to main content
Module

x/markup_tag/mod.ts>sanitize

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

Sanitize &, <, > and " in string.

Parameters

optional
str = [UNSUPPORTED]

(optional)

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

(optional)

Returns

string

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>");