Skip to content

Commit

Permalink
markdown: document this function
Browse files Browse the repository at this point in the history
  • Loading branch information
jordigh committed Jul 30, 2024
1 parent 1b6a803 commit 1382d05
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions app/client/lib/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@ import { sanitizeHTML } from 'app/client/ui/sanitizeHTML';
import { BindableValue, DomElementMethod, subscribeElem } from 'grainjs';
import { marked } from 'marked';

/**Helper function for using Markdown in grainjs elements. It accepts
* both plain Markdown strings, as well as methods that use an observable.
* Example usage:
*
* cssSection(markdown(t(`# New Markdown Function
* We can _write_ [the usual Markdown](https: *markdownguide.org) inside
* a Grainjs element`)));
*
* or
*
* cssSection(markdown(use => use(toggle) ? t('The toggle is **on**') : t('The toggle is **off**'));
*
* Markdown strings are easier for our translators to handle, as it's possible
* to include all of the context around a single markdown string without
* breaking it up into separate strings for grainjs elements.
*/
export function markdown(markdownObs: BindableValue<string>): DomElementMethod {
return elem => subscribeElem(elem, markdownObs, value => setMarkdownValue(elem, value));
}
Expand Down

0 comments on commit 1382d05

Please sign in to comment.