From 1658b00282b631fb5218f477ea7f45f925644cea Mon Sep 17 00:00:00 2001 From: Laurenz Date: Thu, 13 Feb 2020 21:58:49 +0100 Subject: =?UTF-8?q?New=20syntax=20features=20=F0=9F=91=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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) --- src/library/font.rs | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) (limited to 'src/library') 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, list: Vec, + classes: Vec<(String, Vec)>, } parse(header, body, ctx, f) { + let list = header.args.pos.get_all::(&mut f.errors) + .map(|s| s.0.to_lowercase()) + .collect(); + + let tuples: Vec<_> = header.args.key + .get_all::(&mut f.errors) + .collect(); + + let classes = tuples.into_iter() + .map(|(class, mut tuple)| { + let fallback = tuple.get_all::(&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::(&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(); }) } -- cgit v1.2.3