typst / typst/typst

Allow text and regex show rules to match across styled content

Open
#6,076 7 comments 8 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

change request styling
Dominant language
Rust
Stars
56.1k
Forks
1.7k
Avg merge
3d 10h
Merged PRs (30d)
22

Description

Description

Currently, text and regex show rules don't match when using styled content, as in this example:

#show regex("an \w*"): underline

This is an example with regex show rules!

This is an _example_ with regex show rules!

Image

It would be very useful if the show rule would match across styled content. To begin with, this could be limited to elements which have a clear text representation, such as emph in this case. For this, typst would build an internal plain-text representation of the sequence, joining all the element's plain-text representations (e.g. emph.body is text), and then match the regex against that text representation. Such an internal plain-text representation is already used to build PDF bookmarks.

For simplicity, text and regex should not match across linebreaks and parbreaks, i.e. the plain-text representation should start over new on every line- and parbreak. This would then also give ^ more meaning (see https://github.com/typst/typst/issues/5273)

For cases where multiple show rules match a piece of text disjoint, it will be necessary to split element functions. E.g. show "This is": underline together with show "is an": upper would require underline to be split, so as to apply upper, i.e. an equivalent to #underline[This ]#upper[#underline[is] an].

Use Case

Any use cases where text and regex show rules currently break or behave unexpectedly due to styled content. More specialized use cases include sentence casing (see https://github.com/alerque/decasify/issues/38), customization of bibliography (see this forum post).

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

Start with the text and regex show-rule implementation and the existing plain-text representation used to build PDF bookmarks. Investigate how styled sequences such as emph are represented, along with linebreak and parbreak boundaries. Done means matching can span supported styled content while preserving the described non-crossing and overlapping-rule behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.