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
Spacecrypto-bombcrypto-bot - SpaceCrypto And Bombcrypto Bot - MultiScreen

SpaceCrypto And Bombcrypto Bot - MultiScreen This is a open source project inspi

Paulo Bramante 5 Nov 03, 2022
Docker image for epicseven gvg qq chatbot based on Xunbot

XUN_Langskip XUN 是一个基于 NoneBot 和 酷Q 的功能型QQ机器人,目前提供了音乐点播、音乐推荐、天气查询、RSSHub订阅、使用帮助、识图、识番、搜番、上车、磁力搜索、地震速报、计算、日语词典、翻译、自我检查,权限等级功能,由于是为了完成自己在群里的承诺,一时兴起才做的,所

Xavier Xiong 2 Jun 08, 2022
A simple discord bot that generates facts!

fact-bot A simple discord bot that generates facts! How to make a bot Go to https://discord.com/developers/applications Then click on 'New Application

1 Jan 05, 2022
A simple script that will watch a stream for you and earn the channel points.

Credits Main idea: https://github.com/gottagofaster236/Twitch-Channel-Points-Miner Bet system (Selenium): https://github.com/ClementRoyer/TwitchAutoCo

Alessandro Maggio 1.1k Jan 08, 2023
The Official Dropbox API V2 SDK for Python

The offical Dropbox SDK for Python. Documentation can be found on Read The Docs. Installation Create an app via the Developer Console. Install via pip

Dropbox 828 Jan 05, 2023
Clash of Clans developer unofficial api Wrapper to generate ip based token

Clash of Clans developer unofficial api Wrapper to generate ip based token

Aryan Vikash 6 Apr 01, 2022
Discord E-Store Bot

A delivery bot for Discord, works like Amazon where real users can pack & deliver orders in different servers!

Amit Pathak 2 Jan 28, 2022
A simple bot that looks for names and cpfs in the vaccination list made available by the government Fortaleza - CE

A simple bot that looks for names and cpfs in the vaccination list made available by the government Fortaleza - CE

Breno Aquino 1 Dec 21, 2021
Automatic SystemVerilog linting in github actions with the help of Verible

Verible Lint Action Usage See action.yml This is a GitHub Action used to lint Verilog and SystemVerilog source files and comment erroneous lines of co

CHIPS Alliance 10 Dec 26, 2022
A listener for RF >= 4.0 that prints a Stack Trace to console to faster find the code section where the failure appears.

robotframework-stacktrace A listener for RF = 4.0 that prints a Stack Trace to console to faster find the code section where the failure appears. Ins

marketsquare 16 Nov 24, 2022
QR-Code-Grabber - A python script that allows a person to create a qr code token grabber

Qr Code Grabber Description Un script python qui permet a une personne de creer

5 Jun 28, 2022
The Bot provide Hadith API and fetch content via api.hadith.sutanlab.id

Bot Hadith-API on Telegram The Bot provide Hadith API and fetch content via api.hadith.sutanlab.id Built With Python Asynchronous HTTP protocol client

xMan 12 Feb 19, 2022
A simple library for interacting with Amazon S3.

BucketStore is a very simple Amazon S3 client, written in Python. It aims to be much more straight-forward to use than boto3, and specializes only in

Jacobi Petrucciani 219 Oct 03, 2022
Retrieve information from DBLP and update BibTex files automatically

Rebib TLDR: This script retrieves information from DBLP to update your BibTex files. python rebib.py --bibfile xxx.bib It first parses the bib entries

Shangtong Zhang 49 Jan 01, 2023
Video Stream is a telegram bot project that's allow you to play video on telegram group video chat

Video Stream is a telegram bot project that's allow you to play video on telegram group video chat 🚀 Get SESSION_NAME from below: Pyrogram ## ✨ Featu

1 Nov 10, 2021
QR login for pyrogram client

Generate Pyrogram session via QRlogin

ポキ 18 Oct 21, 2022
💬 Send iMessages using Python through the Shortcuts app.

py-imessage-shortcuts Send iMessages using Python through the Shortcuts app. Requires macOS Monterey (macOS 12) or later. Compatible with Apple Silico

Kevin Schaich 10 Nov 30, 2022
Fastest Tiktok Username checker on site.

Tiktok Username Checker Fastest Tiktok Username checker on site

sql 3 Jun 19, 2021
A Telegram Bot written in Python for mirroring files on the Internet to Google Drive

No support is going to be provided of any kind, only maintaining this for vps user on request. This is a Telegram Bot written in Python for mirroring

0 Dec 26, 2021
Automatically copy the Discord Status of a Friend you share a server with (conditions have to be satisfied to work)

CopyDiscordStatusOfUser-SelfBot Basic Function Automatically copy the Discord Status of a friend User whom you share a server with (These conditions h

Certified Baller 5 Aug 05, 2022