(document: string)
| 340 | } |
| 341 | |
| 342 | export const markdownSafetyIssues = (document: string): ReadonlyArray<string> => { |
| 343 | const issues: Array<string> = [] |
| 344 | let fence: string | undefined |
| 345 | const lines = document.split("\n") |
| 346 | for (let lineIndex = 0; lineIndex < lines.length; lineIndex++) { |
| 347 | const line = lines[lineIndex]! |
| 348 | const fenceMatch = /^\s*(`{3,})(?:[^`]*)$/.exec(line) |
| 349 | if (fence !== undefined) { |
| 350 | if (line.trim() === fence) { |
| 351 | fence = undefined |
| 352 | } |
| 353 | continue |
| 354 | } |
| 355 | if (fenceMatch !== null) { |
| 356 | fence = fenceMatch[1]! |
| 357 | continue |
| 358 | } |
| 359 | if ( |
| 360 | line === "<!-- dprint-ignore-file -->" || |
| 361 | line.startsWith("**Replacement:** ") || |
| 362 | line === "**Example**" |
| 363 | ) { |
| 364 | continue |
| 365 | } |
| 366 | let index = 0 |
| 367 | while (index < line.length) { |
| 368 | const character = line[index]! |
| 369 | if (character === "\\") { |
| 370 | index += 2 |
| 371 | continue |
| 372 | } |
| 373 | if (character === "`") { |
| 374 | let end = index + 1 |
| 375 | while (line[end] === "`") { |
| 376 | end++ |
| 377 | } |
| 378 | const delimiter = line.slice(index, end) |
| 379 | const close = line.indexOf(delimiter, end) |
| 380 | if (close === -1) { |
| 381 | issues.push(`line ${lineIndex + 1}: unclosed inline code span`) |
| 382 | break |
| 383 | } |
| 384 | index = close + delimiter.length |
| 385 | continue |
| 386 | } |
| 387 | if (character === "~" || character === "<" || character === "*" || character === "_") { |
| 388 | issues.push(`line ${lineIndex + 1}: unescaped ${JSON.stringify(character)}`) |
| 389 | } |
| 390 | index++ |
| 391 | } |
| 392 | } |
| 393 | if (fence !== undefined) { |
| 394 | issues.push(`unclosed ${fence} code fence`) |
| 395 | } |
| 396 | return issues |
| 397 | } |
| 398 | |
| 399 | export const unannotatedApiIds = ( |
no test coverage detected