Skip to content

Instantly share code, notes, and snippets.

@svick
Created October 3, 2016 17:54
Show Gist options
  • Select an option

  • Save svick/cf2a16607c516ccbaed88df6200920cd to your computer and use it in GitHub Desktop.

Select an option

Save svick/cf2a16607c516ccbaed88df6200920cd to your computer and use it in GitHub Desktop.
string path = @"E:\Users\Svick\git\visualfsharpdocs\docs\conceptual";
var files = Directory.EnumerateFiles(path);
Regex regex = new Regex(@"\[([^]]*?)\]\(http.*?\)");
foreach (var file in files)
{
var lines = File.ReadAllLines(file);
bool code = false;
bool changed = false;
for (int i = 0; i < lines.Length; i++)
{
var line = lines[i];
if (line.TrimStart().StartsWith("```"))
code = !code;
if (code)
{
var newLine = regex.Replace(line, @"$1");
if (newLine != line)
{
lines[i] = newLine;
changed = true;
}
}
}
if (changed)
{
Console.WriteLine(file);
File.WriteAllLines(file, lines);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment