mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-27 03:57:21 +00:00
Allows whitespace-only macro/procedure to be closed by \end (#7911)
* Added some passing macro definition parsing tests * Added two failing tests to illustrate bug #3460 * Allow \end to end an whitespace only/empty macro definition. Fixes #3460 * Added some passing procedure definition tests * Added two failing procedure tests to illustrate bug #3460 * Allow \end to end a whitespace only/empty procedure/function/widget definition. Fixes #3640 * Fixed wording of comment
This commit is contained in:
parent
100eaeff30
commit
fb85e91f82
@ -49,11 +49,11 @@ exports.parse = function() {
|
|||||||
if(this.match[3]) {
|
if(this.match[3]) {
|
||||||
params = $tw.utils.parseParameterDefinition(this.match[4]);
|
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;
|
var reEnd;
|
||||||
if(this.match[5]) {
|
if(this.match[5]) {
|
||||||
// If so, the end of the body is marked with \end
|
// 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");
|
reEnd = new RegExp("((:?^|\\r?\\n)[^\\S\\n\\r]*\\\\end[^\\S\\n\\r]*(?:" + $tw.utils.escapeRegExp(this.match[2]) + ")?(?:$|\\r?\\n))","mg");
|
||||||
} else {
|
} else {
|
||||||
// Otherwise, the end of the definition is marked by the end of the line
|
// Otherwise, the end of the definition is marked by the end of the line
|
||||||
reEnd = /($|\r?\n)/mg;
|
reEnd = /($|\r?\n)/mg;
|
||||||
|
@ -54,11 +54,11 @@ exports.parse = function() {
|
|||||||
paramMatch = reParam.exec(paramString);
|
paramMatch = reParam.exec(paramString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Is this a multiline definition?
|
// Is the remainder of the \define line blank after the parameter close paren?
|
||||||
var reEnd;
|
var reEnd;
|
||||||
if(this.match[3]) {
|
if(this.match[3]) {
|
||||||
// If so, the end of the body is marked with \end
|
// 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");
|
reEnd = new RegExp("((?:^|\\r?\\n)[^\\S\\n\\r]*\\\\end[^\\S\\n\\r]*(?:" + $tw.utils.escapeRegExp(this.match[1]) + ")?(?:$|\\r?\\n))","mg");
|
||||||
} else {
|
} else {
|
||||||
// Otherwise, the end of the definition is marked by the end of the line
|
// Otherwise, the end of the definition is marked by the end of the line
|
||||||
reEnd = /($|\r?\n)/mg;
|
reEnd = /($|\r?\n)/mg;
|
||||||
|
16
editions/test/tiddlers/tests/data/macros/EndInBody.tid
Normal file
16
editions/test/tiddlers/tests/data/macros/EndInBody.tid
Normal file
@ -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
editions/test/tiddlers/tests/data/macros/IndentedEnd.tid
Normal file
16
editions/test/tiddlers/tests/data/macros/IndentedEnd.tid
Normal file
@ -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>
|
@ -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>
|
@ -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>
|
@ -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
editions/test/tiddlers/tests/data/procedures/EndInBody.tid
Normal file
16
editions/test/tiddlers/tests/data/procedures/EndInBody.tid
Normal file
@ -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
editions/test/tiddlers/tests/data/procedures/IndentedEnd.tid
Normal file
16
editions/test/tiddlers/tests/data/procedures/IndentedEnd.tid
Normal file
@ -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>
|
@ -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>
|
@ -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>
|
@ -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…
Reference in New Issue
Block a user