1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2026-01-22 10:54:46 +00:00

Compare commits

...

3 Commits

Author SHA1 Message Date
jeremy@jermolene.com
f823885d67 Docs update 2022-10-24 12:13:07 +01:00
jeremy@jermolene.com
f23ae21260 Switched to \end <name> instead of all those repeated backslashes
Thanks @kookma. See https://github.com/Jermolene/TiddlyWiki5/pull/7004#issuecomment-1286429236
2022-10-22 09:00:59 +01:00
jeremy@jermolene.com
b3982efcd6 First commit 2022-10-20 18:07:36 +01:00
3 changed files with 55 additions and 3 deletions

View File

@@ -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 = /(\r?\n\\end[^\S\n\r]*(?:$|\r?\n))/mg;
reEnd = new RegExp("(\\r?\\n\\\\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;

View File

@@ -0,0 +1,36 @@
title: Macros/NestedMacros
description: Nested Macros
type: text/vnd.tiddlywiki-multiple
tags: [[$:/tags/wiki-test-spec]]
title: Output
\whitespace trim
\define outer()
\whitespace trim
\define middle()
\whitespace trim
\define inner()
\whitespace trim
Jaguar
\end inner
<<inner>>
\end middle
<<middle>>
\end outer
<<outer>>
+
title: ExpectedResult
<p>Jaguar</p>

View File

@@ -1,13 +1,15 @@
caption: Macro Definitions
created: 20150220181617000
modified: 20180820165115455
modified: 20221022135909352
tags: WikiText
title: Macro Definitions in WikiText
type: text/vnd.tiddlywiki
A [[macro|Macros]] is defined using a `\define` [[pragma|Pragma]]. Like any pragma, this can only appear at the start of a tiddler.
The first line of the definition specifies the macro name and any parameters. Each parameter has a name and, optionally, a default value that is used if no value is supplied on a particular call to the macro. The lines that follow contain the text of the macro text (i.e. the snippet represented by the macro name), until `\end` appears on a line by itself:
The first line of the definition specifies the macro name and any parameters. Each parameter has a name and, optionally, a default value that is used if no value is supplied on a particular call to the macro.
The lines that follow contain the text of the macro text (i.e. the snippet represented by the macro name), until `\end` appears on a line by itself:
<$codeblock code={{$:/editions/tw5.com/macro-examples/say-hi}}/>
@@ -17,6 +19,20 @@ Alternatively, the entire definition can be presented on a single line without a
\define sayhi(name:"Bugs Bunny") Hi, I'm $name$.
```
Macro definitions can be nested by specifying the name of the macro in the `\end` marker. For example:
<<wikitext-example-without-html src:"""\define special-button(caption:"Click me")
\define actions()
<$action-sendmessage $message="tm-notify" $param="HelloThere"/>
\end actions
<$button actions=<<actions>>>
$caption$
</$button>
\end special-button
<<special-button>>
""">>
A more formal [[presentation|Macro Definition Syntax]] of this syntax is also available.
!! Accessing variables and parameters