Skip to content

Add notes to a generated document

A content bundle you pull with the ModelDesk CLI describes each element with what the model holds: its name, definition, attributes and relations. A note is prose of your own under an element: the modelling choices behind it, a worked example, a picture with an explanation. You write it as a Markdown file in your publication repository, and every pull places it in the generated text.

You cannot write that prose into data/model/ itself. The CLI manages that folder, and every pull replaces it, hand edits included. A note lives outside it, in the md-notes/ folder of your repository, in your own review flow, and the model knows nothing about it.

Adding a note takes no command line. You create one file, in the GitHub web editor if you like, and the next pull places it, also when the pull runs in a workflow.

Notes work with the MIM document templates of the respec stack: conceptueel, conceptueel-toc, logisch and logisch-toc. The NL-SBB begrippenkader template takes no notes.

  • A publication repository with a .modeldesk/config.json that is pulled with modeldesk bundle pull, by you or by a workflow. See the CLI reference.
  • A CLI that knows notes. A workflow that runs npx @modeldesk/cli@latest always has one.
  • A ModelDesk server that renders the respec stack at version 1.4 or later. Every pull prints the version it received, for example (stack respec 1.4, template conceptueel-toc). See Version requirements.

Every element that gets a file of its own in the bundle, such as an object type, a data type, an enumeration or a code list, has two places where a note can go. These places are called slots. Every package (in MIM, a domain) and the model itself have the same two slots.

Slot Where the note appears
intro Right after the heading and its diagrams, before the table that describes the element. For a package or the model, before its first section.
after At the end of the element’s own content, after its overview sections and constraints. In a hierarchical (-toc) template it comes before the subtypes nested under the element, so the note never reads as part of the last subtype.

The parts the document shows inside another element’s file carry no slots: attributes, relations, enumeration values and constraints. The CLI calls them anchor-level parts. To write about an attribute, put the note on the element that owns it.

A note’s path says which element it belongs to. Find the element’s file under data/model/, and create a file at the same path under md-notes/. End the name in .md for the intro slot, or in .after.md for the after slot:

Element Its generated file intro note after note
The object type Gemeentegebied data/model/bestuurlijk-gebied/objecttype/gemeentegebied.md md-notes/bestuurlijk-gebied/objecttype/gemeentegebied.md md-notes/bestuurlijk-gebied/objecttype/gemeentegebied.after.md
The domain Bestuurlijk gebied data/model/bestuurlijk-gebied/index.md md-notes/bestuurlijk-gebied/index.md md-notes/bestuurlijk-gebied/index.after.md
The model data/model/index.md md-notes/index.md md-notes/index.after.md

Every Markdown file in md-notes/ is a note, so keep other Markdown, such as a README, elsewhere. A file or folder whose name starts with . is skipped, which suits a draft. Images can sit in md-notes/ beside the notes, as long as your publish step copies them; see Images and the publish step.

For a package, after is the end of the package, after its last element; for the model, the end of the document. A note there comes under a heading of its own. That heading becomes a numbered section in the table of contents, beside the package’s categories (or, for the model, beside the packages), and the note’s own headings nest under it.

Write the heading on the note’s first line, in this form:

<!-- heading: Afsluiting -->
The text of the note starts here.

