private string RevertNormalizedPart(string result, string source) { var resultLines = new Regex("(?<=\n)").Split(result); var sourceLines = SplitLines(source); if (resultLines.Length == sourceLines.Length) { for (var index = 0; index < resultLines.Length; index++) { var resultLine = resultLines[index]; var sourceLine = sourceLines[index]; if (string.Equals(NormalizeUtility.Normalize(sourceLine).Trim(), "```")) { // keep the Normalized string for the "```" line only, but use the original line ending. if (sourceLine.EndsWith("\r\n") && resultLine.EndsWith("\n")) { resultLines[index] = resultLine.Replace("\n", "\r\n"); } } else if (string.Equals(NormalizeUtility.Normalize(sourceLine), resultLine)) { resultLines[index] = NormalizeStartSpaces(sourceLine); } } return(string.Concat(resultLines)); } return(result); }
private string TrimNewlineBeforeYamlHeader(string markdown) { if (_rule.HasFlag(MigrationRule.Normalize)) { markdown = NormalizeUtility.Normalize(markdown); } if (!_rule.HasFlag(MigrationRule.YamlHeader)) { return(markdown); } var lines = markdown.Split('\n'); var index = 0; for (; index < lines.Count(); index++) { var line = lines[index]; if (!string.Equals(line, string.Empty)) { break; } } if (index < lines.Count() && string.Equals(lines[index], "---")) { return(string.Join("\n", lines.Skip(index))); } else { return(markdown); } }