mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-27 20:44:07 +00:00
markdown: new utility module
Since we've started using Markdown, why not a simple utility function to start using it?
This commit is contained in:
parent
4621b67c8e
commit
0bf3f9bc43
11
app/client/lib/markdown.ts
Normal file
11
app/client/lib/markdown.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
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));
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user