Project files are not accessible from within package #3

Open
opened 2024-10-28 11:53:00 +00:00 by HEL · 2 comments
Owner

As of Typst 0.12, a package cannot access project files (e.g. with read, yaml, etc.) unless it is included in the project itself.
The manual should warn the user of this behavior in the documentation for schema.load
The user should still be able to pass a path, which is useful in the (rare) case described above

The schema.load function could be adapted to allow passing the file content (via read) and the format (i.e. yaml, json, etc.)

As of Typst 0.12, a package cannot access project files (e.g. with `read`, `yaml`, etc.) unless it is included in the project itself. The manual should warn the user of this behavior in the documentation for `schema.load` The user should still be able to pass a path, which is useful in the (rare) case described above The `schema.load` function could be adapted to allow passing the file content (via `read`) and the format (i.e. `yaml`, `json`, etc.)
HEL added the
enhancement
label 2024-10-28 11:53:00 +00:00

Stumbled into this while trying to render an example. How do I specify the file to render?

Stumbled into this while trying to render an example. How do I specify the file to render?
Author
Owner

The current workaround is to read the file into a raw block and passing that to schema.load:

#let data = raw(read("schema.yaml"), block: true, lang: "yaml")
#let example = schema.load(data)
#schema.render(example)

This is really not ideal an I will probably integrate it directly into schema.load, except if a mechanism to read files outside of the package is added to Typst

Another solution (even less practical) is to include the package in your project

EDIT: You can actually also directly call the yaml or json functions and pass the result:

#let data = yaml("schema.yaml")
#let example = schema.load(data)
#schema.render(example)
The current workaround is to read the file into a raw block and passing that to `schema.load`: ```typst #let data = raw(read("schema.yaml"), block: true, lang: "yaml") #let example = schema.load(data) #schema.render(example) ``` This is really not ideal an I will probably integrate it directly into `schema.load`, except if a mechanism to read files outside of the package is added to Typst Another solution (even less practical) is to include the package in your project EDIT: You can actually also directly call the `yaml` or `json` functions and pass the result: ```typst #let data = yaml("schema.yaml") #let example = schema.load(data) #schema.render(example) ```
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: HEL/rivet-typst#3
No description provided.