使用胡子语法的pandoc变量替换过滤器

pandoc-mustache的Python项目详细描述


Date:May 11, 2019

pandoc-mustache: Variable Substitution in Pandoc

Development StatusPyPI versionPython versionBuild Status

pandoc mustache过滤器允许您将变量放入 pandoc文档文本,其值存储在单独的文件中。什么时候? 运行pandoc变量将替换为其值。

技术说明:此pandoc筛选器不是 这是Mustache template spec。只有 支持变量替换:不支持其他tag types 当前支持。

Example

此文档,在document.md

---
mustache: ./le_gaps.yaml
---
The richest American men live {{diff_le_richpoor_men}} years longer than the poorest men,
while the richest American women live {{diff_le_richpoor_women}} years longer than the poorest women.

结合这些变量定义,在le_gaps.yaml

diff_le_richpoor_men:"14.6"diff_le_richpoor_women:"10.1"

将由pandoc document.md --filterpandoc-mustache转换为:

The richest American men live 14.6 years longer than the poorest men, while the richest American women live 10.1 years longer than the poorest women.

Installation

通过打开终端并运行来安装:

pip install -U pandoc-mustache

支持Python2.7、3.4+、PyPy和PyPy3。

Usage

  1. 在pandoc文档中,通过将 双“胡子”中的变量名,即花括号,如 {{this}}

  2. 变量在一个或多个单独的文件中定义,使用yaml 格式化的键值对。例如:

    place:Montrealtemperature:'7'
  3. 包含胡子变量的pandoc文档指向 包含变量定义的yaml文件。这些 文件使用YAML metadata block中的胡子字段来指示,通常 放在pandoc文档的顶部。绝对路径和相对路径 支持路径:相对路径是相对于 运行pandoc的工作目录。

    例如:

    ---title:My Reportauthor:Jane Smithmustache:./vars.yaml---The temperature in {{place}} was {{temperature}} degrees.

    或者,使用多个文件:

    ---title:My Reportauthor:Jane Smithmustache:-./vars.yaml-./additional_vars.yaml---The temperature in {{place}} was {{temperature}} degrees.The humidity was {{humidity}}%.
  4. 运行pandoc并将文档中的所有变量替换为 通过将--filterpandoc-mustache添加到pandoc命令的值。

Tips and Tricks

  • 在yaml中定义变量时,不需要将字符串括起来 引述。但是如果你想用引号把数字括起来 以完全相同的格式出现在文档中。一些 示例:

    unquoted_string:Montreal  # becomes:Montrealquoted_string:'Montreal'# becomes: Montrealtrailingzero_num:7.40  # becomes:7.4trailingzero_string:'7.40'# becomes: 7.40
  • 如果你在写一份报告计算结果的文件, 您可以编写代码(使用r、python、stata等语言)来编写 每次生成数字时,都会自动将其发送到yaml文件。由 使用变量而不是 硬编码到文本中,文档可以立即更新 如果结果改变。你可以确定 输出文档反映分析的最新结果。

Contributing

Project Status: Inactive – The project has reached a stable, usable state but is no longer being actively developed; support/maintenance will be provided as time allows.

此代码尚未积极开发。它是为了满足我 pandoc的写作需要,目前的功能集对我来说已经足够了。

如果有bug报告,则可以创建问题或提交pull 请求。如果时间允许,我会调查的。

如果您有一个feature请求,那么我不太可能 为你实现它。您可以创建问题以生成讨论。如果 如果你实现了一个特性,你可以提交拉取请求,我会检查它 最后,如果时间允许。如果你对专业感兴趣 添加到代码中,我很高兴欢迎新的维护人员来到 项目。

License

此存储库中的所有文件都发布到公共域 在CC0 license到 允许尽可能广泛的重复使用。

Acknowledgements

这个pandoc过滤器是用sergio correia的 panflute包。这个 panflute存储库也 作为组织这个知识库的灵感。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java将Scanner对象作为构造函数参数传递给UserInterface类   spring未能启动bean“subtocolWebSocketHandler”;嵌套的例外是java。lang.IllegalArgumentException:没有处理程序   Java EE应用程序中后台服务的多线程Java线程(设置守护进程和优先级)?   java Pull to refresh返回列表的第一个位置   无法将comparator类转换为java。可比的   java将json从servlet传递到dojo   JavaHibernate:将子类实例转换为超类实例   java警告调用servlet类时非法反射访问   java静态变量值   java@Entity和@embeddeble之间有什么区别   java将作业配置导入公共作业配置类(注释配置)   sql公共表表达式(以values语句开头)在java中给出错误   java在ImageJ中使用ImageProcessor   java PostgreSQL executeBatch()会随着时间的推移而变慢   java在安卓中以表格形式排列sqllite表数据?   java中SVG的swing定制呈现   java删除与另一个实体映射的实体   java何时/如何添加ListView适配器,使用back按钮恢复它?(片段)   java为什么IBinder和Binder之间的类型转换不是非法的?   java在方法参数列表中使用ArrayList或List