Access the properties within Markdown files

ankitg121 pts0 comments

GitHub - thiswillbeyourgithub/LogseqMarkdownParser: simple python script to load a markdown file and easily access the properties of each block etc. · GitHub

/" data-turbo-transient="true" />

Skip to content

Search or jump to...

Search code, repositories, users, issues, pull requests...

-->

Search

Clear

Search syntax tips

Provide feedback

--><br>We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Cancel

Submit feedback

Saved searches

Use saved searches to filter your results more quickly

-->

Name

Query

To see all available qualifiers, see our documentation.

Cancel

Create saved search

Sign in

/;ref_cta:Sign up;ref_loc:header logged out"}"<br>Sign up

Appearance settings

Resetting focus

You signed in with another tab or window. Reload to refresh your session.<br>You signed out in another tab or window. Reload to refresh your session.<br>You switched accounts on another tab or window. Reload to refresh your session.

Dismiss alert

{{ message }}

thiswillbeyourgithub

LogseqMarkdownParser

Public

Notifications<br>You must be signed in to change notification settings

Fork

Star<br>11

main

BranchesTags

Go to file

CodeOpen more actions menu

Folders and files<br>NameNameLast commit message<br>Last commit date<br>Latest commit

History<br>362 Commits<br>362 Commits

LogseqMarkdownParser

LogseqMarkdownParser

examples

examples

.gitignore

.gitignore

LICENSE

LICENSE

README.md

README.md

bumpver.toml

bumpver.toml

completion.zsh

completion.zsh

setup.py

setup.py

View all files

Repository files navigation

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. 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 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

Here's an example that use LogseqMarkdownParser:

https://github.com/thiswillbeyourgithub/wdoc/tree/main/scripts/TheFiche

https://github.com/thiswillbeyourgithub/MdXLogseqTODOSync

If you do use it, tell me so that I can link it here!

Here's a script example:

import LogseqMarkdownParser

# loading:<br># load file<br>page = LogseqMarkdownParser.parse_file(file_content, verbose=True)<br># load a string<br>page = LogseqMarkdownParser.parse_text(content=my_string, verbose=True)<br># load a string as page manually<br>page = LogseqMarkdownParser.LogseqPage(content=my_string, verbose=True)

# get page properties<br>page.page_properties

# access the blocks as a list<br>page.blocks

# get a block's properties<br>page.blocks[0].properties<br># You can't edit them directly though, only page_properties can be directly edited at this time, see note below

# edit block properties<br>page.blocks[0].set_property(key, value)<br>page.blocks[0].del_property(key)

# inspect a page or block as a dict<br>page.dict() # this include the page properties, each block and their properties<br>page.blocks[0].dict()

# Save as Logseq ready md file<br>page.export_to("some/path.md")

# format as another format<br>print(page.format('json')) # also toml

About

simple python script to load a markdown file and easily access the properties of each block etc.

Resources

Readme

License

AGPL-3.0 license

Uh...

page properties logseqmarkdownparser block file python

Related Articles