Browse Source

Fixes #1032 - allow autolinks in square brackets

Also properly escapes autolink prefixes
main
Eric Amodio 4 years ago
parent
commit
0de56afe4d
2 changed files with 8 additions and 2 deletions
  1. +4
    -2
      src/annotations/autolinks.ts
  2. +4
    -0
      src/system/string.ts

+ 4
- 2
src/annotations/autolinks.ts View File

@ -72,7 +72,9 @@ export class Autolinks implements Disposable {
if (ref.messageRegex === undefined) {
ref.messageRegex = new RegExp(
`(?<=^|\\s|\\()(${ref.prefix}([${ref.alphanumeric ? '\\w' : '0-9'}]+))\\b`,
`(?<=^|\\s|\\(|\\\\\\[)(${Strings.escapeRegex(ref.prefix)}([${
ref.alphanumeric ? '\\w' : '0-9'
}]+))\\b`,
ref.ignoreCase ? 'gi' : 'g',
);
}
@ -148,7 +150,7 @@ export class Autolinks implements Disposable {
try {
if (ref.messageMarkdownRegex === undefined) {
ref.messageMarkdownRegex = new RegExp(
`(?<=^|\\s|\\()(${Strings.escapeMarkdown(ref.prefix).replace(/\\/g, '\\\\')}([${
`(?<=^|\\s|\\(|\\\\\\[)(${Strings.escapeRegex(Strings.escapeMarkdown(ref.prefix))}([${
ref.alphanumeric ? '\\w' : '0-9'
}]+))\\b`,
ref.ignoreCase ? 'gi' : 'g',

+ 4
- 0
src/system/string.ts View File

@ -39,6 +39,10 @@ export namespace Strings {
return s.replace(markdownQuotedRegex, '\t\n> ');
}
export function escapeRegex(s: string) {
return s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
}
export function getCommonBase(s1: string, s2: string, delimiter: string) {
let char;
let index = 0;

Loading…
Cancel
Save