diff --git a/packages/backend/src/core/MfmService.ts b/packages/backend/src/core/MfmService.ts index 4f9f553e7e..0d80bfbdca 100644 --- a/packages/backend/src/core/MfmService.ts +++ b/packages/backend/src/core/MfmService.ts @@ -377,7 +377,7 @@ export class MfmService { } @bindThis - public toHtml(nodes: mfm.MfmNode[] | null, mentionedRemoteUsers: IMentionedRemoteUsers = [], additionalAppenders: Appender[] = []) { + public toHtml(nodes: mfm.MfmNode[] | null, mentionedRemoteUsers: IMentionedRemoteUsers = [], additionalAppenders: Appender[] = [], inline = false) { if (nodes == null) { return null; } @@ -626,9 +626,15 @@ export class MfmService { additionalAppender(doc, body); } - return domserializer.render(body, { + let result = domserializer.render(body, { encodeEntities: 'utf8' }); + + if (inline) { + result = result.replace(/^
/, '').replace(/<\/p>$/, ''); + } + + return result; } // the toMastoApiHtml function was taken from Iceshrimp and written by zotan and modified by marie to work with the current MK version diff --git a/packages/backend/src/core/activitypub/ApRendererService.ts b/packages/backend/src/core/activitypub/ApRendererService.ts index 623e7002cd..7a26c89afb 100644 --- a/packages/backend/src/core/activitypub/ApRendererService.ts +++ b/packages/backend/src/core/activitypub/ApRendererService.ts @@ -584,7 +584,7 @@ export class ApRendererService { const attachment = profile.fields.map(field => ({ type: 'PropertyValue', name: field.name, - value: this.mfmService.toHtml(mfm.parse(field.value)), + value: this.mfmService.toHtml(mfm.parse(field.value), [], [], true), })); const emojis = await this.getEmojis(user.emojis); diff --git a/packages/backend/test/unit/MfmService.ts b/packages/backend/test/unit/MfmService.ts index af1fc4e132..ace67caf33 100644 --- a/packages/backend/test/unit/MfmService.ts +++ b/packages/backend/test/unit/MfmService.ts @@ -63,6 +63,12 @@ describe('MfmService', () => { const output = '
some text
'; assert.equal(mfmService.toHtml(mfm.parse(input)), output); }); + + test('inline', () => { + const input = 'https://example.com'; + const output = 'https://example.com'; + assert.equal(mfmService.toHtml(mfm.parse(input), [], [], true), output); + }); }); describe('toMastoApiHtml', () => {