Content Retrieval in .NET MAUI Markdown Viewer (SfMarkdownViewer)
27 Jul 20262 minutes to read
The .NET MAUI Markdown Viewer control provides built-in methods to retrieve and transform markdown content programmatically. These methods allow developers to access the raw markdown, convert it to HTML, or extract plain text without formatting.
Prerequisites
Before using the SfMarkdownViewer, ensure the following NuGet package is installed in your .NET MAUI project:
Syncfusion.Maui.MarkdownViewer
For a step-by-step setup, refer to the Getting Started documentation.
Supported Methods
| Method | Return Type | Description |
|---|---|---|
| GetMarkdownText | string |
Returns the raw markdown currently assigned to the Source property. |
| GetHtmlText | string |
Converts the rendered markdown to an HTML string. |
| GetText | string |
Extracts the plain text from the markdown, stripping formatting such as headings, emphasis, links, and code blocks. |
GetMarkdownText
The GetMarkdownText method returns the raw markdown content currently assigned to the Source property of the SfMarkdownViewer control.
SfMarkdownViewer markdownViewer = new SfMarkdownViewer();
markdownViewer.Source = "Welcome to **Markdown Viewer**!";
Content = markdownViewer;string markdown = markdownViewer.GetMarkdownText();GetHtmlText
The GetHtmlText method converts the markdown content of the SfMarkdownViewer control into HTML format and provides the result as a string.
SfMarkdownViewer markdownViewer = new SfMarkdownViewer();
markdownViewer.Source = "Welcome to **Markdown Viewer**!";
Content = markdownViewer;string html = markdownViewer.GetHtmlText();GetText
The GetText method extracts the plain text from the markdown content, removing all formatting such as headings, emphasis, links, and code blocks. Links are flattened to their visible text, and image alt text is preserved when available.
SfMarkdownViewer markdownViewer = new SfMarkdownViewer();
markdownViewer.Source = "Welcome to **Markdown Viewer**!";
Content = markdownViewer;string text = markdownViewer.GetText();