private static LinkedList<int> IdentifyBlockBoundaries(string inputString) { var blockBoundaries = new LinkedList<int>(); var previousLine = string.Empty; var currentLine = 0; foreach (var line in new LineReader(() => new StringReader(inputString))) { currentLine++; var trimmedLine = line.TrimStart(' ').TrimEnd(' '); if (trimmedLine.StartsWith("Show") || trimmedLine.StartsWith("Hide") || trimmedLine.StartsWith("# Section:")) { // If the line previous to the Show or Hide line is a comment then we should include that in the block // as it represents the block description. // currentLine > 2 caters for an edge case where the script description is a single line and the first // block has no description. This prevents the script description from being assigned to the first block's description. blockBoundaries.AddLast(previousLine.StartsWith("#") && !previousLine.StartsWith("# Section:") && currentLine > 2 ? currentLine - 2 : currentLine - 1); } previousLine = line; } return blockBoundaries; }