[frontend/mfm] Implement border fn node

This commit is contained in:
pancakes 2024-11-10 21:14:28 +10:00 committed by Laura Hausmann
parent 90511c7b58
commit 326192148f
No known key found for this signature in database
GPG key ID: D044E84C5BE01605

View file

@ -275,7 +275,7 @@ public static class MfmRenderer
"scale" => MfmFnScale(args, document),
"fg" => MfmFnFg(args, document),
"bg" => MfmFnBg(args, document),
"border" => throw new NotImplementedException($"{node.Name}"),
"border" => MfmFnBorder(args, document),
"ruby" => throw new NotImplementedException($"{node.Name}"),
"unixtime" => throw new NotImplementedException($"{node.Name}"),
_ => throw new NotImplementedException($"{node.Name}")
@ -397,4 +397,18 @@ public static class MfmRenderer
return el;
}
private static INode MfmFnBorder(Dictionary<string, string?> args, IDocument document)
{
var el = document.CreateElement("span");
var width = args.GetValueOrDefault("width") ?? "1";
var radius = args.GetValueOrDefault("radius") ?? "0";
var style = args.GetValueOrDefault("style") ?? "solid";
var color = args.ContainsKey("color") ? "#" + args["color"] : "var(--notice-color)";
el.SetAttribute("style", $"display: inline-block; border: {width}px {style} {color}; border-radius: {radius}px;");
return el;
}
}