Bonelate
Bonelate 是一个针对 LaTeX 的轻逻辑模版解析引擎,类似于 mustache。 与采取 mustache 的其他模版解析引擎相比(例如chevron或pymustache), Bonelate 针对 LaTeX 的语法做了很多优化,使 LaTeX 模板文件在不渲染的情况下也可使用 LaTeX 工具编译通过。
优势
Bonelate 针对 LaTeX 的语法设计了模板标记符,
使用 LaTeX 中非特殊字符作为标记符,例如{{!partial}}中的!,
从而在不解析渲染的情况下直接通过 LaTeX 引擎编译也不会报错。
安装 
这个项目使用 Python 开发,请确保你本地安装了它。
使用PyPI安装
$ pip install bonelate[all]
源码安装
$ git clone git@gitee.com:zrr1999/bonelate.git
$ cd bonelate
$ pip install .
使用说明
支持语法
- 模板变量渲染
{{keyName}} - 模板块渲染
{{!keyName}}sth.{{/keyName}}以!开始、以/结束表示模板块,它会根据当前上下文中的键值来对区块进行一次或多次渲染。 它的功能很强大,有类似if、foreach的功能。 - 失效渲染
{{?keyName}} {{/keyName}}该语法与模板块渲染类似,不同在于它是当keyName值为空或否定值时才渲染输出该区块内容。 - 视图渲染
{{.}}可以循环输出整个数组。
简单示例
运行如下代码
from bonelate import render, parse
test_string = r"\LaTeX{} is a {{var}} typesetting system.{{!vars}}.{{/vars}}"
print(render(test_string, {
"var": "high-quality",
"vars": range(10),
}))
得到渲染结果
\LaTeX{} is a high-quality typesetting system...........
命令行示例
如果你的环境变量中有 python 脚本目录,你可以使用
$ bonelate render ./examples/ml_work
如果没有的话,你需要使用如下命令
$ python bonelate render ./examples/ml_work
更新日志
0.1.2 (2021.5.14)
- 优化了插件接口。
- 修复了无法解析嵌套模板的问题。
- 修改了render指令用法
0.1.1 (2021.5.5)
- 完善了README中的用法描述。
- 增加了分隔符特性,{{var:sep}}。
- 遍历渲染改为判断对象是否为Iterable。
- 添加了用于处理Sympy公式的插件。
- 修复部分bug。
0.1.0 (2021.5.2)
- 重构 tokenizer,现在命名为parser。
- 增加了 partial 语法。
- 增加了 docs 目录。
- 增加了更多例子。
- 修改了单元测试。
0.0.2 (2021.4.29)
- 不再兼容mustache语法。
- 增加了命令行指令。
- 增加了更多例子。
- 添加了单元测试(不完全)。
- 修复了大括号内的内容不能正常解析的问题。
- 修复了模板变量中含有空白符不能正常解析的问题。
维护者
如何贡献
非常欢迎你的加入!提一个 Issue 或者提交一个 Pull Request。
贡献者
感谢以下参与项目的人:
使用许可
MIT © Rongrui Zhan
Metadata
Release files for Bonelate 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| Bonelate-0.1.2.tar.gz | 8.1 kB | Without provenance | Details for Bonelate-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| Bonelate-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for Bonelate-0.1.2-py3-none-any.whl |
Total release size: 19.0 kB
Release files / Bonelate-0.1.2.tar.gz
| Download URL | Bonelate-0.1.2.tar.gz |
|---|---|
| Size | 8.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8346c3d12d3da7ca56048e8fbb106e45aa0f7903bc45e20eaf45ed9db5a37e90
|
|
BLAKE2b-256 checksum How to use checksums |
1009591f55af6f45fbae1f0dd46abbb810f03374e4fd9f37a5a5e5f3d1735125
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5
|
Release files / Bonelate-0.1.2-py3-none-any.whl
| Download URL | Bonelate-0.1.2-py3-none-any.whl |
|---|---|
| Size | 10.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8ad7a7d879e2b7e61c79162ba0252beafb6a03014262210494229bd6e2d52753
|
|
BLAKE2b-256 checksum How to use checksums |
aa84483ec885b3c328e4890e2e357b49e2a21d55eb6ad558d8c48584683ceebb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5
|
Security for Bonelate 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.