Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #13 from Yousef-Majidi/issue-10
issue 10
  • Loading branch information
Yousef-Majidi committed Sep 25, 2023
2 parents 9b83415 + 8197c77 commit 8b24da6
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/HtmlProcessor.cs
Expand Up @@ -140,6 +140,23 @@ public static void ProcessFile(string inputPath, string outputPath)
html = HtmlBuilder(Path.GetFileNameWithoutExtension(inputPath), body);

string outputFileName = Path.Combine(outputPath, Path.GetFileNameWithoutExtension(inputPath) + ".html");

// if a file with the same name already exists, append a number to the file name
if (File.Exists(outputFileName))
{
int fileNumber = 1;
string fileName = Path.GetFileNameWithoutExtension(inputPath);
string newFileName = $"{fileName}_{fileNumber}";
outputFileName = Path.Combine(outputPath, newFileName + ".html");

while (File.Exists(outputFileName))
{
fileNumber++;
newFileName = $"{fileName}_{fileNumber}";
outputFileName = Path.Combine(outputPath, newFileName + ".html");
}
}

File.WriteAllText(outputFileName, html);

CommandLineUtils.Logger($"File converted: {outputFileName}");
Expand All @@ -156,6 +173,7 @@ public static void ProcessFile(string inputPath, string outputPath)
CommandLineUtils.Logger($"The specified input file [{inputPath}] is not a text or markdown file");
return;
}

}

[GeneratedRegex("\\n\\s*\\n")]
Expand Down

0 comments on commit 8b24da6

Please sign in to comment.