Skip to content

Markdown 脚本

¥Markdown Scripts

可以使用 Markdown 编写脚本。zx 只会执行代码块。

¥It's possible to write scripts using markdown. Only code blocks will be executed by zx.

你可以运行这个 markdown 文件:

¥You can run this markdown file:

zx docs/markdown.md
js
await $`whoami`
await $`echo ${__dirname}`

__filename 将指向 markdown.md:

¥The __filename will be pointed to markdown.md:

js
console.log(chalk.yellowBright(__filename))

我们也可以在这里使用导入:

¥We can use imports here as well:

js
await import('chalk')

bash 代码(带有 bashsh 语言标签)也将被执行:

¥A bash code (with bash or sh language tags) also will be executed:

bash
VAR=$(date)
echo "$VAR" | wc -c

其他代码块将被忽略:

¥Other code blocks are ignored:

css
body .hero {
  margin: 42px;
}

google/zx 中文网 - 粤ICP备13048890号