chhoumann / MetaEdit

MetaEdit for Obsidian
https://bagerbach.com
GNU General Public License v3.0
393 stars 15 forks source link

Changes to accept every Dataview metadata format #92

Closed theofbonin closed 1 year ago

theofbonin commented 1 year ago

Changes to also parse for "(field:: value)" and "[field:: value]", as opposed to only "field:: value".

theofbonin commented 1 year ago

Hey @chhoumann!

I made some changes and now it seems to be working for every case. I fixed some bugs that I found and made it work with some other cases that I had thought about.

Screenshot 2023-03-02 at 09 53 04 Screenshot 2023-03-02 at 09 53 50 Screenshot 2023-03-02 at 10 00 55

I changed the regex in "parser.ts" to a new one that conforms to the review: /[\[\(]?([^\n\r\(\[]*)::[ ]*([^\)\]\n\r]*)[\]\)]?/g Instead of using \s*, I used [ ]*, because using \s* would cause problems with properties that are declared without a value.

Screenshot 2023-03-02 at 11 47 17

I had to create the "escapeSpecialCharacters" method because properties with special regex characters were causing problems when editing the value. For instance, **Bold Field** was causing: Uncaught (in promise) SyntaxError: Invalid regular expression: /**Bold Field**:{1,2}/

I changed the regexes with ${property.key} to ${this.escapeSpecialCharacters(property.key)}.

I also changed the regexes in "metaController.ts" to conform to the review.


Known issues: When there is more than one of the same field on the same file, it appears many times on the Metaedit screen (you can see this on the second screenshot with the field mood). This shouldn't be an issue because the "right" way to declare fields on dataview is using lists or arrays:

field1:: [value1, value2, value3]
field2::
    - value1
    - value2
    - ...

Even though it does accept many of the same field, like:

field:: value1
field:: value2
field:: value3

This will be considered by dataview as field:: [value1, value2, value3]. Another problem related to this same thing is that when you modify the value of a field, it changes all occurrences of it in the file.

This issue was already happening even without accepting [field:: value] and (field:: value), so it is not really related. However, I could try to figure out a way to work with many of the same field in the same file if you think that would be necessary.

chhoumann commented 1 year ago

This is fantastic, @theofbonin! Everything looks great. Awesome job. You even fixed #54! Thank you for the PR! Tagging here to close: fix #54

I'd love to see issues where you document your findings on the known issues you mention. I think those should be fixed, but I agree that this PR isn't the place to do it. It's good to avoid bloating change requests with too many things at once.

github-actions[bot] commented 1 year ago

:tada: This PR is included in version 1.8.0 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket: