@learnpress/utils
v0.2.1
Published
Shared utility helpers for LearnPress packages
Readme
@learnpress/utils
Shared utility helpers for LearnPress packages.
Install
npm install @learnpress/utilsAPI
stripHtml(html: string): string
Strip all HTML tags and decode HTML entities, returning trimmed plain text. Useful for titles, excerpts, or any place you need a clean text version of rendered HTML.
import { stripHtml } from "@learnpress/utils";
stripHtml("<p>Hello & <strong>world</strong></p>");
// "Hello & world"sanitizeHtml(html: string): string
Sanitize an HTML string for safe rendering. Allows a curated set of tags and attributes commonly used in WordPress post content (img, figure, iframe, video, audio, source, track, …), plus safe iframe embeds from YouTube and Vimeo. External links with target="_blank" automatically get rel="noopener noreferrer".
import parse from "html-react-parser";
import { sanitizeHtml } from "@learnpress/utils";
export function HtmlContent({ html }: { html: string }) {
return <div>{parse(sanitizeHtml(html))}</div>;
}