mirror of
https://github.com/typst/typst
synced 2025-06-28 08:12:53 +08:00
Implement math mode language for raw
(#4687)
This commit is contained in:
parent
831062a588
commit
d06f3f180c
@ -145,9 +145,10 @@ pub struct RawElem {
|
||||
/// The language to syntax-highlight in.
|
||||
///
|
||||
/// Apart from typical language tags known from Markdown, this supports the
|
||||
/// `{"typ"}` and `{"typc"}` tags for
|
||||
/// [Typst markup]($reference/syntax/#markup) and
|
||||
/// [Typst code]($reference/syntax/#code), respectively.
|
||||
/// `{"typ"}`, `{"typc"}`, and `{"typm"}` tags for
|
||||
/// [Typst markup]($reference/syntax/#markup),
|
||||
/// [Typst code]($reference/syntax/#code), and
|
||||
/// [Typst math]($reference/syntax/#math), respectively.
|
||||
///
|
||||
/// ````example
|
||||
/// ```typ
|
||||
@ -288,7 +289,11 @@ impl RawElem {
|
||||
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()
|
||||
}
|
||||
}
|
||||
@ -344,11 +349,12 @@ impl Packed<RawElem> {
|
||||
let foreground = theme.settings.foreground.unwrap_or(synt::Color::BLACK);
|
||||
|
||||
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 =
|
||||
lines.iter().map(|(s, _)| s.clone()).collect::<Vec<_>>().join("\n");
|
||||
let root = match lang.as_deref() {
|
||||
Some("typc") => syntax::parse_code(&text),
|
||||
Some("typm") => syntax::parse_math(&text),
|
||||
_ => syntax::parse(&text),
|
||||
};
|
||||
|
||||
|
BIN
tests/ref/issue-4662-math-mode-language-for-raw.png
Normal file
BIN
tests/ref/issue-4662-math-mode-language-for-raw.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 381 B |
@ -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 ---
|
||||
// Test that the color of a raw block is not overwritten
|
||||
#show raw: set text(fill: blue)
|
||||
|
Loading…
x
Reference in New Issue
Block a user