2023-10-12 18:37:25 +03:00
|
|
|
|
using System.Text;
|
|
|
|
|
using DiffPlex.DiffBuilder.Model;
|
|
|
|
|
|
|
|
|
|
namespace Octobot.Extensions;
|
|
|
|
|
|
|
|
|
|
public static class DiffPaneModelExtensions
|
|
|
|
|
{
|
|
|
|
|
public static string AsMarkdown(this DiffPaneModel model)
|
|
|
|
|
{
|
|
|
|
|
var builder = new StringBuilder();
|
|
|
|
|
foreach (var line in model.Lines)
|
|
|
|
|
{
|
|
|
|
|
if (line.Type is ChangeType.Deleted)
|
|
|
|
|
{
|
2023-10-12 19:51:51 +03:00
|
|
|
|
builder.Append("-- ");
|
2023-10-12 18:37:25 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (line.Type is ChangeType.Inserted)
|
|
|
|
|
{
|
2023-10-12 19:51:51 +03:00
|
|
|
|
builder.Append("++ ");
|
2023-10-12 18:37:25 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (line.Type is not ChangeType.Imaginary)
|
|
|
|
|
{
|
2023-10-12 19:51:51 +03:00
|
|
|
|
builder.AppendLine(line.Text.SanitizeForDiffBlock());
|
2023-10-12 18:37:25 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return builder.ToString().InBlockCode("diff");
|
|
|
|
|
}
|
|
|
|
|
}
|