diff options
| author | Laurenz <laurmaedje@gmail.com> | 2019-10-17 10:12:34 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2019-10-17 10:12:34 +0200 |
| commit | f22f9513aea21408ebf6febd01912e630e9ad5e6 (patch) | |
| tree | 06885bca8bc31d26189f33c059649ed7909af282 /src/library/mod.rs | |
| parent | 9a1d57a11a510b8e6af024b4338ee58d791f3088 (diff) | |
Add pagebreak function ⏭
Diffstat (limited to 'src/library/mod.rs')
| -rw-r--r-- | src/library/mod.rs | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/src/library/mod.rs b/src/library/mod.rs index 9a8b2e21..7c54a9f6 100644 --- a/src/library/mod.rs +++ b/src/library/mod.rs @@ -4,6 +4,7 @@ use crate::func::Scope; mod align; mod styles; +mod breaks; /// Useful imports for creating your own functions. pub mod prelude { @@ -12,13 +13,11 @@ pub mod prelude { pub use crate::layout::{LayoutError, LayoutResult}; pub use crate::parsing::{parse, ParseContext, ParseError, ParseResult}; pub use crate::syntax::{Expression, FuncHeader, SyntaxTree}; - - pub fn err<S: Into<String>, T>(message: S) -> ParseResult<T> { - Err(ParseError::new(message)) - } + pub use super::helpers::*; } pub use align::AlignFunc; +pub use breaks::PagebreakFunc; pub use styles::{BoldFunc, ItalicFunc, MonospaceFunc}; /// Create a scope with all standard functions. @@ -28,5 +27,26 @@ pub fn std() -> Scope { std.add::<ItalicFunc>("italic"); std.add::<MonospaceFunc>("mono"); std.add::<AlignFunc>("align"); + std.add::<PagebreakFunc>("pagebreak"); std } + +pub mod helpers { + use super::prelude::*; + + pub fn has_arguments(header: &FuncHeader) -> bool { + !header.args.is_empty() || !header.kwargs.is_empty() + } + + pub fn parse_maybe_body(body: Option<&str>, ctx: ParseContext) -> ParseResult<Option<SyntaxTree>> { + if let Some(body) = body { + Ok(Some(parse(body, ctx)?)) + } else { + Ok(None) + } + } + + pub fn err<S: Into<String>, T>(message: S) -> ParseResult<T> { + Err(ParseError::new(message)) + } +} |
