Return an array of { start, end } ranges that should NOT be modified.
(text)
| 85 | |
| 86 | /** Return an array of { start, end } ranges that should NOT be modified. */ |
| 87 | function getSkipZones(text) { |
| 88 | const zones = []; |
| 89 | let m; |
| 90 | |
| 91 | // Fenced code blocks ```…``` |
| 92 | const codeBlock = /```[\s\S]*?```/g; |
| 93 | while ((m = codeBlock.exec(text))) zones.push({ start: m.index, end: m.index + m[0].length }); |
| 94 | |
| 95 | // Inline code `…` |
| 96 | const inlineCode = /`[^`\n]+`/g; |
| 97 | while ((m = inlineCode.exec(text))) zones.push({ start: m.index, end: m.index + m[0].length }); |
| 98 | |
| 99 | // Existing markdown links [text](url) |
| 100 | const mdLink = /\[[^\]]*\]\([^)]*\)/g; |
| 101 | while ((m = mdLink.exec(text))) zones.push({ start: m.index, end: m.index + m[0].length }); |
| 102 | |
| 103 | // Headings # … (entire line) |
| 104 | const heading = /^#{1,6}\s+.+$/gm; |
| 105 | while ((m = heading.exec(text))) zones.push({ start: m.index, end: m.index + m[0].length }); |
| 106 | |
| 107 | // JSX / HTML tags (attributes may contain feature words) |
| 108 | const jsxTag = /<[^>]+>/g; |
| 109 | while ((m = jsxTag.exec(text))) zones.push({ start: m.index, end: m.index + m[0].length }); |
| 110 | |
| 111 | // import statements |
| 112 | const imp = /^import\s+.+$/gm; |
| 113 | while ((m = imp.exec(text))) zones.push({ start: m.index, end: m.index + m[0].length }); |
| 114 | |
| 115 | // Frontmatter block |
| 116 | const fm = /^---[\s\S]*?---/; |
| 117 | if ((m = fm.exec(text))) zones.push({ start: m.index, end: m.index + m[0].length }); |
| 118 | |
| 119 | // Markdown table rows (| … |) |
| 120 | const tableRow = /^\|.+\|$/gm; |
| 121 | while ((m = tableRow.exec(text))) zones.push({ start: m.index, end: m.index + m[0].length }); |
| 122 | |
| 123 | // > blockquote lines that contain links |
| 124 | const bqLink = /^>\s.*\[.*\]\(.*\).*$/gm; |
| 125 | while ((m = bqLink.exec(text))) zones.push({ start: m.index, end: m.index + m[0].length }); |
| 126 | |
| 127 | return zones; |
| 128 | } |
| 129 | |
| 130 | function overlapsSkipZone(pos, len, zones) { |
| 131 | const end = pos + len; |