https://github.com/sillyfreak/typst-prequery
Extract metadata from typst documents for preprocessing
https://github.com/sillyfreak/typst-prequery
typst typst-package
Last synced: over 1 year ago
JSON representation
Extract metadata from typst documents for preprocessing
- Host: GitHub
- URL: https://github.com/sillyfreak/typst-prequery
- Owner: SillyFreak
- License: mit
- Created: 2024-06-09T13:52:06.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-02-20T15:18:30.000Z (over 1 year ago)
- Last Synced: 2025-02-24T02:15:59.821Z (over 1 year ago)
- Topics: typst, typst-package
- Language: Typst
- Homepage: https://typst.app/universe/package/prequery
- Size: 10.2 MB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Prequery
This package helps extracting metadata for preprocessing from a typst document, for example image URLs for download from the web. Typst compilations are sandboxed: it is not possible for Typst packages, or even just a Typst document itself, to access the "ouside world". This sandboxing of Typst has good reasons. Yet, it is often convenient to trade a bit of security for convenience by weakening it. Prequery helps with that by providing some simple scaffolding for supporting preprocessing of documents.
## Getting Started
Here's an example for referencing images from the internet:
```typ
#import "@preview/prequery:0.1.0"
// toggle this comment or pass `--input prequery-fallback=true` to enable fallback
// #prequery.fallback.update(true)
#prequery.image(
"https://en.wikipedia.org/static/images/icons/wikipedia.png",
"assets/wikipedia.png")
```
Using `typst query`, the image URL(s) are extracted from the document:
```sh
typst query --input prequery-fallback=true --field value \
main.typ ''
```
This will output the following piece of JSON:
```json
[{"url": "https://en.wikipedia.org/static/images/icons/wikipedia.png", "path": "assets/wikipedia.png"}]
```
Which can then be used to download all images to the expected locations.
## Usage
See the [manual](docs/manual.pdf) for details.