mirror of
https://github.com/livebook-dev/livebook.git
synced 2024-11-10 17:15:09 +08:00
73a79cbdae
* Add support for markdown output * Make cell indicator absolute * Update output typespec * Move rendering to the client * Polishing
36 lines
731 B
JavaScript
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;
|