using Markdig.Syntax.Inlines;

namespace MarkdownEditor.Views.Renderers;

/// <summary>
/// Helper class for extracting plain text from markdown inline elements.
/// </summary>
public static class MarkdownTextHelper
{
    /// <summary>
    /// Extracts plain text from a markdown inline container.
    /// </summary>
    /// <param name="inline">The container inline to extract text from.</param>
    /// <returns>The extracted plain text.</returns>
    public static string ExtractText(ContainerInline? inline)
    {
        if (inline == null) return string.Empty;

        var result = "";
        foreach (var child in inline)
        {
            if (child is LiteralInline literal)
            {
                result += literal.Content.ToString();
            }
            else if (child is ContainerInline container)
            {
                result += ExtractText(container);
            }
        }
        return result;
    }
}

