mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-19 13:28:16 +08:00

committed by
Phil Scott

parent
57a8e6ccc1
commit
9502aaf2b9
@ -34,6 +34,32 @@ namespace Spectre.Console
|
||||
.ReplaceExact("]", "]]");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes markup from the specified string.
|
||||
/// </summary>
|
||||
/// <param name="text">The text to remove markup from.</param>
|
||||
/// <returns>A string that does not have any markup.</returns>
|
||||
public static string RemoveMarkup(this string? text)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(text))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
var result = new StringBuilder();
|
||||
|
||||
var tokenizer = new MarkupTokenizer(text);
|
||||
while (tokenizer.MoveNext() && tokenizer.Current != null)
|
||||
{
|
||||
if (tokenizer.Current.Kind == MarkupTokenKind.Text)
|
||||
{
|
||||
result.Append(tokenizer.Current.Value);
|
||||
}
|
||||
}
|
||||
|
||||
return result.ToString();
|
||||
}
|
||||
|
||||
internal static int CellLength(this string text, RenderContext context)
|
||||
{
|
||||
if (context is null)
|
||||
|
Reference in New Issue
Block a user