Skip to content

17. Links between documents

Contents of FBL 0.28

(FBL 0.23) A link points from an element of one document, the consuming document, to an element of another, the target document, or to the target document as a whole. FBL defines the link once for every kind of tool, because it lies between documents and their files, as ids, references and routing do. A specification language states only which of a tool type's attributes hold links and how its elements are linked to and shown (DISL and DESL refer to this section); how a link is written, resolved and checked is this section's. Only a tool type whose binding declares document.id (17.2) holds links or is linked to.

A link is a string of this form (ABNF, RFC 5234):

link          = "$" document-id "@" document-name [ "#" element-id [ "." name-prop ] [ "=" name ] ]
document-id   = 1*( id-char / escaped )
document-name = 1*( file-char / escaped )
element-id    = 1*( id-char / escaped )
name-prop     = 1*( id-char / escaped )
name          = *( text-char / escaped )
text-char     = %x20-24 / %x26-7E / %x80-10FFFF   ; any character but "%" and controls
file-char     = %x20-22 / %x24 / %x26-7E / %x80-10FFFF
                ; any character but "#" "%" and controls
id-char       = %x20-22 / %x26-2D / %x2F-3C / %x3E-3F / %x41-7E / %x80-10FFFF
                ; any character but "#" "$" "%" "." "=" "@" and controls
escaped       = "%" 2HEXDIG
  • document-id is the target document's id (17.2) and document-name its file's name with its extension and without its folder. element-id is the target element's id. name-prop names the attribute of the target element that names it; name is that attribute's value as last seen, cached so that the link can be shown before it is resolved.
  • A link without # names a document only.
  • A character that would end its part MUST be written as % followed by the two upper-case hexadecimal digits of each of its UTF-8 bytes: % in every part (%25); # in the document name (%23); and $, @, #, . and = in the document id, the element id and the name property (%24, %40, %23, %2E, %3D). Every other character is written as it is, so a file name keeps its dots (provinces.yaml) and a name its dots and equals signs. A writer MAY escape any other character; a reader splits the link at its separators first, the document id ending at the first @, the document name at the first #, the element id at the first . or = and the name property at the first =, and unescapes each part after, reading the hexadecimal digits in either case.
  • Without name-prop, the target element is named by the attribute its tool type declares as its name property (DISL's and DESL's linkable), and else by its first attribute of a text type in declaration order. A name-prop that names no attribute of the target element is read as if it were absent, and load-time validation writes the attribute used in its place (17.4). Without name, the name is filled in by the next load-time validation (17.4).
Link Meaning
$k3f9x2ma@provinces.yaml#nh.name=Noord-Holland The row nh of provinces.yaml, named by name
$p0q7e2zd@release.tml#launch=Launch The element launch of a timeline, named by its type's name property
$m8c1u4wa@ideas.mm#ID_1723.text=v1.2 scope A mind map node whose text is v1.2 scope
$k3f9x2ma@provinces.yaml The document only

A link is a value like any other to the rest of FBL: it is read and written through the slot of the attribute that holds it, and a list of links through a list slot.

17.2 The document id

A binding's document.id is a slot of the body's root that holds the document id: a root key in the yaml and json families, an attribute of the root element in the xml family. A binding with a plugin reader gives no slot; its plugin's contract says where its document id is kept (section 11.4) and reads it as the root's attribute documentId.

"document": { "id": { "key": "id" } }
  • The id is made by the tool type's persistence.documentId rule (DISL, DESL), once, and is never changed except by the fix of link.ambiguous-document (17.6).
  • A body without a document id is given one by its load-time validation (17.4). The template SHOULD hold {newid:document}, replaced by a new document id when the body is created.
  • Two documents of a workspace may hold the same id, as a copy does; resolution tells them apart (17.3). Within one body the element ids are unique: a duplicate is the tool type's std.duplicateId (DISL, DESL), and a link to it is reported as link.ambiguous-document (17.6).

17.3 Workspace and resolution

The workspace of a consuming document is the root folder, among the folders the host has open, that holds it. A host keeps an index of the documents of the workspace whose bindings declare document.id: for each, its path, its file name and its document id, and for each element of a type that can be linked to, its id and the value of its name property. A link is resolved against this index and the target's body only; it MUST NOT resolve to a file outside the workspace.

A link is resolved in these steps:

  1. It is parsed (17.1). A value that does not parse is link.malformed.
  2. The candidates are the documents whose id equals document-id. When there is exactly one, it is the target document.
  3. Otherwise the candidates are narrowed by name: among the candidates when there are several, else among all documents of the workspace, those whose file name equals document-name. When exactly one remains, it is the target document; when several remain, the link is link.ambiguous-document; when none remains, link.broken-document.
  4. Without #, the link resolves to the target document. Otherwise the target element is the element of the target document whose id equals element-id, compared as the target type's persistence.ids.compare says. When there is none, the link is link.broken-element; when there are several, link.ambiguous-document.

Resolution is a function of the index and the target's body: two hosts with the same workspace resolve a link to the same element or report the same finding.

17.4 Load-time validation

When a host loads a consuming document, it MUST, in one edit that is one step of the history (section 7.1):

  1. give the body a document id when its binding declares document.id and the body holds none;
  2. convert a body from an older form that its tool type's definition names, when it is in one;
  3. resolve every link in the body (17.3);
  4. for each link that resolved, rewrite every part that differs from what resolution found: document-id when the document was found by its name, document-name when the file was renamed or moved, name-prop when it names no attribute of the target element, and name when the target element's name changed or the link held none; and
  5. report the links that did not resolve (17.6).

When nothing differs, nothing is written and no step is recorded. A body opened read-only (section 3.4, or by the host) is resolved and shown, and not written. While the consuming document is open, the host follows changes to its target documents (section 7.3) and shows their current names and the target attributes the tool type declares, without writing the consuming document.

A backlink of an element is a link, in any document of the workspace, that resolves to it. Backlinks are computed from the index and MUST NOT be stored in the target document. A host shows an element's backlinks, each with the consuming document's name and the name of the element that holds it, and opens the consuming document with that element selected when one is activated. Before deleting an element that has backlinks, a host MUST say how many links the delete breaks.

Activating a link opens the target document in the host's tool for its type, or brings it to the front, with the target element selected.

17.6 Findings

A finding of a link stands at the element or value that holds it, in the consuming document.

| Code | Severity | Message | Fixes |
|---|---|---|---|
| `link.malformed` | error | "'<text>' is not a link." | Remove the link. The value is kept as written until then. |
| `link.broken-document` | warning | "No document '<name>' with id '<id>' is in the workspace." | Pick another target; remove the link. |
| `link.broken-element` | warning | "'<name>' is no longer in '<document>'." | Pick another element of that document; remove the link. |
| `link.ambiguous-document` | warning | "<n> documents are '<name>' with id '<id>': <paths>." For a duplicate element id: "'<document>' holds <n> elements with id '<id>'." | Choose one of the candidates, listed by path. The link resolves to it, and every other candidate is given a new document id: at once when it is open, and otherwise by its own load-time validation, which a host performs when it next loads it. |

Shown as written in the source.

A link whose finding stands is shown by its cached name, marked as broken or ambiguous.

(informative) links-example/ beside this document is a workspace with one document of each tool type that holds links, the knowledge designer, the mind map, the timeline and the dependency graph, each linking the others; fixtures/links-workspace/ is the conformance fixture of this section, with every finding on each of the four types, copies, moves, stale names and the knowledge file's conversion, and conformance.json saying what each link resolves to. validate-examples.py checks both.

Referenced from