From 0eb5c3d4df819ba5967a589a9feccddd90d15fba Mon Sep 17 00:00:00 2001 From: David Herman Date: Sun, 29 Dec 2024 13:35:17 -0800 Subject: [PATCH] Fix cast crash that could happen in markdown blockquote After 0.19.1, this started crashing: ``` > *Note* > ... ``` due to a force cast I was doing foolishly (which broke because "*Note*" is an EmphasisNode, not a Text node) Changed logic from `child as Text` to `child as? Text` --- .../varabyte/kobwebx/gradle/markdown/handlers/Blockquote.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/gradle-plugins/extensions/markdown/src/main/kotlin/com/varabyte/kobwebx/gradle/markdown/handlers/Blockquote.kt b/tools/gradle-plugins/extensions/markdown/src/main/kotlin/com/varabyte/kobwebx/gradle/markdown/handlers/Blockquote.kt index f5dbe3b4d..9e087530b 100644 --- a/tools/gradle-plugins/extensions/markdown/src/main/kotlin/com/varabyte/kobwebx/gradle/markdown/handlers/Blockquote.kt +++ b/tools/gradle-plugins/extensions/markdown/src/main/kotlin/com/varabyte/kobwebx/gradle/markdown/handlers/Blockquote.kt @@ -58,8 +58,9 @@ fun SilkCalloutBlockquoteHandler( ): NodeScope.(BlockQuote) -> String { return { blockQuote -> val silkCallout = blockQuote.firstChild.firstChild?.let { firstChild -> - firstChild as Text - val regex = """\[!([^ ]+)( "(.*)")?]""".toRegex() + @Suppress("NAME_SHADOWING") + val firstChild = firstChild as? Text ?: return@let null + val regex = """\[!([^ ]+)( "(.*)")?]""".toRegex() // [!TYPE "LABEL"] val typeMatch = regex.find(firstChild.literal) ?: return@let null firstChild.literal = firstChild.literal.substringAfter(typeMatch.value)