mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 01:25:55 +02:00
Render latex using stimulus controller.
This commit is contained in:
parent
c54336fb47
commit
cef74ff35a
8 changed files with 51 additions and 4 deletions
28
assets/controllers/common/latex_controller.js
Normal file
28
assets/controllers/common/latex_controller.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
import {Controller} from "@hotwired/stimulus";
|
||||
|
||||
import "katex";
|
||||
import 'katex/dist/katex.css';
|
||||
import renderMathInElement from "katex/dist/contrib/auto-render";
|
||||
|
||||
/* stimulusFetch: 'lazy' */
|
||||
export default class extends Controller {
|
||||
connect() {
|
||||
this.applyLatex();
|
||||
this.element.addEventListener('markdown:finished', () => this.applyLatex());
|
||||
}
|
||||
|
||||
applyLatex() {
|
||||
renderMathInElement(this.element, {
|
||||
delimiters: [
|
||||
{left: "$$", right: "$$", display: true},
|
||||
{left: "$", right: "$", display: false},
|
||||
{left: "\\(", right: "\\)", display: false},
|
||||
{left: "\\[", right: "\\]", display: true}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
mutate() {
|
||||
this.applyLatex();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue