mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-02-22 22:10:03 +00:00
Add support for named end markers for procedures, functions and widgets
This commit is contained in:
parent
b78f8769a9
commit
52592a4dbc
@ -53,7 +53,7 @@ exports.parse = function() {
|
||||
var reEnd;
|
||||
if(this.match[5]) {
|
||||
// If so, the end of the body is marked with \end
|
||||
reEnd = /(\r?\n\\end[^\S\n\r]*(?:$|\r?\n))/mg;
|
||||
reEnd = new RegExp("(\\r?\\n\\\\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;
|
||||
|
20
editions/test/tiddlers/tests/data/procedures/Nested.tid
Normal file
20
editions/test/tiddlers/tests/data/procedures/Nested.tid
Normal file
@ -0,0 +1,20 @@
|
||||
title: Procedures/Nested
|
||||
description: Nested Procedures
|
||||
type: text/vnd.tiddlywiki-multiple
|
||||
tags: [[$:/tags/wiki-test-spec]]
|
||||
|
||||
title: Output
|
||||
|
||||
\whitespace trim
|
||||
\procedure alpha(x)
|
||||
\procedure beta(y)
|
||||
<$text text=<<y>>/>
|
||||
\end beta
|
||||
<$transclude $variable="beta" y={{{ [<x>addprefix<x>] }}}/>
|
||||
\end alpha
|
||||
|
||||
<<alpha "Elephant">>
|
||||
+
|
||||
title: ExpectedResult
|
||||
|
||||
<p>ElephantElephant</p>
|
@ -11,9 +11,11 @@ The usual form allows custom functions to span multiple lines:
|
||||
```
|
||||
\function <function-name>(<param-name>[:<param-default-value>],<param-name>[:<param-default-value>]...)
|
||||
<multiple-line-definition-text>
|
||||
\end
|
||||
\end [<function-name>]
|
||||
```
|
||||
|
||||
Note that the `\end` marker can optionally specify the name of the function to which it relates, enabling function definitions to be nested inside procedures, macros or widget definitions.
|
||||
|
||||
There is also a single line form for shorter functions:
|
||||
|
||||
```
|
||||
|
@ -11,9 +11,11 @@ The usual form allows procedures to span multiple lines:
|
||||
```
|
||||
\procedure <procedure-name>(<param-name>[:<param-default-value>],<param-name>[:<param-default-value>]...)
|
||||
<multiple-line-definition-text>
|
||||
\end
|
||||
\end [<procedure-name>]
|
||||
```
|
||||
|
||||
Note that the `\end` marker can optionally specify the name of the procedure to which it relates which allows procedure definitions to be nested.
|
||||
|
||||
There is also a single line form for shorter procedures:
|
||||
|
||||
```
|
||||
@ -37,3 +39,17 @@ Alternatively, the entire definition can be presented on a single line without a
|
||||
```
|
||||
\procedure sayhi(name:"Bugs Bunny") Hi, I'm $name$.
|
||||
```
|
||||
|
||||
Procedure definitions can be nested by specifying the name of the procedure in the `\end` marker. For example:
|
||||
|
||||
<<wikitext-example-without-html src:"""\procedure special-button(caption:"Click me")
|
||||
\procedure actions()
|
||||
<$action-sendmessage $message="tm-notify" $param="HelloThere"/>
|
||||
\end actions
|
||||
<$button actions=<<actions>>>
|
||||
$caption$
|
||||
</$button>
|
||||
\end special-button
|
||||
|
||||
<<special-button>>
|
||||
""">>
|
@ -11,9 +11,11 @@ The usual form allows custom widgets to span multiple lines:
|
||||
```
|
||||
\widget <widget-name>(<param-name>[:<param-default-value>],<param-name>[:<param-default-value>]...)
|
||||
<multiple-line-definition-text>
|
||||
\end
|
||||
\end [<widget-name>]
|
||||
```
|
||||
|
||||
Note that the `\end` marker can optionally specify the name of the widget to which it relates which allows widget definitions to be nested.
|
||||
|
||||
There is also a single line form for shorter widgets:
|
||||
|
||||
```
|
||||
|
Loading…
x
Reference in New Issue
Block a user