ChatText (消息文本)
把消息的 text + entities 渲染出来:粗体、斜体、剧透(点击揭开)、行内代码与带语言标签可复制的代码块、引用块、链接与提及。不走 v-html,实体树由 ui-core 的纯函数生成,Flutter 端照同一算法移植。
基础用法
entities 的偏移与长度按 UTF-16 code unit 计,嵌套任意层;交叉、越界、切开 emoji 的区间都会先被 normalizeKunChatEntities 规整,所以任何数据都能渲染。
Basic.vue
剧透
通关了!最后的反转是 列车长就是白本人,而且 第三章那封信 早就暗示过了。
Spoiler.vue
单行预览
雪之下小春结局是 !强烈推荐,攻略见 论坛
wine Game.exePreview.vue
接管链接与提及
点一下链接或提及Events.vue
输入框快捷写法
parseKunChatMarkdown 把输入框里的 **粗** __斜__++下划线++ ~~删~~ ||剧透|| `代码````语言⏎代码⏎``` [文字](链接) [文字](mention:ID) 与行首 > 引用转成 text + entities;formatKunChatMarkdown 反过来, 编辑已发消息或恢复草稿时用。两者互逆(url 实体由服务端重新识别,不写回)。
属性
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| text * | string | — | Message text. |
| entities | KunChatEntity[] | null | null | Formatting ranges over `text`, in UTF-16 code units. Normalized before rendering, so malformed input renders instead of throwing. |
| preview | boolean | false | One-line summary rendering for previews (conversation rows, reply and pinned bars): blocks flatten inline, links are plain text, spoilers are masked so their text is not in the DOM at all. |
事件
| 事件 | 回调参数 | 说明 |
|---|---|---|
| link | url: string, event: MouseEvent | A link was clicked. It opens in a new tab unless you call `event.preventDefault()`, e.g. to route an in-site URL. |
| mention | userId: string, event: MouseEvent | A mention was clicked. It is a real link to the profile (`userLinkTemplate`); call `event.preventDefault()` to handle it yourself. |