# LogseqMarkdownParser
a simple python script to load a markdown file and easily access the properties of each block etc. You can also parse it as json, handy when using [jq](https://github.com/jqlang/jq). toml output is also supported. You can use it as a cli tol or as a python library.
# Notes to reader
* **Why make this?** I wanted a script that reads a Logseq page, extracts every "DONE" tasks and append it to another file. So I made this little parser. The resulting script can be found in `examples/done_mover.py`. If you need anything just create an issue.
* **How stable is it?** Probably okay, I use it for specific things so things might go south in edge cases. Please open an issue if you found a bug.
* Note that the github version might be more up to date than the PyPI version
* **Does it take into account the logbook (i.e. what's added to the block when clicking on 'DOING')?** I didn't think about that initially. I think it should be parsed as normal block content and not as a property.
* **What's the deal with properties?** page.page_properties is a python dict, you can edit it freely as it's only appended to the top of the page when exporting. But page.blocks[0].properties is an ImmutableDict because the properties are stored inside the text content using Logseq format. To edit a block property, use the `del_property` and `set_property` method.
## Features
* Implements classes `LogseqPage` and `LogseqBlock`
* read pages, page properties, block and block properties as a regular python dictionary
* easily save to a path as a Logseq-ready markdown file with `page.export_to`
* Static typing with [beartype](https://beartype.readthedocs.io/) if you have it installed (otherwise no typechecking).
* parse for the cli as json: `LogseqMarkdownParser some_file.md --out_format='json' |jq`
* parse for the cli as toml: `LogseqMarkdownParser some_file.md --out_format='toml' > output.toml`
* supports stdin: `cat some_file.md | LogseqMarkdownParser --out_format='json' | jq`
* shell completion: `eval "$(LogseqMarkdownParser -- --completion)"` or `eval "$(cat completion.zsh)"`
## How to
* Install with `python -m pip install LogseqMarkdownParser`
### Usage
``` python
import LogseqMarkdownParser
# loading:
# load file
page = LogseqMarkdownParser.parse_file(file_content, verbose=True)
# load a string
page = LogseqMarkdownParser.parse_text(content=my_string, verbose=True)
# load a string as page manually
page = LogseqMarkdownParser.LogseqPage(content=my_string, verbose=True)
# get page properties
page.page_properties
# access the blocks as a list
page.blocks
# get a block's properties
page.blocks[0].properties
# You can't edit them directly though, only page_properties can be directly edited at this time, see note below
# edit block properties
page.blocks[0].set_property(key, value)
page.blocks[0].del_property(key)
# inspect a page or block as a dict
page.dict() # this include the page properties, each block and their properties
page.blocks[0].dict()
# Save as Logseq ready md file
page.export_to("some/path.md")
# format as another format
print(page.format('json')) # also toml
```
Raw data
{
"_id": null,
"home_page": "https://github.com/thiswillbeyourgithub/LogseqMarkdownParser",
"name": "LogseqMarkdownParser",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "Logseq, PKM, Markdown, parsing, parser, properties, block, text",
"author": "thiswillbeyourgithub",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/28/32/cd49d6b4974abdd11bb7430399f632ffecda691d361226a9b13576e5e8f9/logseqmarkdownparser-3.1.tar.gz",
"platform": null,
"description": "# LogseqMarkdownParser\na simple python script to load a markdown file and easily access the properties of each block etc. You can also parse it as json, handy when using [jq](https://github.com/jqlang/jq). toml output is also supported. You can use it as a cli tol or as a python library.\n\n# Notes to reader\n* **Why make this?** I wanted a script that reads a Logseq page, extracts every \"DONE\" tasks and append it to another file. So I made this little parser. The resulting script can be found in `examples/done_mover.py`. If you need anything just create an issue.\n* **How stable is it?** Probably okay, I use it for specific things so things might go south in edge cases. Please open an issue if you found a bug.\n* Note that the github version might be more up to date than the PyPI version\n* **Does it take into account the logbook (i.e. what's added to the block when clicking on 'DOING')?** I didn't think about that initially. I think it should be parsed as normal block content and not as a property.\n* **What's the deal with properties?** page.page_properties is a python dict, you can edit it freely as it's only appended to the top of the page when exporting. But page.blocks[0].properties is an ImmutableDict because the properties are stored inside the text content using Logseq format. To edit a block property, use the `del_property` and `set_property` method.\n\n## Features\n* Implements classes `LogseqPage` and `LogseqBlock`\n* read pages, page properties, block and block properties as a regular python dictionary\n* easily save to a path as a Logseq-ready markdown file with `page.export_to`\n* Static typing with [beartype](https://beartype.readthedocs.io/) if you have it installed (otherwise no typechecking).\n* parse for the cli as json: `LogseqMarkdownParser some_file.md --out_format='json' |jq`\n* parse for the cli as toml: `LogseqMarkdownParser some_file.md --out_format='toml' > output.toml`\n* supports stdin: `cat some_file.md | LogseqMarkdownParser --out_format='json' | jq`\n* shell completion: `eval \"$(LogseqMarkdownParser -- --completion)\"` or `eval \"$(cat completion.zsh)\"`\n\n## How to\n* Install with `python -m pip install LogseqMarkdownParser`\n### Usage\n``` python\nimport LogseqMarkdownParser\n\n# loading:\n# load file\npage = LogseqMarkdownParser.parse_file(file_content, verbose=True)\n# load a string\npage = LogseqMarkdownParser.parse_text(content=my_string, verbose=True)\n# load a string as page manually\npage = LogseqMarkdownParser.LogseqPage(content=my_string, verbose=True)\n\n# get page properties\npage.page_properties\n\n# access the blocks as a list\npage.blocks\n\n# get a block's properties\npage.blocks[0].properties\n# You can't edit them directly though, only page_properties can be directly edited at this time, see note below\n\n# edit block properties\npage.blocks[0].set_property(key, value)\npage.blocks[0].del_property(key)\n\n# inspect a page or block as a dict\npage.dict() # this include the page properties, each block and their properties\npage.blocks[0].dict()\n\n# Save as Logseq ready md file\npage.export_to(\"some/path.md\")\n\n# format as another format\nprint(page.format('json')) # also toml\n```\n",
"bugtrack_url": null,
"license": null,
"summary": "parse logseq markdown text with easy access to properties, hierarchy, TODO etc",
"version": "3.1",
"project_urls": {
"Homepage": "https://github.com/thiswillbeyourgithub/LogseqMarkdownParser"
},
"split_keywords": [
"logseq",
" pkm",
" markdown",
" parsing",
" parser",
" properties",
" block",
" text"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "5bbb6733dc7e35f76c3c40ac5ecbe3ad410ca307feb0fa4065d5723e98576599",
"md5": "2d2b3776d55744fa969732743ec2ab01",
"sha256": "51b6f3b8d1df10cd69bc170aa763d77b44e02973558433612cc365acb0b84605"
},
"downloads": -1,
"filename": "LogseqMarkdownParser-3.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "2d2b3776d55744fa969732743ec2ab01",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 15278,
"upload_time": "2024-07-31T16:32:15",
"upload_time_iso_8601": "2024-07-31T16:32:15.013090Z",
"url": "https://files.pythonhosted.org/packages/5b/bb/6733dc7e35f76c3c40ac5ecbe3ad410ca307feb0fa4065d5723e98576599/LogseqMarkdownParser-3.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "2832cd49d6b4974abdd11bb7430399f632ffecda691d361226a9b13576e5e8f9",
"md5": "d965a286f8e8609a9545dc693a04ed6a",
"sha256": "42e3590f97cb184418d5c643c89298f1e8df91144730594e4784e2f022e29113"
},
"downloads": -1,
"filename": "logseqmarkdownparser-3.1.tar.gz",
"has_sig": false,
"md5_digest": "d965a286f8e8609a9545dc693a04ed6a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 15875,
"upload_time": "2024-07-31T16:32:16",
"upload_time_iso_8601": "2024-07-31T16:32:16.583418Z",
"url": "https://files.pythonhosted.org/packages/28/32/cd49d6b4974abdd11bb7430399f632ffecda691d361226a9b13576e5e8f9/logseqmarkdownparser-3.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-31 16:32:16",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "thiswillbeyourgithub",
"github_project": "LogseqMarkdownParser",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "logseqmarkdownparser"
}