Skip to content

Commit

Permalink
Some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey-helldar committed Mar 2, 2023
1 parent 667f8dd commit 44c500d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
22 changes: 13 additions & 9 deletions src/node/plugins/replacer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ export class Replacer
Array.from(patterns, (pattern: RegExp) => {
const matches = this.manager.text.matchAll(pattern)

Array.from(matches, item => this.manager.text = callback(item))
Array.from(matches).reverse().forEach(
item => this.manager.text = callback(item)
)
})
}

Expand All @@ -54,10 +56,12 @@ export class Replacer
let link: string = this.getFormatLink()
let value: string = this.getFormatValue()

const isSameRepository = match[1].includes(this.getRepository())

const replaces = this.getExpandReplaces()

const codePrefix: string = this.asCode() ? '<code>' : ''
const codeSuffix: string = this.asCode() ? '</code>' : ''
const codePrefix: string = this.asCode() && isSameRepository ? '<code>' : ''
const codeSuffix: string = this.asCode() && isSameRepository ? '</code>' : ''

for (let i = 1; i <= 4; i++) {
if (match[i] === undefined) {
Expand All @@ -73,7 +77,7 @@ export class Replacer

link = link.replace('https://github.com/', '').replace('$key', this.getKey())

value = match[1].includes(this.getRepository())
value = isSameRepository
? value.replace(this.getRepository(), '').replace('/$key/', this.hasForceSplitter() ? this.getSplitter() : '')
: value.replace('/$key/', this.getSplitter())

Expand All @@ -82,11 +86,11 @@ export class Replacer

private replace(match: Array<string>, to: string): string
{
return this.manager.text.replace(match[0], to)
// const index: number = match['index']
// const from: string = match[0]
//
// return text.slice(0, index) + to + text.slice(index + from.length)
// return this.manager.text.replace(match[0], to)
const index: number = match['index']
const from: string = match[0]

return this.manager.text.slice(0, index) + to + this.manager.text.slice(index + from.length)
}

private getRepository(): string
Expand Down
7 changes: 5 additions & 2 deletions src/node/plugins/transformers/tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ export const tagsTransformer = Manager.create()
.setKey('tag')
.setCompactPatterns([
/\[[\s\w\d`.\-]+]\(https:\/\/github\.com\/([\w\d\-_]+)\/([\w\d\-_]+)\/releases\/tag\/(v?\d+\.\d+\.\d+-?\w*\.?\d*)\)/g,
/https:\/\/github\.com\/([\w\d\-_]+)\/([\w\d\-_]+)\/releases\/tag\/(v?\d+\.\d+\.\d+-?\w*\.?\d*)/g
// /(?<!:)(?<=^|\s)(v?\d+\.\d+\.\d+-?\w*\.?\d*)(?<!:)/g
/https:\/\/github\.com\/([\w\d\-_]+)\/([\w\d\-_]+)\/releases\/tag\/(v?\d+\.\d+\.\d+-?\w*\.?\d*)/g,
/(?<!:)(?<=^|\s)(v?\d+\.\d+\.\d+-?\w*\.?\d*)(?<!:)/g
])
.setExpandFormat('$1/$key/$2', '$1/releases/tag/$2')
.setExpandValueReplaces({
2: (value: string) => value.startsWith('v') ? value.substring(1) : value
})

0 comments on commit 44c500d

Please sign in to comment.