The line is an HTML comment, so it shows nowhere in the document. The pull reads it and writes the heading into the generated text, with an id of its own (see below), so the line takes no {#id}. A note in any other slot needs no heading line.

The heading is needed because ReSpec builds sections from headings. Without one, anything after a package’s last element would belong to that element’s section, and a heading inside the note cannot climb out of it.

The heading gets a stable id, made of the package’s anchor and the heading text: the heading Afsluiting under a domain anchored domein_bestuurlijk_gebied gets the id domein_bestuurlijk_gebied-afsluiting. The text part is the heading lowercased, with accents removed and every run of other characters turned into one -.

  1. In your repository, find the element’s file under data/model/.

  2. Create the note file at the same path under md-notes/, as in Name the note file. In the GitHub web editor: Add file › Create new file, and type the whole path as the name, folders included.

  3. Write the note. See Writing a note.

  4. Commit the file, then pull. When a workflow pulls your bundle, run it; when you pull yourself, run modeldesk bundle pull.

    The pull places the note in the slot, in every generated file that shows the element: its own file, its package’s file and data/model/index.md. It also records the note in .modeldesk/notes.json, which has to be committed with the pulled text. See Pull in a workflow.

Once a note is placed, editing its text needs no pull: the generated file includes the note by its path, and ReSpec reads the note when it builds the document. Adding a note, removing one, or changing the heading line of a package’s or the model’s after note does need a pull, because each of those changes the generated text.

To remove a note, delete the file and take its slot out of .modeldesk/notes.json, then pull. If you delete only the file, the next pull stops because the file that notes.json names is missing.

If you have the CLI, modeldesk note add creates the file at the right path for you, and records it in notes.json straight away:

Terminal window
modeldesk note add Gemeentegebied
Created md-notes/bestuurlijk-gebied/objecttype/gemeentegebied.md, the intro note of Gemeentegebied (objecttype).

For the after slot, add --slot after. For the after note of a package or the model, also give its heading, which the CLI writes as the file’s first line:

Terminal window
modeldesk note add Domein Bestuurlijk gebied --slot after --heading Afsluiting

note add finds the element in the record of the last pull, .modeldesk/respec.manifest.json, which you keep out of Git, so pull first in a fresh checkout. When several elements share the name, it asks which one you mean, or asks for --element <id> when it cannot ask. See note add in the CLI reference for every flag.

A pull in a workflow, such as GitHub Actions, places the notes and records the new ones in .modeldesk/notes.json, as a pull at your desk does. It needs nothing from an earlier pull: it matches note files to elements by path, using the bundle the server sends.

The workflow commits what the pull wrote. Add .modeldesk to the commit beside data/model, so the recorded notes are kept; Git leaves out the manifest, which your .gitignore excludes:

- name: Commit the pulled text and notes
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add data/model .modeldesk
git diff --cached --quiet || git commit -m "Pull the content bundle"
git push

A commit needs contents: write in the workflow’s permissions instead of contents: read.

When a note file cannot be placed, the pull stops before it writes anything and the workflow run fails, so you see it in the list of runs. The run’s log names the file and why. See What a pull checks.

.modeldesk/notes.json records which note goes where. The pull writes it, and so does note add:

{
"notes": {
"dafddbaf-9e2a-4eda-88f7-9fae3a47362f": {
"name": "Gemeentegebied",
"intro": "md-notes/bestuurlijk-gebied/objecttype/gemeentegebied.md"
},
"125cd721-c388-49ef-bc26-d9ee56964357": {
"name": "Domein Bestuurlijk gebied",
"intro": "data/model-overzicht.md",
"after": "md-notes/bestuurlijk-gebied/index.after.md"
}
}
}
  • The key is the element’s id. Because entries are keyed by id, a note stays in place when the element is renamed in the model, although its generated file then moves. The note file stays where it is.
  • name is the element’s name, for the person reading the file. Every pull updates it to the element’s current name; nothing else reads it.
  • intro and after are each optional, and each holds the path of a note file.
  • An entry can name a file outside md-notes/. That is how a document carries over notes it already has, such as the data/model-overzicht.md above: add the entry by hand.
  • Paths are relative to the repository root, the folder that holds .modeldesk/. A path must stay outside data/model/, which every pull replaces, and inside the repository. It may not be absolute or a URL, and may not contain a .. segment, a backslash, %, # or ?, or a folder or file name that starts or ends with a space. The document reads a note path as a URL, where those characters mean something else.
  • The file holds only notes. The CLI refuses a key it does not know, and an element id that appears twice.

The CLI keeps the order of the entries and writes the file with two-space indentation. A pull rewrites it only when it adds a note or an element’s name changed. A rewrite uses the CLI’s own layout, so a file you laid out differently by hand gets that layout the first time the pull changes it.

The notes folder is md-notes/ at the root of the repository unless notesDir in .modeldesk/config.json names another, for example when your publish step reads only certain folders:

{
"model": "3f2b…-model-uuid",
"stack": "respec",
"template": "conceptueel-toc",
"notesDir": "docs/notes/"
}

Note paths then start with that folder: docs/notes/bestuurlijk-gebied/index.after.md. The folder cannot be the repository root itself, lie in data/model/ or hold it, or be a symlink.

A note is Markdown, and ReSpec processes it as it processes any chapter of your document, so definitions, links and figures work inside it.

  • Start headings at #. ReSpec nests a note’s headings one level below the element, whatever level you start at. Keep the order within the note: #, then ## below it.
  • Note headings are unnumbered and stay out of the table of contents, like the generated subsections such as Overzicht attribuutsoorten. The only numbered heading is the one in the heading line of a package’s or the model’s after note.
  • Give a heading an explicit id when you link to it, as in ## Worked example {#gemeentegebied-example}. Without one, ReSpec derives the id from the text. When two notes have the same heading text, ReSpec numbers the second id (background-0), so a link to it moves when the notes change.
  • Give every image alt text, as in ![Map of the municipal boundaries](media/gemeentegrenzen.png), so readers who cannot see the image know what it shows.
  • Image paths are relative to the repository root, not to the note’s folder: the note is included in the document, and the document resolves the path. Write media/gemeentegrenzen.png, even in a note deep under md-notes/.
  • Use one note file per slot. A file placed in two slots shows its headings twice, so their ids repeat or get numbered.

The published copy of your document needs the images your notes show. A ReSpec snapshot, as Geonovum’s NL-ReSpec-template publishes, inlines every included Markdown file, so the note files themselves need not be copied. An image a note links must sit in a folder your publish step copies. The NL-ReSpec-template copies data, media, js and css next to the snapshot, so with that template, put note images in media/.

Name the folders your publish step copies in publishDirs in .modeldesk/config.json:

{
"model": "3f2b…-model-uuid",
"stack": "respec",
"template": "conceptueel-toc",
"publishDirs": ["data", "media", "js", "css"]
}

With publishDirs set, a pull warns about every image a note links outside those folders. Without it, the pull does not check where images sit.

A pull checks .modeldesk/notes.json, the notes folder and the notes before it writes anything. The checks that need nothing from the server run before it asks the server for anything, so a broken notes.json never starts a diagram render. The checks on the note files in md-notes/ need the bundle, so they run once it has arrived.

The pull stops, writes nothing, and lists every problem it found at once when:

  • notes.json is not valid JSON, has a key the CLI does not know, or names an element id twice;
  • a note file that notes.json names does not exist;
  • a file in md-notes/ matches no element in the bundle. The error lists generated files close to the path you wrote, such as the same file name in another folder;
  • a file in md-notes/ is for a slot that notes.json already gives another file, or two files in md-notes/ are for the same slot of one element;
  • a note path lies in data/model/, leaves the repository, or breaks one of the path rules above;
  • an entry names a slot the element does not carry (the error names the slots it does carry);
  • the after note of a package or the model has no heading line, or a blank one;
  • the notes folder is the repository root, lies in data/model/ or holds it, or is a symlink;
  • the server renders no note slots at all (see Version requirements).

The pull warns, with a line that starts with warning:, and goes on when:

  • the element of an entry in notes.json is not in the bundle. The entry is kept, since the element may exist on another branch or version of the model;
  • a note in a slot that takes no heading starts with a heading line, which then does nothing;
  • an image a note links does not exist;
  • an image lies outside the publishDirs;
  • an image has no alt text;
  • two notes have the same heading text and neither gives it an explicit {#id};
  • one note file fills more than one slot;
  • the element appears more than once in a file, as a subtype under two supertypes does in a hierarchical template. Its note goes in at the first place only;
  • notes.json changed while the pull ran, for example while it asked you something. The pull leaves the file as it is, and the next pull records what this one could not.

A file in md-notes/ for an element that only another version of the model has cannot be placed yet, so a pull of a version without that element stops on it.

modeldesk bundle pull --dry-run shows the note files the pull would record, with one adopt line each, where each note would go, with one fill line per slot, and how many empty slots the pull takes out of the generated text:

adopt md-notes/bestuurlijk-gebied/index.after.md: Domein Bestuurlijk gebied after
fill Gemeentegebied intro: md-notes/bestuurlijk-gebied/objecttype/gemeentegebied.md
fill Domein Bestuurlijk gebied after: md-notes/bestuurlijk-gebied/index.after.md under the heading "Afsluiting"
slots removed: 14

When an element was renamed, the preview also shows the name the pull would update in notes.json. A dry run writes nothing, notes.json included.

Notes need both sides to know them:

  • The server must render the respec stack at version 1.4 or later, with a MIM template. When the server renders no note slots and you have notes for the elements it sent, the pull stops once, before writing anything, and names the stack version the server rendered. Either the server is older than notes, or the template takes none, as the NL-SBB template does. To pull without notes, move .modeldesk/notes.json and the notes folder aside.
  • The CLI must know notes. A CLI from before notes ignores the notes and places none, and the files it pulls from an up-to-date server carry <!-- md-slot … --> lines. Those are HTML comments, invisible in the document, but they show up in your diffs. Update the CLI to place your notes and drop those lines.
  • When the server is newer than your CLI and sends a slot your CLI cannot read, the pull stops before writing anything and tells you to update @modeldesk/cli.

npx @modeldesk/cli@latest always runs the latest release. A global install updates with npm install -g @modeldesk/cli.

  • The pull says a note file matches no element. Compare the path with the element’s file under data/model/: the folders and the name must be the same, with md-notes/ in place of data/model/. The error suggests paths close to yours. If the element was renamed, its file has moved; rename the note file to match.
  • The pull says an after note needs a heading. Add <!-- heading: Your heading --> as the note’s first line.
  • note add says to run modeldesk bundle pull first. It finds elements in the record of the last pull, which a fresh checkout does not have. Pull, then add the note.
  • note add says several elements have the name. It lists them with their type and file, and their id when it cannot ask. Pass the id of the one you mean with --element <id>; the id is also in .modeldesk/respec.manifest.json.
  • note add says anchor-level parts carry no note slots. The name belongs to an attribute, a relation or another part shown inside an element’s file. Put the note on the element that owns it.
  • The pull stops because a note does not exist. Create the file at the path the error names, or take the slot out of notes.json.
  • A note does not appear in the document. Check the pull’s warnings: an element that is not in the bundle gets no note. Also check that a pull ran after you added the file, and that the workflow committed .modeldesk with the pulled text.
  • An image is missing from the published document. Move it into a folder your publish step copies, and set publishDirs so the next pull warns you in time.
  • Pulled files contain <!-- md-slot lines. Your CLI predates notes. Update it and pull again.