typst / typst/typst

Improve `block.body` return on absence of content

Open
#7,116 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug layout
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.