Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/danymat/Obsidian-Markdown-Parser
This repository will give you tools to parse and fetch useful informations of your notes in your Obsidian vault.
https://github.com/danymat/Obsidian-Markdown-Parser
markdown-parser markdownfile obsidian obsidian-extractor obsidian-markdown-parser obsidian-md obsidian-vault parser python vault yaml zettelkasten
Last synced: 3 months ago
JSON representation
This repository will give you tools to parse and fetch useful informations of your notes in your Obsidian vault.
- Host: GitHub
- URL: https://github.com/danymat/Obsidian-Markdown-Parser
- Owner: danymat
- License: mit
- Created: 2021-01-29T08:17:27.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-08-30T02:36:04.000Z (about 3 years ago)
- Last Synced: 2024-05-11T07:35:47.378Z (6 months ago)
- Topics: markdown-parser, markdownfile, obsidian, obsidian-extractor, obsidian-markdown-parser, obsidian-md, obsidian-vault, parser, python, vault, yaml, zettelkasten
- Language: Python
- Homepage:
- Size: 102 KB
- Stars: 50
- Watchers: 3
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- project-awesome - danymat/Obsidian-Markdown-Parser - This repository will give you tools to parse and fetch useful informations of your notes in your Obsidian vault. (Python)
- jimsghstars - danymat/Obsidian-Markdown-Parser - This repository will give you tools to parse and fetch useful informations of your notes in your Obsidian vault. (Python)
README
# Obsidian Markdown Parser
![(Github All Releases)](https://img.shields.io/github/downloads/danymat/Obsidian-Extractor/total)
This repository will give you tools to parse and fetch useful informations of your notes in your Obsidian vault.
## Motives
I like to do some python scripts with my vault, so this repository is the tool I needed in order to parse my Markdown files.
## State of the Art
At the moment, I have implemented a basic parsing library.
### Parser
#### Usage
```python
from src.Parser import Parser
parser = Parser('/path/to/vault')
```By default, the parser will ignore `.git` and `.obsidian` sub-directories.
If you want to specify which directories to ignore, it has to be done at instanciation.
```python
parser = Parser('/path/to/vault', ignoredDirectories=['directory1', '.obsidian', '.git'])
```Be careful, it will rewrite `.git` and `.obsidian`, so please add them back in the ignoredDirectories if you want to ignore them plus the ones you specified.
#### Attributes
- `mdFiles` Array of MarkdownFile in vault
#### Methods
- `findSubFilesForFiles(files)` returns a set of `MarkdownFile` linked with the **set** of `MarkdownFile` specified
- `searchFilesWithTag(tag)` returns a set of `MarkdownFile` with a specified tag### YamlParser
#### Usage
```python
from src.yamlParser import YamlParser, YAML_METHOD# the file contents need to be read
file = MarkdownFile
file = self._openFile()
self.fStream = file.read()
file.close()findYAMLTags = YamlParser(self.fStream)
# find all values for a particular key
# this will return a set with the values that have "tags" as key
values = findYAMLTags.findAllYAML(YAML_METHOD.FIND_VALUE, "tags")yamlIterator = YamlParser(self.fStream)
# return all keys and values as a dictionary with the key as string and its values as set
print(yamlIterator.findAllYAML(YAML_METHOD.ITERATE))
```#### Methods
- `.findAllYAML()` with the parameters `YAML_METHOD.FIND_VALUE` and `"{key}"` with `{key}`
as the YAML key returns the associated values as a set
- `.findAllYAML()` with the parameter `YAML_METHOD.ITERATE` will return all key-value
pairs in YAML as a dictionary with the key as a string and its associated
values as a setCurrently, the YAML parser is limited [(see the comments for details)](https://github.com/danymat/Obsidian-Markdown-Parser/blob/main/src/YamlParser.py).
### MarkdownFile
#### Attributes
- `fileName` file name (string) of the current markdown file, with `.md` extension (e.g `'file.md'`)
- `path` relative path (string) of the current markdown file (e.g `'testVault/file.md'`)
- `tags` set of tags in current file (e.g `{'tag2', 'tag3'}`)
- `links` set of links in markdown files (e.g `{'file2'}`)### Examples
```python
parser = Parser('test/testVault')
```- Find all fileNames that doesn't have a tag
```python
fileWithoutTags = [file.fileName for file in parser.mdFiles if len(file.tags) == 0]
```- Find all files that have `tag1` in them
```python
filesWithSpecificTag = [file for file in parser.mdFiles if 'tag1' in file.tags]
# OR
filesWithSpecificTag = parser.searchFilesWithTag('tag1')
```## Roadmap
New features I intend to add:
- [ ] Add more tests
- [X] Ignore .obsidian/ folder## Contributing
If you would like to add shiny new features, or correct bugs I unfortunately added, please fork
this repository, and create a pull request from it. Below is the list of all contributors for this repository, if you contributed please consider adding your name !Contributors:
- Daniel Mathiot ([danymat](https://github.com/danymat))