summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2019-03-13 19:13:49 +0100
committerLaurenz <laurmaedje@gmail.com>2019-03-13 19:15:51 +0100
commit89205368c2788842abb13f1c174607d85dc4abe1 (patch)
treedce7fe4cbaf6c2ddeee6aa0d1126bf3fd2db1c95 /src/lib.rs
parent0c87c0c5a5b7379e938ef9f37673f9c9c0bff051 (diff)
Fix space handling for multiline 🔨
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/lib.rs b/src/lib.rs
index deb5b066..ae12bf8b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -37,20 +37,32 @@ use std::error;
use std::fmt;
use std::io::Write;
use crate::syntax::SyntaxTree;
-use crate::doc::Document;
+use crate::doc::{Document, Style};
/// Emits various compiled intermediates from source code.
pub struct Compiler<'s> {
/// The source code of the document.
source: &'s str,
+ /// Style for typesetting.
+ style: Style,
}
impl<'s> Compiler<'s> {
/// Create a new compiler from a document.
#[inline]
pub fn new(source: &'s str) -> Compiler<'s> {
- Compiler { source }
+ Compiler {
+ source,
+ style: Style::default(),
+ }
+ }
+
+ /// Set the default style for typesetting.
+ #[inline]
+ pub fn style(&mut self, style: Style) -> &mut Self {
+ self.style = style;
+ self
}
/// Return an iterator over the tokens of the document.
@@ -69,7 +81,7 @@ impl<'s> Compiler<'s> {
#[inline]
pub fn typeset(&self) -> Result<Document, Error> {
let tree = self.parse()?;
- Engine::new(&tree).typeset().map_err(Into::into)
+ Engine::new(&tree, self.style.clone()).typeset().map_err(Into::into)
}
/// Write the document as a _PDF_, returning how many bytes were written.
@@ -159,7 +171,7 @@ mod test {
}
#[test]
- fn long() {
+ fn long_styled() {
test("wikipedia", r#"
Typesetting is the composition of text by means of arranging physical types or the
digital equivalents. Stored letters and other symbols (called sorts in mechanical