Feat: allow new pragmas to be indented (#7624)

This commit is contained in:
Saq Imtiaz 2023-07-21 14:40:42 +02:00 committed by GitHub
parent 0fd6b986a0
commit 61a08cbd7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 125 additions and 4 deletions

View File

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

View File

@ -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;
};
/*

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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