mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
Enable edit mode for mathjax blocks
This commit is contained in:
parent
cd36fe2518
commit
b0378690c0
1 changed files with 28 additions and 5 deletions
|
@ -8,16 +8,39 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
export let mathjax: string;
|
export let mathjax: string;
|
||||||
export let type: "inline" | "block" | "chemistry";
|
export let type: "inline" | "block" | "chemistry";
|
||||||
|
|
||||||
$: delimiters = type === "inline" ? ["\\[", "\\]"] : ["\\(", "\\)"];
|
let edit = false;
|
||||||
|
$: delimiters = type === "inline" ? ["\\(", "\\)"] : ["\\[", "\\]"];
|
||||||
$: converted = convertMathjax(`${delimiters[0]}${mathjax}${delimiters[1]}`);
|
$: converted = convertMathjax(`${delimiters[0]}${mathjax}${delimiters[1]}`);
|
||||||
|
|
||||||
|
function autofocus(element: HTMLElement): void {
|
||||||
|
element.focus();
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div on:click={console.log}>
|
{#if edit}
|
||||||
|
{#if type === "block"}
|
||||||
|
<div
|
||||||
|
contenteditable="true"
|
||||||
|
bind:innerHTML={mathjax}
|
||||||
|
on:blur={() => (edit = false)}
|
||||||
|
use:autofocus
|
||||||
|
/>
|
||||||
|
{:else}
|
||||||
|
<span
|
||||||
|
contenteditable="true"
|
||||||
|
bind:innerHTML={mathjax}
|
||||||
|
on:blur={() => (edit = false)}
|
||||||
|
use:autofocus
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
|
{:else}
|
||||||
|
<div class="d-contents" on:click={() => (edit = true)}>
|
||||||
{@html converted}
|
{@html converted}
|
||||||
</div>
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
div {
|
.d-contents {
|
||||||
display: contents;
|
display: contents;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
Loading…
Reference in a new issue