mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
Set default value of raw.theme
to auto
, and allow setting raw.theme
to auto
(#4186)
This commit is contained in:
parent
ea4c64a799
commit
374b82f8ca
@ -233,10 +233,10 @@ pub struct RawElem {
|
|||||||
/// ````
|
/// ````
|
||||||
#[parse(
|
#[parse(
|
||||||
let (theme_path, theme_data) = parse_theme(engine, args)?;
|
let (theme_path, theme_data) = parse_theme(engine, args)?;
|
||||||
theme_path.map(Some)
|
theme_path
|
||||||
)]
|
)]
|
||||||
#[borrowed]
|
#[borrowed]
|
||||||
pub theme: Option<EcoString>,
|
pub theme: Smart<EcoString>,
|
||||||
|
|
||||||
/// The raw file buffer of syntax theme file.
|
/// The raw file buffer of syntax theme file.
|
||||||
#[internal]
|
#[internal]
|
||||||
@ -321,7 +321,7 @@ impl Packed<RawElem> {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
});
|
});
|
||||||
|
|
||||||
let theme = theme.as_deref().unwrap_or(&RAW_THEME);
|
let theme = theme.as_ref().map(std::ops::Deref::deref).unwrap_or(&RAW_THEME);
|
||||||
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![];
|
||||||
@ -784,12 +784,19 @@ fn load_theme(path: &str, bytes: &Bytes) -> StrResult<Arc<synt::Theme>> {
|
|||||||
fn parse_theme(
|
fn parse_theme(
|
||||||
engine: &mut Engine,
|
engine: &mut Engine,
|
||||||
args: &mut Args,
|
args: &mut Args,
|
||||||
) -> SourceResult<(Option<EcoString>, Option<Bytes>)> {
|
) -> SourceResult<(Option<Smart<EcoString>>, Option<Bytes>)> {
|
||||||
let Some(Spanned { v: path, span }) = args.named::<Spanned<EcoString>>("theme")?
|
let Some(Spanned { v: path, span }) =
|
||||||
|
args.named::<Spanned<Smart<EcoString>>>("theme")?
|
||||||
else {
|
else {
|
||||||
|
// Argument `theme` not found.
|
||||||
return Ok((None, None));
|
return Ok((None, None));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let Smart::Custom(path) = path else {
|
||||||
|
// Argument `theme` is `auto`.
|
||||||
|
return Ok((Some(Smart::Auto), None));
|
||||||
|
};
|
||||||
|
|
||||||
// Load theme file.
|
// Load theme file.
|
||||||
let id = span.resolve_path(&path).at(span)?;
|
let id = span.resolve_path(&path).at(span)?;
|
||||||
let data = engine.world.file(id).at(span)?;
|
let data = engine.world.file(id).at(span)?;
|
||||||
@ -797,7 +804,7 @@ fn parse_theme(
|
|||||||
// Check that parsing works.
|
// Check that parsing works.
|
||||||
let _ = load_theme(&path, &data).at(span)?;
|
let _ = load_theme(&path, &data).at(span)?;
|
||||||
|
|
||||||
Ok((Some(path), Some(data)))
|
Ok((Some(Smart::Custom(path)), Some(data)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The syntect syntax definitions.
|
/// The syntect syntax definitions.
|
||||||
|
BIN
tests/ref/raw-theme-set-to-auto.png
Normal file
BIN
tests/ref/raw-theme-set-to-auto.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.1 KiB |
@ -633,6 +633,21 @@ fn main() {
|
|||||||
`code`
|
`code`
|
||||||
```
|
```
|
||||||
|
|
||||||
|
--- raw-theme-set-to-auto ---
|
||||||
|
```typ
|
||||||
|
#let hi = "Hello World"
|
||||||
|
```
|
||||||
|
|
||||||
|
#set raw(theme: "/assets/themes/halcyon.tmTheme")
|
||||||
|
```typ
|
||||||
|
#let hi = "Hello World"
|
||||||
|
```
|
||||||
|
|
||||||
|
#set raw(theme: auto)
|
||||||
|
```typ
|
||||||
|
#let hi = "Hello World"
|
||||||
|
```
|
||||||
|
|
||||||
--- raw-unclosed ---
|
--- raw-unclosed ---
|
||||||
// Test unterminated raw text.
|
// Test unterminated raw text.
|
||||||
//
|
//
|
||||||
|
Loading…
x
Reference in New Issue
Block a user