(selector: string, text: string, linkFiles = false)
| 262 | } |
| 263 | |
| 264 | text(selector: string, text: string, linkFiles = false): void { |
| 265 | const el = this.root.querySelector(selector)! |
| 266 | if (!linkFiles) { |
| 267 | el.textContent = text |
| 268 | } else { |
| 269 | let curIndex = 0 |
| 270 | let match: RegExpExecArray | null |
| 271 | fileRE.lastIndex = 0 |
| 272 | while ((match = fileRE.exec(text))) { |
| 273 | const { 0: file, index } = match |
| 274 | const frag = text.slice(curIndex, index) |
| 275 | el.appendChild(document.createTextNode(frag)) |
| 276 | const link = document.createElement('a') |
| 277 | link.textContent = file |
| 278 | link.className = 'file-link' |
| 279 | link.onclick = () => { |
| 280 | fetch( |
| 281 | new URL( |
| 282 | `${base}__open-in-editor?file=${encodeURIComponent(file)}`, |
| 283 | import.meta.url, |
| 284 | ), |
| 285 | ) |
| 286 | } |
| 287 | el.appendChild(link) |
| 288 | curIndex += frag.length + file.length |
| 289 | } |
| 290 | if (curIndex < text.length) { |
| 291 | el.appendChild(document.createTextNode(text.slice(curIndex))) |
| 292 | } |
| 293 | } |
| 294 | } |
| 295 | close(): void { |
| 296 | this.parentNode?.removeChild(this) |
| 297 | document.removeEventListener('keydown', this.closeOnEsc) |
no outgoing calls