Skip to content

Commit 99a5b56

Browse files
Merge pull request #5 from TheDragonCode/1.x
Added blobs parser
2 parents 26b6121 + 4fcec11 commit 99a5b56

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

README.md

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

4141
## Example
4242

index.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@
5656
<li>https://github.com/Laravel-Lang/common/tree/v1.0.13</li>
5757
</ul>
5858

59+
<ul>
60+
<li>https://github.com/Laravel-Lang/common/blob/main/composer.json</li>
61+
<li>https://github.com/Laravel-Lang/common/blob/main/src/Services/Renderer/ParagraphRenderer.php</li>
62+
<li>https://github.com/Laravel-Lang/common/blob/v14.6.2/composer.json</li>
63+
<li>https://github.com/Laravel-Lang/common/blob/v14.6.2/src/Services/Renderer/ParagraphRenderer.php</li>
64+
</ul>
65+
5966
<p>**Full Changelog**: https://github.com/Laravel-Lang/common/compare/12.18.3...12.8.4</p>
6067

6168
<p>**Full Changelog**: 12.18.3...12.8.4</p>
@@ -104,6 +111,13 @@
104111
<li>https://github.com/Laravel-Lang/lang/tree/v1.0.13</li>
105112
</ul>
106113

114+
<ul>
115+
<li>https://github.com/Laravel-Lang/publisher/blob/main/composer.json</li>
116+
<li>https://github.com/Laravel-Lang/publisher/blob/main/src/Services/Renderer/ParagraphRenderer.php</li>
117+
<li>https://github.com/Laravel-Lang/publisher/blob/v14.6.2/composer.json</li>
118+
<li>https://github.com/Laravel-Lang/publisher/blob/v14.6.2/src/Services/Renderer/ParagraphRenderer.php</li>
119+
</ul>
120+
107121
<p>**Full Changelog**: https://github.com/Laravel-Lang/lang/compare/12.18.3...12.8.4</p>
108122

109123
<p>**Full Changelog**: 12.18.3...12.8.4</p>
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 { replace } from '../helpers.js'
3+
import { template } from '../template.js'
4+
import { regex } from '../regex'
5+
import { url } from '../url'
6+
7+
export const blobsCompact: GitHubLinkifyTransformer = (text: string, repo: string) => {
8+
const replacer = (value, item) => replace(value, item, template('blob', `${ item[1] }/${ item[2] }`, item[3]))
9+
10+
text = regex(text, /\[[\w\d\s`]+]\(https:\/\/github\.com\/([\w\d\-_]+)\/([\w\d\-_]+)\/blob\/([\w\d\/\.\-_]+)\)/g, replacer)
11+
text = regex(text, /https:\/\/github\.com\/([\w\d\-_]+)\/([\w\d\-_]+)\/blob\/([\w\d\/\.\-_]+)/g, replacer)
12+
13+
return text
14+
}
15+
16+
export const blobsExpand: GitHubLinkifyTransformer = (text: string, repo: string) => {
17+
const replacer = (value, item) => value.replace(item[0], url(repo, `${ item[1].includes(repo) ? '' : item[1] + '#' }${ item[2] }`, `${ item[1] }/blob/${ item[2] }`))
18+
19+
text = regex(text, /::blob::([\w\d\-_\/]+)::([\w\d\/\.\-_]+)::/g, replacer)
20+
21+
return text
22+
}

src/node/plugins/transformers/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ import { compareCompact, compareExpand } from './compare.js'
66
import { commitCompact, commitExpand } from './commit.js'
77
import { tagsCompact, tagsExpand } from './tags.js'
88
import { treesCompact, treesExpand } from './trees.js'
9+
import { blobsCompact, blobsExpand } from './blobs.js'
910

1011
const compact = [
1112
mentionCompact,
1213
pullRequestCompact,
1314
compareCompact,
1415
commitCompact,
1516
treesCompact,
17+
blobsCompact,
1618
tagsCompact
1719
]
1820

@@ -22,6 +24,7 @@ const expand = [
2224
compareExpand,
2325
commitExpand,
2426
treesExpand,
27+
blobsExpand,
2528
tagsExpand
2629
]
2730

0 commit comments

Comments
 (0)