-
Notifications
You must be signed in to change notification settings - Fork 41
Closed
Description
Currently, all translators are internal since IVdomElementTranslator is internal, and some other member within the method of the interface
It seems pretty simple
internal sealed partial class VdomSpectreTranslator
{
[Export(typeof(IVdomElementTranslator))]
internal sealed class TextElementTranslator : IVdomElementTranslator
{
public bool TryTranslate(VNode node, TranslationContext context, out IRenderable? renderable)
{
renderable = null;
if (node.Kind != VNodeKind.Element)
{
return false;
}
if (!string.Equals(node.TagName, "span", StringComparison.OrdinalIgnoreCase))
{
return false;
}
if (!node.Attributes.TryGetValue("data-text", out var value) || !string.Equals(value, "true", StringComparison.OrdinalIgnoreCase))
{
return false;
}
string? text;
if (node.Attributes.TryGetValue("data-content", out var inlineContent) && inlineContent is not null)
{
if (node.Children.Any())
{
// Prefer explicit content attribute when present and require no additional children.
return false;
}
text = inlineContent;
}
else
{
text = CollectInnerText(node);
if (string.IsNullOrWhiteSpace(text))
{
// Missing required text content.
return false;
}
}
var styleAttributes = GetAttribute(node, "data-style");
if (string.IsNullOrEmpty(styleAttributes))
{
renderable = new Markup(text);
}
else
{
var style = Style.Parse(styleAttributes ?? string.Empty);
renderable = new Markup(text, style);
}
return true;
}
}
}
This is the translator for span which is what Markup creates.
Now, I would like to support overflow which exist in Spectre but not implemented.
Generally people will be able to create more with those interfaces exposed maybe even creating their own custom components
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels