[backend/mfm] Only use div as root element for public preview in MfmConverter.ToHtmlAsync
This commit is contained in:
parent
63eabbd8d0
commit
37707a0712
2 changed files with 9 additions and 7 deletions
|
@ -59,13 +59,13 @@ public class MfmConverter(IOptions<Config.InstanceSection> config)
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<string> ToHtmlAsync(
|
public async Task<string> ToHtmlAsync(
|
||||||
IEnumerable<MfmNode> nodes, List<Note.MentionedUser> mentions, string? host,
|
IEnumerable<MfmNode> nodes, List<Note.MentionedUser> mentions, string? host, string? quoteUri = null,
|
||||||
string? quoteUri = null, bool quoteInaccessible = false, bool replyInaccessible = false
|
bool quoteInaccessible = false, bool replyInaccessible = false, bool divAsRoot = false
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
var context = BrowsingContext.New();
|
var context = BrowsingContext.New();
|
||||||
var document = await context.OpenNewAsync();
|
var document = await context.OpenNewAsync();
|
||||||
var element = document.CreateElement("div");
|
var element = document.CreateElement(divAsRoot ? "div" : "p");
|
||||||
var nodeList = nodes.ToList();
|
var nodeList = nodes.ToList();
|
||||||
var hasContent = nodeList.Count > 0;
|
var hasContent = nodeList.Count > 0;
|
||||||
|
|
||||||
|
@ -130,11 +130,11 @@ public class MfmConverter(IOptions<Config.InstanceSection> config)
|
||||||
|
|
||||||
public async Task<string> ToHtmlAsync(
|
public async Task<string> ToHtmlAsync(
|
||||||
string mfm, List<Note.MentionedUser> mentions, string? host, string? quoteUri = null,
|
string mfm, List<Note.MentionedUser> mentions, string? host, string? quoteUri = null,
|
||||||
bool quoteInaccessible = false, bool replyInaccessible = false
|
bool quoteInaccessible = false, bool replyInaccessible = false, bool divAsRoot = false
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
var nodes = MfmParser.Parse(mfm);
|
var nodes = MfmParser.Parse(mfm);
|
||||||
return await ToHtmlAsync(nodes, mentions, host, quoteUri, quoteInaccessible, replyInaccessible);
|
return await ToHtmlAsync(nodes, mentions, host, quoteUri, quoteInaccessible, replyInaccessible, divAsRoot);
|
||||||
}
|
}
|
||||||
|
|
||||||
private INode FromMfmNode(
|
private INode FromMfmNode(
|
||||||
|
|
|
@ -67,12 +67,14 @@ public class NoteModel(
|
||||||
|
|
||||||
if (Note is { Text: not null })
|
if (Note is { Text: not null })
|
||||||
{
|
{
|
||||||
TextContent[Note.Id] = await mfmConverter.ToHtmlAsync(Note.Text, await GetMentions(Note), Note.UserHost);
|
TextContent[Note.Id] = await mfmConverter.ToHtmlAsync(Note.Text, await GetMentions(Note), Note.UserHost,
|
||||||
|
divAsRoot: true);
|
||||||
if (Note.Renote is { Text: not null })
|
if (Note.Renote is { Text: not null })
|
||||||
{
|
{
|
||||||
TextContent[Note.Renote.Id] = await mfmConverter.ToHtmlAsync(Note.Renote.Text,
|
TextContent[Note.Renote.Id] = await mfmConverter.ToHtmlAsync(Note.Renote.Text,
|
||||||
await GetMentions(Note.Renote),
|
await GetMentions(Note.Renote),
|
||||||
Note.Renote.UserHost);
|
Note.Renote.UserHost,
|
||||||
|
divAsRoot: true);
|
||||||
MediaAttachments[Note.Renote.Id] = await GetAttachments(Note.Renote);
|
MediaAttachments[Note.Renote.Id] = await GetAttachments(Note.Renote);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue