Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve recipe descriptions #159

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/main/kotlin/org/openrewrite/RecipeMarkdownGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import java.nio.file.StandardOpenOption
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.util.*
import java.util.regex.Pattern
import java.util.stream.Collectors
import kotlin.io.path.toPath
import kotlin.system.exitProcess
Expand Down Expand Up @@ -1082,15 +1083,20 @@ import TabItem from '@theme/TabItem';

@Suppress("UNNECESSARY_SAFE_CALL") // Recipes from third parties may lack description
private fun getFormattedRecipeDescription(recipeDescriptor: RecipeDescriptor): String {
val specialCharacters = listOf('<', '>', '{', '}')
val formattedRecipeDescription = recipeDescriptor?.description
val formattedRecipeDescription = recipeDescriptor?.description ?: ""
val specialCharsOutsideBackticksRegex = Pattern.compile("[<>{}](?=(?:[^`]*`[^`]*`)*[^`]*\$)")

if (formattedRecipeDescription?.contains("```") == true) {
// Assume that the recipe description is already Markdown
return formattedRecipeDescription
}
if (specialCharacters.any { recipeDescriptor?.description?.contains(it) == true }) {

if (specialCharsOutsideBackticksRegex.matcher(formattedRecipeDescription).find()) {
// If special characters exist and are not wrapped in backticks, wrap the entire string in triple backticks
return "```\n${formattedRecipeDescription?.replace("```", "")?.trim()}\n```\n"
}

// Special characters may exist here - but they are already wrapped in backticks
return "_" + formattedRecipeDescription?.replace("\n", " ")?.trim() + "_"
}

Expand Down
Loading