From df43dffaaf2300541deb3c6e83779dc7fde77888 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Tue, 11 Feb 2020 01:47:57 -0500 Subject: [PATCH] Closes #946 - adds alphanumeric flag to autolinks Fixes ignoreCase flag on autolinks --- package.json | 15 ++++++++++----- src/annotations/autolinks.ts | 11 ++++++++--- src/config.ts | 1 + 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 1e9f1ed..24f7ef6 100644 --- a/package.json +++ b/package.json @@ -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 `` as the variable for the reference number" + }, + "alphanumeric": { + "type": "boolean", + "description": "Specifies whether alphanumeric should be allowed in ``", + "default": false + }, + "ignoreCase": { + "type": "boolean", + "description": "Specifies whether case should be ignored when matching the prefix", + "default": false } } }, diff --git a/src/annotations/autolinks.ts b/src/annotations/autolinks.ts index d2cb72f..dd6a2a5 100644 --- a/src/annotations/autolinks.ts +++ b/src/annotations/autolinks.ts @@ -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' ); } diff --git a/src/config.ts b/src/config.ts index 9254e37..0b3bd70 100644 --- a/src/config.ts +++ b/src/config.ts @@ -132,6 +132,7 @@ export interface AutolinkReference { prefix: string; url: string; title?: string; + alphanumeric?: boolean; ignoreCase?: boolean; }