Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allows whitespace-only macro/procedure to be closed by \end #7911

Merged
merged 7 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions core/modules/parsers/wikiparser/rules/fnprocdef.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions core/modules/parsers/wikiparser/rules/macrodef.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 16 additions & 0 deletions editions/test/tiddlers/tests/data/macros/EndInBody.tid
Original file line number Diff line number Diff line change
@@ -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: <<hello>>
+
title: ExpectedResult

<p>Out: hello \end</p>
16 changes: 16 additions & 0 deletions editions/test/tiddlers/tests/data/macros/IndentedEnd.tid
Original file line number Diff line number Diff line change
@@ -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: <<hello>>
+
title: ExpectedResult

<p>Out: hello \end</p>
16 changes: 16 additions & 0 deletions editions/test/tiddlers/tests/data/macros/MismatchedNamedEnd.tid
Original file line number Diff line number Diff line change
@@ -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: <<hello>>
+
title: ExpectedResult

<p>Out: \end goodbye</p>
18 changes: 18 additions & 0 deletions editions/test/tiddlers/tests/data/macros/WhitespaceOnlyWithEnd.tid
Original file line number Diff line number Diff line change
@@ -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: <<max>>
+
title: ExpectedResult

<p>Nothing
\end</p><p>Out: </p>
Original file line number Diff line number Diff line change
@@ -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: <<empty>>
+
title: ExpectedResult

<p>Out: </p>
16 changes: 16 additions & 0 deletions editions/test/tiddlers/tests/data/procedures/EndInBody.tid
Original file line number Diff line number Diff line change
@@ -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: <<hello>>
+
title: ExpectedResult

<p>Out: hello \end</p>
16 changes: 16 additions & 0 deletions editions/test/tiddlers/tests/data/procedures/IndentedEnd.tid
Original file line number Diff line number Diff line change
@@ -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: <<hello>>
+
title: ExpectedResult

<p>Out: hello \end</p>
Original file line number Diff line number Diff line change
@@ -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: <<hello>>
+
title: ExpectedResult

<p>Out: \end goodbye</p>
Original file line number Diff line number Diff line change
@@ -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: <<max>>
+
title: ExpectedResult

<p>Nothing
\end</p><p>Out: </p>
Original file line number Diff line number Diff line change
@@ -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: <<empty>>
+
title: ExpectedResult

<p>Out: </p>
Loading