Improve `block.body` return on absence of content
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 56.1k
- Forks
- 1.7k
- Avg merge
- 3d 10h
- Merged PRs (30d)
- 22
Description
Description
Per the code at https://github.com/typst/typst/blob/ddd8ae7f49d7adf35702fd9347d53fdd726ead55/crates/typst-library/src/layout/container.rs#L428-L435
block.body returns auto when the block was created internally, without any content. While this may seem harmless at first since those blocks are internal, this behavior is observable if you write e.g.
#show block: it => it.body
#line()
This prints auto, which shouldn't be possible as a block's body should always be content or none per the docs.
While you're normally not supposed to write such rules and anything goes, some workarounds for some particular issues use show block - this was found by @jassielof when trying to use https://github.com/typst/typst/issues/2639#issuecomment-2994374209, leading to errors as auto.func() doesn't exist.
Perhaps it should return some form of opaque content to mean "internal stuff, don't touch" instead of auto to remain consistent with the documented type for body?
Reproduction URL
No response
Operating system
No response
Typst version
- I am using the latest version of Typst
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Inspect crates/typst-library/src/layout/container.rs at lines 428-435, then reproduce the issue with the provided show block rule and line() example. Determine how an internally created block with no content should satisfy the documented body type, and verify that the result no longer exposes auto.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100