From 9167ba593c640796c2bcd0263fdca3ff9a94a87f Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Thu, 12 Oct 2023 16:29:48 +0200 Subject: [PATCH] [mastodon-client] Omit paragraph tags for user profile fields --- packages/backend/src/server/api/mastodon/converters/user.ts | 2 +- packages/backend/src/server/api/mastodon/helpers/mfm.ts | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/backend/src/server/api/mastodon/converters/user.ts b/packages/backend/src/server/api/mastodon/converters/user.ts index 665b95c02..08f0a252e 100644 --- a/packages/backend/src/server/api/mastodon/converters/user.ts +++ b/packages/backend/src/server/api/mastodon/converters/user.ts @@ -110,7 +110,7 @@ export class UserConverter { private static encodeField(f: Field): MastodonEntity.Field { return { name: f.name, - value: MfmHelpers.toHtml(mfm.parse(f.value)) ?? escapeMFM(f.value), + value: MfmHelpers.toHtml(mfm.parse(f.value), undefined, true) ?? escapeMFM(f.value), verified_at: f.verified ? (new Date()).toISOString() : null, } } diff --git a/packages/backend/src/server/api/mastodon/helpers/mfm.ts b/packages/backend/src/server/api/mastodon/helpers/mfm.ts index 2b4fa2acf..931036e29 100644 --- a/packages/backend/src/server/api/mastodon/helpers/mfm.ts +++ b/packages/backend/src/server/api/mastodon/helpers/mfm.ts @@ -7,7 +7,8 @@ import mfm from "mfm-js"; export class MfmHelpers { public static toHtml( nodes: mfm.MfmNode[] | null, - mentionedRemoteUsers: IMentionedRemoteUsers = [] + mentionedRemoteUsers: IMentionedRemoteUsers = [], + inline: boolean = false ) { if (nodes == null) { return null; @@ -203,6 +204,6 @@ export class MfmHelpers { appendChildren(nodes, doc.body); - return `

${doc.body.innerHTML}

`; + return inline ? doc.body.innerHTML : `

${doc.body.innerHTML}

`; } }