如何消除Asciidoc中include语句换行后产生的多余空格
Asciidoc中解决include语句后跟句号的格式问题
我们用Asciidoc编写文档并通过Antora发布时,常会用include语句复用重复片段(比如「联系我们」)。但Asciidoc要求每个include单独占一行,换行后会自动插入空格,导致include片段后跟句号时出现「like this .」的错误格式,而非预期的「like this.」。
当前使用的代码示例:
include::partial$contact-support.adoc[] if you would like to request a feature or get support. You can also join the include::partial$decodable-slack.adoc[] .
以下几种方案都不够理想:
- 无法在片段中固定加入句号,因为片段并非总是用于句末
- 为句中、句末场景分别创建独立片段太繁琐
- 改写语句把片段挪到句末同样麻烦
可行解决方法
方法1:使用行连接符+消除空格
在include语句的末尾添加+,将其与后续的句号行连接,Asciidoc就不会在两者之间插入空格:
include::partial$contact-support.adoc[] if you would like to request a feature or get support. You can also join the include::partial$decodable-slack.adoc[]+ .
方法2:将片段定义为内联属性引用
把复用片段定义为文档属性,之后在文本中内联调用,这样能完全避免换行空格问题:
- 在文档开头或Antora的属性文件中定义属性:
:contact-support: {include::partial$contact-support.adoc[]} :decodable-slack: {include::partial$decodable-slack.adoc[]}
- 在正文内联使用属性:
{contact-support} if you would like to request a feature or get support. You can also join the {decodable-slack}.
这种方式更适合高频复用的片段,既保证格式正确,又简化了后续调用。
内容的提问来源于stack exchange,提问作者Robin Moffatt
相关产品推荐
相关产品推荐

