From bcca4eca813b98cb00d32b97a5932843d33b4f34 Mon Sep 17 00:00:00 2001 From: Cameron Fischer Date: Thu, 23 Mar 2023 18:37:35 -0400 Subject: [PATCH] Fixed issue with trailing newlines in macrodefs (#7371) --- .../parsers/wikiparser/rules/macrodef.js | 2 +- .../tests/data/macros/TrailingNewlines.tid | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 editions/test/tiddlers/tests/data/macros/TrailingNewlines.tid diff --git a/core/modules/parsers/wikiparser/rules/macrodef.js b/core/modules/parsers/wikiparser/rules/macrodef.js index 1d7ac9211..1efd3449a 100644 --- a/core/modules/parsers/wikiparser/rules/macrodef.js +++ b/core/modules/parsers/wikiparser/rules/macrodef.js @@ -58,7 +58,7 @@ exports.parse = function() { var reEnd; if(this.match[3]) { // If so, the end of the body is marked with \end - reEnd = new RegExp("(\\r?\\n\\s*\\\\end[^\\S\\n\\r]*(?:" + $tw.utils.escapeRegExp(this.match[1]) + ")?(?:$|\\r?\\n))","mg"); + 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/TrailingNewlines.tid b/editions/test/tiddlers/tests/data/macros/TrailingNewlines.tid new file mode 100644 index 000000000..18037fac2 --- /dev/null +++ b/editions/test/tiddlers/tests/data/macros/TrailingNewlines.tid @@ -0,0 +1,22 @@ +title: Macros/TrailingNewlines +description: Trailing newlines in macros must not be dropped +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\define inner() +Paragraph 1 + +Paragraph 2 +\end +\define outer() +<$macrocall $name=inner /> + +\end +<> + ++ +title: ExpectedResult + +

Paragraph 1

Paragraph 2

\ No newline at end of file