Implement math mode language for raw (#4687)

This commit is contained in:
Jakob Peters 2024-08-11 13:15:30 -07:00 committed by GitHub
parent 831062a588
commit d06f3f180c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 5 deletions

View File

@ -145,9 +145,10 @@ pub struct RawElem {
/// The language to syntax-highlight in. /// The language to syntax-highlight in.
/// ///
/// Apart from typical language tags known from Markdown, this supports the /// Apart from typical language tags known from Markdown, this supports the
/// `{"typ"}` and `{"typc"}` tags for /// `{"typ"}`, `{"typc"}`, and `{"typm"}` tags for
/// [Typst markup]($reference/syntax/#markup) and /// [Typst markup]($reference/syntax/#markup),
/// [Typst code]($reference/syntax/#code), respectively. /// [Typst code]($reference/syntax/#code), and
/// [Typst math]($reference/syntax/#math), respectively.
/// ///
/// ````example /// ````example
/// ```typ /// ```typ
@ -288,7 +289,11 @@ impl RawElem {
syntax.file_extensions.iter().map(|s| s.as_str()).collect(), syntax.file_extensions.iter().map(|s| s.as_str()).collect(),
) )
}) })
.chain([("Typst", vec!["typ"]), ("Typst (code)", vec!["typc"])]) .chain([
("Typst", vec!["typ"]),
("Typst (code)", vec!["typc"]),
("Typst (math)", vec!["typm"]),
])
.collect() .collect()
} }
} }
@ -344,11 +349,12 @@ impl Packed<RawElem> {
let foreground = theme.settings.foreground.unwrap_or(synt::Color::BLACK); let foreground = theme.settings.foreground.unwrap_or(synt::Color::BLACK);
let mut seq = vec![]; let mut seq = vec![];
if matches!(lang.as_deref(), Some("typ" | "typst" | "typc")) { if matches!(lang.as_deref(), Some("typ" | "typst" | "typc" | "typm")) {
let text = let text =
lines.iter().map(|(s, _)| s.clone()).collect::<Vec<_>>().join("\n"); lines.iter().map(|(s, _)| s.clone()).collect::<Vec<_>>().join("\n");
let root = match lang.as_deref() { let root = match lang.as_deref() {
Some("typc") => syntax::parse_code(&text), Some("typc") => syntax::parse_code(&text),
Some("typm") => syntax::parse_math(&text),
_ => syntax::parse(&text), _ => syntax::parse(&text),
}; };

Binary file not shown.

After

Width:  |  Height:  |  Size: 381 B

View File

@ -585,6 +585,10 @@ if true {
} }
``` ```
--- issue-4662-math-mode-language-for-raw ---
// Test lang: "typm" syntax highlighting without enclosing dollar signs
#raw("pi^2", lang: "typm")
--- issue-2259-raw-color-overwrite --- --- issue-2259-raw-color-overwrite ---
// Test that the color of a raw block is not overwritten // Test that the color of a raw block is not overwritten
#show raw: set text(fill: blue) #show raw: set text(fill: blue)