diff options
| author | Laurenz <laurmaedje@gmail.com> | 2020-02-13 21:58:49 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2020-02-13 21:58:49 +0100 |
| commit | 1658b00282b631fb5218f477ea7f45f925644cea (patch) | |
| tree | 13a0f51f335e687c363a5afb9cc73993a69489cc /src/library/font.rs | |
| parent | 60099aed50b89daef29543c4700470e566c48798 (diff) | |
New syntax features 👔
- Forced line breaks with backslash followed by whitespace
- (Multline) raw text in backticks
- Set font class fallbacks with [font.family] (e.g. [font.family: monospace=("CMU Typewriter Text")])
- More sophisticated procedure to find end of function, which accounts for comments, strings, raw text and nested functions (this is a mix of a feature and a bug fix)
Diffstat (limited to 'src/library/font.rs')
| -rw-r--r-- | src/library/font.rs | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/src/library/font.rs b/src/library/font.rs index 9c69e1dd..ba778693 100644 --- a/src/library/font.rs +++ b/src/library/font.rs @@ -9,21 +9,45 @@ function! { pub struct FontFamilyFunc { body: Option<SyntaxModel>, list: Vec<String>, + classes: Vec<(String, Vec<String>)>, } parse(header, body, ctx, f) { + let list = header.args.pos.get_all::<StringLike>(&mut f.errors) + .map(|s| s.0.to_lowercase()) + .collect(); + + let tuples: Vec<_> = header.args.key + .get_all::<String, Tuple>(&mut f.errors) + .collect(); + + let classes = tuples.into_iter() + .map(|(class, mut tuple)| { + let fallback = tuple.get_all::<StringLike>(&mut f.errors) + .map(|s| s.0.to_lowercase()) + .collect(); + (class.to_lowercase(), fallback) + }) + .collect(); + FontFamilyFunc { body: body!(opt: body, ctx, f), - list: header.args.pos.get_all::<StringLike>(&mut f.errors) - .map(|s| s.0.to_lowercase()) - .collect(), + list, + classes, } } layout(self, ctx, errors) { - styled(&self.body, ctx, Some(&self.list), - |s, list| { - s.fallback.list = list.clone(); + styled(&self.body, ctx, Some(()), + |s, _| { + if !self.list.is_empty() { + s.fallback.list = self.list.clone(); + } + + for (class, fallback) in &self.classes { + s.fallback.set_class_list(class.clone(), fallback.clone()); + } + s.fallback.flatten(); }) } |
