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
Add support for string literal attributes with textual substitution #6663
Comments
|
New in v5.2.2. See https://tiddlywiki.com/#HTML%20in%20WikiText, scroll down to the heading "Style Attributes". |
Oh, did you mean |
Thanks @CodaCodr it was a typo 🙇 |
I just want to add the ability to include field content, or from a text reference, into "textural substitutions" is also important. |
One question popped up, while reading the spec. How can we dynamically create the substitution string.
|
For example:
I'm not sure what you mean. |
that would be the way, within the filter. I could not see it illustrated. Thanks |
I think a simple example would be as follows, where
|
Hi @pmario that's a very interesting example – you've got two layers of substitution nested inside each other. I'm not sure that we'd want to recursively apply the substitutions because of the ease of setting up an infinite loop. |
A passing depending on how you handle this would the use of text references be possible? All one needs to test is there is a leading !!, internal or trailing"!!" It could be included in the syntax, the question is can it be processed? For example;
Rather than needing the filter as follows.
This above example |
Using the presence of EDIT 1st May 2022: added the critical word "not" above It would be more consistent to recognise the existing
The problem is that the transclusion would be handled by the textual substitution mechanism, and the result would be passed to the emptyMessage attribute, and hence get wikified when rendered. That would mean that we'd end up wikifying the result of the text reference, which would not be intended. |
Jeremy, Regardless of the validity of the approach I suggested to permit fields to be included as references, inside these concatinations, is there a way to address this need "using field values" without forcing the use of filters such as Or is there already a way I have missed? |
Hi @AnthonyMuscio the proposal at the moment doesn't include provision for textual substitution of text references. The rationale is to keep things simple with a single new mechanism for substituting filter results, only keeping the variable substitution syntax for backwards compatibility. As it stands, the syntax for the examples you give would be There is a way to address the need that you raise, which would be to introduce a third substitution syntax (perhaps So, the question is whether it is worth having a special syntax for textual substitution of text references, and the considerations are the complexity that it brings. |
This is sufficient and quite powerful as it stands where we can effectively use "any filter" to generate a "string" that will be substituted, and through that even a "text reference" As a result I agree lets not complicate it but instead document it as fields and text references can be substituted through the filter From my naïve perspective can we say effectively that
|
Not anywhere, only inside string literal attributes.
Please play closer attention to the syntax. Filter substitutions use curly braces: |
A question; in this manufactured case it only works if you use the wikify widget
If I follow the new substitution's correctly will this or something similar work?
If so that would be wonderful. |
@AnthonyMuscio no, that will not work. Firstly your example does not use string literal attributes. Secondly, you are passing wikitext where a filter is expected. As Jeremy mentioned earlier in this thread, there is no intention to support automatic wikification due to performance considerations. Wikifying some wikitext to return a string will always be slower than generating it directly via a filter, where possible. |
I think IMO It should be possible to even tell the macro, that it should treat the variable as a tiddlywiki list.
the output may be: (I'm not sure if the macro should iterate over an array )
If brackets are a problem the filter can look like this:
would create
and so on. ... No code written yet. Just some thoughts. |
Thanks @pmario
Why? The idea is to make it easy to insert expressions like The overall goal here is to make a better alternative to macros for textual substitution tasks, hence the desire to make it as powerful as is appropriate.
I don't see how the reasoning in #6781 applies here. The point there is that there is no workaround available to give the ability to return multiple results from the "filter" prefix. That doesn't apply here. But it still may be reasonable to accept the entire list that the
Here we're trying to improve on that syntax; it's indirect and verbose.
I don't think that looks very good. Generally if we've got a choice between two apparently mutually exclusive choices, the worst option is to support both. That means that users have to grapple with the complexity of both. Good system design is about keeping things conceptually simple for users. I think a macro is not the best approach for what you're trying to do because we can't use computed parameters within a filter. The approach I was thinking was that the string literal syntax would be a shortcut for a filter operator alternative. For example:
would be a shortcut for:
(Important to note that the shortcut syntax would be able to cope with double square brackets and other character combinations that would be illegal in the filter operator form). In the filter operator form, it might be nice to also support
Mind you, there would be nothing to stop us supporting parameters with the shortcut syntax too:
|
I would very much like to see this implemented. I do something similar with my custom |
I understand this is to be part of TW 5.3.0?
I understand the back tick format is also used for inline code highlighting.
|
No, this enhancement is not planned for v5.3.0. This ticket is part of showing the roadmap for how we will eventually be able to deprecate macros.
No, the context is different. Here the backticks are used as special quotation symbols for attributes, not as freestanding syntax like code sections. |
I wanted to solve exactly that problem with
ProposalAdd an
ExampleA very common usecase is the dynamic creation of URLs, where our users always have problems and the naive implementation creates several technical problems Code with Function Definition
Eg: create a dynamic link to the HelloThere tiddler at tiddlywiki.com
Rendered as: .But it should be a link. We need to create external links using the A HTML tag, which is complicated and error-prone, because the HTML code needs additional parameters like "class", "rel" and "target"
|
Edit: I did add the following intro text to the first post I wanted to solve exactly that problem with
|
Hi @pmario as things stand, the link widget is only used for tiddler links, and is not involved in rendering external links, even if they were made using the same double square bracket syntax as pretty links. This is useful; it means, for example, that it is easy to scan a parse tree looking for tiddler links. The relationship between tiddler links and external links is that tiddler links are layered over the top of the implementation of external links. Adding the facility to make external links would be smooshing together functionality that is really quite different, making a frankenstein widget with two only tenuously related areas of functionality. I think the red flag here is that it is an attempt to optimise for brevity at the widget layer. I think that that is almost always a bad idea because it inevitably leads to more complex semantics for the widgets that are the primitives in our system. The more complex that those semantics become the harder it is to reason about how the primitives combine together. In this case, it sounds like your use case could be served with a custom |
That's right. I'll test that |
Just to be sure we need to be able to do stuff a shown in an even simpler way. https://talk.tiddlywiki.org/t/how-text-substitution-can-look-like-with-v5-3-0-prerelease/6607
slightly related: #6826 |
From @pmario With 5.3.0 pending, and this feature "Add support for string literal attributes with textual substitution an example may be;
Although perhaps
I understand the motivation for the first value, but it seems an unnecessary handicap.
|
@Jermolene A couple of questions as I work on an implementation:
|
Hi @saqimtiaz I think A separate point, should we perhaps allow escape sequences within substituted strings?
Another point, can we allow line breaks within substituted strings? It would be quite useful in some situations.
Also, I wonder if we might support arbitrary numbers of backticks to demarcate the string. So it would be possible to do:
|
Good idea, that makes perfect sense.
Are you thinking in terms of allowing escape sequences to pass through without processing? |
I was wondering about additionally substituting escape sequences with the character string they represent, in the same way that JavaScript allows escape sequences in template literals. |
Just as a reference.
I think having double backtick to cover "single backticks" is a nice to have. Markdown does the same thing, which can be tested here in the editor too. I did have a look at: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#description and did search for "secape". ... It said:
Not sure, if the dollar sign is important for us.
Later in the text it references "normal" string-escape sequences: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#escape_sequences So |
There is a draft implementation at #7526, I will continue work on it after the weekend. |
Yes. The main way that people might bump into it is if they are writing text that includes backslash characters. In practice, those are rare in English, but when they do occur the escaping is going to be nightmarish. Something to consider is the impact on regular expressions – if we support escaping then users have to write this:
instead of
|
Yes, rare in English prose text, but not if you use |
Do you mean that we shouldn't perform escaping of substitution templates? In other words, that we should leave backslash sequences alone. |
TLDR; I do not have a good idea, but I'll think about it. Reasoning With unix systems and forward slashes paths are easy. But windows is a different beast here. eg:
The fun part start with network mounts that use UNC paths eg: or
WSL Windows Subsystem for Linux is a new feature in Windows, but mounting drives can be tricky. There are 2 doc paragraphs, which show how to mount a windows drive in a WSL unix instance
It says:
So now imagine I want to dynamically create the path in the |
Hi @pmario Windows file paths are definitely relevant as an example of typing backslashes. However, the context here isn't the general content that might be written by users, but rather the type of strings that might need to be used with textual substitution like this. So, I might have a wiki entirely filled with Windows file system documentation that makes extensive use of backslashes, but that doesn't mean that we'd find any backslashes inside template literal strings. |
IMO the chance is high, that windows paths are dynamically created using template literals even for documentation strings. It will be a pita. I'm pretty sure about that. |
Hi @pmario I did a brief search on stack overflow to see if there were a lot of people complaining about escaping path separators in JavaScript template literals, and couldn't find evidence of widespread problems. Maybe we could resolve the problem by adding support for tagged template literals (as JS calls them; it might not be a helpful name for us to use). This just means that the quoted string is preceded by the name of a function that is used to transform the string. That function can replace the escaped string with the raw input string, and thus we could provide a
|
I do like the idea of "tagged templates" if that's doable. I think it would definitely be worth exploring. Then for the default behaviour we could use default escape rules and for windows-paths we could have a tagged template that is more relaxed using backsalshes. |
What do you think @saqimtiaz? One disadvantage of the |
IMO the tag could still be |
I'm away until Monday afternoon with just my phone so a more considered reply will follow then. My immediate instinct is that we should consider that the new attribute form is driven by the need to provide an easier form of text substitution for our end users, who are largely not programmers. As such, I think the default behaviour should be that text that is provided in the new attributes is parsed just as text in double quotes currnelty is with regards to escaping, and that any alternate behaviour is opted into with an extension of the syntax/operator prefix. |
My current opinion regarding escape characters and sequences is that if needed, this can be accomplished either via filter operators, or via adding support for tagged templates in the future. The default behaviour regarding escaping should be identical to other types of attributes. |
That makes sense. We could introduce operators for "jsescape" and "jsunescape". |
A common use case for macros is to construct a string from component parts. For example:
It is proposed to introduce a shortcut syntax to cover these simple use cases.
The shortcut syntax uses backticks to quote the string, with the following substitutions:
$(variable-name)$
is replaced with the value of the variable${filter}$
is replaced with the first result of evaluating the filterThe example above could be expressed as follows using the new syntax:
An example using filters:
An example of transcluding a tiddler:
The text was updated successfully, but these errors were encountered: