Personal, hyper-specific collection of HTML and Markdown conversion utilities
npm install dry-utils-textbash
npm install dry-utils-text
`
Features
- Markdown to HTML: Convert Markdown content to sanitized HTML using Showdown with sensible defaults (tables, GitHub-style headers, and indented sublist fixes).
- HTML Sanitization: Clean and sanitize HTML content for secure rendering while automatically locking down external links.
- HTML Standardization: Normalize untrusted HTML through a Markdown conversion cycle for consistent downstream rendering.
- Configurable Pipelines: Override Showdown or Turndown options when you need bespoke Markdown or HTML output.
Usage
$3
Convert Markdown content to sanitized HTML with proper security measures. Pass Showdown converter options to customize the output:
`typescript
import { markdownToHtml } from "dry-utils-text";
const markdown = "# Hello World\n\nThis is bold and this is italic.";
const html = markdownToHtml(markdown);
// Results in: "Hello World
This is bold and this is italic.
"
`
$3
Safely clean HTML content to remove potentially dangerous elements:
`typescript
import { sanitizeHtmlContent } from "dry-utils-text";
const unsafeHtml = "Safe content ";
const safeHtml = sanitizeHtmlContent(unsafeHtml);
// Results in: "Safe content "
`
$3
Process untrusted HTML by converting it to Markdown and back to sanitized HTML. You can override the Showdown or Turndown options used during the conversion cycle:
`typescript
import { standardizeUntrustedHtml } from "dry-utils-text";
const untrustedHtml =
"Text with ";
const standardizedHtml = standardizeUntrustedHtml(untrustedHtml);
// Results in sanitized, standardized HTML
`
$3
- External links automatically get target="_blank" and rel="noopener noreferrer" attributes
- Dangerous HTML elements and attributes are stripped using sanitize-html`'s default allowlists with extra link hardening