livebook/assets/js/hooks/markdown_renderer.js
Jonatan Kłosko b3b79afed4
Refactor JS hooks (#1055)
* Restructure hook files

* Simplify app.js

* Refactor hooks

* Implement password toggle with JS commands
2022-03-16 11:33:53 +01:00

34 lines
685 B
JavaScript

import { getAttributeOrThrow } from "../lib/attribute";
import Markdown from "../lib/markdown";
/**
* A hook used to render Markdown content on the client.
*
* ## Configuration
*
* * `data-id` - id of the renderer, under which the content event
* is pushed
*/
const MarkdownRenderer = {
mounted() {
this.props = this.getProps();
const markdown = new Markdown(this.el, "");
this.handleEvent(
`markdown_renderer:${this.props.id}:content`,
({ content }) => {
markdown.setContent(content);
}
);
},
getProps() {
return {
id: getAttributeOrThrow(this.el, "data-id"),
};
},
};
export default MarkdownRenderer;