Skip to content

misplaced-attachment

Whether an attachment sits outside the attachment folder of the notes that use it, and which notes are its proper home.

Two things here are easy to get wrong:

  • The judgement is about the FOLDER, not the path. getAttachmentFilePath answers about the proper path, folder and templated base name both, so judging on it raw flags every attachment whose NAME does not match a rename template. That is a different defect. So the comparison is folder against folder, through getAttachmentFolderPathForAttachment, which also skips the name generation that dominates the cost of the question when Custom Attachment Location answers it. - The proper folder is asked for the REAL attachment, never a dummy. A folder template may read the attachment’s own name, extension or stats, so getAttachmentFolderPath’s dummy-file route can answer about a file that does not exist.

A reference is judged from the note that makes it: A.md linking B/image.png, which sits in B.md’s folder, is A linking an EXTERNAL attachment, even when B uses it too. Whether such a reference is worth reporting depends on whether the attachment has a proper note anywhere, which is known only after every note has been judged, so MisplacedAttachmentIndex collects the verdicts and MisplacedAttachmentIndex.getReported applies the ExternalAttachmentLinkMode at the end.

Rendering is the caller’s: this module only judges and collects.

Class Description
MisplacedAttachmentIndex The verdicts of a walk over every reference to an attachment, grouped by the note that makes the reference. It keeps every external reference, every note that uses each attachment, and each attachment’s proper notes: the notes that reference it and whose own folder holds it. Which entries count as reported depends on the ExternalAttachmentLinkMode and on the proper notes, which are known only once the whole vault has been walked, so ask MisplacedAttachmentIndex.getReported after the walk.
Interface Description
AttachmentPlacement The folder an attachment sits in, judged against the folder one note’s configuration puts its attachments in.
GetAttachmentPlacementParams Parameters for getAttachmentPlacement.
MisplacedAttachmentEntry One reference to an attachment outside the attachment folder of the note that makes it. The same attachment referenced from two notes is two entries, because the two notes can configure different attachment folders.
RecordAttachmentPlacementParams Parameters for recordAttachmentPlacement.
Function Description
getAttachmentPlacement Judges where an attachment sits against the attachment folder of one note. Asks the attachment-path seam once, folder-only, for the REAL attachment, so a Custom Attachment Location folder template that reads the attachment’s own name is honoured and no name is generated.
recordAttachmentPlacement Judges one resolved reference and records the verdict in the index. Records nothing under ExternalAttachmentLinkMode.Ignore, for a note that is not treated as an attachment, and for an ignored or shared path. Otherwise the referencing note becomes a proper note of the attachment when its folder holds it, and the reference becomes an entry when it does not.
Enum Description
ExternalAttachmentLinkMode Which references to an attachment outside the referencing note’s attachment folder are reported.