use of mathml instead of katex
Some checks are pending
ci/woodpecker/push/publish Pipeline is pending

This commit is contained in:
Mylloon 2023-04-21 19:34:34 +02:00
parent dce767d641
commit 22b68f549e
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
5 changed files with 17 additions and 39 deletions

7
Cargo.lock generated
View file

@ -859,6 +859,7 @@ dependencies = [
"chrono", "chrono",
"comrak", "comrak",
"glob", "glob",
"latex2mathml",
"minify-html", "minify-html",
"ramhorns", "ramhorns",
"reqwest", "reqwest",
@ -1270,6 +1271,12 @@ version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4345964bb142484797b161f473a503a434de77149dd8c7427788c6e13379388" checksum = "d4345964bb142484797b161f473a503a434de77149dd8c7427788c6e13379388"
[[package]]
name = "latex2mathml"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "678cf5bdb3ba63a264e6e0c9eee36538ca1d2da0afa4dd801c1f96309e710765"
[[package]] [[package]]
name = "lazy_static" name = "lazy_static"
version = "1.4.0" version = "1.4.0"

View file

@ -20,5 +20,6 @@ serde_yaml = "0.9"
minify-html = "0.10.8" minify-html = "0.10.8"
glob = "0.3.1" glob = "0.3.1"
comrak = "0.18" comrak = "0.18"
latex2mathml = "0.2.3"
reqwest = { version = "0.11", features = ["json"] } reqwest = { version = "0.11", features = ["json"] }
chrono = "0.4.24" chrono = "0.4.24"

View file

@ -18,7 +18,6 @@ pub struct FileMetadata {
#[derive(Content)] #[derive(Content)]
pub struct Metadata { pub struct Metadata {
pub info: FileMetadata, pub info: FileMetadata,
pub math: bool,
pub mermaid: bool, pub mermaid: bool,
pub syntax_highlight: bool, pub syntax_highlight: bool,
} }
@ -54,7 +53,7 @@ pub fn get_options() -> ComrakOptions {
github_pre_lang: false, github_pre_lang: false,
full_info_string: true, full_info_string: true,
width: 0, // 0 mean disabled? width: 0, // 0 mean disabled?
unsafe_: false, // could be true? change by metadata could be good for compatibility unsafe_: true,
escape: false, // may change in the future? escape: false, // may change in the future?
list_style: ListStyleType::Dash, list_style: ListStyleType::Dash,
sourcepos: false, sourcepos: false,
@ -65,8 +64,11 @@ pub fn get_options() -> ComrakOptions {
pub fn read(raw_text: &str) -> File { pub fn read(raw_text: &str) -> File {
let arena = Arena::new(); let arena = Arena::new();
// LaTeX conversion to MathML
let text = latex2mathml::replace(raw_text).unwrap_or_default();
let options = get_options(); let options = get_options();
let root = parse_document(&arena, raw_text, &options); let root = parse_document(&arena, &text, &options);
// Find metadata // Find metadata
let metadata = get_metadata(root); let metadata = get_metadata(root);

View file

@ -2,31 +2,7 @@
<a href="/blog">Retour à la liste des posts</a> <a href="/blog">Retour à la liste des posts</a>
</footer> </footer>
{{#data}} {{#post}} {{#metadata}} {{#math}} {{#data}} {{#post}} {{#metadata}} {{#mermaid}}
<!-- KaTeX -->
<script
defer
src="//cdn.jsdelivr.net/npm/katex@0.16.6/dist/katex.min.js"
integrity="sha384-j/ZricySXBnNMJy9meJCtyXTKMhIJ42heyr7oAdxTDBy/CYA9hzpMo+YTNV5C+1X"
crossorigin="anonymous"
></script>
<script
defer
src="//cdn.jsdelivr.net/npm/katex@0.16.6/dist/contrib/auto-render.min.js"
integrity="sha384-+VBxd3r6XgURycqtZ117nYw44OOcIax56Z4dCRWbxyPt0Koah1uHoK0o4+/RRE05"
crossorigin="anonymous"
onload="renderMathInElement(document.body);"
></script>
<script>
window.addEventListener("load", () => {
for (let item of document.getElementsByClassName("language-math")) {
katex.render(item.textContent, item, {
displayMode: item.classList.contains("math-display"),
});
}
});
</script>
{{/math}} {{#mermaid}}
<!-- Mermaid diagrams --> <!-- Mermaid diagrams -->
<script type="module"> <script type="module">
import mermaid from "https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs"; import mermaid from "https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs";

View file

@ -39,15 +39,7 @@
<meta content="/icons/apple-touch-icon.png" property="og:image" /> <meta content="/icons/apple-touch-icon.png" property="og:image" />
<meta content="#43B581" data-react-helmet="true" name="theme-color" /> <meta content="#43B581" data-react-helmet="true" name="theme-color" />
{{#data}} {{#post}} {{#metadata}} {{#math}} {{#data}} {{#post}} {{#metadata}} {{#syntax_highlight}}
<!-- KaTeX -->
<link
rel="stylesheet"
href="//cdn.jsdelivr.net/npm/katex@0.16.6/dist/katex.min.css"
integrity="sha384-mXD7x5S50Ko38scHSnD4egvoExgMPbrseZorkbE49evAfv9nNcbrXJ8LLNsDgh9d"
crossorigin="anonymous"
/>
{{/math}} {{#syntax_highlight}}
<!-- Syntax highligthing --> <!-- Syntax highligthing -->
<link <link
rel="stylesheet" rel="stylesheet"