
Inline media can be created by: 1. Attach media to note as usual 2. Copy media URL (public one, for remote instances) 3. Use the new $[media url ] MFM extension to place it wherever you wish. (The trailing space is necessary as the parser currently treats the closing ] as a part of the URL) The Iceshrimp frontend may make this easier later on (by having a "copy inline MFM" button on attachments, maybe?) Federates as <img>, <video>, <audio>, or <a download> HTML tags depending on the media type for interoperability. (<a download> is not handled for incoming media yet). The media will also be present in the attachments field, both as a fallback for instance software that do not support inline media, but also for MFM federation to discover which media it is allowed to embed (and metadata like alt text and sensitive-ness). This is not required for remote instances sending inline media, as it will be extracted out from the HTML. The Iceshrimp frontend does not render inline media yet. That is blocked on #67.
24 lines
No EOL
845 B
C#
24 lines
No EOL
845 B
C#
using Iceshrimp.Backend.Core.Database.Tables;
|
|
using Iceshrimp.Backend.Core.Extensions;
|
|
using Iceshrimp.Backend.Core.Helpers.LibMfm.Conversion;
|
|
using Iceshrimp.MfmSharp;
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
namespace Iceshrimp.Backend.Components.PublicPreview.Renderers;
|
|
|
|
public class MfmRenderer(MfmConverter converter) : ISingletonService
|
|
{
|
|
public async Task<MarkupString?> RenderAsync(
|
|
string? text, string? host, List<Note.MentionedUser> mentions, List<Emoji> emoji, string rootElement
|
|
)
|
|
{
|
|
if (text is null) return null;
|
|
var parsed = MfmParser.Parse(text);
|
|
|
|
// Ensure we are rendering HTML markup (AsyncLocal)
|
|
converter.SupportsHtmlFormatting.Value = true;
|
|
|
|
var serialized = (await converter.ToHtmlAsync(parsed, mentions, host, emoji: emoji, rootElement: rootElement)).Html;
|
|
return new MarkupString(serialized);
|
|
}
|
|
} |