# 多行选择不包含硬换行时使用的内联“预格式化文本”格式

**URL:** <https://meta.discourse.org/t/inline-preformatted-text-formatting-used-when-multi-line-selection-doesnt-contain-hard-break/387049>\
**Category:** Bug\
**Tags:** composer\
**Created:** [2025年十月29日 12:01 UTC](https://meta.discourse.org/t/inline-preformatted-text-formatting-used-when-multi-line-selection-doesnt-contain-hard-break/387049 "2025-10-29T12:01:29Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![per1234](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/per1234/32/569645_2.png) [@per1234](https://meta.discourse.org/u/per1234)\
**Post date:** [2025年十月29日 12:01 UTC](https://meta.discourse.org/t/inline-preformatted-text-formatting-used-when-multi-line-selection-doesnt-contain-hard-break/387049/1 "2025-10-29T12:01:29Z")

</div>

### 优先级/严重性：

中

### 平台

#### 操作系统

Windows 11

#### 浏览器

Google Chrome 141.0.7390.123

#### Discourse

`ad36231adab58a8a249bfe8139aade2bde2134d3`

### 描述：

“预格式化文本”格式有两种样式：

- 行内：用于在文本段落中使用非文本内容（例如，“调用 `foo` 函数”），或单行非文本内容。
- 块：用于多行非文本内容。

用户在作曲家中使用格式时，可以选择以下两种方法之一：

- 主动：在添加要格式化的内容之前切换格式模式。
- 被动：以未格式化的形式添加内容，然后选择该内容并应用格式。

🐛 在以下条件下，将“预格式化文本”格式应用于多行选择会使用不当的“行内”样式：

- 作曲家处于“富文本编辑器”模式。
- 格式被动应用。
- 所选内容中不存在硬换行符。

这导致帖子难以阅读，并且非文本内容难以复制（这是共享代码的常见要求）。

### 可复现步骤：

1. 打开作曲家。
2. 将编辑器模式开关置于“富文本编辑器”位置。
3. 在作曲家中键入 `foo`。
4. 按下 **Shift** + **Enter** 键盘快捷键添加“软换行”。
5. 在作曲家中键入 `bar`。  
❗ 不要添加换行符。
6. 按下 **Ctrl** + **Shift** + **Home** 键盘快捷键，从第二行的末尾到帖子的开头选择所有内容。
7. 点击作曲家工具栏上的 **\</\>** 按钮。

🐛 所选的每一行都以行内样式单独格式化：

`foo`  
`bar`

正确的行为是将内容放入单个代码块中：

```plaintext
foo
bar

```

### 其他上下文

我选择手动输入内容进行演示，以避免引入不必要的复杂性，即考虑从何处复制的内容可能存在的格式。但是，粘贴内容也会出现此错误，并且内容不包含硬换行符的条件更有可能与此类内容一起出现（因为用户在键入时很可能会使用 **Enter** ，即使他们实际上不想要硬换行符）。

* * *

如果使用“全选”/ **Ctrl** + **A** 选择内容，则不会出现此错误。

* * *

Markdown 编辑器在被动地将多行选择应用于“预格式化文本”格式时，始终将所选内容放入代码块中，这具有正确的行为。

* * *

我可以在 [try.discourse.org](http://try.discourse.org) 的“[安全模式](https://meta.discourse.org/t/how-to-use-discourse-safe-mode/53504)”中复现此错误。

* * *

最初报告于 [Why did the Forum functions change? - #37 by sterretje - Website and Forum - Arduino Forum](https://forum.arduino.cc/t/why-did-the-forum-functions-change/1400777/37)

---

_[View the full topic](https://meta.discourse.org/t/inline-preformatted-text-formatting-used-when-multi-line-selection-doesnt-contain-hard-break/387049)._
