mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-23 10:07:19 +00:00
Feat: allow new pragmas to be indented (#7624)
This commit is contained in:
parent
0fd6b986a0
commit
61a08cbd7b
@ -35,7 +35,7 @@ Instantiate parse rule
|
||||
exports.init = function(parser) {
|
||||
this.parser = parser;
|
||||
// Regexp to match
|
||||
this.matchRegExp = /^\\(function|procedure|widget)\s+([^(\s]+)\((\s*([^)]*))?\)(\s*\r?\n)?/mg;
|
||||
this.matchRegExp = /\\(function|procedure|widget)\s+([^(\s]+)\((\s*([^)]*))?\)(\s*\r?\n)?/mg;
|
||||
};
|
||||
|
||||
/*
|
||||
@ -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 = new RegExp("(\\r?\\n\\\\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 {
|
||||
// Otherwise, the end of the definition is marked by the end of the line
|
||||
reEnd = /($|\r?\n)/mg;
|
||||
|
@ -26,7 +26,7 @@ Instantiate parse rule
|
||||
exports.init = function(parser) {
|
||||
this.parser = parser;
|
||||
// Regexp to match
|
||||
this.matchRegExp = /^\\parameters\s*\(([^)]*)\)(\s*\r?\n)?/mg;
|
||||
this.matchRegExp = /\\parameters\s*\(([^)]*)\)(\s*\r?\n)?/mg;
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -0,0 +1,24 @@
|
||||
title: Functions/Function/Indented
|
||||
description: Indented function definition
|
||||
type: text/vnd.tiddlywiki-multiple
|
||||
tags: [[$:/tags/wiki-test-spec]]
|
||||
|
||||
title: Output
|
||||
|
||||
\whitespace trim
|
||||
\function .dividebysomething(factor:0.5)
|
||||
[divide<factor>]
|
||||
\end
|
||||
|
||||
\function multiplebysomething(first:ignored,factor:2)
|
||||
[multiply<factor>multiply[2].dividebysomething[0.25]]
|
||||
\end
|
||||
|
||||
<$text text={{{ [[4]function[multiplebysomething]] }}}/>
|
||||
|
|
||||
<$text text={{{ [[6]function[multiplebysomething],[ignored],[4]] }}}/>
|
||||
|
||||
+
|
||||
title: ExpectedResult
|
||||
|
||||
<p>64|192</p>
|
@ -0,0 +1,20 @@
|
||||
title: Procedures/Nested/Indented
|
||||
description: Nested Procedures that are indented
|
||||
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>
|
@ -0,0 +1,22 @@
|
||||
title: Procedures/TrailingNewlines
|
||||
description: Trailing newlines in procedures must not be dropped
|
||||
type: text/vnd.tiddlywiki-multiple
|
||||
tags: [[$:/tags/wiki-test-spec]]
|
||||
|
||||
title: Output
|
||||
|
||||
\procedure inner()
|
||||
Paragraph 1
|
||||
|
||||
Paragraph 2
|
||||
\end
|
||||
\procedure outer()
|
||||
<$macrocall $name=inner />
|
||||
|
||||
\end
|
||||
<<outer>>
|
||||
|
||||
+
|
||||
title: ExpectedResult
|
||||
|
||||
<p>Paragraph 1</p><p>Paragraph 2</p>
|
@ -0,0 +1,33 @@
|
||||
title: Transclude/CustomWidget/Simple/Indented
|
||||
description: Custom widget definition indented
|
||||
type: text/vnd.tiddlywiki-multiple
|
||||
tags: [[$:/tags/wiki-test-spec]]
|
||||
|
||||
title: Output
|
||||
|
||||
\whitespace trim
|
||||
<$transclude $tiddler='TiddlerOne' one='Ferret'>
|
||||
</$transclude>
|
||||
+
|
||||
title: TiddlerOne
|
||||
|
||||
\whitespace trim
|
||||
<!-- Define the <$my.widget> widget by defining a transcludable variable with that name -->
|
||||
\widget $my.widget(one:'Jaguar')
|
||||
\whitespace trim
|
||||
<$text text=<<one>>/>
|
||||
<$slot $name="ts-raw">
|
||||
Whale
|
||||
</$slot>
|
||||
\end
|
||||
<$my.widget one="Dingo">
|
||||
Crocodile
|
||||
</$my.widget>
|
||||
<$my.widget one="BumbleBee">
|
||||
Squirrel
|
||||
</$my.widget>
|
||||
<$my.widget/>
|
||||
+
|
||||
title: ExpectedResult
|
||||
|
||||
<p>DingoCrocodileBumbleBeeSquirrelJaguarWhale</p>
|
@ -0,0 +1,20 @@
|
||||
title: Transclude/Parameterised/Shortcut/ParametersIndented
|
||||
description: Simple parameterised transclusion using the parameters pragma (indented)
|
||||
type: text/vnd.tiddlywiki-multiple
|
||||
tags: [[$:/tags/wiki-test-spec]]
|
||||
|
||||
title: Output
|
||||
|
||||
\whitespace trim
|
||||
<$transclude $tiddler='TiddlerOne' one='Ferret'/>
|
||||
<$transclude $tiddler='TiddlerOne'/>
|
||||
+
|
||||
title: TiddlerOne
|
||||
|
||||
\whitespace trim
|
||||
\parameters(one:'Jaguar')
|
||||
<$text text=<<one>>/>
|
||||
+
|
||||
title: ExpectedResult
|
||||
|
||||
<p>FerretJaguar</p>
|
@ -1,5 +1,5 @@
|
||||
created: 20220917112416666
|
||||
modified: 20230419103154329
|
||||
modified: 20230721064409436
|
||||
tags: Concepts [[WikiText Parser Modes]]
|
||||
title: Pragmas
|
||||
type: text/vnd.tiddlywiki
|
||||
@ -8,6 +8,8 @@ A <<.def pragma>> is a special component of WikiText that provides control over
|
||||
|
||||
Pragmas occupy lines that start with `\`. They can only appear at the start of the text of a tiddler, but blank lines and comments are allowed between them. If a pragma appears in the main body of the text, it is treated as if it was ordinary text.
|
||||
|
||||
<<.from-version "5.2.6">> Pragmas can have preceding optional whitespace characters.
|
||||
|
||||
The following pragmas are available:
|
||||
|
||||
<<list-links "[tag[Pragmas]]">>
|
||||
|
Loading…
Reference in New Issue
Block a user