client: Remove syntax highlight in preview when disabled

This commit is contained in:
Elian Doran 2024-10-31 21:33:00 +02:00
parent f57ab4b9f0
commit c3e10b2b76
No known key found for this signature in database

View File

@ -71,16 +71,23 @@ export default class CodeBlockOptions extends OptionsWidget {
this.$wordWrap.on("change", () => this.updateCheckboxOption("codeBlockWordWrap", this.$wordWrap)); this.$wordWrap.on("change", () => this.updateCheckboxOption("codeBlockWordWrap", this.$wordWrap));
// Set up preview // Set up preview
const sampleEl = this.$widget.find(".code-sample"); this.$sampleEl = this.$widget.find(".code-sample");
library_loader }
.requireLibrary(library_loader.HIGHLIGHT_JS)
.then(() => { #setupPreview(shouldEnableSyntaxHighlight) {
const highlightedText = hljs.highlight(SAMPLE_CODE, { const text = SAMPLE_CODE;
language: SAMPLE_LANGUAGE if (shouldEnableSyntaxHighlight) {
library_loader
.requireLibrary(library_loader.HIGHLIGHT_JS)
.then(() => {
const highlightedText = hljs.highlight(text, {
language: SAMPLE_LANGUAGE
});
this.$sampleEl.html(highlightedText.value);
}); });
sampleEl.html(highlightedText.value); } else {
}); this.$sampleEl.text(text);
this.$sampleWrapper = this.$widget.find(".note-detail-readonly-text"); }
} }
async optionsLoaded(options) { async optionsLoaded(options) {
@ -106,5 +113,7 @@ export default class CodeBlockOptions extends OptionsWidget {
this.$themeSelect.val(options.codeBlockTheme); this.$themeSelect.val(options.codeBlockTheme);
this.setCheckboxState(this.$wordWrap, options.codeBlockWordWrap); this.setCheckboxState(this.$wordWrap, options.codeBlockWordWrap);
this.$widget.closest(".note-detail-printable").toggleClass("word-wrap", options.codeBlockWordWrap === "true"); this.$widget.closest(".note-detail-printable").toggleClass("word-wrap", options.codeBlockWordWrap === "true");
this.#setupPreview(options.codeBlockTheme !== "none");
} }
} }