1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2026-05-29 16:52:18 +00:00

Change from {%if%} to <%if%>

See discussion here - https://talk.tiddlywiki.org/t/proposed-if-widget/7882/64
This commit is contained in:
Jeremy Ruston
2023-09-06 15:45:51 +01:00
parent f0b4f3b2ee
commit 2411ebc1ca
9 changed files with 33 additions and 33 deletions
@@ -6,7 +6,7 @@ module-type: wikirule
Conditional shortcut syntax
```
This is a {% if [{something}] %}Elephant{% elseif [{else}] %}Pelican{% else %}Crocodile{% endif %}
This is a <% if [{something}] %>Elephant<% elseif [{else}] %>Pelican<% else %>Crocodile<% endif %>
```
\*/
@@ -22,19 +22,19 @@ exports.types = {inline: true, block: false};
exports.init = function(parser) {
this.parser = parser;
// Regexp to match
this.matchRegExp = /\{\%\s*if\s+/mg;
this.terminateIfRegExp = /\%\}/mg;
this.matchRegExp = /\<\%\s*if\s+/mg;
this.terminateIfRegExp = /\%\>/mg;
};
exports.findNextMatch = function(startPos) {
// Look for the next {% if shortcut
// Look for the next <% if shortcut
this.matchRegExp.lastIndex = startPos;
this.match = this.matchRegExp.exec(this.parser.source);
// If not found then return no match
if(!this.match) {
return undefined;
}
// Check for the next %}
// Check for the next %>
this.terminateIfRegExp.lastIndex = this.match.index;
this.terminateIfMatch = this.terminateIfRegExp.exec(this.parser.source);
// If not found then return no match
@@ -51,7 +51,7 @@ Parse the most recent match
exports.parse = function() {
// Get the filter condition
var filterCondition = this.parser.source.substring(this.match.index + this.match[0].length,this.terminateIfMatch.index);
// Advance the parser position to past the %}
// Advance the parser position to past the %>
this.parser.pos = this.terminateIfMatch.index + this.terminateIfMatch[0].length;
return this.parseIfBlock(filterCondition);
};
@@ -77,7 +77,7 @@ exports.parseIfBlock = function(filterCondition) {
$tw.utils.addAttributeToParseTreeNode(listWidget,"variable","condition");
$tw.utils.addAttributeToParseTreeNode(listWidget,"limit","1");
// Parse the body looking for else or endif
var reEndString = "\\{\\%\\s*(endif)\\s*\\%\\}|\\{\\%\\s*(else)\\s*\\%\\}|\\{\\%\\s*(elseif)\\s+([\\s\\S]+?)\\%\\}",
var reEndString = "\\<\\%\\s*(endif)\\s*\\%\\>|\\<\\%\\s*(else)\\s*\\%\\>|\\<\\%\\s*(elseif)\\s+([\\s\\S]+?)\\%\\>",
ex;
if(this.is.block) {
ex = this.parser.parseBlocksTerminatedExtended(reEndString);
@@ -93,7 +93,7 @@ exports.parseIfBlock = function(filterCondition) {
// Nothing to do if we just found an endif
} else if(ex.match[2] === "else") {
// If we found an else then we need to parse the body looking for the endif
var reEndString = "\\{\\%\\s*(endif)\\s*\\%\\}",
var reEndString = "\\<\\%\\s*(endif)\\s*\\%\\>",
ex;
if(this.is.block) {
ex = this.parser.parseBlocksTerminatedExtended(reEndString);
@@ -5,7 +5,7 @@ tags: [[$:/tags/wiki-test-spec]]
title: Text
This is a {% if [<something>match[one]] %}Elephant{% endif %}, I think.
This is a <% if [<something>match[one]] %>Elephant<% endif %>, I think.
+
title: Output
@@ -5,7 +5,7 @@ tags: [[$:/tags/wiki-test-spec]]
title: Text
This is a {% if [<something>match[one]] %}Elephant{% else %}Crocodile{% endif %}, I think.
This is a <% if [<something>match[one]] %>Elephant<% else %>Crocodile<% endif %>, I think.
+
title: Output
@@ -5,7 +5,7 @@ tags: [[$:/tags/wiki-test-spec]]
title: Text
This is a {% if [<something>match[one]] %}Elephant{% elseif [<something>match[two]] %}Antelope{% else %}Crocodile{% endif %}, I think.
This is a <% if [<something>match[one]] %>Elephant<% elseif [<something>match[two]] %>Antelope<% else %>Crocodile<% endif %>, I think.
+
title: Output
@@ -5,7 +5,7 @@ tags: [[$:/tags/wiki-test-spec]]
title: Text
This is a {% if [<something>match[one]] %}Elephant
This is a <% if [<something>match[one]] %>Elephant
+
title: Output
@@ -5,7 +5,7 @@ tags: [[$:/tags/wiki-test-spec]]
title: Output
This is a {% if 1 2 3 4 5 6 %}Elephant{% endif %}, I think.
This is a <% if 1 2 3 4 5 6 %>Elephant<% endif %>, I think.
+
title: ExpectedResult
@@ -6,15 +6,15 @@ tags: [[$:/tags/wiki-test-spec]]
title: Output
\procedure test(animal)
{% if [<animal>match[Elephant]] %}
<% if [<animal>match[Elephant]] %>
It is an elephant
{% else %}
{% if [<animal>match[Giraffe]] %}
<% else %>
<% if [<animal>match[Giraffe]] %>
It is a giraffe
{% else %}
<% else %>
It is completely unknown
{% endif %}
{% endif %}
<% endif %>
<% endif %>
\end
<<test "Giraffe">>
@@ -7,20 +7,20 @@ title: Text
\whitespace trim
This is a&#32;
{% if [<something>match[one]] %}
{% if [<another>match[one]] %}
<% if [<something>match[one]] %>
<% if [<another>match[one]] %>
Indian
{% elseif [<another>match[two]] %}
<% elseif [<another>match[two]] %>
African
{% else %}
<% else %>
Unknown
{% endif %}
<% endif %>
&#32;Elephant
{% elseif [<something>match[two]] %}
<% elseif [<something>match[two]] %>
Antelope
{% else %}
<% else %>
Crocodile
{% endif %}
<% endif %>
, I think.
+
title: Output
@@ -10,15 +10,15 @@ For example:
<$macrocall $name='wikitext-example-without-html'
src='\procedure test(animal)
{% if [<animal>match[Elephant]] %}
<% if [<animal>match[Elephant]] %>
It is an elephant
{% else %}
{% if [<animal>match[Giraffe]] %}
<% else %>
<% if [<animal>match[Giraffe]] %>
It is a giraffe
{% else %}
<% else %>
It is completely unknown
{% endif %}
{% endif %}
<% endif %>
<% endif %>
\end
<<test "Giraffe">>