import MarkdownIt from "markdown-it";
import sanitizeHtml from "sanitize-html";
const md = new MarkdownIt({ html: false, linkify: true });
const TAGS = ["strong", "em", "s", "code"];
const optionsFor = (links: boolean): sanitizeHtml.IOptions => ({
allowedTags: links ? [...TAGS, "a"] : TAGS,
allowedAttributes: { a: ["href", "rel"] },
allowedSchemes: ["http", "https", "mailto"],
transformTags: {
a: sanitizeHtml.simpleTransform("a", { rel: "nofollow ugc noopener noreferrer" })
}
});
export const renderInline = (source: string, links = true): string =>
sanitizeHtml(md.renderInline(source), optionsFor(links));