New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conditional Shortcut Syntax #7710
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Is the |
Ignore the last question. I found it in the code and in the parse- and widget-tree |
I think I found a bug. I think the following example should result in Especially since
|
Here's one test I wrote for the it("if widget should short-circuit child rendering, so only one child ever gets rendered", function() {
var wiki = new $tw.Wiki();
// Construct four widget nodes
var text = "<$if filter='[[1]compare:number:eq[2]]'><$then>yes<$log message='then' /></$then><$elseif filter='[[3]compare:number:eq[4]]'>maybe<$log message='elseif1' /></$elseif><$elseif filter='[[5]compare:number:eq[6]]'>another<$log message='elseif2' /></$elseif><$else>no<$log message='else' /></$else></$if>";
var falsey = text;
var elseif2 = falsey.replace("eq[6]]","eq[5]]");
var elseif1 = elseif2.replace("eq[4]]","eq[3]]"); // Both second and first elseifs are true, first one wins
var truthy = elseif1.replace("eq[2]]","eq[1]]"); // The "main" if condition and both elseifs are true, "main" condition wins
var widgetNodeF = createWidgetNode(parseText(falsey,wiki),wiki);
var widgetNodeT = createWidgetNode(parseText(truthy,wiki),wiki);
var widgetNodeE1 = createWidgetNode(parseText(elseif1,wiki),wiki);
var widgetNodeE2 = createWidgetNode(parseText(elseif2,wiki),wiki);
// Render four widget nodes to the DOM
console.log('Rendering F');
var wrapperF = renderWidgetNode(widgetNodeF);
console.log('Rendering T');
var wrapperT = renderWidgetNode(widgetNodeT);
console.log('Rendering E1');
var wrapperE1 = renderWidgetNode(widgetNodeE1);
console.log('Rendering E2');
var wrapperE2 = renderWidgetNode(widgetNodeE2);
// Test the rendering of all four
expect(wrapperF.innerHTML).toBe("<p>no</p>");
expect(wrapperT.innerHTML).toBe("<p>yes</p>");
expect(wrapperE1.innerHTML).toBe("<p>maybe</p>");
expect(wrapperE2.innerHTML).toBe("<p>another</p>");
}); Expected output if all goes well is "Rendering F" followed by exactly one Anyway, I hope this is somewhat helpful in building a similar test for the list widgets built with the |
The parse tree can be checked directly. See eg: test-wikitext-parser.js |
Thanks, but what I'm trying to test is that certain parts of the parse tree do not get turned into widgets. Checking the parse tree won't help with that. |
It's also possible to check the parse-tree, which only contains the widgets, which will be active |
See discussion here - https://talk.tiddlywiki.org/t/proposed-if-widget/7882/64
2411ebc changes the syntax from |
I am not sure if this question is relevant, but the underlaying $list widget shows the below error when an empty line is inserted:
shows
but without extra empty line, it works (see below)
It seems adding empty line between $list and $list-template, and $list-empty shows the above error. |
@Jermolene ... Did you have a look at this one: #7710 (comment) -- I think it's a bug |
Hi @pmario that is a case that I wasn't sure how to handle: what to do if the |
Thanks @rmunn that is helpful.
I'm not sure that it is enough for our purposes here, but the new(ish) wiki-based test framework supports actions that are performed after the initial rendering to force a refresh. TiddlyWiki5/editions/test/tiddlers/tests/data/transclude/Variable-Refreshing.tid Lines 1 to 27 in 2c406da
|
Thanks @kookma this is an interesting one. At the moment, the list widget only looks at its immediate children when searching for the One possible fix would be to do a recursive search for the The trouble with that approach is that it might have unexpected consequences. For example, here the inner list widget will always evaluate to an empty list, and thus its content will never be rendered. However, if we supported recursive searching then the outer list widget would still find the
Perhaps the best we can do is to make HTML elements explicitly transparent when searching for We'd still be left with the problem that a stray |
Unless there's a reason not to, I'd suggest handling that case in line with the existing behavior: "When no template is specified, the body of the ListWidget serves as the item template." If there's a As for the block-mode parsing issue that @kookma found,
I'd suggest being slightly more limited, and just do a search for either children, or grandchildren where the immediate parent is a |
I found it hard to type Can it be two same char just like And if this will be alias for some widgets, I want to add effect widgets described in https://talk.tiddlywiki.org/t/config-tiddler-title-for-default-light-dark-palette-e-g-config-palette-default-dark/8071/22?u=linonetwo |
Hi @linonetwo
Double parenthesis is currently unused and so might be a promising choice:
|
I think standard double parenthesis are way to common in prose text. Especially if someone explains an algorithm with "pseudo syntax" and IMO it's very close to LISP which may cause confusion. |
This is not common in daily writing, if encounter this, maybe can use """ to wrap the.
Also can wrap them with ``` code block I think this syntax won't work in a block. |
@Jermolene Have you considered One drawback is these Already discussed in #7680 |
Really? I would be interested to understand why that might be. I would not expect to encounter double parenthesis in general prose, but only in technical contextx.
Hmmm those needs are readily catered for with the codeblock syntax, or the triple double quote syntax. I don't think that a rare use case like that should drive the choice of syntax that would affect far more users.
There are two problems: backslash at the start of a line indicates a pragma, and pragmas have the restriction that they must precede ordinary parsed text. The other issue is that there is no lineline syntax for pragmas. |
I have sometimes seen double parentheses used as a way of making a note to self in some text to come back and fix later. E.g,, in a novel in progress, the author might write:
Then later when he's done writing the scene, he'd go online and do a bit of research and decide which models are plausible for a criminal to be able to get hold of easily in ((name of town)). I know a couple people (online and in real life) who have written books, and some of them have mentioned that they use this approach a lot so they don't have to interrupt the flow of words to go and do fiddly research; they leave the research until a time when inspiration isn't hitting. So I would agree with avoiding double parentheses for anything. It's used fairly often as far as I've seen, precisely because it doesn't occur in normal text but it's extremely easy to type, and easy to search for later when you're looking for your notes-to-self. |
Is it hard to relax this limitation? Or use |
I would actually take the fact that double parenthesis is used as ad-hoc markup as validation: it demonstrates that it is a construction that is rarely used in prose, and is not visually distracting.
Of course, in TiddlyWiki we would suggest using
It is a limitation in the sense that it needs to be consistent with the new syntax. A syntax that closely resembles the pragma syntax but has subtly different rules seems like it would be confusing. |
I've cherry picked the list widget enhancements into a new PR in #7784 |
What's interesting here is the styling via
But, anyway...
Because the syntax can be viewed as subsuming Not sure if either is a great name, though. 😕 |
I can't test your example now, but I would not have expected it to work.
I've ended up going for "shortcut syntax", meaning it's a shortcut for the underlying widget syntax. |
IMO, that's not a good reason for choosing the name. Fresh eyes don't know the background or (perhaps) understand the reasoning. Fresh eyes certainly don't need to know that baggage to use it. If, as you mentioned, there are more shortcuts to come, you (we) need a better name, IMO. |
Hi @CodaCodr the requirement here isn't to come up with a word or phrase that will be self explanatory. We just need to name the concept, which means a label that is unique/distinctive within the context. In this case, we have an opportunity to choose a name that leads the user towards a deeper understanding of what is going on. |
Try this. IMO your second example shows a CSS link so the formatting is overwritte.
Have a closer look to the parse-tree preview. You'll see it's similar to the first example |
I strongly urge you to reconsider (the effect on fresh eyes). This is the kind of thing that can foster cognitive overload in a newcomer -- "will I ever understand this stuff?" That's not to say that the background/underlying "truth" shouldn't be made available and attention drawn to it, but elsewhere, perhaps behind "Learn more" or similar. But to place that in its name? I don't need to be reminded (nor, least of all, do you) but a newcomer? And does it scale? 50 new pence. Windows NT. I'm harping on because this stuff matters. :-| |
This PR adds a new shortcut syntax for expressing if/then/else logic. It takes a different approach to #7691. Instead of adding a new widget, it adds a new parser rule for a shortcut syntax that expands to a series of nested
<$list>
widgets. For example:Behind the scenes, the
<$list>
widget is extended with two new features:<$list-empty>
widget within the list widget, instead of using the attribute, and similarly to use a<$list-template>
widget to define the templateThere are also some changes to the core parser to support the new syntax.
Progress
<%...%>
syntax (ie the term we would also use for other constructions like switch/case that use the same syntax)