Skip to content

Add reading features to a generated document

A content bundle you pull with the ModelDesk CLI becomes a ReSpec document in your publication repository. The ModelDesk ReSpec runtime (@modeldesk/respec) is a small script you add to that document. It makes the diagrams interactive, and it can add reading features: a button that shows an element in the diagrams that draw it, a find dialog, cards that preview a linked element, and more.

The runtime reads only what the bundle marks in the generated files. It works with every template of the respec stack, MIM and NL-SBB alike, and with a template of your own that follows the same markers (see template lint).

  • A publication repository with a ReSpec document that includes the generated files under data/model/, as modeldesk bundle pull writes them.
  • The data/model/index.json the pull writes beside the fragments, committed and published with them. Most reading features need it. See The index.
  1. Take the latest version, which npm view @modeldesk/respec version prints, and compute its integrity hash:

    Terminal window
    curl -fsSL https://cdn.jsdelivr.net/npm/@modeldesk/respec@<version>/dist/modeldesk-respec.js \
    | openssl dgst -sha384 -binary | openssl base64 -A

    Put sha384- in front of what it prints.

  2. Add the script to the <head> of your index.html, before the script that loads ReSpec:

    <script
    src="https://cdn.jsdelivr.net/npm/@modeldesk/respec@<version>/dist/modeldesk-respec.js"
    integrity="sha384-…"
    crossorigin="anonymous"
    ></script>

    Load it as a plain script: leave out async and defer, so it is in place before ReSpec starts. Also leave out class="remove", which ReSpec uses for scripts it drops from the published copy. The runtime has to stay in that copy to keep working there.

  3. Reload the document. If it has diagrams, they now open in a full view, and a jump from a diagram highlights where it lands. These two features are on by default; everything else is off until you turn it on.

The integrity attribute makes the browser refuse a file that differs from the one released under that version. A new version reaches your document only when you change the version and the hash.

The script carries its own stylesheet and adds it to the page. If your organisation manages its stylesheets centrally, link the same stylesheet as a file instead, at the same version as the script, before the script:

<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@modeldesk/respec@<version>/dist/modeldesk-respec.css"
integrity="sha384-…"
crossorigin="anonymous"
/>

You can also @import it from your own stylesheet; that way it cannot carry a hash, so pin the version in the URL. The runtime sees the linked stylesheet and adds no copy of its own. If the link fails to load, it adds its copy after all. A site whose Content Security Policy refuses inline styles has to link the file, and allow its origin in style-src.

The runtime reads its settings from a modeldesk entry in your respecConfig. In Geonovum’s NL-ReSpec-template that object is in js/config.js. Add the features you want:

var respecConfig = {
// …your existing ReSpec settings
modeldesk: {
features: {
diagramBacklinks: true,
usedBy: true,
hoverCards: true,
quickFind: true,
copyLink: true,
breadcrumb: true,
metadataDisclosure: true,
layout: true,
},
},
};

Each feature takes true to turn it on, false to turn it off, or an object to turn it on with options. A feature you leave out keeps its default.

Feature Default Needs the index What readers get
diagrams on no Each diagram has a button above it that opens a full view, where readers pan and zoom with the mouse, a touch screen or the keyboard. Clicking an element there goes to its section.
landing on no A jump from a diagram briefly highlights the heading it lands on, and keeps a table’s header in view when the target is a table row.
diagramBacklinks off yes A diagram button beside each element heading, and at the end of the table rows that list the element, with the number of the page’s diagrams that draw it. It opens the full view on the element, centred and outlined; when several diagrams draw it, the view’s title lists them and ‹ › step through them.
usedBy off yes Under each element heading, Gebruikt door with links to the elements that refer to it, grouped by kind.
hoverCards off yes Hovering or focusing a link to another element shows a card with that element’s name, kind and definition.
quickFind off yes Ctrl+K or Cmd+K, or a Zoeken in document button in the header, opens a dialog that finds the document’s elements by name or kind as you type.
copyLink off no Beside each element heading, a button that copies the link to the element. With the index, the element’s URI is shown as well, with a button that copies it.
breadcrumb off no A line at the top of the window with the path to the element being read, such as the package and the object type, each a link. Not shown on narrow screens or in print.
metadataDisclosure off no Each element’s administrative metadata is collapsed behind a Toon alle metadata button. In the MIM templates that is the identification; in the NL-SBB begrippenkader, the IRI and the change and history notes. Print shows all of it.
layout off no On a narrow screen, property tables put each label above its value and wide tables scroll sideways. In print, each MIM package starts on a new page; the begrippen of an NL-SBB begrippenkader follow each other.
status off no A status badge on each element heading. No built-in template marks a status yet, so it adds nothing to their documents.

