Skip to content

Commit

Permalink
Remove empty spaces in links when producing text masks for vale. (#825)
Browse files Browse the repository at this point in the history
Signed-off-by: Theo Truong <[email protected]>
  • Loading branch information
nhtruong authored Mar 1, 2025
1 parent fcbfc10 commit f81e8f3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
14 changes: 5 additions & 9 deletions tools/src/prepare-for-vale/KeepDescriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export default class KeepDescriptions {
}

process(): void {
this.root_folder
const files = fg.globSync([`${this.root_folder}/**/*.{yaml,yml}`], { dot: true })
files.forEach((path) => {
this.logger.log(path)
Expand All @@ -38,14 +37,14 @@ export default class KeepDescriptions {

var inside_text = false
contents.split(/\r?\n/).forEach((line) => {
if (line.match(/^[\s]+((description|x-deprecation-message): \|)/)) {
if (line.match(/^\s+((description|x-deprecation-message): \|)/)) {
inside_text = true
} else if (line.match(/^[\s]+((description|x-deprecation-message):)[\s]+/)) {
} else if (line.match(/^\s+((description|x-deprecation-message):)[\s]+/)) {
let cleaned_line = this.prune(line, /(description|x-deprecation-message):/, ' ')
cleaned_line = this.prune_vars(cleaned_line)
cleaned_line = this.remove_links(cleaned_line)
fs.writeSync(writer, cleaned_line)
} else if (inside_text && line.match(/^[\s]*[\w\\$]*:/)) {
} else if (inside_text && line.match(/^\s*[\w\\$]*:/)) {
inside_text = false
} else if (inside_text) {
let cleaned_line = this.remove_links(line)
Expand All @@ -59,7 +58,7 @@ export default class KeepDescriptions {
}

prune_vars(line: string): string {
return this.prune(line, /([`])(?:(?=(\\?))\2.)*?\1/g, '*')
return this.prune(line, /(`)(?:(?=(\\?))\2.)*?\1/g, '*')
}

prune(line: string, regex: RegExp, char: string): string {
Expand All @@ -69,9 +68,6 @@ export default class KeepDescriptions {
}

remove_links(line: string): string {
return line.replace(/\[([^\]]+)\]\([^)]+\)/g, (match, p1) => {
const spaces = ' '.repeat(match.length - p1.length - 1)
return ' ' + p1 + spaces
})
return line.replace(/\[([^\]]+)]\([^)]+\)/g, '$1')
}
}
6 changes: 3 additions & 3 deletions tools/tests/prepare-for-vale/fixtures/spec.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@



For a successful response, this value is always true. On failure, an exception is returned instead Supported units .
For a successful response, this value is always true. On failure, an exception is returned instead Supported units.



The item level REST category class codes during indexing link with a title .
The item level REST category class codes during indexing link with a title.



Here is link one and link two .
Here is link one and link two.
Line two


Expand Down

0 comments on commit f81e8f3

Please sign in to comment.