-
Notifications
You must be signed in to change notification settings - Fork 20
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
Add option to delete Tag #4
Comments
Was this implemented? |
No, and it will not be. (I closed the issue without comment since it was opened without comment.) I've previously discussed the reasoning for not including this (on the Obsidian forums); the short version is that 1) it's an inherently destructive operation that can't be undone, and 2) just deleting the tag without considering the surrounding text may introduce formatting errors into the note, that require potentially endless special cases to handle. So, the recommended approach to delete a tag is to merge it into a designated "trash" tag (name it whatever you like), then delete that tag from notes individually when the opportunity arises. (Since as a human you can fix the formatting of surrounding text in an intelligent way.) |
Thanks for deliberate answer. I did not consider formatting issues, because the only way I use tags is in metadata section of a note. My current approach is to use |
Devil's advocate Why not have an option to make the tag no longer a tag
to
Alternativel, the following The latter is a non destructive transformation that shouldn't introduce any obvious corner cases. Personally, I mostly want to clean it out of the UI layer and not necessarily the note. This could be accomplished with some sed but I trust your parser more than randomly a CLI tool |
That wouldn't work for front matter tags, since the |
Yeah I ended up manually doing that but ran into an edge case that required a vault restore. Attaching a simple script here for others to use. Here's a script if anyone needs to do this manually.
|
But why?I currently use the system outlined here of modifying a tag and then using sed to delete it. What I'm wondering right now is why if you can rename a tag safely without corrupting the data, why you can't rename it to ""?
I would say that objection
Why do I care?Since this is what I currently do myself, I'm interested to know what you know about the dangers here as well as just trying to make my life easier by having you enhance a plugin for me. :-) |
Regexes cannot safely parse YAML. Note for example that YAML tags can appear like this: ---
Tag:
- a/b
- "c, d/e"
- '#f'
--- (Where As for the body, your regex also doesn't handle comma-separated tags or leading spaces. As I've said previously, I consider tag deletion to be something that requires manual attention for all but the simplest and most regular of cases. I find it hard to come up with an algorithm that could correctly delete a tag from all of my notes, let alone anyone else's. |
Thanks, yes, good points on the tag arrays, however, there are sed programs that will neatly handle those as well using lesser known commands of sed to manipulate the pattern space to handle multiple lines at a time. But it is no doubt tricky. But I keep wondering out loud, haven't you solved the same problem already, that of identifying the various tag possibilities when changing the name? I would think that deletion is the most trivial of the "change this string" operations once the tag string identifier is located in the right markdown file through some plugin magic that you are already using to rename. |
Removing the tag is trivial - removing it without breaking what's around the tag is the problem, especially in YAML but also in
No, it's actually not possible with sed - regular expressions and even sed constructs are insufficient to correctly parse YAML, and nothing less than a full YAML parser will do. (There are multiple Obsidian plugins that attempt to manipulate YAML using regular expressions, and without exception they either fail to read some forms of perfectly valid YAML or else they write out broken YAML in its place when they make a change.) A simple example (from issue #13): ---
Quality: &a C/2
RLEVEL: &b
Utility: &c
Field: &d
Type: &e ⚪/Figure
tags: [*a, *b, *c, *d, *e]
--- This is an example YAML snippet from an actual user of this plugin, as presented in issue #13. And it's not the craziest YAML I've seen, not by a long shot. |
YAML is actually pretty hard to read & replace even with a parser if you care about preserving user formatting. |
This comment was marked as off-topic.
This comment was marked as off-topic.
I find it's even harder in the body. But I think my script above does a good job. I'd love to hear any comments on it. |
That's not true. It has two valid tags in it, which I will leave you as an exercise for understanding how YAML works.
No, it has two immediately obvious bugs, one of which indicates you don't understand YAML, the other that you didn't pay attention to what I said above about how Obsidian processes YAML tag field names. And that's not counting
Yes, which is another big reason why Tag Wrangler doesn't support it. The entire point of this discussion is that Tag Wrangler cannot handle all the edge cases (such as inline tag discussion in the text body) and handling the edge cases correctly in the metadata is just as difficult, if not more so. That's why, if I ever add this feature it will be something interactive, that simply takes you to each instance in turn so you can remove it by hand. No script is going to be able to handle deleting |
No description provided.
The text was updated successfully, but these errors were encountered: