Transform to mathjax components for fieldHTML

This commit is contained in:
Henrik Giesel 2021-08-04 03:40:56 +02:00
parent 5129aca66f
commit b0b2ae3ece
3 changed files with 8 additions and 5 deletions

View file

@ -6,7 +6,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import { convertMathjax } from "./mathjax";
export let mathjax: string;
$: console.log(mathjax, convertMathjax(`\\(${mathjax}\\)`));
$: converted = convertMathjax(`\\(${mathjax}\\)`);
</script>

View file

@ -41,10 +41,11 @@ export function toMathjaxTags(html: string): string {
.replace(
mathjaxInlineDelimiterPattern,
(_match: string, text: string) =>
`<anki-mathjax-inline>${text}</anki-cloze>`
`<anki-mathjax-inline>${text}</anki-mathjax-inline>`
)
.replace(
mathjaxBlockDelimiterPattern,
(_match: string, text: string) => `<anki-mathjax-block>${text}</anki-cloze>`
(_match: string, text: string) =>
`<anki-mathjax-block>${text}</anki-mathjax-block>`
);
}

View file

@ -17,6 +17,7 @@ import { bridgeCommand } from "./lib";
import { onInput, onKey, onKeyUp } from "./input-handlers";
import { onFocus, onBlur } from "./focus-handlers";
import { nightModeKey } from "components/context-keys";
import { toMathjaxTags, toMathjaxDelimiters } from "editable/mathjax-components";
function onCutOrCopy(): void {
bridgeCommand("cutOrCopy");
@ -92,11 +93,13 @@ export class EditingArea extends HTMLDivElement {
}
set fieldHTML(content: string) {
this.imageHandle.then(() => (this.activeInput.fieldHTML = content));
this.imageHandle.then(
() => (this.activeInput.fieldHTML = toMathjaxTags(content))
);
}
get fieldHTML(): string {
return this.activeInput.fieldHTML;
return toMathjaxDelimiters(this.activeInput.fieldHTML);
}
connectedCallback(): void {