A small package to markdownify Notion blocks.

Overview

markdownify-notion

PyPI Changelog License

A small package to markdownify notion blocks.

Installation

Install this library using pip:

$ pip install markdownify-notion

Usage

Usage instructions go here.

Development

To contribute to this library, first checkout the code. Then create a new virtual environment:

cd markdownify-notion
python -mvenv venv
source venv/bin/activate

Or if you are using pipenv:

pipenv shell

Now install the dependencies and test dependencies:

pip install -e '.[test]'

To run the tests:

pytest
Comments
  • Support fror code blocks

    Support fror code blocks

    Code blocks seem to be more or less the same as other, as I've been calling, "text-y" blocks. Except they include a "language" property after the list of rich text objects (still within the block[_type] property.

    {
      "type": "code",
      //...other keys excluded
      "code": {
        "text": [{
          "type": "text",
          "text": {
            "content": "const a = 3"
          }
        }],
        "language": "javascript"
      }
    }
    

    Option 1

    Maybe this is as simple as "enclosing" md_text by "```" and grabbing the "language"

    md_text = f"```{block[_type]['language']}\n{md_text}\n```"
    
    enhancement 
    opened by chekos 3
  • Support image blocks

    Support image blocks

    Image, video, and file blocks have the same structure

    {
      "type": "image",
      //...other keys excluded
      "image": {
        "type": "external",
        "external": {
            "url": "https://website.domain/images/image.png"
        }
      }
    }
    

    https://developers.notion.com/reference/block#image-blocks

    image blocks need to just produce ![Alt Text](url) markdown.

    File and Video blocks might end up as regular links.

    opened by chekos 1
  • Support `rich_text` rename from API v2022-02-22

    Support `rich_text` rename from API v2022-02-22

    Per changes https://developers.notion.com/changelog/releasing-notion-version-2022-02-22

    The text property in content blocks has been renamed to rich_text.

    opened by MrBretticus 0
  • Support lists

    Support lists

    Probably something like this

    if "bulleted_list" in _type:
            return “* “.join(_text_chunks)
    

    technically, numbered list could be just “1. “ and markdown automatically understands them as n + 1

    enhancement 
    opened by chekos 0
  • Code blocks have a space in the first line of actual code

    Code blocks have a space in the first line of actual code

    something like

    from rich import print
    print("hi")
    

    ends up like

     from rich import print
    print("hi")
    

    because the " ".join(_text_chunks)

    but just like we return on bookmarks we can return on the code blocks with "".join(_text_chunks)

    opened by chekos 0
  • Bookmarks should end in new line

    Bookmarks should end in new line

    If I'm putting a bookmark in Notion instead of a link I am expecting a new line. Bookmarks take a whole block in Notion so they clearly separate paragraph blocks in Notion. They should clearly separate paragraphs in markdown too.

    enhancement 
    opened by chekos 0
  • Cleaner way to handle bookmark blocks

    Cleaner way to handle bookmark blocks

    Right now (version 0.1) writes markdown links with Alt text as the text by default.

    A bookmark block looks like:

    {
      "type": "bookmark",
      //...other keys excluded
      "bookmark": {
        "caption": "",
        "url": "https://website.domain"
      }
    }
    

    markdownify_block() right now builds the markdown string as

    md_text = f"[Alt text]({_content['url']})"
    

    Version 0.1 was focused on paragraph and heading_* blocks mostly so this was overlooked.

    Option 1 (rejected)

    was to use a bookmark's caption as the Alt text. This would require that we add captions to all bookmarks which is not something that's commonplace.

    Option 2

    is to "clean" the URL and use that as the Alt text. For example, "https://github.com/stedolan/jq/issues/124#issuecomment-17875972" would become "github.com/stedolan/jq/issues/124".

    from urllib.parse import urlparse
    # ...
    _url = _content['url']
    _, netloc, path, *_  = urlparse(_url)
    md_text = f"[{netloc + path}]({_url})"
    

    This way we're not obfuscating the link's destination.

    Option 3 (maybe in the future)

    We could ping the URL and extract the page's title and/or other info. This option may be cool to implement down the line but not right now.

    enhancement 
    opened by chekos 0
  • Got this idea from chatgpt to use pypandoc

    Got this idea from chatgpt to use pypandoc

    The suggested code is

    import requests
    from bs4 import BeautifulSoup
    from pypandoc import convert_text
    
    # Replace with your own API key and page ID
    api_key = 'your_api_key'
    page_id = 'your_page_id'
    
    # Construct the API endpoint for retrieving the page
    endpoint = f'https://api.notion.com/v1/pages/{page_id}'
    
    # Send the GET request to the API and retrieve the page
    response = requests.get(endpoint, headers={
      'Authorization': f'Bearer {api_key}'
    })
    
    # Parse the page's properties from the API response
    properties = response.json()['properties']
    
    # Convert the page's contents to HTML
    html = BeautifulSoup(properties['rich_text']['rich_text'], 'html.parser').prettify()
    
    # Use pypandoc to convert the HTML to markdown
    markdown = convert_text(html, 'html', 'markdown')
    
    # Print the markdown to the console
    print(markdown)
    
    opened by chekos 0
  • Support equation blocks

    Support equation blocks

    These are pretty simple blocks, just equation which we can just wrap between $ for markdown support

    {
      "type": "equation",
      //...other keys excluded
      "equation": {
        
        "expression": "e=mc^2"
      }
    }
    
    opened by chekos 0
  • Support embed blocks

    Support embed blocks

    Seems that embed blocks have the same structure as bookmark blocks

    https://developers.notion.com/reference/block#embed-blocks

    Just need to add corresponding tests and change the if statement to == bookmark or embed

    opened by chekos 0
