Closed haakonstorm closed 4 years ago
Woops, forgot about this one.
Are you looking to support some sort of custom Markdown > Toggle Block conversion or would you like to handle it in the script?
I can give some code snippets the next time I loop back to this
Anything goes!
What would be awesome would be somehow to use md2notion
as a CLI interface to Notion. My daemonized script is trying to parse what the user is doing, and decide when the activity changed context. Continously logging to inside a temporarily named, open, "toggle", and then upon changing context, somehow retroactively changing the text in the toggle block itself, then closing the toggle block and opening a new. As in opening and closing chapters in a book, that's the idea.
Probably the easiest way to get a ToggleBlock
into Notion through this script, it'd be easiest to just post-process the output of convert()
and change one of the blocks into a ToggleBlock
.
from md2notion.upload import convert, uploadBlock
from notion.block import ToggleBlock
rendered = convert(mdFile)
# Example output for rendered:
# [ {'title': 'test', 'type': <class 'notion.block.TextBlock'>},
# {'title': 'this is a test', 'type': <class 'notion.block.TextBlock'>},
# { 'title': 'this is a really big test. How big? pretty big but I bet you '
# "didn't see it coming. It's not "
# '[here](https://example.com)...',
# 'type': <class 'notion.block.TextBlock'>},
# { 'children': [],
# 'title': "It's here",
# 'type': <class 'notion.block.BulletedListBlock'>},
# { 'children': [],
# 'title': 'Or here',
# 'type': <class 'notion.block.BulletedListBlock'>},
# { 'children': [],
# 'title': 'or maybe here',
# 'type': <class 'notion.block.BulletedListBlock'>}]
# Just change the class of one of the blocks to a `ToggleBlock`
rendered[0]['type'] = notion.block.ToggleBlock
# Upload all the blocks
for blockDescriptor in rendered:
uploadBlock(blockDescriptor, page, mdFile.name)
Personally, I would just use notion-py directly for that though, especially if you want to be able to open and close the Toggle blocks. It has a more rich feature set than this library.
Hi Cobertos and thanks for
md2notion
! As I don't know Python well enough to usenotion-py
, I piggybacked on your skills and wrote a quickzsh
wrapper around this script, so I can useNotion
as a place to dump various system logs. Basically I take whatever comes onstdin
, dumps that to file and hands it tomd2notion
who does a great job. However, I'd love for somehow to be able to add "toggle" Blocks in Notion. You know the ones that start with>
in Notion, but isn't a QuoteBlock? Possible somehow?