1.2.1 • Published 3 years ago
mdtt v1.2.1
MDTT
MDTT is a tagged template library for markdown. It automatically sanitizes markdown used in tagged template inputs, while still allowing nested templates.
Examples
When unsafe input is used, it's automatically sanitized.
import MDTT from 'mdtt';
const m = MDTT();
// Untrusted input from another source
const unsafe = '**world**';
console.log(m`Hello, ${unsafe}!`);
// Hello, \*\*world\*\*!
However, safe input works just fine.
// Trusted input, generated by MDTT
const safe = m`**bold** text`;
console.log(m`Ooh, ${safe}`);
// Ooh, **bold** text
Arrays are also supported.
console.log(m`Items:\n${['Item 1', 'Item 2'].map((n) => m`- ${n}\n`)}`);
// Items:
// - Item 1
// - Item 2
You can also enable HTML sanitization.
import MDTT from 'mdtt';
const m = MDTT({ sanitizeHtml: true });
// Untrusted input from another source
const unsafe = '<div>untrusted</div>';
console.log(m`<h1>Hello, ${unsafe}!</h1>`);
// <h1>Hello, <div>untrusted</div>!</h1>