diff --git a/core/src/main/kotlin/eu/iamgio/quarkdown/lexer/walker/FunctionCallArgumentsWalkerLexer.kt b/core/src/main/kotlin/eu/iamgio/quarkdown/lexer/walker/FunctionCallArgumentsWalkerLexer.kt index 8ca0ef8a..b0ea8df7 100644 --- a/core/src/main/kotlin/eu/iamgio/quarkdown/lexer/walker/FunctionCallArgumentsWalkerLexer.kt +++ b/core/src/main/kotlin/eu/iamgio/quarkdown/lexer/walker/FunctionCallArgumentsWalkerLexer.kt @@ -7,12 +7,12 @@ import eu.iamgio.quarkdown.lexer.tokens.PlainTextToken /** * Beginning of a function argument. */ -private const val ARG_DELIMITER_OPEN = '{' +const val ARG_DELIMITER_OPEN = '{' /** * End of a function argument. */ -private const val ARG_DELIMITER_CLOSE = '}' +const val ARG_DELIMITER_CLOSE = '}' /** * End of named argument's name. diff --git a/core/src/main/kotlin/eu/iamgio/quarkdown/parser/BlockTokenParser.kt b/core/src/main/kotlin/eu/iamgio/quarkdown/parser/BlockTokenParser.kt index 49d0c9ed..962dc819 100644 --- a/core/src/main/kotlin/eu/iamgio/quarkdown/parser/BlockTokenParser.kt +++ b/core/src/main/kotlin/eu/iamgio/quarkdown/parser/BlockTokenParser.kt @@ -48,6 +48,8 @@ import eu.iamgio.quarkdown.lexer.tokens.ParagraphToken import eu.iamgio.quarkdown.lexer.tokens.SetextHeadingToken import eu.iamgio.quarkdown.lexer.tokens.TableToken import eu.iamgio.quarkdown.lexer.tokens.UnorderedListToken +import eu.iamgio.quarkdown.lexer.walker.ARG_DELIMITER_CLOSE +import eu.iamgio.quarkdown.lexer.walker.ARG_DELIMITER_OPEN import eu.iamgio.quarkdown.util.iterator import eu.iamgio.quarkdown.util.nextOrNull import eu.iamgio.quarkdown.util.takeUntilLastOccurrence @@ -405,13 +407,14 @@ class BlockTokenParser(private val context: MutableContext) : BlockTokenVisitor< groups.forEachRemaining { arg -> // If this group contains the name of a named argument, // it is applied to the very next argument. - if (arg.firstOrNull() != '{' && arg.lastOrNull() != '}') { + if (arg.firstOrNull() != ARG_DELIMITER_OPEN && arg.lastOrNull() != ARG_DELIMITER_CLOSE) { argName = arg return@forEachRemaining } // Regular argument wrapped in brackets, which are stripped off. - val argContent = arg.trimDelimiters().trim() + // Common indentation is also removed. + val argContent = arg.trimDelimiters().trimIndent().trim() // An expression from the raw string is created. ValueFactory.expression(argContent, context)?.let { diff --git a/test/src/test/kotlin/eu/iamgio/quarkdown/test/FullPipelineTest.kt b/test/src/test/kotlin/eu/iamgio/quarkdown/test/FullPipelineTest.kt index 928edbbb..0c5922d7 100644 --- a/test/src/test/kotlin/eu/iamgio/quarkdown/test/FullPipelineTest.kt +++ b/test/src/test/kotlin/eu/iamgio/quarkdown/test/FullPipelineTest.kt @@ -384,6 +384,20 @@ class FullPipelineTest { assertEquals("
18
", it) } + execute( + """ + .divide { + .cos {.pi} + } by:{ + .sin { + 1 + } + } + """.trimIndent(), + ) { + assertEquals("-1.1883951
", it) + } + execute("$ 4 - 2 = $ .subtract {4} {2}") { assertEquals("__QD_INLINE_MATH__$4 - 2 =\$__QD_INLINE_MATH__ 2
", it) assertTrue(attributes.hasMath)