| 242 | // at whitespace, a closing paren (markdown link syntax), a backtick, or a |
| 243 | // quote; trailing prose punctuation is trimmed separately. |
| 244 | function repoLinkPattern() { |
| 245 | // The slug is interpolated into a regex source, so escape every character |
| 246 | // that would otherwise be read as a metacharacter. Backslash has to come |
| 247 | // first in the class so it is escaped before it can pair with a later |
| 248 | // replacement. |
| 249 | const slug = REPO_SLUG.replace(/[\\^$.*+?()[\]{}|/]/g, "\\$&"); |
| 250 | return new RegExp( |
| 251 | "(?:https?:\\/\\/)?(?:" + |
| 252 | `raw\\.githubusercontent\\.com\\/${slug}\\/main\\/` + |
| 253 | "|" + |
| 254 | `github\\.com\\/${slug}\\/(blob|tree)\\/main\\/` + |
| 255 | ")([^\\s)\\]`\"'<>]+)", |
| 256 | "g" |
| 257 | ); |
| 258 | } |
| 259 | |
| 260 | // Trailing characters that belong to the surrounding sentence, not the URL. |
| 261 | // The escaped codepoints are the CJK punctuation the translated docs end |