summaryrefslogtreecommitdiff
path: root/crates/typst-library/src/foundations
diff options
context:
space:
mode:
authorTobias Schmitz <tobiasschmitz2001@gmail.com>2025-06-10 14:46:27 +0200
committerGitHub <noreply@github.com>2025-06-10 12:46:27 +0000
commita18ca3481da17a4de1cc7f9890f0c61efb480655 (patch)
tree84fb3fb78574856e20626f96754957bde5920dfb /crates/typst-library/src/foundations
parent82da96ed957a68017e092e2606226b45c34324f1 (diff)
Report errors in external files (#6308)
Co-authored-by: Laurenz <laurmaedje@gmail.com>
Diffstat (limited to 'crates/typst-library/src/foundations')
-rw-r--r--crates/typst-library/src/foundations/bytes.rs11
-rw-r--r--crates/typst-library/src/foundations/plugin.rs4
2 files changed, 13 insertions, 2 deletions
diff --git a/crates/typst-library/src/foundations/bytes.rs b/crates/typst-library/src/foundations/bytes.rs
index d633c99a..180dcdad 100644
--- a/crates/typst-library/src/foundations/bytes.rs
+++ b/crates/typst-library/src/foundations/bytes.rs
@@ -7,6 +7,7 @@ use std::sync::Arc;
use ecow::{eco_format, EcoString};
use serde::{Serialize, Serializer};
+use typst_syntax::Lines;
use typst_utils::LazyHash;
use crate::diag::{bail, StrResult};
@@ -286,6 +287,16 @@ impl Serialize for Bytes {
}
}
+impl TryFrom<&Bytes> for Lines<String> {
+ type Error = Utf8Error;
+
+ #[comemo::memoize]
+ fn try_from(value: &Bytes) -> Result<Lines<String>, Utf8Error> {
+ let text = value.as_str()?;
+ Ok(Lines::new(text.to_string()))
+ }
+}
+
/// Any type that can back a byte buffer.
trait Bytelike: Send + Sync {
fn as_bytes(&self) -> &[u8];
diff --git a/crates/typst-library/src/foundations/plugin.rs b/crates/typst-library/src/foundations/plugin.rs
index 31f8cd73..a04443bf 100644
--- a/crates/typst-library/src/foundations/plugin.rs
+++ b/crates/typst-library/src/foundations/plugin.rs
@@ -151,8 +151,8 @@ pub fn plugin(
/// A [path]($syntax/#paths) to a WebAssembly file or raw WebAssembly bytes.
source: Spanned<DataSource>,
) -> SourceResult<Module> {
- let data = source.load(engine.world)?;
- Plugin::module(data).at(source.span)
+ let loaded = source.load(engine.world)?;
+ Plugin::module(loaded.data).at(source.span)
}
#[scope]