@bokeh/bokehjs
Version:
Interactive, novel data visualization
41 lines • 1.42 kB
JavaScript
import { Widget, WidgetView } from "./widget";
import { div } from "../../core/dom";
import { Marked } from "marked";
import Purify from "dompurify";
export class MarkdownView extends WidgetView {
static __name__ = "MarkdownView";
_markdown = new Marked();
contents = div({ style: { display: "contents" } });
connect_signals() {
super.connect_signals();
const { text, disable_math } = this.model.properties;
this.on_change([text, disable_math], () => this._render_markdown(this.model.text));
}
_render_markdown(text) {
const html = this._markdown.parse(text, { async: false });
const html_with_math = this.has_math_disabled ? html : this.process_tex(html);
this.contents.innerHTML = Purify.sanitize(html_with_math);
}
render() {
super.render();
this.shadow_el.append(this.contents);
this._render_markdown(this.model.text);
}
get has_math_disabled() {
return this.model.disable_math || !this.contains_tex_string(this.model.text);
}
}
export class Markdown extends Widget {
static __name__ = "Markdown";
constructor(attrs) {
super(attrs);
}
static {
this.prototype.default_view = MarkdownView;
this.define(({ Str, Bool }) => ({
text: [Str, ""],
disable_math: [Bool, false],
}));
}
}
//# sourceMappingURL=markdown.js.map