gristlabs_grist-core/app/client/lib/markdown.ts
Jordi Gutiérrez Hermoso 0bf3f9bc43 markdown: new utility module
Since we've started using Markdown, why not a simple utility function
to start using it?
2024-07-30 13:41:47 -04:00

12 lines
472 B
TypeScript

import { sanitizeHTML } from 'app/client/ui/sanitizeHTML';
import { BindableValue, DomElementMethod, subscribeElem } from 'grainjs';
import { marked } from 'marked';
export function markdown(markdownObs: BindableValue<string>): DomElementMethod {
return elem => subscribeElem(elem, markdownObs, value => setMarkdownValue(elem, value));
}
function setMarkdownValue(elem: Element, markdownValue: string): void {
elem.innerHTML = sanitizeHTML(marked(markdownValue));
}