/

环境变量

Quarkdown 可以在编译时从宿主系统中读取环境变量,使文档能够根据其编译所在的环境来调整内容。

读取环境变量

.env {name} 文档 ↗ 返回给定名称的环境变量的值,若未设置则返回 none

示例 1

This page was compiled with .env {SHELL} as the default shell.

This page was compiled with

Error

Cannot read environment variable 'SHELL': not enough privileges to perform this action.
Missing required permission: process.
To grant this permission, run with: --allow process

as the default shell.

示例 2

由于结果可能是 none,你可以使用可选项函数 来处理缺失的值:

.container background:{.env {COLOR}::otherwise {teal}}
    Hello, world!

Error

Cannot read environment variable 'COLOR': not enough privileges to perform this action.
Missing required permission: process.
To grant this permission, run with: --allow process

权限

读取环境变量需要 process 权限

quarkdown c main.qd --allow process