diff --git a/tools/src/prepare-for-vale/KeepDescriptions.ts b/tools/src/prepare-for-vale/KeepDescriptions.ts index 65d205c31..82c692252 100644 --- a/tools/src/prepare-for-vale/KeepDescriptions.ts +++ b/tools/src/prepare-for-vale/KeepDescriptions.ts @@ -45,7 +45,7 @@ export default class KeepDescriptions { } else if (inside_text && line.match(/^[\s]*[\w\\$]*:/)) { inside_text = false } else if (inside_text) { - const cleaned_line = line.replace(/\[([^\]]+)\]\([^)]+\)/g, '$1') + const cleaned_line = this.remove_links(line) fs.writeSync(writer, this.prune_vars(cleaned_line)) } if (line.length > 0) { @@ -63,4 +63,8 @@ export default class KeepDescriptions { return Array(match.length + 1).join(char) }) } + + remove_links(line: string): string { + return line.replace(/\[([^\]]+)\]\([^)]+\)/g, '$1') + } } diff --git a/tools/tests/prepare-for-vale/prepare-for-vale.test.ts b/tools/tests/prepare-for-vale/prepare-for-vale.test.ts index c46fc7340..7d3de7d0a 100644 --- a/tools/tests/prepare-for-vale/prepare-for-vale.test.ts +++ b/tools/tests/prepare-for-vale/prepare-for-vale.test.ts @@ -20,3 +20,31 @@ const spec = (args: string[]): any => { test('--help', () => { expect(spec(['--help']).stdout).toContain('Usage: prepare-for-vale [options]') }) + +test('process single link', () => { + const input = ['description: This is a [link](https://opensearch.org).'] + const expectedOutput = 'description: This is a link.\n' + const result = spec(input).stdout + expect(result).toBe(expectedOutput) +}) + +test('process two links', () => { + const input = ['description: Here is [link one](https://opensearch.org) and [link two](https://opensearch.org/).'] + const expectedOutput = 'description: Here is link one and link two.\n' + const result = spec(input).stdout + expect(result).toBe(expectedOutput) +}) + +test('process plain text without links', () => { + const input = ['description: This is plain text without any links.'] + const expectedOutput = 'description: This is plain text without any links.\n' + const result = spec(input).stdout + expect(result).toBe(expectedOutput) +}) + +test('process complex link structures', () => { + const input = ['description: Check this [link with a title](https://opensearch.org "title").'] + const expectedOutput = 'description: Check this link with a title.\n' + const result = spec(input).stdout + expect(result).toBe(expectedOutput) +})