Skip to content

Commit ad5ec2d

Browse files
committed
Release v1.1.0
1 parent 99a5b56 commit ad5ec2d

File tree

15 files changed

+94
-19
lines changed

15 files changed

+94
-19
lines changed

lib/node/plugins/helpers.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export declare const replace: (text: string, match: Array<string>, to: string) => string;

lib/node/plugins/helpers.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export const replace = (text, match, to) => {
2+
return text.replace(match[0], to);
3+
// const index: number = match['index']
4+
// const from: string = match[0]
5+
//
6+
// return text.slice(0, index) + to + text.slice(index + from.length)
7+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import type { GitHubLinkifyTransformer } from '../../types/transformer.js';
2+
export declare const blobsCompact: GitHubLinkifyTransformer;
3+
export declare const blobsExpand: GitHubLinkifyTransformer;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { replace } from '../helpers.js';
2+
import { template } from '../template.js';
3+
import { regex } from '../regex';
4+
import { url } from '../url';
5+
export const blobsCompact = (text, repo) => {
6+
const replacer = (value, item) => replace(value, item, template('blob', `${item[1]}/${item[2]}`, item[3]));
7+
text = regex(text, /\[[\w\d\s`]+]\(https:\/\/github\.com\/([\w\d\-_]+)\/([\w\d\-_]+)\/blob\/([\w\d\/\.\-_]+)\)/g, replacer);
8+
text = regex(text, /https:\/\/github\.com\/([\w\d\-_]+)\/([\w\d\-_]+)\/blob\/([\w\d\/\.\-_]+)/g, replacer);
9+
return text;
10+
};
11+
export const blobsExpand = (text, repo) => {
12+
const replacer = (value, item) => value.replace(item[0], url(repo, `${item[1].includes(repo) ? '' : item[1] + '#'}${item[2]}`, `${item[1]}/blob/${item[2]}`));
13+
text = regex(text, /::blob::([\w\d\-_\/]+)::([\w\d\/\.\-_]+)::/g, replacer);
14+
return text;
15+
};

lib/node/plugins/transformers/commit.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { regex } from '../regex.js';
2+
import { replace } from '../helpers.js';
23
import { template } from '../template.js';
34
import { url } from '../url.js';
45
export const commitCompact = (text, repo) => {
5-
const replacerFull = (value, item) => value.replace(item[0], template('commit', `${item[1]}/${item[2]}`, item[3]));
6-
const replacerShort = (value, item) => value.replace(item[0], template('commit', repo, item[1]));
6+
const replacerFull = (value, item) => replace(value, item, template('commit', `${item[1]}/${item[2]}`, item[3]));
7+
const replacerShort = (value, item) => replace(value, item, template('commit', repo, item[1]));
78
text = regex(text, /<a.*href\s?=\s?"?https:\/\/github\.com\/([\w\d\-_]+)\/([\w\d\-_]+)\/commit\/([\w\d]{40})"?.*>.*<\/a>/g, replacerFull);
89
text = regex(text, /\[[\w\d\s`]+]\(https:\/\/github\.com\/([\w\d\-_]+)\/([\w\d\-_]+)\/commit\/([\w\d]{40})\)/g, replacerFull);
910
text = regex(text, /https:\/\/github\.com\/([\w\d\-_]+)\/([\w\d\-_]+)\/commit\/([\w\d]{40})/g, replacerFull);

lib/node/plugins/transformers/compare.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { regex } from '../regex.js';
2+
import { replace } from '../helpers.js';
23
import { template } from '../template.js';
34
import { url } from '../url.js';
45
export const compareCompact = (text, repo) => {
5-
const replacerFull = (value, item) => value.replace(item[0], template('compare', `${item[1]}/${item[2]}`, item[3], item[4]));
6-
const replacerShort = (value, item) => value.replace(item[0], template('compare', repo, item[1], item[2]));
7-
text = regex(text, /\[[\s\w\d`.\-]+]\(https:\/\/github\.com\/([\w\d\-_]+)\/([\w\d\-_]+)\/compare\/([\w\d.\-]+)\.\.\.([\w\d.\-]+)\)/g, replacerFull);
8-
text = regex(text, /https:\/\/github\.com\/([\w\d\-_]+)\/([\w\d\-_]+)\/compare\/([\w\d.\-]+)\.\.\.([\w\d.\-]+)/g, replacerFull);
6+
const replacerFull = (value, item) => replace(value, item, template('compare', `${item[1]}/${item[2]}`, item[3], item[4]));
7+
const replacerShort = (value, item) => replace(value, item, template('compare', repo, item[1], item[2]));
8+
text = regex(text, /\[[\s\w\d`.\-]+]\(https:\/\/github\.com\/([\w\d\-_]+)\/([\w\d\-_]+)\/compare\/([\w\d.\-]+)\.{3}([\w\d.\-]+)\)/g, replacerFull);
9+
text = regex(text, /https:\/\/github\.com\/([\w\d\-_]+)\/([\w\d\-_]+)\/compare\/([\w\d.\-]+)\.{3}([\w\d.\-]+)/g, replacerFull);
910
text = regex(text, /([\w\d.\-]+)\.{3}([\w\d.\-]+)/g, replacerShort);
1011
return text;
1112
};

lib/node/plugins/transformers/index.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,30 @@ import { mentionCompact, mentionExpand } from './mention.js';
22
import { pullRequestCompact, pullRequestExpand } from './pull-request.js';
33
import { compareCompact, compareExpand } from './compare.js';
44
import { commitCompact, commitExpand } from './commit.js';
5+
import { tagsCompact, tagsExpand } from './tags.js';
6+
import { treesCompact, treesExpand } from './trees.js';
7+
import { blobsCompact, blobsExpand } from './blobs.js';
58
const compact = [
69
mentionCompact,
710
pullRequestCompact,
811
compareCompact,
9-
commitCompact
12+
commitCompact,
13+
treesCompact,
14+
blobsCompact,
15+
tagsCompact
1016
];
1117
const expand = [
1218
mentionExpand,
1319
pullRequestExpand,
1420
compareExpand,
15-
commitExpand
21+
commitExpand,
22+
treesExpand,
23+
blobsExpand,
24+
tagsExpand
1625
];
1726
const resolveRepoUrl = (url) => url.replace('https://github.com/', '');
1827
export const transform = (text, repo) => {
19-
// compact
20-
Array.from(compact, (tranformer) => text = tranformer(text, resolveRepoUrl(repo)));
21-
// expand
22-
Array.from(expand, (tranformer) => text = tranformer(text, resolveRepoUrl(repo)));
28+
Array.from(compact, (transformer) => text = transformer(text, resolveRepoUrl(repo)));
29+
Array.from(expand, (transformer) => text = transformer(text, resolveRepoUrl(repo)));
2330
return text;
2431
};

lib/node/plugins/transformers/mention.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { regex } from '../regex.js';
2+
import { replace } from '../helpers.js';
23
import { template } from '../template.js';
34
import { url } from '../url.js';
45
export const mentionCompact = (text, repo) => {
5-
const replacer = (value, item) => value.replace(item[0], template('mention', item[1]));
6+
const replacer = (value, item) => replace(value, item, template('mention', item[1]));
67
text = regex(text, /<\s*a.+@([a-zA-Z][\w\d\-_]*).+<\/\s*a\s*>/g, replacer);
78
text = regex(text, /\[[\s`@]*[\w\d\-]+[\s`]*]\(https:\/\/github\.com\/([\w\d\-]+)\/?\)/g, replacer);
89
text = regex(text, /@([a-zA-Z][\w\d\-_]*)/g, replacer);
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import { regex } from '../regex.js';
2+
import { replace } from '../helpers.js';
23
import { template } from '../template.js';
34
import { url } from '../url.js';
45
export const pullRequestCompact = (text, repo) => {
5-
const replacerFull = (value, item) => value.replace(item[0], template('pull_request', `${item[1]}/${item[2]}`, item[3]));
6-
const replacerShort = (value, item) => value.replace(item[0], template('pull_request', repo, item[1]));
6+
const replacerFull = (value, item) => replace(value, item, template('pull_request', `${item[1]}/${item[2]}`, item[3]));
7+
const replacerShort = (value, item) => replace(value, item, template('pull_request', repo, item[1]));
78
text = regex(text, /\[[\s`#@]*\d+]\(https:\/\/github\.com\/([\w\d\-_]+)\/([\w\d\-_]+)\/pull\/(\d+)\)/g, replacerFull);
89
text = regex(text, /https:\/\/github\.com\/([\w\d\-_]+)\/([\w\d\-_]+)\/pull\/(\d+)/g, replacerFull);
910
text = regex(text, /#(\d+)/g, replacerShort);
1011
return text;
1112
};
1213
export const pullRequestExpand = (text, repo) => {
1314
const replacer = (value, item) => value.replace(item[0], url(repo, `${item[1]}#${item[2]}`, `${item[1]}/pull/${item[2]}`));
14-
text = regex(text, /::pull_request::([\w\d\-_\/]+)::([\w\d\-_]+)::/g, replacer);
15+
text = regex(text, /::pull_request::([\d\w.\-_\/]+)::([\d\w.\-_\/]+)::/g, replacer);
1516
return text;
1617
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import type { GitHubLinkifyTransformer } from '../../types/transformer.js';
2+
export declare const tagsCompact: GitHubLinkifyTransformer;
3+
export declare const tagsExpand: GitHubLinkifyTransformer;

0 commit comments

Comments
 (0)