forked from vhaudiquet/rhema-together
Messages were plain text, so headings, lists, code, tables, and links from people and the agent showed as literal markup. Render them with markdown-it, with raw HTML off and unsafe link schemes blocked. External links open in a new tab, and @rhema stays highlighted. Code, tables, quotes, and images get styles that fit the message body.
38 lines
1.4 KiB
Vue
38 lines
1.4 KiB
Vue
<script setup lang="ts">
|
|
import { computed } from 'vue'
|
|
import type { Message } from '~/types'
|
|
import { fullTime, relativeTime } from '~/utils/format'
|
|
import { memberColorVar } from '~/utils/member'
|
|
import { renderMarkdown } from '~/utils/markdown'
|
|
|
|
const props = defineProps<{ message: Message; color?: string | null; avatar?: string | null }>()
|
|
|
|
const html = computed(() => renderMarkdown(props.message.text))
|
|
const style = computed(() => ({ '--member': memberColorVar(props.color) }))
|
|
</script>
|
|
|
|
<template>
|
|
<div v-if="message.author_kind === 'system'" class="msg msg-system">
|
|
{{ message.text }}
|
|
</div>
|
|
|
|
<div v-else-if="message.author_kind === 'agent'" class="msg msg-agent">
|
|
<div class="msg-head">
|
|
<span class="msg-agent-label">rhema</span>
|
|
<span class="msg-time" :title="fullTime(message.created_at)">{{ relativeTime(message.created_at) }}</span>
|
|
</div>
|
|
<div class="msg-text" v-html="html"></div>
|
|
</div>
|
|
|
|
<div v-else class="msg msg-human">
|
|
<AppAvatar :name="message.author_name" :color="color" :src="avatar" size="sm" />
|
|
<div class="msg-body">
|
|
<div class="msg-head">
|
|
<span class="msg-author member-name" :style="style">{{ message.author_name }}</span>
|
|
<span class="msg-time" :title="fullTime(message.created_at)">{{ relativeTime(message.created_at) }}</span>
|
|
</div>
|
|
<div class="msg-text" v-html="html"></div>
|
|
</div>
|
|
</div>
|
|
</template>
|