Skip to content

如何为列表的每个层级指定不同的样式?

如何为列表的每个层级指定不同的样式?

群友的魔法

typst
#let styled-list(..funcs, body, applied: x => x) = {
  let funcs = funcs.pos()
  body.children.map(x => {
    if x.func() != list.item {
      applied(x)
    } else {
      let body = if x.body.func() == [].func() {
        styled-list(
          ..funcs.slice(1),
          funcs.at(0),
          x.body,
          applied: funcs.at(0)
        )
      } else {
        funcs.at(0)(x.body)
      }
      list.item(body)
    }
  }).sum()
}

#styled-list(
  it => {
    set text(red)
    it
  },
  it => {
    set text(green)
    it
  },
  it => {
    set text(blue)
    it
  },
)[
  - abcd
    - abcd
      - abcd
      - abcd
        - abcd
    - abcd
  - abcd
    - abcd
]
Typst compiled imageTypst compiled image

贡献者

The avatar of contributor named as jkjkil4 jkjkil4
The avatar of contributor named as QuadnucYard QuadnucYard
The avatar of contributor named as 梦飞翔 梦飞翔

页面历史

Comments
  • Latest
  • Oldest
  • Hottest

基于 MIT 许可发布