disable katex conversion on non-windows builds.

I am not going to spend time figuring out how to get katex working on Windows. If someone wants, feel free.
This commit is contained in:
KtorZ 2024-12-13 16:43:09 +01:00
parent da1c478b2f
commit b1977214ca
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
3 changed files with 18 additions and 10 deletions

View File

@ -10,7 +10,7 @@
- [Bitwise operations](https://aiken-lang.github.io/prelude/aiken/builtin.html#Bitwise) - [Bitwise operations](https://aiken-lang.github.io/prelude/aiken/builtin.html#Bitwise)
- [Ripemd-160 hashing](https://aiken-lang.github.io/prelude/aiken/builtin.html#ripemd_160) - [Ripemd-160 hashing](https://aiken-lang.github.io/prelude/aiken/builtin.html#ripemd_160)
- **aiken-projects**: The generated documentation may now include maths typesetting rendered using [KaTex](https://katex.org/). See [#1070](https://github.com/aiken-lang/aiken/pull/1070) @adrian052. - **aiken-projects**: The generated documentation may now include maths typesetting rendered using [KaTex](https://katex.org/). See [#1070](https://github.com/aiken-lang/aiken/pull/1070) @adrian052.
- Both inline (delimited by single `$` symbols) and blocks (delimited by doubled `$$` symbols) are now parsed and rendered as SVG upon generating documentation. For example: - (Linux & MacOS only) Both inline (delimited by single `$` symbols) and blocks (delimited by doubled `$$` symbols) are now parsed and rendered as SVG upon generating documentation. For example:
``` ```
$$ $$

View File

@ -53,6 +53,8 @@ uplc = { path = '../uplc', version = "1.1.8" }
vec1 = "1.10.1" vec1 = "1.10.1"
walkdir.workspace = true walkdir.workspace = true
zip = "0.6.4" zip = "0.6.4"
[target.'cfg(not(windows))'.dependencies]
katex = "0.4" katex = "0.4"
[dev-dependencies] [dev-dependencies]

View File

@ -13,7 +13,6 @@ 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 regex::Regex;
use serde::Serialize; use serde::Serialize;
@ -273,7 +272,6 @@ fn generate_module(
let rendered_content = convert_latex_markers( let rendered_content = convert_latex_markers(
module module
.render() .render()
.as_ref()
.expect("Module documentation template rendering"), .expect("Module documentation template rendering"),
); );
@ -286,23 +284,29 @@ fn generate_module(
) )
} }
fn convert_latex_markers(input: &str) -> String { #[cfg(windows)]
fn convert_latex_markers(input: String) -> String {
input
}
#[cfg(not(windows))]
fn convert_latex_markers(input: String) -> String {
let re_inline = Regex::new(r#"<span class="math math-inline">\s*(.+?)\s*</span>"#).unwrap(); let re_inline = Regex::new(r#"<span class="math math-inline">\s*(.+?)\s*</span>"#).unwrap();
let re_block = Regex::new(r#"<span class="math math-display">\s*(.+?)\s*</span>"#).unwrap(); let re_block = Regex::new(r#"<span class="math math-display">\s*(.+?)\s*</span>"#).unwrap();
let opts_inline = Opts::builder() let opts_inline = katex::Opts::builder()
.display_mode(false) // Inline math .display_mode(false) // Inline math
.output_type(OutputType::Mathml) .output_type(katex::OutputType::Mathml)
.build() .build()
.unwrap(); .unwrap();
let opts_block = katex::Opts::builder() let opts_block = katex::Opts::builder()
.display_mode(true) // Block math .display_mode(true) // Block math
.output_type(OutputType::Mathml) .output_type(katex::OutputType::Mathml)
.build() .build()
.unwrap(); .unwrap();
let input = re_inline.replace_all(input, |caps: &regex::Captures| { let input = re_inline.replace_all(&input, |caps: &regex::Captures| {
let formula = &caps[1]; let formula = &caps[1];
katex::render_with_opts(formula, &opts_inline).unwrap_or_else(|_| formula.to_string()) katex::render_with_opts(formula, &opts_inline).unwrap_or_else(|_| formula.to_string())
}); });
@ -752,7 +756,9 @@ mod tests {
#[test] #[test]
fn convert_latex_markers_simple() { fn convert_latex_markers_simple() {
assert_eq!( assert_eq!(
convert_latex_markers(r#"<span class="math math-inline">\frac{4}{5}</span>"#), convert_latex_markers(
r#"<span class="math math-inline">\frac{4}{5}</span>"#.to_string()
),
r#"<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mfrac><mn>4</mn><mn>5</mn></mfrac></mrow><annotation encoding="application/x-tex">\frac{4}{5}</annotation></semantics></math></span>"#, r#"<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mfrac><mn>4</mn><mn>5</mn></mfrac></mrow><annotation encoding="application/x-tex">\frac{4}{5}</annotation></semantics></math></span>"#,
); );
} }
@ -761,7 +767,7 @@ mod tests {
fn convert_latex_markers_sequence() { fn convert_latex_markers_sequence() {
assert_eq!( assert_eq!(
convert_latex_markers( convert_latex_markers(
r#"<span class="math math-inline">\frac{4}{5}</span><span class="math math-inline">e^{i \times \pi}</span>"# r#"<span class="math math-inline">\frac{4}{5}</span><span class="math math-inline">e^{i \times \pi}</span>"#.to_string()
), ),
r#"<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mfrac><mn>4</mn><mn>5</mn></mfrac></mrow><annotation encoding="application/x-tex">\frac{4}{5}</annotation></semantics></math></span><span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>e</mi><mrow><mi>i</mi><mo>×</mo><mi>π</mi></mrow></msup></mrow><annotation encoding="application/x-tex">e^{i \times \pi}</annotation></semantics></math></span>"#, r#"<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mfrac><mn>4</mn><mn>5</mn></mfrac></mrow><annotation encoding="application/x-tex">\frac{4}{5}</annotation></semantics></math></span><span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>e</mi><mrow><mi>i</mi><mo>×</mo><mi>π</mi></mrow></msup></mrow><annotation encoding="application/x-tex">e^{i \times \pi}</annotation></semantics></math></span>"#,
); );