/
如果你使用过 Typst,可能熟悉用于样式化元素的 #show 指令。
Quarkdown 提供了一种类似的、强大的机制,它涉及函数扩展 ,允许你不仅自定义元素的外观,还能自定义其行为与内容。
若干 Markdown 元素关联到一个名为*原语(primitive)*的特殊函数。例如,标题(#、## 等)由 .heading 原语函数支撑。
扩展一个原语允许你通过 .super 拦截并修改调用本身,.super 会调用原始函数并可选地覆盖其参数。
提示:有关受支持原语的完整列表,请参阅原语模块。
.extend {heading}
.super background:{red}
## This is red提示:有关大多数原语支持的样式属性列表,请参阅样式属性 。
where 参数允许你根据原始函数调用的参数来条件性地应用样式。
.extend {heading} where:{depth: .depth::equals {2}}
.super background:{red}
## This is red (depth 2)
### This is not red (depth 3)被拦截调用的任意参数都可以用在条件中,例如通过 ref 使用交叉引用标识符 :
.extend {math} where:{ref: .ref::startswith {einstein}}
.super foreground:{skyblue} fontsize:{larger}
$ E=mc^2 $ {#einstein-relativity}
$ F=ma $被拦截的参数也可以在运行时被修改。一个常见的用例是转换元素的 Markdown 内容。
Here we add an icon to all external links. Note that body arguments work with .super normally.
.extend {link} where:{url: .url::startswith {https://quarkdown.com}::not}
content:
.super
.content .icon {box-arrow-up-right}
Check out the [docs](https://quarkdown.com/docs)
and the [repo](https://github.com/iamgio/quarkdown)Quarkdown 支持通过 .match {content} {pattern} {replacement} 文档 ↗ 函数,按照正则表达式模式转换任意内容,该函数会将 content 中 pattern 的所有出现替换为 replacement。
.extend {paragraph}
content:
.super
.content::match {[Qq]uark(down|s)?}
***.1***
Quarkdown takes its name from quarksQuarkdown takes its name from quarks