summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs29
1 files changed, 11 insertions, 18 deletions
diff --git a/src/main.rs b/src/main.rs
index d0762b3e..03680204 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -16,19 +16,16 @@ fn main() -> anyhow::Result<()> {
loader.search_path("fonts");
loader.search_system();
- // Resolve the canonical path because the compiler needs it for module
- // loading.
+ // Determine source and destination path.
let src_path = Path::new(&args[1]);
+ let dest_path = if let Some(arg) = args.get(2) {
+ PathBuf::from(arg)
+ } else {
+ let name = src_path
+ .file_name()
+ .ok_or_else(|| anyhow!("source path is not a file"))?;
- // Find out the file name to create the output file.
- let name = src_path
- .file_name()
- .ok_or_else(|| anyhow!("source path is not a file"))?;
-
- let dest_path = if args.len() <= 2 {
Path::new(name).with_extension("pdf")
- } else {
- PathBuf::from(&args[2])
};
// Ensure that the source file is not overwritten.
@@ -36,6 +33,9 @@ fn main() -> anyhow::Result<()> {
bail!("source and destination files are the same");
}
+ // Resolve the file id of the source file.
+ let src_id = loader.resolve_path(src_path).context("source file not found")?;
+
// Read the source.
let src = fs::read_to_string(&src_path)
.map_err(|_| anyhow!("failed to read source file"))?;
@@ -44,14 +44,7 @@ fn main() -> anyhow::Result<()> {
let mut cache = typst::cache::Cache::new(&loader);
let scope = typst::library::new();
let state = typst::exec::State::default();
- let pass = typst::typeset(
- &mut loader,
- &mut cache,
- Some(&src_path),
- &src,
- &scope,
- state,
- );
+ let pass = typst::typeset(&mut loader, &mut cache, src_id, &src, &scope, state);
// Print diagnostics.
let map = typst::parse::LineMap::new(&src);