Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

<ItemGroup>
<PackageReference Include="Markdig" Version="0.*" />
<PackageReference Include="ReverseMarkdown" Version="4.7.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Text.RegularExpressions;

using Markdig;
using ReverseMarkdown;

using McpSamples.MarkdownToHtml.HybridApp.Configurations;
using McpSamples.MarkdownToHtml.HybridApp.Extensions;
Expand All @@ -21,6 +22,13 @@ public interface IMarkdownToHtmlTool
/// <param name="markdown">The markdown text.</param>
/// <returns>The converted HTML text.</returns>
Task<string> ConvertAsync(string markdown);

/// <summary>
/// Converts HTML text to markdown.
/// </summary>
/// <param name="html"></param>
/// <returns></returns>
Task<string> ReverseConvertAsync(string html);
}

/// <summary>
Expand Down Expand Up @@ -77,4 +85,25 @@ public async Task<string> ConvertAsync([Description("The markdown text")] string

return await Task.FromResult(html);
}


[McpServerTool(Name = "convert_html_to_markdown", Title = "Convert HTML to Markdown")]
[Description("Converts HTML text to Markdown.")]
public async Task<string> ReverseConvertAsync([Description("The HTML text")] string html)
{
var converter = new Converter();
var markdown = default(string);

try
{
markdown = converter.Convert(html);
}
catch (Exception ex)
{
logger.LogError(ex, "Error converting HTML to Markdown");
markdown = $"Error: {ex.Message}";
}

return await Task.FromResult(markdown);
}
}