Skip to content

修复 2.4 节双连字符被渲染为长破折号的问题 - #544

Closed
Goldloli wants to merge 1 commit into
progit:masterfrom
Goldloli:fix/undoing-double-dash
Closed

Goldloli wants to merge 1 commit into
progit:masterfrom
Goldloli:fix/undoing-double-dash

Conversation

@Goldloli

Copy link
Copy Markdown

问题

2.4 撤消操作 → 撤消对文件的更改 一节的 IMPORTANT 提示中,git checkout -- <file> 被渲染成 git checkout — <file>(两个连字符变成了 U+2014 长破折号),读者会误以为这里是一个破折号,而不是 Git 的双连字符选项。对应 issue #536,#539 是同一问题的重复 issue。

原因

该行是正文中的行内代码,AsciiDoc 会把被空格包围的 -- 替换为长破折号(em dash,U+2014);同页 listing block 中的 -- 不参与该替换,所以只有这一处正文受影响。

改动

只改一行,对 -- 的第一个连字符做反斜杠转义,使其按字面量渲染:

-请务必记得 `git checkout -- <file>` 是一个危险的命令。
+请务必记得 `git checkout \-- <file>` 是一个危险的命令。

本地验证

用与 Gemfile 一致的 asciidoctor 2.0.12 渲染该节,对比修改前后的 HTML 输出:

asciidoctor -o /tmp/undoing_before.html book/02-git-basics/sections/undoing.asc   # 修改前
asciidoctor -o /tmp/undoing_after.html  book/02-git-basics/sections/undoing.asc   # 修改后
  • 修改前:git checkout 渲染为 git checkout&#8201;&#8212;&#8201;&lt;file&gt;(带窄空格的长破折号)
  • 修改后:git checkout -- &lt;file&gt;(与同页 listing block 中 git checkout -- CONTRIBUTING.md 的渲染一致)

另外全库确认正文行内代码中「空格 + -- + 空格」只有这一处,没有同类问题遗漏:

grep -rn '`[^`]* -- [^`]*`' --include=*.asc book/
# book/02-git-basics/sections/undoing.asc:134 (仅此一处,即本 PR 修改处)

Fixes #536
Closes #539(重复 issue)

@Goldloli

Copy link
Copy Markdown
Author

抱歉,这个 PR 与 #539 重复了:#539 已对同一行(book/02-git-basics/sections/undoing.asc:134)做了完全相同的修复(\-- 转义),且 CI build 已通过、mergeStateStatus 为 CLEAN。我先关闭本 PR,避免重复占用维护者时间。本地用 asciidoctor 2.0.12(与 Gemfile 同版本)渲染验证的结果与 #539 的修复一致(修改前 git checkout&#8201;&#8212;&#8201;&lt;file&gt; → 修改后 git checkout -- &lt;file&gt;),供 #539 参考。

@Goldloli Goldloli closed this Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

两个连字符--被渲染成了一个长破折号—

1 participant