livebook/assets/js/markdown_renderer/index.js
Jonatan Kłosko 73a79cbdae
Add support for markdown output (#404)
* Add support for markdown output

* Make cell indicator absolute

* Update output typespec

* Move rendering to the client

* Polishing
2021-06-26 16:47:52 +02:00

36 lines
731 B
JavaScript

import { getAttributeOrThrow } from "../lib/attribute";
import Markdown from "../cell/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 = getProps(this);
const markdown = new Markdown(this.el, "");
this.handleEvent(
`markdown-renderer:${this.props.id}:content`,
({ content }) => {
markdown.setContent(content);
}
);
},
updated() {
this.props = getProps(this);
},
};
function getProps(hook) {
return {
id: getAttributeOrThrow(hook.el, "data-id"),
};
}
export default MarkdownRenderer;