For those who wants to do a similar thing for VS Code, JB Rider, or in MSBuild, here is the actual code:
var inputLines = inputFileContents.Split(new[] { NewLine }, StringSplitOptions.None);
var outputBuilder = new StringBuilder(inputLines.Length * 20);
var lastLineIndex = inputLines.Length - 1;
for (var i = 0; i < inputLines.Length; i++)
{
var line = inputLines[i];
if (!string.IsNullOrWhiteSpace(line))
{
var parts = line.Split(new[] { @"/*md", @"md*/" }, StringSplitOptions.None);
if (parts.Length != 1)
line = parts.Any(s => !string.IsNullOrWhiteSpace(s)) ? string.Concat(parts) : null;
}
if (line != null)
{
if (i < lastLineIndex)
outputBuilder.AppendLine(line);
else
outputBuilder.Append(line);
}
}
var output = outputBuilder.ToString();