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:
parent
da1c478b2f
commit
b1977214ca
|
@ -10,7 +10,7 @@
|
|||
- [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)
|
||||
- **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:
|
||||
|
||||
```
|
||||
$$
|
||||
|
|
|
@ -53,6 +53,8 @@ uplc = { path = '../uplc', version = "1.1.8" }
|
|||
vec1 = "1.10.1"
|
||||
walkdir.workspace = true
|
||||
zip = "0.6.4"
|
||||
|
||||
[target.'cfg(not(windows))'.dependencies]
|
||||
katex = "0.4"
|
||||
|
||||
[dev-dependencies]
|
||||
|
|
|
@ -13,7 +13,6 @@ use aiken_lang::{
|
|||
};
|
||||
use askama::Template;
|
||||
use itertools::Itertools;
|
||||
use katex::{Opts, OutputType};
|
||||
use pulldown_cmark as markdown;
|
||||
use regex::Regex;
|
||||
use serde::Serialize;
|
||||
|
@ -273,7 +272,6 @@ fn generate_module(
|
|||
let rendered_content = convert_latex_markers(
|
||||
module
|
||||
.render()
|
||||
.as_ref()
|
||||
.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_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
|
||||
.output_type(OutputType::Mathml)
|
||||
.output_type(katex::OutputType::Mathml)
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
let opts_block = katex::Opts::builder()
|
||||
.display_mode(true) // Block math
|
||||
.output_type(OutputType::Mathml)
|
||||
.output_type(katex::OutputType::Mathml)
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
let input = re_inline.replace_all(input, |caps: ®ex::Captures| {
|
||||
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())
|
||||
});
|
||||
|
@ -752,7 +756,9 @@ mod tests {
|
|||
#[test]
|
||||
fn convert_latex_markers_simple() {
|
||||
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>"#,
|
||||
);
|
||||
}
|
||||
|
@ -761,7 +767,7 @@ mod tests {
|
|||
fn convert_latex_markers_sequence() {
|
||||
assert_eq!(
|
||||
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>"#,
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue