8 个版本 (4 个破坏性更新)

0.5.1 2022年7月10日
0.5.0 2022年1月7日
0.4.2 2021年12月29日
0.4.1 2021年11月5日
0.1.0 2020年2月27日

#357 in 模板引擎

MIT 许可证

15KB
286 代码行

Build Status Crate Docs

mdbook-tera

Tera 预处理器,用于 mdBook
API 文档托管在 docs.rs 上。

$ mdbook-tera --help
mdbook-tera 0.5.1
A mdBook preprocessor that renders Tera

USAGE:
    mdbook-tera [OPTIONS] [SUBCOMMAND]

OPTIONS:
    -h, --help                       Print help information
        --json <FILE>                Sets context from JSON file
        --template-include <GLOB>    Include tera templates matching a glob expression [default:
                                     **/*.tera]
        --template-root <PATH>       Root directory to include templates from [default: ./src]
        --toml <FILE>                Sets context from TOML file
    -V, --version                    Print version information

SUBCOMMANDS:
    help        Print this message or the help of the given subcommand(s)
    supports    Check whether a renderer is supported by this preprocessor

用法

首先安装 Tera 预处理器。

cargo install mdbook-tera

然后在你的 book.toml 文件中,添加如下 Tera 预处理器。

默认配置

# Default options, load a TOML context file from ./src/context.toml
[preprocessor.tera]

JSON 配置

[preprocessor.tera]
command = "mdbook-tera --json ./src/context.json"

在 Markdown 文件中的用法

查看 example-book 了解基本用法。

只需在 context.toml 文件中定义你的值,并在 Tera 语句中使用它们。你可以使用键 ctx 访问书籍上下文。

# My Heading

{{ my_value }}

依赖项

~15–26MB
~383K SLoC