You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何消除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:将片段定义为内联属性引用

把复用片段定义为文档属性,之后在文本中内联调用,这样能完全避免换行空格问题:

  1. 在文档开头或Antora的属性文件中定义属性:
:contact-support: {include::partial$contact-support.adoc[]}
:decodable-slack: {include::partial$decodable-slack.adoc[]}
  1. 在正文内联使用属性:
{contact-support} if you would like to request a feature or get support. You can also join the {decodable-slack}.

这种方式更适合高频复用的片段,既保证格式正确,又简化了后续调用。

内容的提问来源于stack exchange,提问作者Robin Moffatt

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 21:49:56