The interface text follows the document’s language, not the reader’s: Dutch when the lang of your index.html starts with nl, English otherwise. The labels in the table above are the Dutch ones; an English document shows Used by, Find in document and Show all metadata.

Two features take options:

modeldesk: {
features: {
status: { filter: true },
metadataDisclosure: { fields: ['identificatie', 'heeftTijdlijnGeldigheid', 'heeftTijdlijnRegistratie'] },
},
},
  • status: { filter: true } adds checkboxes before the first element, one per status the document uses, that hide the elements of a status. The element a link points at is never hidden.
  • metadataDisclosure: { fields: [...] } collapses the properties you list instead of the default metadata. Use the property names in the generated files’ data-md-field attributes.

A feature name the runtime does not know, or a value it cannot use, is reported once in the browser’s console and otherwise ignored. The rest of your settings still apply.

data/model/index.json lists every element the document shows, with its anchor, its kind and the elements it refers to, and every diagram with the elements it shows. Every pull writes it again. Commit it with the fragments, and make sure your publish step copies it along with them.

The runtime fetches the index only while ReSpec builds the document, and only when a feature that is on needs it. It reads it from data/model/index.json next to your index.html. If your fragments are somewhere else, give the path:

modeldesk: {
index: 'content/model/index.json',
features: { … },
},

The path has to be relative to the document. If the index is missing, the features that need it stay off without a message, and the rest of the document works as before.

The index is written to the convention of the CLI that pulled it, and each runtime version reads the conventions it knows. When the two do not match, the console says so and the features that need the index stay off. Move to a newer runtime when you move to a newer CLI.

When ReSpec saves the document as a static HTML file, as a publish step does, the copy keeps neither your respecConfig nor the data/ folder. The runtime therefore writes what it needs into the page while ReSpec builds it: your feature settings and, for hover cards, find and the diagram buttons, the name, anchor and kind of each element and the diagrams that draw it. The published copy runs from that and fetches nothing.

What the runtime added for reading, the Gebruikt door lists, badges and URIs, is part of the copy. If a reader’s browser cannot load the script, they still have all of it. The buttons that only work with the script, such as the full view, the diagram buttons, copying, finding and filtering, are not in the copy; the runtime adds them again each time the copy opens with the script.

Without the script while ReSpec builds the document, readers get the document as ReSpec renders it, with the diagrams and their links. Without any stylesheet, the features that only work styled, such as the full view, the cards, the breadcrumb and collapsing, stay off and nothing is hidden.

The runtime is tested against WCAG 2.1 level AA, the level the Dutch Webrichtlijnen require: every control it adds works with the keyboard and has a name a screen reader announces, nothing it adds widens the page on a narrow screen, and animations stop for readers who ask for reduced motion.

  • Nothing changes after you add the script. Check that the script element has no async, defer or class="remove", and that it comes before the script that loads ReSpec. If the integrity value does not match the file, the browser refuses the script and says so in the console.
  • A feature you turned on does not appear. Open the browser’s console. The runtime reports a misspelt feature name, a value it cannot use, an index it cannot read or an index of a convention it does not know, each once, starting with @modeldesk/respec:.
  • The index features stay off without a message. The runtime found no index. Check that data/model/index.json exists next to the fragments, that your publish step copies it, and that you view the document through a web server rather than from disk.
  • The console says the stylesheet is of another version. The version in your stylesheet link differs from the script’s. Give both the same version.
  • A diagram shows without links. Its SVG could not be included, so the figure shows the PNG. The full view still opens on it. See Diagrams in the bundle.