[upgrade] added functionality to handle Properties#51
Conversation
- functionality to handle [Properties](https://help.obsidian.md/properties) - limitation: - links in properties are not being handled
Veethahavya
left a comment
There was a problem hiding this comment.
also added:
- a notebook to illustrate functionality
|
@mfarragher would be great if this PR could go in (allowing support for frontmatter properties is even more important now with the release of Obsidian Bases) |
mfarragher
left a comment
There was a problem hiding this comment.
I'm going to merge this into a branch called dev_with_properties to do further development.
Examples of tweaks I'll make:
.obsidian/types.jsoncontains types likedatetime. That could be used to make the parsing logic more robust and generalise better than it does currently.- I'll re-organise the files used for tests
- Some of the original tests that check the vault object are failing (they need to account for the new
rich.mdfile in this PR).
| if isinstance(value, str): | ||
| if clean_key == 'date' and len(value) == 10 and value[4] == '-' and value[7] == '-': | ||
| try: | ||
| value = datetime.datetime.strptime(value, '%Y-%m-%d').date() | ||
| except ValueError: | ||
| print(f"Failed to parse date for key '{clean_key}' with value '{value}' in frontmatter of {filepath}") | ||
| elif clean_key == 'time' and len(value) == 19 and value[4] == '-' and value[7] == '-' and value[10] == 'T': | ||
| try: | ||
| value = datetime.datetime.strptime(value, '%Y-%m-%dT%H:%M:%S') | ||
| except ValueError: | ||
| pass | ||
| elif clean_key == 'due' and len(value) == 10 and value[4] == '-' and value[7] == '-': | ||
| try: | ||
| value = datetime.datetime.strptime(value, '%Y-%m-%d').date() | ||
| except ValueError: | ||
| pass | ||
| elif value.startswith("[[") and value.endswith("]]"): | ||
| # Handle single wikilink as a string | ||
| value = _get_all_wikilinks_from_source_text(value, remove_aliases=True)[0] | ||
| elif isinstance(value, list): | ||
| # Handle list of strings, checking for wikilinks | ||
| new_list = [] | ||
| for item in value: | ||
| if isinstance(item, str) and item.startswith("[[") and item.endswith("]]"): | ||
| # Extract the wikilink | ||
| new_list.extend(_get_all_wikilinks_from_source_text(item, remove_aliases=True)) | ||
| else: | ||
| new_list.append(item) | ||
| value = new_list | ||
| if clean_key in ('date', 'due') and all(isinstance(item, str) and len(item) == 10 and item[4] == '-' and item[7] == '-' for item in value): | ||
| try: # Convert to date objects if they match the pattern | ||
| value = datetime.datetime.strptime(value, '%Y-%m-%d').date() | ||
| except ValueError: | ||
| pass | ||
| props[clean_key] = value |
There was a problem hiding this comment.
This parsing looks like it could be simplified
|
@Veethahavya I've reworked the logic so that it is all integrated in However a few edge case tests aren't working now and I'm not sure why, but it might be quicker for you to debug?: issue #56 |
Solves:
Credits: