diff --git a/src/PortToDocs/src/libraries/XmlHelper.cs b/src/PortToDocs/src/libraries/XmlHelper.cs index e4582c6..f22a71c 100644 --- a/src/PortToDocs/src/libraries/XmlHelper.cs +++ b/src/PortToDocs/src/libraries/XmlHelper.cs @@ -203,19 +203,57 @@ public static string GetFormattedAsXml(string value, bool removeUndesiredEndline private static string ReplaceEndLinesWithParas(string updatedValue) { string[] splitted = updatedValue.Split(_splittingSeparators, _splittingStringSplitOptions); - bool moreThanOne = splitted.Count() > 1; + + if (splitted.Length == 1) + { + // No need to add paras + return splitted[0]; + } StringBuilder newValue = new(); - foreach (string s in splitted) + ReadOnlySpan ros; + bool addStartParaNext = true; + for (int i = 0; i < splitted.Length; i++) { - if (moreThanOne && !s.StartsWith("")) + ros = splitted[i]; + + if (ros.StartsWith("") && ros.EndsWith("")) { - newValue.Append(""); + // No change + newValue.Append(ros); + // Next time we find a line not surrounded by paras, we need to add the starting one first + addStartParaNext = true; } - newValue.Append(s); - if (moreThanOne && !s.EndsWith("")) + else { - newValue.Append(""); + if (addStartParaNext) + { + newValue.Append(""); + addStartParaNext = false; + } + + if (splitted[i].Equals("- or -")) + { + newValue.Append("-or-"); + } + else + { + newValue.Append(ros); + } + if (!ros.EndsWith("")) + { + if (ros[^1] is '.' or ':' || (i + 1) >= splitted.Length || splitted[i].Equals("-or-") || splitted[i].Equals("- or -")) + { + // We're done with this line + newValue.Append(""); + addStartParaNext = true; + } + else + { + // Space separator, the next line will get appended next + newValue.Append(' '); + } + } } }