Skip to main content

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

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

Release files for LogseqMarkdownParser 3.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for LogseqMarkdownParser 3.3
File Size Uploaded
logseqmarkdownparser-3.3.tar.gz 21.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for LogseqMarkdownParser 3.3
File Interpreter ABI Platform
LogseqMarkdownParser-3.3-py3-none-any.whl Python 3 none any Details

Total release size: 45.5 kB

Release files / logseqmarkdownparser-3.3.tar.gz

Download URL logseqmarkdownparser-3.3.tar.gz
Size 21.8 kB
Tags Source
SHA-256 checksum
How to use checksums
31546115334ea79d4a2f84a41c27250c66b09f826e0bfc792630824fb0e3e07b
BLAKE2b-256 checksum
How to use checksums
bff34277780d2f77409021b7d7a58c6463888fc6b46f57cf0229170d4cecb708
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.20

Release files / LogseqMarkdownParser-3.3-py3-none-any.whl

Download URL LogseqMarkdownParser-3.3-py3-none-any.whl
Size 23.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
eb9b9b6fcd9365b15280f7723b7ea5b48fff642a33dfcf3883c8f5dcc2fc46eb
BLAKE2b-256 checksum
How to use checksums
536e3f40d7c86ef8da5967d9d5c8428a4e8aff8148de30db5fcb842c67225e92
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.20

Release history Release notifications | RSS feed

This release

3.3 This release

2 release files

3.1

2 release files

3.0

2 release files

2.14

2 release files

2.13

2 release files

2.12

2 release files

2.10

2 release files

2.8

2 release files

2.7

2 release files

2.6

2 release files

2.5

2 release files

2.4

2 release files

2.3

2 release files

2.2

2 release files

2.1

2 release files

1.4

2 release files

1.3

2 release files

1.2

2 release files

1.0

2 release files

0.9

2 release files

0.8

2 release files

0.7

2 release files

0.6

2 release files

0.5

2 release files

0.4

2 release files

0.2

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page