fix: revert removal of parsing rich content in display name

This reverts commit 5be48b102f.
zio/stable
Daniel Roe 2022-12-17 16:06:45 +00:00
parent 5be48b102f
commit b545efeacc
No known key found for this signature in database
GPG Key ID: 22D5008E4F5D9B55
4 changed files with 34 additions and 46 deletions

View File

@ -81,7 +81,6 @@ watchEffect(() => {
font-bold sm:text-2xl text-xl
:content="getDisplayName(account, { rich: true })"
:emojis="account.emojis"
:markdown="false"
/>
<AccountBotIndicator v-if="account.bot" />
</div>

View File

@ -5,17 +5,13 @@ defineOptions({
name: 'ContentRich',
})
const { content, emojis, markdown = true } = defineProps<{
const props = defineProps<{
content: string
markdown?: boolean
emojis?: Emoji[]
}>()
export default () => h(
'span',
{ class: 'content-rich' },
contentToVNode(content, {
emojis: emojisArrayToObject(emojis || []),
markdown,
}),
contentToVNode(props.content, emojisArrayToObject(props.emojis || [])),
)

View File

@ -12,7 +12,7 @@ function decode(text: string) {
* Parse raw HTML form Mastodon server to AST,
* with interop of custom emojis and inline Markdown syntax
*/
export function parseMastodonHTML(html: string, customEmojis: Record<string, Emoji> = {}, markdown = true) {
export function parseMastodonHTML(html: string, customEmojis: Record<string, Emoji> = {}) {
let processed = html
// custom emojis
.replace(/:([\w-]+?):/g, (_, name) => {
@ -21,10 +21,7 @@ export function parseMastodonHTML(html: string, customEmojis: Record<string, Emo
return `<img src="${emoji.url}" alt=":${name}:" class="custom-emoji" data-emoji-id="${name}" />`
return `:${name}:`
})
if (markdown) {
// handle code blocks
processed = processed
.replace(/>(```|~~~)(\w*)([\s\S]+?)\1/g, (_1, _2, lang, raw) => {
const code = htmlToText(raw)
const classes = lang ? ` class="language-${lang}"` : ''
@ -56,14 +53,13 @@ export function parseMastodonHTML(html: string, customEmojis: Record<string, Emo
}
}
})
}
return parse(processed)
}
export function convertMastodonHTML(html: string, customEmojis: Record<string, Emoji> = {}) {
export async function convertMastodonHTML(html: string, customEmojis: Record<string, Emoji> = {}) {
const tree = parseMastodonHTML(html, customEmojis)
return render(tree)
return await render(tree)
}
export function htmlToText(html: string) {

View File

@ -13,12 +13,9 @@ import AccountHoverWrapper from '~/components/account/AccountHoverWrapper.vue'
*/
export function contentToVNode(
content: string,
{ emojis = {}, markdown = true }: {
emojis?: Record<string, Emoji>
markdown?: boolean
} = {},
customEmojis: Record<string, Emoji> = {},
): VNode {
const tree = parseMastodonHTML(content, emojis, markdown)
const tree = parseMastodonHTML(content, customEmojis)
return h(Fragment, (tree.children as Node[]).map(n => treeToVNode(n)))
}