diff --git a/tools/src/prepare-for-vale/KeepDescriptions.ts b/tools/src/prepare-for-vale/KeepDescriptions.ts index 8995f8df5..6a3481049 100644 --- a/tools/src/prepare-for-vale/KeepDescriptions.ts +++ b/tools/src/prepare-for-vale/KeepDescriptions.ts @@ -41,15 +41,21 @@ export default class KeepDescriptions { if (line.match(/^[\s]+(description: \|)/)) { inside_description = true } else if (line.match(/^[\s]+(description:)[\s]+/)) { - fs.writeSync(writer, line.replace("description:", " ")) + fs.writeSync(writer, this.prune(line).replace("description:", " ")) } else if (inside_description && line.match(/^[\s]*[\w]*:/)) { inside_description = false } else if (inside_description) { - fs.writeSync(writer, line) + fs.writeSync(writer, this.prune(line)) } if (line.length > 0) { fs.writeSync(writer, "\n") } }) } + + prune(line: string): string { + return line.replace(/([`])(?:(?=(\\?))\2.)*?\1/g, (match) => { + return Array(match.length + 1).join('*') + }) + } } diff --git a/tools/tests/prepare-for-vale/fixtures/spec.txt b/tools/tests/prepare-for-vale/fixtures/spec.txt index a54608e03..55fb7ab28 100644 --- a/tools/tests/prepare-for-vale/fixtures/spec.txt +++ b/tools/tests/prepare-for-vale/fixtures/spec.txt @@ -24,3 +24,9 @@ Line one Line with a description: that describes itself. + + + + Line one + Line with backticks: that includes *******. + Line with two backticks: that includes ******* and *******. diff --git a/tools/tests/prepare-for-vale/fixtures/spec.yaml b/tools/tests/prepare-for-vale/fixtures/spec.yaml index 8801c55e2..09b51c951 100644 --- a/tools/tests/prepare-for-vale/fixtures/spec.yaml +++ b/tools/tests/prepare-for-vale/fixtures/spec.yaml @@ -24,3 +24,9 @@ components: description: |- Line one Line with a description: that describes itself. + ObjectWithCode: + type: object + description: |- + Line one + Line with backticks: that includes `x.y.z`. + Line with two backticks: that includes `x.y.z` and `z.y.x`.