Skip to content

Commit e0b85b0

Browse files
Added trees parser
1 parent 4eb2169 commit e0b85b0

File tree

6 files changed

+41
-5
lines changed

6 files changed

+41
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { githubLinkifyPlugin } from 'vuepress-plugin-github-linkify'
3535
* [x] pull requests
3636
* [x] compares
3737
* [x] tags
38-
* [ ] trees
38+
* [x] trees
3939
* [ ] blobs
4040

4141
## Example

index.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@
5151
<li>[ar]: Translate Updated Laravel Framework 9.x keys by @mohamedsabil83 in #2606</li>
5252
</ul>
5353

54+
<ul>
55+
<li>https://github.com/Laravel-Lang/common/tree/v1.0.13/.run</li>
56+
<li>https://github.com/Laravel-Lang/common/tree/v1.0.13</li>
57+
</ul>
58+
5459
<p>**Full Changelog**: https://github.com/Laravel-Lang/common/compare/12.18.3...12.8.4</p>
5560

5661
<p>**Full Changelog**: 12.18.3...12.8.4</p>
@@ -94,6 +99,11 @@
9499
<li>[ar]: Translate Updated Laravel Framework 9.x keys by @mohamedsabil83 in https://github.com/Laravel-Lang/lang/pull/2606</li>
95100
</ul>
96101

102+
<ul>
103+
<li>https://github.com/Laravel-Lang/lang/tree/v1.0.13/.run</li>
104+
<li>https://github.com/Laravel-Lang/lang/tree/v1.0.13</li>
105+
</ul>
106+
97107
<p>**Full Changelog**: https://github.com/Laravel-Lang/lang/compare/12.18.3...12.8.4</p>
98108

99109
<p>**Full Changelog**: 12.18.3...12.8.4</p>

src/node/plugins/transformers/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import { mentionCompact, mentionExpand } from './mention.js'
44
import { pullRequestCompact, pullRequestExpand } from './pull-request.js'
55
import { compareCompact, compareExpand } from './compare.js'
66
import { commitCompact, commitExpand } from './commit.js'
7-
import { tagsCompact, tagsExpand } from './tags'
7+
import { tagsCompact, tagsExpand } from './tags.js'
8+
import { treesCompact, treesExpand } from './trees.js'
89

910
const compact = [
1011
mentionCompact,
1112
pullRequestCompact,
1213
compareCompact,
1314
commitCompact,
15+
treesCompact,
1416
tagsCompact
1517
]
1618

@@ -19,6 +21,7 @@ const expand = [
1921
pullRequestExpand,
2022
compareExpand,
2123
commitExpand,
24+
treesExpand,
2225
tagsExpand
2326
]
2427

src/node/plugins/transformers/pull-request.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const pullRequestCompact: GitHubLinkifyTransformer = (text: string, repo:
1818
export const pullRequestExpand: GitHubLinkifyTransformer = (text: string, repo: string) => {
1919
const replacer = (value, item) => value.replace(item[0], url(repo, `${ item[1] }#${ item[2] }`, `${ item[1] }/pull/${ item[2] }`))
2020

21-
text = regex(text, /::pull_request::([\w\d\-_\/]+)::([\w\d\-_]+)::/g, replacer)
21+
text = regex(text, /::pull_request::([\d\w.\-_\/]+)::([\d\w.\-_\/]+)::/g, replacer)
2222

2323
return text
2424
}

src/node/plugins/transformers/tags.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import type { GitHubLinkifyTransformer } from '../../types/transformer.js'
12
import { regex } from '../regex.js'
23
import { replace } from '../helpers.js'
34
import { template } from '../template.js'
45
import { url } from '../url.js'
56

6-
export const tagsCompact = (text: string, repo: string) => {
7+
export const tagsCompact: GitHubLinkifyTransformer = (text: string, repo: string) => {
78
const replacerFull = (value, item) => replace(value, item, template('tag', `${ item[1] }/${ item[2] }`, item[3]))
89
const replacerShort = (value, item) => replace(value, item, template('tag', repo, item[1]))
910

@@ -14,7 +15,7 @@ export const tagsCompact = (text: string, repo: string) => {
1415
return text
1516
}
1617

17-
export const tagsExpand = (text: string, repo: string) => {
18+
export const tagsExpand: GitHubLinkifyTransformer = (text: string, repo: string) => {
1819
const replacer = (value, item) => value.replace(item[0], url(repo, `${ item[1].includes(repo) ? '' : item[1] + '#' }${ item[2].replace('v', '') }`, `${ item[1] }/releases/tag/${ item[2] }`))
1920

2021
text = regex(text, /::tag::([\w\d.\-\/]+)::([\w\d.\-]+)::/g, replacer)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import type { GitHubLinkifyTransformer } from '../../types/transformer.js'
2+
import { regex } from '../regex.js'
3+
import { replace } from '../helpers.js'
4+
import { template } from '../template.js'
5+
import { url } from '../url.js'
6+
7+
export const treesCompact: GitHubLinkifyTransformer = (text: string, repo: string) => {
8+
const replacer = (value, item) => replace(value, item, template('tree', `${ item[1] }/${ item[2] }`, `${ item[3] }`))
9+
10+
text = regex(text, /\[[\s`#@]*\d+]\(https:\/\/github\.com\/([\w\d\-_]+)\/([\w\d\-_]+)\/tree\/([\d\w.\-_\/]+)\)/g, replacer)
11+
text = regex(text, /https:\/\/github\.com\/([\w\d\-_]+)\/([\w\d\-_]+)\/tree\/([\d\w.\-_\/]+)/g, replacer)
12+
13+
return text
14+
}
15+
16+
export const treesExpand: GitHubLinkifyTransformer = (text: string, repo: string) => {
17+
const replacer = (value, item) => replace(value, item, url(repo, `${ item[1].includes(repo) ? '' : item[1] + '#' }${ item[2] }`, `${ item[1] }/tree/${ item[2] }`))
18+
19+
text = regex(text, /::tree::([\d\w.\-_\/]+)::([\d\w.\-_\/]+)::/g, replacer)
20+
21+
return text
22+
}

0 commit comments

Comments
 (0)