Switched to KaTeX for LaTeX rendering and used cmark-provided delimiters
This commit is contained in:
parent
5925dd3bfa
commit
51af046fcb
|
@ -53,6 +53,7 @@ uplc = { path = '../uplc', version = "1.1.7" }
|
||||||
vec1 = "1.10.1"
|
vec1 = "1.10.1"
|
||||||
walkdir.workspace = true
|
walkdir.workspace = true
|
||||||
zip = "0.6.4"
|
zip = "0.6.4"
|
||||||
|
katex = "0.4"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
blst = "0.3.11"
|
blst = "0.3.11"
|
||||||
|
|
|
@ -13,7 +13,9 @@ use aiken_lang::{
|
||||||
};
|
};
|
||||||
use askama::Template;
|
use askama::Template;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
use katex::{Opts, OutputType};
|
||||||
use pulldown_cmark as markdown;
|
use pulldown_cmark as markdown;
|
||||||
|
use regex::Regex;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use serde_json as json;
|
use serde_json as json;
|
||||||
use std::{
|
use std::{
|
||||||
|
@ -269,9 +271,7 @@ fn generate_module(
|
||||||
};
|
};
|
||||||
|
|
||||||
let rendered_content = convert_latex_markers(
|
let rendered_content = convert_latex_markers(
|
||||||
inject_math_library(
|
|
||||||
module.render().expect("Module documentation template rendering"),
|
module.render().expect("Module documentation template rendering"),
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
(
|
(
|
||||||
|
@ -285,21 +285,31 @@ fn generate_module(
|
||||||
|
|
||||||
|
|
||||||
fn convert_latex_markers(input: String) -> String {
|
fn convert_latex_markers(input: String) -> String {
|
||||||
input.replace("#[", "\\(")
|
let re_inline = Regex::new(r#"<span class="math math-inline">\s*(.+?)\s*</span>"#).unwrap();
|
||||||
.replace("]#", "\\)")
|
let re_block = Regex::new(r#"<span class="math math-display">\s*(.+?)\s*</span>"#).unwrap();
|
||||||
}
|
|
||||||
|
|
||||||
fn inject_math_library(html: String) -> String {
|
let opts_inline = Opts::builder()
|
||||||
let mathjax_script = r#"
|
.display_mode(false) // Inline math
|
||||||
<script type="text/javascript" id="MathJax-script" async
|
.output_type(OutputType::Mathml)
|
||||||
src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js">
|
.build()
|
||||||
</script>
|
.unwrap();
|
||||||
<script>
|
|
||||||
MathJax.typeset();
|
|
||||||
</script>
|
|
||||||
"#;
|
|
||||||
|
|
||||||
html.replace("</head>", &format!("{}\n</head>", mathjax_script))
|
let opts_block = katex::Opts::builder()
|
||||||
|
.display_mode(true) // Block math
|
||||||
|
.output_type(OutputType::Mathml)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let input = re_inline.replace_all(&input, |caps: ®ex::Captures| {
|
||||||
|
let formula = &caps[1];
|
||||||
|
katex::render_with_opts(formula, &opts_inline).unwrap_or_else(|_| formula.to_string())
|
||||||
|
});
|
||||||
|
|
||||||
|
re_block.replace_all(&input, |caps: ®ex::Captures| {
|
||||||
|
let formula = &caps[1];
|
||||||
|
katex::render_with_opts(formula, &opts_block).unwrap_or_else(|_| formula.to_string())
|
||||||
|
})
|
||||||
|
.to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate_static_assets(search_indexes: Vec<SearchIndex>) -> Vec<DocFile> {
|
fn generate_static_assets(search_indexes: Vec<SearchIndex>) -> Vec<DocFile> {
|
||||||
|
|
Loading…
Reference in New Issue