Browse Source

Closes #946 - adds alphanumeric flag to autolinks

Fixes ignoreCase flag on autolinks
main
Eric Amodio 4 years ago
parent
commit
df43dffaaf
3 changed files with 19 additions and 8 deletions
  1. +10
    -5
      package.json
  2. +8
    -3
      src/annotations/autolinks.ts
  3. +1
    -0
      src/config.ts

+ 10
- 5
package.json View File

@ -70,11 +70,6 @@
"type": "string",
"description": "Specifies the short prefix to use to generate autolinks for the external resource"
},
"ignoreCase": {
"type": "boolean",
"description": "Specifies whether case should be ignored when matching the prefix",
"default": false
},
"title": {
"type": [
"string",
@ -86,6 +81,16 @@
"url": {
"type": "string",
"description": "Specifies the url of the external resource you want to link to. Use `<num>` as the variable for the reference number"
},
"alphanumeric": {
"type": "boolean",
"description": "Specifies whether alphanumeric should be allowed in `<num>`",
"default": false
},
"ignoreCase": {
"type": "boolean",
"description": "Specifies whether case should be ignored when matching the prefix",
"default": false
}
}
},

+ 8
- 3
src/annotations/autolinks.ts View File

@ -65,7 +65,10 @@ export class Autolinks implements Disposable {
if (!isCacheable(ref)) continue;
if (ref.messageRegex === undefined) {
ref.messageRegex = new RegExp(`(?<=^|\\s|\\()(${ref.prefix}([0-9]+))\\b`, 'g');
ref.messageRegex = new RegExp(
`(?<=^|\\s|\\()(${ref.prefix}([${ref.alphanumeric ? '\\w' : '0-9'}]+))\\b`,
ref.ignoreCase ? 'gi' : 'g'
);
}
do {
@ -127,8 +130,10 @@ export class Autolinks implements Disposable {
try {
if (ref.messageMarkdownRegex === undefined) {
ref.messageMarkdownRegex = new RegExp(
`(?<=^|\\s|\\()(${Strings.escapeMarkdown(ref.prefix).replace(/\\/g, '\\\\')}([0-9]+))\\b`,
'g'
`(?<=^|\\s|\\()(${Strings.escapeMarkdown(ref.prefix).replace(/\\/g, '\\\\')}([${
ref.alphanumeric ? '\\w' : '0-9'
}]+))\\b`,
ref.ignoreCase ? 'gi' : 'g'
);
}

+ 1
- 0
src/config.ts View File

@ -132,6 +132,7 @@ export interface AutolinkReference {
prefix: string;
url: string;
title?: string;
alphanumeric?: boolean;
ignoreCase?: boolean;
}

Loading…
Cancel
Save