Releases(0.5)
  • 0.5(Oct 29, 2022)

    What's Changed

    • Add support for rich_text. Closes #10 by @chekos in https://github.com/chekos/markdownify-notion/pull/11

    New Contributors

    • @chekos made their first contribution in https://github.com/chekos/markdownify-notion/pull/11

    Full Changelog: https://github.com/chekos/markdownify-notion/compare/0.4...0.5

    Source code(tar.gz)
    Source code(zip)
  • 0.4(Aug 16, 2022)

    Adds support for lists #9. Bulleted lists like

    • one item
    • two items

    and numbered lists like

    1. this one
    2. and this one

    Full Changelog: https://github.com/chekos/markdownify-notion/compare/0.3...0.4

    Source code(tar.gz)
    Source code(zip)
  • 0.3(Feb 1, 2022)

  • 0.2.1(Jan 29, 2022)

  • 0.2(Jan 26, 2022)

    First minor release 🚀

    • Added support for code blocks (#2)
    • Better handling of bookmark blocks (#1)
      • Now links will be "cleaned" URLs instead of Alt text
      • For example, a bookmark to the URL https://github.com/chekos/markdownify-notion/issues/2#issuecomment-1022691136 will now produce the markdown [github.com/chekos/markdownify-notion/issues/2](https://github.com/chekos/markdownify-notion/issues/2#issuecomment-1022691136) instead of [Alt text](https://github.com/chekos/markdownify-notion/issues/2#issuecomment-1022691136)

    Full Changelog: https://github.com/chekos/markdownify-notion/compare/0.1...0.2

    Source code(tar.gz)
    Source code(zip)
  • 0.1(Jan 25, 2022)

    Initial release.

    • got a minimal markdownify_block() function working for heading_[123], paragraph and bookmark blocks. This works for the type of content i have in my tils so far.
    Source code(tar.gz)
    Source code(zip)
Owner
Sergio Sánchez Zavala
data visualization analyst. public policy wonk. Hip Hop head. tijuana, baja california, méxico -> san francisco bay area, ca, usa
Sergio Sánchez Zavala
Python wrapper for Coinex APIs

coinexpy - Python wrapper for Coinex APIs Through coinexpy you can simply buy or sell crypto in your Coinex account Features place limit order place m

Iman Mousaei 16 Jan 02, 2023
Python implementation for PetitPotam

PetitPotam Coerce NTLM authentication from Windows hosts Installtion $ pip3 install impacket Usage usage: petitpotam.py [-h] [-debug] [-port [destinat

Oliver Lyak 137 Dec 28, 2022
Typed interactions with the GitHub API v3

PyGitHub PyGitHub is a Python library to access the GitHub API v3 and Github Enterprise API v3. This library enables you to manage GitHub resources su

5.7k Jan 06, 2023
Repository to access information of stocks in Bombay Stock Exchange.

BSE Repository to access information of stocks in Bombay Stock Exchange. The code in this repository uses BSE API and conclusions made using the code

1 Nov 13, 2021
The elegance of Airflow + the power of AWS

Orkestra The elegance of Airflow + the power of AWS

Stephan Fitzpatrick 42 Nov 01, 2022
Posts word definitions on Twitter daily

Word Of The Day bot Post daily word definitions on social media. Twitter account: https://twitter.com/WordOfTheDay_B Introduction The goal of this pro

Lucas Rijllart 1 Jan 08, 2022
A community made discord bot coded in Python and running on AWS.

Pogbot Project Open Group Discord This is an open source community ran project. Join the discord for more information on how to participate. Coded in

Project Open Group 2 Jul 27, 2022
A Discord API Wrapper for Userbots/Selfbots written in Python.

DisCum A simple, easy to use, non-restrictive, synchronous Discord API Wrapper for Selfbots/Userbots written in Python. -using requests and websockets

Liam 450 Dec 27, 2022
Display relevant information for the amazing Banano coin.

Display relevant information for the amazing Banano coin. It'll also show your current [email 

Ron Talman 4 Aug 14, 2022
A pdisk uploader bot written in Python

Pdisk Uploader Bot 🔥 Upload on Pdisk by Url, File and also by direct forward post from other channel... Features Post to Post Conversion Url Upload D

Paritosh Kumar 33 Oct 21, 2022
Python library for the DeepL language translation API.

The DeepL API is a language translation API that allows other computer programs to send texts and documents to DeepL's servers and receive high-quality translations. This opens a whole universe of op

DeepL 535 Jan 04, 2023
Telegram 隨機色圖,支援每日自動爬取

Telegram 隨機色圖機器人 使用此原始碼的Bot 開放的隨機色圖機器人: @katonei_bot 已實現的功能 爬取每日R18排行榜 不夠色!再來一張 Tag 索引,指定Tag色圖 將爬取到的色圖轉為 WebP 格式儲存,節省空間 需要注意的事件 好久之前的怪東西,代碼質量不保證 請在使用A

cluckbird 15 Oct 18, 2021
Another Autoscaler is a Kubernetes controller that automatically starts, stops, or restarts pods from a deployment at a specified time using a cron annotation.

Another Autoscaler Another Autoscaler is a Kubernetes controller that automatically starts, stops, or restarts pods from a deployment at a specified t

Diego Najar 66 Nov 19, 2022
Discord group chat spammer concept.

GC Spammer [Concept] GC-Spammer for https://discord.com/ Warning: This is purely a concept. In the past the script worked, however, Discord ratelimite

Roover 3 Feb 28, 2022
The simple way of using Imgur.

PyImgur The simple way of using Imgur. You can upload images, download images, read comments, update your albums, message people and more. In fact, yo

Andreas Damgaard Pedersen 120 Dec 06, 2022
A modular Telegram Python bot running on python3 with a sqlalchemy database.

Nao Tomori Robot Found Me On Telegram As Nao Tomori 🌼 A modular Telegram Python bot running on python3 with a sqlalchemy database. How to setup/deplo

Stinkyproject 1 Nov 24, 2021
• Create Your Own YouTube Info Api.

youtube_data_api • Create Your Own YouTube Info Api. Deploy How to Use https://{ Heroku App Name }.herokuapp.com/api?link={YouTube link} In local Host

lokaman chendekar 12 Oct 02, 2022
Ts-matterbridge - Integrate TeamSpeak Chat with MatterBridge

TeamSpeak-MatterBridge Bot You can use this bot to integrate TeamSpeak Chat with

4 Sep 25, 2022
🦈 Blahaj is a discord bot that shares random images of himself on discord.

🦈 Blahaj Bot Blahaj is a discord bot that shares random images of himself on discord. ⚙️ Developer's Guide To use the bot, follow along the steps Hea

Atul Anand 3 Oct 21, 2022
Monitor robot of Apple Store's products, using DingTalk notification.

概述 本项目应用主要用来监测Apple Store线下直营店货源情况,主要使用Python实现。 首先感谢iPhone-Pickup-Monitor项目带来的灵感,同时有些实现也直接使用了该项目的一些代码。 本项目在iPhone-Pickup-Monitor原有功能的基础上去掉了声音通知,但添加了多

Lennon Chin 159 Dec 09, 2022