Skip to content

Commit 2ec9eaa

Browse files
authored
Consistently escape recipe.displayName (#204)
* Consistently escape recipe.displayName * Use the same escape everywhere * Remove enum * Also escape description as needed * Consistently format lists of recipes in condensed format * Minor fixes as seen in render * Fix parse issue with recipeDescriptors.yml * Group by artifactId * Final touches
1 parent be192a7 commit 2ec9eaa

4 files changed

Lines changed: 7480 additions & 7499 deletions

File tree

build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ tasks.named<JavaExec>("run").configure {
167167
// Additional modules whose versions we want to show, but not (yet) their recipes
168168
dependencies {
169169
"recipe"("org.openrewrite:rewrite-cobol:$rewriteVersion")
170-
"recipe"("org.openrewrite:rewrite-csharp:$rewriteVersion")
171170
"recipe"("org.openrewrite:rewrite-javascript:$rewriteVersion")
172171
"recipe"("org.openrewrite:rewrite-polyglot:$rewriteVersion")
173172
"recipe"("org.openrewrite:rewrite-python:$rewriteVersion")

src/main/kotlin/org/openrewrite/RecipeDescriptorExtensions.kt

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,35 @@ package org.openrewrite
33
import org.openrewrite.config.OptionDescriptor
44
import org.openrewrite.config.RecipeDescriptor
55

6+
fun RecipeDescriptor.displayNameEscaped(): String {
7+
return escape(displayName)
8+
// Always remove URLs in markdown format [text](url)
9+
.replace(Regex("\\[([^]]+)]\\([^)]+\\)"), "$1")
10+
}
11+
fun RecipeDescriptor.descriptionEscaped(): String {
12+
if (description.isNullOrBlank()) {
13+
return ""
14+
}
15+
return escape(description)
16+
.replace("\n", " ")
17+
.trim()
18+
}
19+
private fun escape(string: String): String = string
20+
.replace("&", "&amp;")
21+
.replace("<", "&lt;")
22+
.replace(">", "&gt;")
23+
.replace("\"", "&quot;")
24+
.replace("'", "&#39;")
25+
626
fun RecipeDescriptor.asYaml(): String {
727
val s = StringBuilder()
828
s.appendLine("""
929
---
1030
type: specs.openrewrite.org/v1beta/recipe
1131
name: $name
12-
displayName: $displayName
32+
displayName: ${displayNameEscaped()}
1333
description: |
14-
${description?.replace("\n", "\n ")?.replace("```. [Source]", "```\n [Source]") ?: ""}
34+
${descriptionEscaped()}
1535
""".trimIndent())
1636
if (tags.isNotEmpty()) {
1737
s.appendLine("tags:")

0 commit comments

Comments
 (0)