# 富文本编辑器功能建议：斜杠命令（类似 Notion）

**URL:** <https://meta.discourse.org/t/feature-suggestion-for-rich-text-editor-slash-command-a-la-notion/387188>\
**Category:** Feature\
**Tags:** composer\
**Created:** [2025年十月30日 14:56 UTC](https://meta.discourse.org/t/feature-suggestion-for-rich-text-editor-slash-command-a-la-notion/387188 "2025-10-30T14:56:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jrgong](https://avatars.discourse-cdn.com/v4/letter/j/c57346/32.png) [@jrgong](https://meta.discourse.org/u/jrgong)\
**Post date:** [2025年十月30日 14:56 UTC](https://meta.discourse.org/t/feature-suggestion-for-rich-text-editor-slash-command-a-la-notion/387188/1 "2025-10-30T14:56:57Z")

</div>

这可能只是我一时糊涂，但它可能很有用，因为它已成为许多应用程序（如 Notion）的用户体验/用户界面标准。

是否可以添加一个“/”命令功能，当用户在新/空行上时，会弹出一个上下文菜单，提供创建特定元素（如图像、链接、GIF、投票等）的选项？

如果插件和主题组件能够“访问”这一点，那就太好了。

有什么想法吗？这有意义吗？

---

<div class="post-metadata">

**Author:** ![chapoi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chapoi/32/537252_2.png) [@chapoi](https://meta.discourse.org/u/chapoi)\
**Post date:** [2025年十月31日 00:31 UTC](https://meta.discourse.org/t/feature-suggestion-for-rich-text-editor-slash-command-a-la-notion/387188/2 "2025-10-31T00:31:07Z")

</div>

我相信这已经在我们的关注之中，但我们收到的社区请求越多越好！

---

<div class="post-metadata">

**Author:** ![NateDhaliwal](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/natedhaliwal/32/313494_2.png) [@NateDhaliwal](https://meta.discourse.org/u/NateDhaliwal)\
**Post date:** [2025年十一月2日 08:56 UTC](https://meta.discourse.org/t/feature-suggestion-for-rich-text-editor-slash-command-a-la-notion/387188/3 "2025-11-02T08:56:01Z")

</div>

这可以通过 TC/插件或直接的 PR/代码库更改来实现吗？因为查看 [这个](https://github.com/discourse/discourse/blob/main/frontend%2Fdiscourse%2Fapp%2Fcomponents%2Fd-editor.gjs#L310)，它似乎不容易使用 TC/插件进行修改，因为它还需要一个 [`lib/`](https://github.com/discourse/discourse/tree/main/frontend%2Fdiscourse%2Fapp%2Flib%2Fautocomplete) 文件？

---

<div class="post-metadata">

**Author:** ![chapoi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chapoi/32/537252_2.png) [@chapoi](https://meta.discourse.org/u/chapoi)\
**Post date:** [2025年十一月4日 00:23 UTC](https://meta.discourse.org/t/feature-suggestion-for-rich-text-editor-slash-command-a-la-notion/387188/4 "2025-11-04T00:23:30Z")

</div>

我绝对不是该问的人，但我怀疑任何与 Composer 相关的东西是否能轻易地通过 TC 实现，或者根本不可能。我把这个问题交给我们的内部专家 @renato 🙂

---

<div class="post-metadata">

**Author:** ![renato](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/renato/32/383632_2.png) [@renato](https://meta.discourse.org/u/renato)\
**Post date:** [2025年十一月9日 13:07 UTC](https://meta.discourse.org/t/feature-suggestion-for-rich-text-editor-slash-command-a-la-notion/387188/5 "2025-11-09T13:07:17Z")

</div>

富文本编辑器组合器可以通过注册的扩展进行高度自定义，这些扩展遵循 [`RichEditorExtension`](https://github.com/discourse/discourse/blob/54723610355e58514646d6162e8a2511b160738b/frontend/discourse/app/lib/composer/rich-editor-extensions.js#L74-L99) 类型。每个自定义的 ProseMirror 节点/标记/插件等都通过 `registerRichEditorExtension` 调用进行处理。

如果为富文本编辑器 **仅** 创建一个斜杠命令功能，那将是可行的方法，尽管在我看来，我们已经有了非常接近我们想要的斜杠命令的自动完成实现，并且它还能轻松支持 Markdown 模式，这一点非常吸引人。

自动完成功能旨在同时适用于 **两种** 编辑器，而不仅仅是富文本编辑器，它位于富文本编辑器特定自定义的 **上方** 。表情符号、提及和标签在两种编辑器模式下工作方式相同。

它们在 `setupEditor` 中应用，并在该编辑器实例销毁时（例如在模式之间切换时）一并销毁：

> <https://github.com/discourse/discourse/blob/5ae2289db54df4fa2381857679796cb58d1ce7ec/frontend/discourse/app/components/d-editor.gjs#L615-L617>

> <https://github.com/discourse/discourse/blob/5ae2289db54df4fa2381857679796cb58d1ce7ec/frontend/discourse/app/components/d-editor.gjs#L472-L480>

> [@NateDhaliwal](#):
>
> 这是否可以通过 TC/插件或直接的 PR/代码库更改来实现？

是的，可以通过主题组件或插件来构建此功能（尽管目前通过 `setupEditor`/析构函数可能会有些棘手），但这方面我们理想情况下应该允许进一步的自定义——新的主题组件或插件应该能够为斜杠命令添加更多选项，并具有其特定的过滤规则——因此，核心提供的插件 API 是理想的选择。
