[frontend/mfm] Implement ruby fn node
This commit is contained in:
parent
e29a3083f4
commit
90f6456e30
1 changed files with 40 additions and 3 deletions
|
@ -1,6 +1,7 @@
|
|||
using System.Text.RegularExpressions;
|
||||
using AngleSharp;
|
||||
using AngleSharp.Dom;
|
||||
using AngleSharp.Text;
|
||||
using Iceshrimp.Parsing;
|
||||
using Iceshrimp.Shared.Schemas.Web;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
@ -79,7 +80,7 @@ public static partial class MfmRenderer
|
|||
};
|
||||
// @formatter:on
|
||||
|
||||
if (node.Children.Length > 0)
|
||||
if (node.Children.Length > 0 && rendered.ChildNodes.Length == 0)
|
||||
{
|
||||
foreach (var childNode in node.Children)
|
||||
{
|
||||
|
@ -277,7 +278,7 @@ public static partial class MfmRenderer
|
|||
"fg" => MfmFnFg(args, document),
|
||||
"bg" => MfmFnBg(args, document),
|
||||
"border" => MfmFnBorder(args, document),
|
||||
"ruby" => throw new NotImplementedException($"{node.Name}"),
|
||||
"ruby" => MfmFnRuby(node, document),
|
||||
"unixtime" => throw new NotImplementedException($"{node.Name}"),
|
||||
_ => throw new NotImplementedException($"{node.Name}")
|
||||
};
|
||||
|
@ -483,4 +484,40 @@ public static partial class MfmRenderer
|
|||
|
||||
return el;
|
||||
}
|
||||
|
||||
private static string? GetNodeText(MfmNodeTypes.MfmNode node)
|
||||
{
|
||||
return node switch
|
||||
{
|
||||
MfmNodeTypes.MfmTextNode mfmTextNode => mfmTextNode.Text,
|
||||
_ => null,
|
||||
};
|
||||
}
|
||||
|
||||
private static INode MfmFnRuby(MfmNodeTypes.MfmFnNode node, IDocument document)
|
||||
{
|
||||
var el = document.CreateElement("ruby");
|
||||
|
||||
if (node.Children.Length != 1) return el;
|
||||
var childText = GetNodeText(node.Children[0]);
|
||||
if (childText == null) return el;
|
||||
var split = childText.SplitSpaces();
|
||||
if (split.Length < 2) return el;
|
||||
|
||||
el.TextContent = split[0];
|
||||
|
||||
var rp1 = document.CreateElement("rp");
|
||||
rp1.TextContent = "(";
|
||||
el.AppendChild(rp1);
|
||||
|
||||
var rt = document.CreateElement("rt");
|
||||
rt.TextContent = split[1];
|
||||
el.AppendChild(rt);
|
||||
|
||||
var rp2 = document.CreateElement("rp");
|
||||
rp1.TextContent = ")";
|
||||
el.AppendChild(rp2);
|
||||
|
||||
return el;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue