1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-07-06 20:14:22 +00:00

Add support for named end markers for procedures, functions and widgets

This commit is contained in:
jeremy@jermolene.com 2022-11-23 16:30:20 +00:00
parent b78f8769a9
commit 52592a4dbc
5 changed files with 44 additions and 4 deletions

View File

@ -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;

View 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>

View File

@ -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:
```

View File

@ -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>>
""">>

View File

@ -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:
```