diff --git a/core/modules/parsers/wikiparser/rules/fnprocdef.js b/core/modules/parsers/wikiparser/rules/fnprocdef.js index 3f21b8da7..85bd14d5c 100644 --- a/core/modules/parsers/wikiparser/rules/fnprocdef.js +++ b/core/modules/parsers/wikiparser/rules/fnprocdef.js @@ -49,11 +49,11 @@ exports.parse = function() { if(this.match[3]) { params = $tw.utils.parseParameterDefinition(this.match[4]); } - // Is this a multiline definition? + // Is the remainder of the line blank after the parameter close paren? var reEnd; if(this.match[5]) { - // If so, the end of the body is marked with \end - reEnd = new RegExp("(\\r?\\n[^\\S\\n\\r]*\\\\end[^\\S\\n\\r]*(?:" + $tw.utils.escapeRegExp(this.match[2]) + ")?(?:$|\\r?\\n))","mg"); + // If so, it is a multiline definition and the end of the body is marked with \end + reEnd = new RegExp("((:?^|\\r?\\n)[^\\S\\n\\r]*\\\\end[^\\S\\n\\r]*(?:" + $tw.utils.escapeRegExp(this.match[2]) + ")?(?:$|\\r?\\n))","mg"); } else { // Otherwise, the end of the definition is marked by the end of the line reEnd = /($|\r?\n)/mg; diff --git a/core/modules/parsers/wikiparser/rules/macrodef.js b/core/modules/parsers/wikiparser/rules/macrodef.js index 74a94a385..2001f70d5 100644 --- a/core/modules/parsers/wikiparser/rules/macrodef.js +++ b/core/modules/parsers/wikiparser/rules/macrodef.js @@ -54,11 +54,11 @@ exports.parse = function() { paramMatch = reParam.exec(paramString); } } - // Is this a multiline definition? + // Is the remainder of the \define line blank after the parameter close paren? var reEnd; if(this.match[3]) { - // If so, the end of the body is marked with \end - reEnd = new RegExp("(\\r?\\n[^\\S\\n\\r]*\\\\end[^\\S\\n\\r]*(?:" + $tw.utils.escapeRegExp(this.match[1]) + ")?(?:$|\\r?\\n))","mg"); + // If so, it is a multiline definition and the end of the body is marked with \end + reEnd = new RegExp("((?:^|\\r?\\n)[^\\S\\n\\r]*\\\\end[^\\S\\n\\r]*(?:" + $tw.utils.escapeRegExp(this.match[1]) + ")?(?:$|\\r?\\n))","mg"); } else { // Otherwise, the end of the definition is marked by the end of the line reEnd = /($|\r?\n)/mg; diff --git a/editions/test/tiddlers/tests/data/macros/EndInBody.tid b/editions/test/tiddlers/tests/data/macros/EndInBody.tid new file mode 100644 index 000000000..e93a0917d --- /dev/null +++ b/editions/test/tiddlers/tests/data/macros/EndInBody.tid @@ -0,0 +1,16 @@ +title: Macros/EndInBody +description: \end line starting with non-whitespace is part of macro body +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\define hello() + hello \end +\end + +Out: <> ++ +title: ExpectedResult + +

Out: hello \end

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/macros/IndentedEnd.tid b/editions/test/tiddlers/tests/data/macros/IndentedEnd.tid new file mode 100644 index 000000000..97f2c4197 --- /dev/null +++ b/editions/test/tiddlers/tests/data/macros/IndentedEnd.tid @@ -0,0 +1,16 @@ +title: Macros/IndentedEnd +description: \end line starting with whitespace ends a macro body +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\define hello() + hello \end + \end + +Out: <> ++ +title: ExpectedResult + +

Out: hello \end

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/macros/MismatchedNamedEnd.tid b/editions/test/tiddlers/tests/data/macros/MismatchedNamedEnd.tid new file mode 100644 index 000000000..b66821753 --- /dev/null +++ b/editions/test/tiddlers/tests/data/macros/MismatchedNamedEnd.tid @@ -0,0 +1,16 @@ +title: Macros/MismatchedNamedEnd +description: Mismatched named end is part of the body +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\define hello() + \end goodbye +\end + +Out: <> ++ +title: ExpectedResult + +

Out: \end goodbye

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/macros/WhitespaceOnlyWithEnd.tid b/editions/test/tiddlers/tests/data/macros/WhitespaceOnlyWithEnd.tid new file mode 100644 index 000000000..6998672ba --- /dev/null +++ b/editions/test/tiddlers/tests/data/macros/WhitespaceOnlyWithEnd.tid @@ -0,0 +1,18 @@ +title: Macros/WhitespaceOnlyWithEnd +description: The /end should be detected when macro definition contains only whitespace +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\define max() +\end +Nothing +\end + +Out: <> ++ +title: ExpectedResult + +

Nothing +\end

Out:

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/macros/WhitespaceOnlyWithEnd2.tid b/editions/test/tiddlers/tests/data/macros/WhitespaceOnlyWithEnd2.tid new file mode 100644 index 000000000..60db278d6 --- /dev/null +++ b/editions/test/tiddlers/tests/data/macros/WhitespaceOnlyWithEnd2.tid @@ -0,0 +1,15 @@ +title: Macros/WhitespaceOnlyWithEnd2 +description: Line with \end can start with whitespace +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\define empty() + \end + +Out: <> ++ +title: ExpectedResult + +

Out:

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/procedures/EndInBody.tid b/editions/test/tiddlers/tests/data/procedures/EndInBody.tid new file mode 100644 index 000000000..3aa13fad5 --- /dev/null +++ b/editions/test/tiddlers/tests/data/procedures/EndInBody.tid @@ -0,0 +1,16 @@ +title: Procedures/EndInBody +description: \end line starting with non-whitespace is part of procedure body +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\procedure hello() + hello \end +\end + +Out: <> ++ +title: ExpectedResult + +

Out: hello \end

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/procedures/IndentedEnd.tid b/editions/test/tiddlers/tests/data/procedures/IndentedEnd.tid new file mode 100644 index 000000000..664be3446 --- /dev/null +++ b/editions/test/tiddlers/tests/data/procedures/IndentedEnd.tid @@ -0,0 +1,16 @@ +title: Procedures/IndentedEnd +description: \end line starting with whitespace ends a procedure body +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\procedure hello() + hello \end + \end + +Out: <> ++ +title: ExpectedResult + +

Out: hello \end

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/procedures/MismatchedNamedEnd.tid b/editions/test/tiddlers/tests/data/procedures/MismatchedNamedEnd.tid new file mode 100644 index 000000000..0b5385c6e --- /dev/null +++ b/editions/test/tiddlers/tests/data/procedures/MismatchedNamedEnd.tid @@ -0,0 +1,16 @@ +title: Procedures/MismatchedNamedEnd +description: Mismatched named end is part of the body +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\procedure hello() + \end goodbye +\end + +Out: <> ++ +title: ExpectedResult + +

Out: \end goodbye

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/procedures/WhitespaceOnlyWithEnd.tid b/editions/test/tiddlers/tests/data/procedures/WhitespaceOnlyWithEnd.tid new file mode 100644 index 000000000..51f0b87df --- /dev/null +++ b/editions/test/tiddlers/tests/data/procedures/WhitespaceOnlyWithEnd.tid @@ -0,0 +1,18 @@ +title: Procedures/WhitespaceOnlyWithEnd +description: The /end should be detected when procedure definition contains only whitespace +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\procedure max() +\end +Nothing +\end + +Out: <> ++ +title: ExpectedResult + +

Nothing +\end

Out:

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/procedures/WhitespaceOnlyWithEnd2.tid b/editions/test/tiddlers/tests/data/procedures/WhitespaceOnlyWithEnd2.tid new file mode 100644 index 000000000..54d3ebbf6 --- /dev/null +++ b/editions/test/tiddlers/tests/data/procedures/WhitespaceOnlyWithEnd2.tid @@ -0,0 +1,15 @@ +title: Procedures/WhitespaceOnlyWithEnd2 +description: Line with \end can start with whitespace +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\procedure empty() + \end + +Out: <> ++ +title: ExpectedResult + +

Out:

\ No newline at end of file