Character ranges of fenced + inline code, so we never expand `![[…]]` there.
(md: string)
| 27 | |
| 28 | /** Character ranges of fenced + inline code, so we never expand `![[…]]` there. */ |
| 29 | function codeRanges(md: string): Array<[number, number]> { |
| 30 | const ranges: Array<[number, number]> = [] |
| 31 | // Fenced code blocks (``` or ~~~), including indistinct fences. |
| 32 | const fence = /^([ \t]*)(`{3,}|~{3,})[^\n]*\n[\s\S]*?(?:\n\1\2[^\n]*|$)/gm |
| 33 | for (const m of md.matchAll(fence)) ranges.push([m.index!, m.index! + m[0].length]) |
| 34 | // Inline code spans (`…`), skipping ones already inside a fence. |
| 35 | const inline = /`+[^`\n]*`+/g |
| 36 | for (const m of md.matchAll(inline)) { |
| 37 | const at = m.index! |
| 38 | if (!ranges.some(([s, e]) => at >= s && at < e)) ranges.push([at, at + m[0].length]) |
| 39 | } |
| 40 | return ranges |
| 41 | } |
| 42 | |
| 43 | function inCode(index: number, ranges: Array<[number, number]>): boolean { |
| 44 | return ranges.some(([s, e]) => index >= s && index < e) |
no outgoing calls
no test coverage detected