# 不间断空格和窄不间断空格被替换为空格

**URL:** https://meta.discourse.org/t/no-break-space-and-narrow-no-break-space-are-replaced-by-space/169410
**Category:** Feature
**Created:** [2020 年11 月 6 日 08:51 UTC](https://meta.discourse.org/t/no-break-space-and-narrow-no-break-space-are-replaced-by-space/169410 "2020-11-06T08:51:29Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### 作者： ![jesus2099](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jesus2099/32/119720_2.png) [@jesus2099](https://meta.discourse.org/u/jesus2099)
#### 发布日期： [2020 年11 月 6 日 08:51 UTC](https://meta.discourse.org/t/no-break-space-and-narrow-no-break-space-are-replaced-by-space/169410/1 "2020-11-06T08:51:29Z")

</div>

是否可以在帖子中允许使用不换行空格（NBSP，U+00A0）甚至窄不换行空格（NNBSP，U+202F）？

目前，Discourse 会将它们替换为普通空格（SP，U+0020）（即使在代码片段中也是如此），从而导致法语数字在文本换行时显示错误。

在法语中，至少在标点符号如 `!?;:»` 之前、标点符号如 `«–—` 之后，以及大数字的三位数分组之间，应使用窄不换行空格（NNBSP）。

以下是不符合法语标准的显示示例：

> **[Should a recording title include an umlaut when the release had none?](https://community.metabrainz.org/t/should-a-recording-title-include-an-umlaut-when-the-release-had-none/502642/2?u=jesus2099)**
>
> As there is only 1 track to this recording, we must consider what is printed on the only release. And it shows: HANSEL AND GRETEL. Adding an accent where it is missing on a full uppercase printed title is very different IMO than adding a...

 ![image](https://global.discourse-cdn.com/meta/original/3X/7/c/7ca7fcd9a7f26cd6fb0bf8be5ca158208a69d255.png)

2 400 000 和 28 800 不应像这样被切断，它们应保持在同一行。

我认为，如果文本中包含 NBSP 或 NNBSP，那并非拼写错误，也不是无意的失误。

---

<div class="post-metadata">

### 作者： ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### 发布日期： [2020 年11 月 6 日 18:22 UTC](https://meta.discourse.org/t/no-break-space-and-narrow-no-break-space-are-replaced-by-space/169410/2 "2020-11-06T18:22:25Z")

</div>

这些有 HTML 实体吗？例如 `\u0026nbsp;` 可以这样使用：&nbsp; &nbsp; &nbsp; ← 空格

---

<div class="post-metadata">

### 作者： ![jesus2099](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jesus2099/32/119720_2.png) [@jesus2099](https://meta.discourse.org/u/jesus2099)
#### 发布日期： [2020 年11 月 6 日 19:22 UTC](https://meta.discourse.org/t/no-break-space-and-narrow-no-break-space-are-replaced-by-space/169410/3 "2020-11-06T19:22:16Z")

</div>

让我们试试 `\u0026#x202F;` 作为窄不换行空格千位分隔符：80\u0026#x202F;000 测试 80\u0026#x202F;000 测试 80\u0026#x202F;000 测试 80\u0026#x202F;000 测试 80\u0026#x202F;000 80\u0026#x202F;000 测试 80\u0026#x202F;000 测试 80\u0026#x202F;000 80\u0026#x202F;000 测试 80\u0026#x202F;000 测试 80\u0026#x202F;000 测试 80\u0026#x202F;000 测试 80\u0026#x202F;000 测试 80\u0026#x202F;000 测试 80\u0026#x202F;000 测试 80\u0026#x202F;000 80\u0026#x202F;000 测试 80\u0026#x202F;000 测试 80\u0026#x202F;000 测试 80\u0026#x202F;000 测试 80\u0026#x202F;000。

这样确实有效！  
我已经在另一个论坛上编辑了我的帖子，现在数字显示正常。  
虽然没有对应的命名 HTML 实体，但我可以像这样使用 Unicode 代码。🙂👍  
感谢提供变通方案，@codinghorror。

---

<div class="post-metadata">

### 作者： ![Julien\_Palard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/julien_palard/32/198784_2.png) [@Julien\_Palard](https://meta.discourse.org/u/Julien_Palard)
#### 发布日期： [2021 年11 月 4 日 10:24 UTC](https://meta.discourse.org/t/no-break-space-and-narrow-no-break-space-are-replaced-by-space/169410/4 "2021-11-04T10:24:46Z")

</div>

+1 同意此观点，在法语中，我们在 `:`、`!`、`?` 之前使用不换行空格，因为它们与前一个单词之间有空格，我们不希望它们出现在下一行的开头。

当前将不换行空格替换为普通空格的行为：

![Screenshot 2021-11-04 at 11-18-55 Jolie admin Flask - Entraide - AFPy](https://cdck-file-uploads-global.s3.dualstack.us-west-2.amazonaws.com/meta/optimized/3X/8/d/8da25d4968ec4f85e9f9f3408a4ac7c76694f448_2_690x42.png)

通过保留不换行空格，不再出现“孤立的冒号”：

![Screenshot 2021-11-04 at 11-19-43 Jolie admin Flask - Entraide - AFPy](https://cdck-file-uploads-global.s3.dualstack.us-west-2.amazonaws.com/meta/optimized/3X/1/9/190ff49b1af5814a323f50ff81a9dec9764b5c7c_2_690x42.png)

我认为没有必要为这些字符使用 HTML 转义序列，就像没有必要为任何其他非 ASCII 字符使用 HTML 转义序列一样：页面以 UTF-8 编码提供给浏览器，不换行空格像其他所有字符一样拥有 UTF-8 表示形式，例如：

→, √, ½, ñ, Ł, …

（换句话说，为什么 Discourse 允许大多数 Unicode 序列，却不允许不换行空格？）

---

<div class="post-metadata">

### 作者： ![jesus2099](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jesus2099/32/119720_2.png) [@jesus2099](https://meta.discourse.org/u/jesus2099)
#### 发布日期： [2021 年11 月 4 日 13:51 UTC](https://meta.discourse.org/t/no-break-space-and-narrow-no-break-space-are-replaced-by-space/169410/5 "2021-11-04T13:51:31Z")

</div>

是的，我完全同意。  
我从来记不住窄不间断空格（NARROW NO-BREAK SPACE）的 `\u0026#x202F;` 语法。😕

---

<div class="post-metadata">

### 作者： ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### 发布日期： [2021 年11 月 14 日 05:54 UTC](https://meta.discourse.org/t/no-break-space-and-narrow-no-break-space-are-replaced-by-space/169410/6 "2021-11-14T05:54:59Z")

</div>

> [@Julien\_Palard](#):
>
> （换句话说，为什么 Discourse 允许大多数 Unicode 序列，但不允许不间断空格？）

@j.jaffeux 和 @zogstrip，你们怎么看？

---

<div class="post-metadata">

### 作者： ![jesus2099](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jesus2099/32/119720_2.png) [@jesus2099](https://meta.discourse.org/u/jesus2099)
#### 发布日期： [2021 年11 月 14 日 19:10 UTC](https://meta.discourse.org/t/no-break-space-and-narrow-no-break-space-are-replaced-by-space/169410/7 "2021-11-14T19:10:39Z")

</div>

还有 `U+202F` **窄不间断空格** 。  
如法语印刷品般最自然的标点符号前字符。

---

<div class="post-metadata">

### 作者： ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### 发布日期： [2021 年11 月 15 日 00:14 UTC](https://meta.discourse.org/t/no-break-space-and-narrow-no-break-space-are-replaced-by-space/169410/8 "2021-11-15T00:14:28Z")

</div>

这是我们的文本清理器：

> <https://github.com/discourse/discourse/blob/2b848213f7dc6999ddf0809e68e1ceb980597c9d/lib/text_cleaner.rb#L74-L78>

我认为这样做是为了避免一种微不足道的垃圾信息形式，即人们编辑帖子但什么都没改变，然后大家挠头说……有什么变化吗？

---

<div class="post-metadata">

### 作者： ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### 发布日期： [2021 年11 月 15 日 17:04 UTC](https://meta.discourse.org/t/no-break-space-and-narrow-no-break-space-are-replaced-by-space/169410/9 "2021-11-15T17:04:06Z")

</div>

> [@sam](#):
>
> 我认为这样做是为了避免一种微不足道的破坏形式，即人们编辑帖子，但没有任何改变，然后人们挠头说……有什么改变？

是的，我也记得是这样。如果有一种更好的方法来处理/显示使用此类“字符”进行破坏时的差异，我很乐意删除这个 `mornalize_whitespaces` 方法。

---

<div class="post-metadata">

### 作者： ![oca](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/oca/32/156060_2.png) [@oca](https://meta.discourse.org/u/oca)
#### 发布日期： [2023 年1 月 26 日 08:41 UTC](https://meta.discourse.org/t/no-break-space-and-narrow-no-break-space-are-replaced-by-space/169410/10 "2023-01-26T08:41:30Z")

</div>

当一个新的设置（默认启用）要求时，是否可以实现 `mornalize_whitespaces`？然后，本地管理员可以在其使用中选择退出此功能，因为与字体排印相比，他们的使用中捣乱问题较小？

---

<div class="post-metadata">

### 作者： ![Jagster](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jagster/32/192154_2.png) [@Jagster](https://meta.discourse.org/u/Jagster)
#### 发布日期： [2023 年1 月 26 日 12:06 UTC](https://meta.discourse.org/t/no-break-space-and-narrow-no-break-space-are-replaced-by-space/169410/11 "2023-01-26T12:06:40Z")

</div>

> [@Julien\_Palard](#):
>
> 在法语中，我们在“:”、“!”、“?”前使用不间断空格，因为它们与前面的单词有空格

快速谷歌搜索表明并非如此。或者是我误解了“ **有空格** ”的意思？ ← 据我所知，这个问号没有空格。

而且，这种不分割千位数的语法规则适用于所有（西方）语言。就像这里也不应该出现这种情况一样 😉

---

<div class="post-metadata">

### 作者： ![Julien\_Palard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/julien_palard/32/198784_2.png) [@Julien\_Palard](https://meta.discourse.org/u/Julien_Palard)
#### 发布日期： [2023 年1 月 26 日 15:27 UTC](https://meta.discourse.org/t/no-break-space-and-narrow-no-break-space-are-replaced-by-space/169410/12 "2023-01-26T15:27:36Z")

</div>

> [@Jagster](#):
>
> 快速的谷歌搜索表明事实并非如此。

我想看看是哪些来源告诉你法国人在单词和标点符号之间“粘”在一起。

这里有一些来源表明标点符号（？、！、：，而不是 . 或 ,）应该与它们左边的单词分开，例如：“Comment vas-tu ? »

- [https://jacques-andre.fr/faqtypo/lessons.pdf](https://jacques-andre.fr/faqtypo/lessons.pdf) 第 32 页，这是一本关于法语排版的免费书籍
- 在《Lexique des règles typographiques en usage à l’Imprimerie nationale》（法国国家印刷局使用的排版规则词汇表）第 149 页，我们看到：“espace fine insécable ? espace juistifiante”，所以他们没有说使用 U+00A0（不间断空格），而是使用 U+202F（窄不间断空格）（我不知道如何在键盘上输入它，但它仍然不是 U+0020（空格））。（可悲的是，这本书不是免费的，所以我没有它的超链接）。
- [法语维基百科](https://fr.wikipedia.org/wiki/Point_d%27interrogation) 提到：“En France, il est d’usage de placer une espace fine insécable avant le point d’interrogation, ou une espace insécable si la fine n’est pas disponible。”（在法国，习惯上在问号前放置一个窄不间断空格，或者在没有窄不间断空格的情况下放置一个不间断空格。）

---

<div class="post-metadata">

### 作者： ![Jagster](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jagster/32/192154_2.png) [@Jagster](https://meta.discourse.org/u/Jagster)
#### 发布日期： [2023 年1 月 26 日 15:45 UTC](https://meta.discourse.org/t/no-break-space-and-narrow-no-break-space-are-replaced-by-space/169410/13 "2023-01-26T15:45:03Z")

</div>

> [@Julien\_Palard](#):
>
> 我想知道是哪些来源告诉你法国人会把单词和标点符号“粘”在一起。

一本供初学者学习法语的教材/练习册，他们认为自己可以学会法语 😉 我应该回去……, 我不知道英语里怎么说，但有点像成人的社区晚校——一种消磨闲暇时光、学习新东西的方式——然后拍下那段文字的照片。

但我承认我错了。你肯定比我更了解这个。
