From 8738482b763163e529433353f5c1859f0c86c0bf Mon Sep 17 00:00:00 2001 From: kevin Date: Sun, 5 Nov 2023 17:30:54 -0800 Subject: [PATCH] Fix bug in which argument parsing was not correctly done --- .../ktt/view/plugins/MacrosPlugin.kt | 2 +- .../ktt/view/plugins/MacrosPluginTest.kt | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/com/vandenbreemen/ktt/view/plugins/MacrosPlugin.kt b/src/main/kotlin/com/vandenbreemen/ktt/view/plugins/MacrosPlugin.kt index 963f3ed..165e302 100644 --- a/src/main/kotlin/com/vandenbreemen/ktt/view/plugins/MacrosPlugin.kt +++ b/src/main/kotlin/com/vandenbreemen/ktt/view/plugins/MacrosPlugin.kt @@ -15,7 +15,7 @@ class MacrosPlugin(private val macroRegistry: MacroRegistry): PageRenderingPlugi val argMap: MutableMap = mutableMapOf() if(macro.groupValues[2].isNotEmpty()) { - val argumentsRaw = macro.groupValues[2].split("[\\s]*[,][\\s]*") + val argumentsRaw = macro.groupValues[2].split("[\\s]*[,][\\s]*".toRegex()) argumentsRaw.mapNotNull { argument -> argument.split("=").let { rawPair -> if(rawPair.size != 2) { diff --git a/src/test/kotlin/com/vandenbreemen/ktt/view/plugins/MacrosPluginTest.kt b/src/test/kotlin/com/vandenbreemen/ktt/view/plugins/MacrosPluginTest.kt index 409e4a1..319d0c5 100644 --- a/src/test/kotlin/com/vandenbreemen/ktt/view/plugins/MacrosPluginTest.kt +++ b/src/test/kotlin/com/vandenbreemen/ktt/view/plugins/MacrosPluginTest.kt @@ -14,6 +14,10 @@ class MacrosPluginTest { override fun execute(args: Map): String { val message = args["message"] ?: "(missing message)" + val additional = args["additional"] + if(additional != null) { + return "got pair: ${Pair(message, additional).toString()}" + } return "HiMsg: $message" } } @@ -80,4 +84,22 @@ This is a special test. rendered.shouldContain("HiMsg: (missing message)") } + @Test + fun `should handle macros with multiple arguments`() { + val markdown = """ +# Hello world + +this is a test of some wiki content. + +{@macro:HelloWorld message=Hi how are you?, additional=this/is/a/test} + +This is a special test. + """.trimIndent() + + val rendered = plugin.process(markdown) + + println("RENDERED:\n===================\n$rendered") + rendered.shouldContain("got pair: (Hi how are you?, this/is/a/test)") + } + } \ No newline at end of file