-
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Images inside an admonition aren't detected #45
Comments
Hi, the reason for the cleaner seeing the images as used is because admonition isn't registering the files as references in Obsidian so things like backlinks etc are not working either. I see the plugin is in maintenance mode so I suspect that won't be fixed any time soon. I haven't used admonition myself so unsure how it is used, is the pattern |
Thanks, the issue with implementing this is that the cleaner would need to go through each file in a users vault and parse out what could be an image and/or file link. As described in #44, this is something that is not preferential as it would increase the time it takes for a cleanup cycle drastically. The best solution for this issue in particular (admonition) is for the plugin to register which files are being referenced using the Obsidian API but with the maintenance mode this might take a while. As a temporary solution that could help you is to add image links to the frontmatter. images: "[[path/to/image.png]]" This will register the image / file in the Obsidian resolvedLinks metadata cache which the cleaner is using to find files which should be removed or not. |
Hi @davidkopp I haven't been able to get to a proper conclusion regarding implementing this. The reasoning for this is that, if I am going to implement this, the implementation needs to read each file in the vault and parse out the admonition blocks as mentioned in my previous comment. My question is for you and others that might use Admonition who'd like this implemented, to run the following command in their vault Developer Console (Ctrl+Shift+i / Cmd+Shift+i). I've added as many comments as possible but in short, it will go iterate through the vault using Obsidians metadata API to get some stats about how many markdown files are in the vault and how many code blocks are used (code block stats will be: how many, where they are located in the file and how big they are), this data will let me get an indication of how many files I can expect in a typical vault and get some ideas as to how long the operation might take. const filesWithCodeBlocks = Object.values(this.app.vault.fileMap)
.filter((f) => f.extension === "md") // filter out only markdown files
.map((file) => this.app.metadataCache.getFileCache(file)) // get information about sections etc for file
.filter((file) => file.sections) // filter out files that have sections (aka non-empty files)
.map(
(file) => file.sections.filter((section) => section.type === "code"), // find each section in each file that is a code-block
)
.filter((data) => data.length > 0); // filter out blocks files that did not contain any code-blocks
this.app.vault.create(
"./obsidian-file-cleaner-redux-admonition.json",
JSON.stringify(filesWithCodeBlocks),
); This will create a file in the root of your vault named The output will be similar to the following except for the the comments and prettyfied formatting. [
[ // <- Single file containing one or more code blocks (this example, one file with 2 code-blocks)
{ "type": "code",
"position": { // Position of the code block in the markdown file
"start": { "line": 0, "col": 0, "offset": 0 },
"end": { "line": 2, "col": 3, "offset": 29 }
}
},
{ "type": "code",
"position": {
"start": { "line": 6, "col": 0, "offset": 42 },
"end": { "line": 8, "col": 3, "offset": 71 }
}
}
]
] Please create a gist with this file and add the link in a comment and I'll continue looking into this. Thanks |
Here the gist: https://gist.github.com/davidkopp/93a09b28d1fa099900d9f496040b8080 Thanks for your effort! |
Hi @davidkopp, I've realized a couple of weeks ago that I would need to rewrite the plugin so that extending support would be easier. I'm hoping to have something that can be tested soon. |
Great to hear 😀 With BRAT I need a tag or a manifest-beta.json for that, specifying a branch is not supported. |
Will do, I've set up a pre-release workflow in the rewrite branch so when I feel comfortable with the release candidate I'll do a v1.0.0-0 pre-release for you to test. |
I just created a pre-release which supports admonition and can be found at 1.0.0-3 There is still stuff to do for the v1.0.0 milestone that I want to add but I might release it earlier if the Admonition support works and isn't too slow :) Looking forward to hearing the results. Oh and as mentioned in my previous comment (#45 (comment)), please make a backup / clone your vault before testing 😅 |
Awesome and thanks for testing. I'm gonna look over the remaining issues I've planned for v1.0.0 and see if there is anything that needs to get in, if not I think I should be able to have a release ready by either end of the week or some time next week. |
I'm in the process of releasing v1.0.0 and I'm merging in the changes for supporting Admonition, the issue will be closed but don't hesitate to open it / a new one once it's released and issues should come up. Thanks for your patience :) |
Example:
The plugin wants to delete the image, because it somehow doesn't see it inside this admonition. In a Obsidian callout it works like expected. However, I need to use the old syntax of the admonition plugin and I can't switch fully to callouts.
The text was updated successfully, but these errors were encountered: