Operator Scope of Action:
Operator First Added:
The links() operator builds a List from a collection of links.
selects the note whose links that should be inspected. The scope - i.e. what's looked at - can be single note (item) or one-or-more items (group). Text links are listed in anchor order (i.e. as ordered in $Text); prior to this the output was usually the same but was in fact arbitrary. The optional item|group argument may be:
- omitted (including parentheses enclosing note) - in which case the implied context is the item-scope 'this'.
- a quoted single note name ("Some note") or its quoted path ("/Reviews/Some note"), i.e. a literal string.
- a quoted item designator (e.g. "original" in an $AgentAction context), i.e. a literal string with special meaning.
- an unquoted attribute holding an appropriate string value.
- a simple expression yielding a single note's name or path.
- from v5.9.0, also:
N.B. The item|group argument is not fully evaluated - only use simple expressions.
Aliases can never the target of item|group, even by use of paths.
The kind argument filters the directionality of the links collected. It is mandatory, and should not be quoted. It can only be is one of these values:
The optional linkType argument is a regular expression pattern. It collects only links of a specified link type, or such type(s) as match the linkType pattern amongst the link type names defined in the current TBX. Regular expression wild-card characters are permitted and retain their special meanings. If the linkType value contains white space or periods, it must be enclosed in double quotes:
If linkType is left empty, links of all types are collected except prototype links. Prototype links are always omitted. Single quotes can be used to enclose linkType but if the quoted string includes a single quote this must be backslash-escaped or double quote used instead:
links.outbound."Peter's place".$Name OK
links.outbound.'Peter's place'.$Name wrong
links.outbound.'Peter\'s place'.$Name OK
The attribute argument is the name of the attribute whose values are to be collected in the result. An attribute reference, e.g. $Name("nextSibling") is invalid - the command work but the reference is ignored and the stated attribute for the linked note is used.
constructs a set of all the titles (from Name attribute) of notes that are linked to the top-level note named 'config' via links with the link type 'supports'. This does the same but for all link types;
For multi-word link type names use quotes (or if using regex characters):
Whilst it is likely that 'Name' will be the most usual value for attribute, it can be any currently defined attribute:
collects a list of values of the attribute 'SchoolName' for notes that have an inbound link to the current note of link type "went to".
Beware when using a TBX that has notes with duplicate (same) $Name values. As a set contains unique values, if several notes have identical names, then
will list the distinct Names only once in MySet, and so the latter will have fewer values than the actual number of matching links. In the same scenario:
will create a list containing duplicates.
When using links() in the context of an agent's action, remember that aliases can have different links to originals. Therefore, it likely you will want to use 'original' as the note item for the call.
The format() or List.format() operators can help make more use of links() data during export, e.g. as lists or lists of links. Internally, if analysing links and there is no real need to keep set-type data, using agents employing linkedTo() and linkedFrom() will find most of the same data as links() can provide.
The links() function can be chained by dot operators pertinent to lists For instance:
If desired the chaining can be done to a set of parentheses - this can sometimes help make sense of the intended order of execution of the tasks:
More examples of links() syntax:
links("A note;A different note").inbound."*untitled".$Path