feat(web): render messages as markdown
ci / checks (push) Successful in 1m58s
ci / test (push) Successful in 1m54s
ci / chart (push) Successful in 5s
ci / web (push) Successful in 18s
ci / docker (push) Successful in 16s
ci / publish-edge-image (push) Successful in 9s
ci / publish-edge-chart (push) Successful in 3s
ci / checks (push) Successful in 1m58s
ci / test (push) Successful in 1m54s
ci / chart (push) Successful in 5s
ci / web (push) Successful in 18s
ci / docker (push) Successful in 16s
ci / publish-edge-image (push) Successful in 9s
ci / publish-edge-chart (push) Successful in 3s
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.
This commit is contained in:
1 parent
d4aac727ad
commit
a8f7e74ba0
5 files changed
+235
-20
No files matched your search
@@ -3,16 +3,11 @@ 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 segments = computed(() => {
|
||||
const parts = props.message.text.split(/(@rhema\b)/gi)
|
||||
return parts
|
||||
.filter((part) => part.length > 0)
|
||||
.map((part) => ({ text: part, mention: /^@rhema$/i.test(part) }))
|
||||
})
|
||||
|
||||
const html = computed(() => renderMarkdown(props.message.text))
|
||||
const style = computed(() => ({ '--member': memberColorVar(props.color) }))
|
||||
</script>
|
||||
|
||||
@@ -26,12 +21,7 @@ const style = computed(() => ({ '--member': memberColorVar(props.color) }))
|
||||
<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">
|
||||
<template v-for="(segment, index) in segments" :key="index">
|
||||
<span v-if="segment.mention" class="mention">{{ segment.text }}</span>
|
||||
<template v-else>{{ segment.text }}</template>
|
||||
</template>
|
||||
</div>
|
||||
<div class="msg-text" v-html="html"></div>
|
||||
</div>
|
||||
|
||||
<div v-else class="msg msg-human">
|
||||
@@ -41,12 +31,7 @@ const style = computed(() => ({ '--member': memberColorVar(props.color) }))
|
||||
<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">
|
||||
<template v-for="(segment, index) in segments" :key="index">
|
||||
<span v-if="segment.mention" class="mention">{{ segment.text }}</span>
|
||||
<template v-else>{{ segment.text }}</template>
|
||||
</template>
|
||||
</div>
|
||||
<div class="msg-text" v-html="html"></div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
Reference in new issue
Block a user