mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-11-10 14:11:29 +08:00
* Set up markdown rendering, update theme. * Improve focus and handle expanding for markdown cells * Add keybindings for expanding/navigating cells * Improve editor autofocus when navigating with shortcuts * Add tests * Render markdown on the client * Don't render cell initial data and make a request instead
44 lines
856 B
JavaScript
44 lines
856 B
JavaScript
import marked from "marked";
|
|
import morphdom from "morphdom";
|
|
|
|
/**
|
|
* Renders markdown content in the given container.
|
|
*/
|
|
class Markdown {
|
|
constructor(container, content) {
|
|
this.container = container;
|
|
this.content = content;
|
|
|
|
this.__render();
|
|
}
|
|
|
|
setContent(content) {
|
|
this.content = content;
|
|
this.__render();
|
|
}
|
|
|
|
__render() {
|
|
const html = this.__getHtml();
|
|
// Wrap the HTML in another element, so that we
|
|
// can use morphdom's childrenOnly option.
|
|
const wrappedHtml = `<div>${html}</div>`;
|
|
|
|
morphdom(this.container, wrappedHtml, { childrenOnly: true });
|
|
}
|
|
|
|
__getHtml() {
|
|
const html = marked(this.content);
|
|
|
|
if (html) {
|
|
return html;
|
|
} else {
|
|
return `
|
|
<div class="text-gray-300">
|
|
Empty markdown cell
|
|
</div>
|
|
`;
|
|
}
|
|
}
|
|
}
|
|
|
|
export default Markdown;
|