如何在Asciidoc中仅引入.adoc文件的标题?
简化Asciidoc复用经验标题的方法
方法1:属性控制条件渲染
在_includes/experiences.adoc中通过属性定义区分标题和内容:
:show-experience-details: true == Experience one ifdef::show-experience-details[] *Company name, Location* - Dates 具体工作内容描述 endif::show-experience-details[] == Experience two ifdef::show-experience-details[] *Another Company, Location* - Dates 第二份工作内容描述 endif::show-experience-details[]
然后在resume.adoc中引入时覆盖属性,只加载标题:
:show-experience-details: false include::_includes/experiences.adoc[]
方法2:拆分独立标题文件
把经验标题单独抽取为独立文件,实现多处复用:
- 创建
_includes/experience-titles.adoc:
== Experience one == Experience two
- 在
_includes/experiences.adoc中组合标题与内容:
include::_includes/experience-titles.adoc[] // 对应Experience one的详情 *Company name, Location* - Dates 具体工作内容描述 // 对应Experience two的详情 *Another Company, Location* - Dates 第二份工作内容描述
- 在
resume.adoc中直接引入标题文件:
include::_includes/experience-titles.adoc[]
这种方式结构清晰,后续维护标题或内容都更便捷。
方法3:命令行过滤(本地构建场景)
如果使用Asciidoctor本地构建,可以借助命令行过滤器只提取标题行:
include::_includes/experiences.adoc[] | grep "^=="
注意这种方法依赖系统的grep工具,跨平台兼容性稍弱。
内容的提问来源于stack exchange,提问作者Jean-Charles
相关产品推荐
相关产品推荐

