Skip to content

Commit

Permalink
Merge pull request #5 from TheDragonCode/1.x
Browse files Browse the repository at this point in the history
Added blobs parser
  • Loading branch information
andrey-helldar authored Mar 1, 2023
2 parents 26b6121 + 4fcec11 commit 99a5b56
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { githubLinkifyPlugin } from 'vuepress-plugin-github-linkify'
* [x] compares
* [x] tags
* [x] trees
* [ ] blobs
* [x] blobs

## Example

Expand Down
14 changes: 14 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@
<li>https://github.com/Laravel-Lang/common/tree/v1.0.13</li>
</ul>

<ul>
<li>https://github.com/Laravel-Lang/common/blob/main/composer.json</li>
<li>https://github.com/Laravel-Lang/common/blob/main/src/Services/Renderer/ParagraphRenderer.php</li>
<li>https://github.com/Laravel-Lang/common/blob/v14.6.2/composer.json</li>
<li>https://github.com/Laravel-Lang/common/blob/v14.6.2/src/Services/Renderer/ParagraphRenderer.php</li>
</ul>

<p>**Full Changelog**: https://github.com/Laravel-Lang/common/compare/12.18.3...12.8.4</p>

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

<ul>
<li>https://github.com/Laravel-Lang/publisher/blob/main/composer.json</li>
<li>https://github.com/Laravel-Lang/publisher/blob/main/src/Services/Renderer/ParagraphRenderer.php</li>
<li>https://github.com/Laravel-Lang/publisher/blob/v14.6.2/composer.json</li>
<li>https://github.com/Laravel-Lang/publisher/blob/v14.6.2/src/Services/Renderer/ParagraphRenderer.php</li>
</ul>

<p>**Full Changelog**: https://github.com/Laravel-Lang/lang/compare/12.18.3...12.8.4</p>

<p>**Full Changelog**: 12.18.3...12.8.4</p>
Expand Down
22 changes: 22 additions & 0 deletions src/node/plugins/transformers/blobs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { GitHubLinkifyTransformer } from '../../types/transformer.js'
import { replace } from '../helpers.js'
import { template } from '../template.js'
import { regex } from '../regex'
import { url } from '../url'

export const blobsCompact: GitHubLinkifyTransformer = (text: string, repo: string) => {
const replacer = (value, item) => replace(value, item, template('blob', `${ item[1] }/${ item[2] }`, item[3]))

text = regex(text, /\[[\w\d\s`]+]\(https:\/\/github\.com\/([\w\d\-_]+)\/([\w\d\-_]+)\/blob\/([\w\d\/\.\-_]+)\)/g, replacer)
text = regex(text, /https:\/\/github\.com\/([\w\d\-_]+)\/([\w\d\-_]+)\/blob\/([\w\d\/\.\-_]+)/g, replacer)

return text
}

export const blobsExpand: GitHubLinkifyTransformer = (text: string, repo: string) => {
const replacer = (value, item) => value.replace(item[0], url(repo, `${ item[1].includes(repo) ? '' : item[1] + '#' }${ item[2] }`, `${ item[1] }/blob/${ item[2] }`))

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

return text
}
3 changes: 3 additions & 0 deletions src/node/plugins/transformers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import { compareCompact, compareExpand } from './compare.js'
import { commitCompact, commitExpand } from './commit.js'
import { tagsCompact, tagsExpand } from './tags.js'
import { treesCompact, treesExpand } from './trees.js'
import { blobsCompact, blobsExpand } from './blobs.js'

const compact = [
mentionCompact,
pullRequestCompact,
compareCompact,
commitCompact,
treesCompact,
blobsCompact,
tagsCompact
]

Expand All @@ -22,6 +24,7 @@ const expand = [
compareExpand,
commitExpand,
treesExpand,
blobsExpand,
tagsExpand
]

Expand Down

0 comments on commit 99a5b56

Please sign in to comment.