diff --git a/assets/controllers/pages/latex_preview_controller.js b/assets/controllers/pages/latex_preview_controller.js new file mode 100644 index 00000000..8c1279f1 --- /dev/null +++ b/assets/controllers/pages/latex_preview_controller.js @@ -0,0 +1,21 @@ +import {Controller} from "@hotwired/stimulus"; +import katex from "katex"; +import "katex/dist/katex.css"; + +/* stimulusFetch: 'lazy' */ +export default class extends Controller { + static targets = ["input", "preview"]; + + updatePreview() + { + katex.render(this.inputTarget.value, this.previewTarget, { + throwOnError: false, + }); + } + + connect() + { + this.updatePreview(); + this.inputTarget.addEventListener('input', this.updatePreview.bind(this)); + } +} \ No newline at end of file diff --git a/templates/Parts/edit/edit_form_styles.html.twig b/templates/Parts/edit/edit_form_styles.html.twig index 003be938..77439f20 100644 --- a/templates/Parts/edit/edit_form_styles.html.twig +++ b/templates/Parts/edit/edit_form_styles.html.twig @@ -70,11 +70,11 @@ {% import 'components/collection_type.macro.html.twig' as collection %}