mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-16 23:02:35 +08:00
feat(ck-mermaid): support read-only mode
This commit is contained in:
parent
19c90445fa
commit
b81c15c84c
@ -1,6 +1,7 @@
|
|||||||
import AbstractTextTypeWidget from "./abstract_text_type_widget.js";
|
import AbstractTextTypeWidget from "./abstract_text_type_widget.js";
|
||||||
import libraryLoader from "../../services/library_loader.js";
|
import libraryLoader from "../../services/library_loader.js";
|
||||||
import { applySyntaxHighlight } from "../../services/syntax_highlight.js";
|
import { applySyntaxHighlight } from "../../services/syntax_highlight.js";
|
||||||
|
import { getMermaidConfig } from "../mermaid.js";
|
||||||
|
|
||||||
const TPL = `
|
const TPL = `
|
||||||
<div class="note-detail-readonly-text note-detail-printable">
|
<div class="note-detail-readonly-text note-detail-printable">
|
||||||
@ -112,9 +113,26 @@ export default class ReadOnlyTextTypeWidget extends AbstractTextTypeWidget {
|
|||||||
renderMathInElement(this.$content[0], {trust: true});
|
renderMathInElement(this.$content[0], {trust: true});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await this.#applyInlineMermaid();
|
||||||
await applySyntaxHighlight(this.$content);
|
await applySyntaxHighlight(this.$content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async #applyInlineMermaid() {
|
||||||
|
const $el = this.$content.find('code[class="language-mermaid"]').closest("pre");
|
||||||
|
if (!$el.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rewrite the code block from <pre><code> to <div> in order not to apply a codeblock style to it.
|
||||||
|
$el.replaceWith((i, content) => {
|
||||||
|
return $('<div class="mermaid-diagram">').text($(content).text());
|
||||||
|
});
|
||||||
|
|
||||||
|
// Initialize mermaid
|
||||||
|
await libraryLoader.requireLibrary(libraryLoader.MERMAID);
|
||||||
|
mermaid.init(getMermaidConfig(), this.$content.find(".mermaid-diagram"));
|
||||||
|
}
|
||||||
|
|
||||||
async refreshIncludedNoteEvent({noteId}) {
|
async refreshIncludedNoteEvent({noteId}) {
|
||||||
this.refreshIncludedNote(this.$content, noteId);
|
this.refreshIncludedNote(this.$content, noteId);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user