New to Telerik UI for Blazor? Start a free 30-day trial
Convert Editor Value to Plain Text
Updated on May 13, 2025
Environment
| Product | Editor for Blazor |
Description
How to convert the HTML string value of the Editor and retrieve it as plain text?
Solution
The HTML value of the Editor can be converted to plain text and other formats with our Document Processing library.
Here are the required steps:
- Add the
Telerik.Documents.CoreandTelerik.Documents.FlowNuGet packages to your project. - Import the required namespaces:
Telerik.Windows.Documents.Flow.FormatProviders.HtmlTelerik.Windows.Documents.Flow.FormatProviders.TxtTelerik.Windows.Documents.Flow.Model
- Create an
HtmlFormatProviderinstance. - Use the HTML provider's
Importmethod to create aRadFlowDocumentfrom the Editor's HTML value. - Create a
TxtFormatProviderinstance. - Use the TXT provider's
Exportmethod to export theRadFlowDocumentas plain text.
To export to another format, use the corresponding namespace and format provider, instead of Txt.
Obtain the Editor HTML value as plain text
RAZOR
@*TxtFormatProvider*@
@using Telerik.Windows.Documents.Flow.FormatProviders.Txt;
@*HtmlFormatProvider*@
@using Telerik.Windows.Documents.Flow.FormatProviders.Html;
@*RadFlowDocument*@
@using Telerik.Windows.Documents.Flow.Model;
<TelerikEditor @bind-Value="@HtmlValue" />
<p><TelerikButton OnClick="@ConvertValue">Convert to Plain Text</TelerikButton></p>
<TelerikTextArea @bind-Value="@PlainTxtValue" Width="100%" Rows="5" />
@code {
private string HtmlValue { get; set; } =
@"
<h1>Title</h1>
<p>Paragraph paragraph paragraph.</p>
<ul>
<li>List item 1</li>
<li>List item 2</li>
</ul>
";
private string PlainTxtValue { get; set; }
private void ConvertValue(MouseEventArgs e)
{
HtmlFormatProvider htmlProvider = new HtmlFormatProvider();
RadFlowDocument document = htmlProvider.Import(HtmlValue, new TimeSpan(0, 0, 5));
TxtFormatProvider txtProvider = new TxtFormatProvider();
PlainTxtValue = txtProvider.Export(document);
}
}