Fixed language picker bug in viewer
This commit is contained in:
parent
049a1b0125
commit
8b3c78cb84
@ -6,23 +6,22 @@
|
|||||||
export let language: string | undefined;
|
export let language: string | undefined;
|
||||||
|
|
||||||
let displayCode: string | undefined;
|
let displayCode: string | undefined;
|
||||||
|
let displayLanguage: string | undefined;
|
||||||
let showAlert = false;
|
let showAlert = false;
|
||||||
let initial = true;
|
|
||||||
|
|
||||||
$: if(code) {
|
$: if(code) {
|
||||||
highlight();
|
highlight();
|
||||||
initial = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$: if(language) {
|
$: if(language !== displayLanguage) {
|
||||||
if(initial || !code) {
|
highlight();
|
||||||
highlight();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function highlight() {
|
function highlight() {
|
||||||
if(language) {
|
if(language) {
|
||||||
const res = hljs.highlight(language!, code!);
|
const res = hljs.highlight(code!, {
|
||||||
|
language
|
||||||
|
});
|
||||||
if(!res.errorRaised) {
|
if(!res.errorRaised) {
|
||||||
displayCode = res.value;
|
displayCode = res.value;
|
||||||
}
|
}
|
||||||
@ -33,6 +32,7 @@
|
|||||||
language = res.language;
|
language = res.language;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
displayLanguage = language;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function copy() {
|
async function copy() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user