Repository navigation
Enhancement (config): Add option $mediaLinkFormat to use wikilinks for media - #215
Open
El1as42 wants to merge 3 commits into
Conversation
…verwriting each other With `$medialocation = 1` (default), the images of all of a notebook's pages are saved in the notebook's `media` folder, named after the page's Section and name, e.g. `mysection-mypage-image1.png`. So subpages with the same name (e.g. `Exercise` under two different pages) and identically-named pages of a Section got the same image names, and the images of one page overwrote the images of the other. Both pages then showed the same images. Now image names include the page's parent pages and the postfix of identically-named pages, i.e. the `.md` file's path within the notebook, e.g. `mysection-mypage-mysubpage-image1.png`. Image names of first level pages that are not identically-named are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The error showed the result of the previous `New-Item` or `Move-Item` call (e.g. the `media` folder) instead of the image's destination path, making it impossible to tell which file name failed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…for media Media are linked with markdown links with relative paths, e.g. ``. Markdown viewers like Obsidian have to update these paths whenever notes or media are moved, which is fragile, especially for paths containing spaces or parentheses. The new option `$mediaLinkFormat = 2` uses wikilinks with only the file name instead, e.g. `![[mynotebook-mysection-mypage-image1.png]]` for images and `[[mynotebook-mysection-mypage-attachment.pdf]]` for attachments. Such viewers find linked files anywhere by their name, so links don't break when moving notes or media. Since wikilinks contain only the file name, media file names must be unique across notebooks: - Image and attachment names are prefixed with the notebook, Section, and page path, i.e. the `.md` file's path within the notes destination. - `#` and `^` are replaced, since they have a special meaning in wikilinks. - Prefixes longer than 100 characters are shortened to their start (e.g. the notebook) and end (e.g. the page), with a hash of the full prefix in between, and attachment names to 150 characters, with a hash of the full name. So names stay unique, and media paths stay well below the path limit of 260 characters on Windows, also after moving the notes to another folder. Images are matched by their prefix, which may contain any parentheses. Wikilinks have no alternative text or pandoc link attributes, so these are omitted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
El1as42
force-pushed
the
enhancement/config-add-option-medialinkformat-to-use-wikilinks-for-media
branch
from
October 14, 2026 08:29
4527627 to
fb16de6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #213
Builds on #214 (its two commits are the first commits here), since media names must be unique within a notebook before they can be unique across notebooks. I'll rebase once it is merged, so that only the last commit remains.
Changes
$mediaLinkFormat:1uses markdown links with relative paths (default, existing behavior),2uses wikilinks with only the file name, e.g.![[mynotebook-mysection-mypage-image1.png]]for images and[[mynotebook-mysection-mypage-attachment.pdf]]for attachments.2:.mdfile's path within the notes destination.#and^are replaced, since they have a special meaning in wikilinks.mynotebook-1a2b3c4d-mypage-image1.png. Attachment names longer than 150 characters are shortened, with a hash of the full name. So names stay unique, and media paths stay well below the path limit of 260 characters of Windows PowerShell 5.1, also after moving the notes to another folder. (Without this, a page nested three subpages deep in a notebook with a long name got image paths of 268 characters, and its images failed to be saved.)f(g(x))from nested ones, ora)from a page nameda) Exercise. Wikilinks have no alternative text or pandoc link attributes, so these are omitted.README.mdandconfig.example.ps1document the option.Tests: a
New-SectionGroupConversionConfigtest for both values: media names are unique across the two fake notebooks,#and^are replaced, long subpage paths are shortened with a hash, attachments are prefixed and long attachment names shortened, and images (with alternative text and link attributes, two on one line, nested and unbalanced parentheses) and attachments are converted to wikilinks, or kept as markdown links with1. Unit tests pass on Windows PowerShell 5.1 and PowerShell 7.0. In this repo's CI (run on my fork), all jobs that can currently run pass: Windows PowerShell 5.1 (windows-2022) and PowerShell 7.1 to 7.4. The other jobs currently fail for any PR, before checkout: thewindows-2019runner image was retired, and the PowerShell 6.0 to 7.0 container images are too old foractions/checkout(GLIBC_2.28' not found). Also tested on real notebook pages on Windows PowerShell 5.1, including a page nested three subpages deep in a notebook with a long name: images are converted to wikilinks, the linked files exist with these names, and the longest media path is 198 characters.🤖 Generated with Claude Code