mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-22 17:41:55 +08:00
This upgrades to Mathjax 4.1 and latest katex Implement rich text composer support for math Adds support for /( )/ and /[ /] which was missing and very common now Removes math javascript from our repo --------- Co-authored-by: Mark McClure <mcmcclur@unca.edu>
50 lines
1.1 KiB
JavaScript
Vendored
50 lines
1.1 KiB
JavaScript
Vendored
import { getURLWithCDN } from "discourse/lib/get-url";
|
|
import loadScript from "discourse/lib/load-script";
|
|
import { getKaTeXBasePath } from "discourse/plugins/discourse-math/lib/math-bundle-paths";
|
|
|
|
function getBasePath() {
|
|
return getKaTeXBasePath();
|
|
}
|
|
|
|
let katexPromise;
|
|
let cssPromise;
|
|
let mhchemPromise;
|
|
let copyTexPromise;
|
|
|
|
export async function loadKaTeX() {
|
|
if (!cssPromise) {
|
|
cssPromise = loadScript(getURLWithCDN(`${getBasePath()}/katex.min.css`), {
|
|
css: true,
|
|
});
|
|
}
|
|
await cssPromise;
|
|
|
|
if (!katexPromise) {
|
|
katexPromise = loadScript(getURLWithCDN(`${getBasePath()}/katex.min.js`));
|
|
}
|
|
await katexPromise;
|
|
|
|
return window.katex;
|
|
}
|
|
|
|
export function loadMhchem() {
|
|
if (!mhchemPromise) {
|
|
mhchemPromise = loadScript(
|
|
getURLWithCDN(`${getBasePath()}/contrib/mhchem.min.js`)
|
|
);
|
|
}
|
|
return mhchemPromise;
|
|
}
|
|
|
|
export function loadCopyTex() {
|
|
if (!copyTexPromise) {
|
|
copyTexPromise = loadScript(
|
|
getURLWithCDN(`${getBasePath()}/contrib/copy-tex.min.js`)
|
|
);
|
|
}
|
|
return copyTexPromise;
|
|
}
|
|
|
|
export function getKaTeX() {
|
|
return window.katex;
|
|
}
|