|
1 | 1 | namespace DocLinkChecker.Helpers
|
2 | 2 | {
|
3 | 3 | using System;
|
| 4 | + using System.Collections; |
4 | 5 | using System.Collections.Generic;
|
5 | 6 | using System.Diagnostics;
|
6 | 7 | using System.IO;
|
@@ -220,17 +221,29 @@ private static (PipeTable table, List<MarkdownError> errors)
|
220 | 221 | private static (PipeTable table, List<MarkdownError> errors)
|
221 | 222 | ValidatePipeTableWithText(string markdownFilePath, string markdown, Table table)
|
222 | 223 | {
|
223 |
| - PipeTable pipeTable = new (markdownFilePath, table.Line, table.Column); |
| 224 | + PipeTable pipeTable = null; |
| 225 | + int start = 0; |
| 226 | + int len = 0; |
| 227 | + string line = string.Empty; |
224 | 228 | List<MarkdownError> errors = new ();
|
225 | 229 |
|
226 |
| - int start = table.Span.Start; |
227 |
| - while (start > 0 && markdown.Substring(start, 1) != "\n") |
| 230 | + try |
228 | 231 | {
|
229 |
| - start--; |
230 |
| - } |
| 232 | + pipeTable = new (markdownFilePath, table.Line, table.Column); |
| 233 | + |
| 234 | + start = Math.Max(table.Span.Start, 0); |
| 235 | + while (start > 0 && markdown.Substring(start, 1) != "\n") |
| 236 | + { |
| 237 | + start--; |
| 238 | + } |
231 | 239 |
|
232 |
| - int len = markdown.IndexOf('\r', start) - start; |
233 |
| - string line = markdown.Substring(start, len); |
| 240 | + len = markdown.IndexOf('\r', start) - start; |
| 241 | + line = markdown.Substring(start, len); |
| 242 | + } |
| 243 | + catch (Exception ex) |
| 244 | + { |
| 245 | + Console.WriteLine($"PipeTable error {ex.Message}.\nfilepath: {markdownFilePath}\nmarkdown: {markdown.Substring(0, 40)}...\nTable: line={table.Line} col={table.Column} start={table.Span.Start}"); |
| 246 | + } |
234 | 247 |
|
235 | 248 | int row = 0;
|
236 | 249 | int nrCols = -1;
|
|
0 commit comments