Is there a way to style a table's cell based on its contents?

I csv file which I wish to read and print as a table. I want to highlight some of the entries by making them bold. I save the csv file with asterix’ (*) around the entries I wished to be bold. I’ve also tried to save them as bold(entry). Though this is simply printed as *entry* and bold(entry) and not entry. The styling options examples I’ve found seems to be mostly be about conditioning on the index of cell and not the content of it. Is there a way style the cell based on its contents? - sort of like,

#show table.cell.where(contains "*"): strong 

perhaps with something to remove the * as well.

Maybe something like this:

#show table.cell: it => {
  show regex("^\*.*\*$"): it => strong(it.text.slice(1, -1))
  it
}
2 Likes

Thank you - that seems to work

1 Like

Hello @Hans_Vinther-Larsen! Thank you for this topic, I have renamed your post to “Is there a way to style a table’s cell based on its contents?”. If it is wrong please correct it!
Good titles are questions you would ask your friend about Typst. :smiley:

You want to apply the eval function to evaluate your strings as Typst code. For example:

#let data = csv("data.csv")
#table(columns: 4, ..data.flatten().map(eval.with(mode: "markup")))
1 Like

Me three.

Thank you very much, the regex solution looks very cool and adaptable, ie looking for numbers in a certain range and the like.