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
Notion4ever - Python tool for export all your content of Notion page using official Notion API

NOTION4EVER Notion4ever is a small python tool that allows you to free your cont

null 50 Dec 30, 2022
A small repository with convenience functions for working with the Notion API.

Welcome! Within this respository are a few convenience functions to assist with the pulling and pushing of data from the Notion API.

null 10 Jul 9, 2022
A small Python app to create Notion pages from Jira issues

Jira to Notion This little program will capture a Jira issue and create a corresponding Notion subpage. Mac users can fetch the current issue from the

Dr. Kerem Koseoglu 12 Oct 27, 2022
Unofficial Python API client for Notion.so

notion-py Unofficial Python 3 client for Notion.so API v3. Object-oriented interface (mapping database tables to Python classes/attributes) Automatic

Jamie Alexandre 3.9k Jan 3, 2023
A way to export your saved reddit posts to a Notion table.

reddit-saved-to-notion A way to export your saved reddit posts and comments to a Notion table.Uses notion-sdk-py and praw for interacting with Notion

null 19 Sep 12, 2022
Import Notion Tasks to

Notion-to-Google-Calendar (1 way) Import Notion Tasks to Google Calendar NO MORE UPDATES WILL BE MADE TO THIS REPO. Attention has been put on a 2-way

null 12 Aug 11, 2022
Notion API Database Python Implementation

Python Notion Database Notion API Database Python Implementation created only by database from the official Notion API. Installing / Getting started p

minwook 78 Dec 19, 2022
A simple object model for the Notion SDK.

A simplified object model for the Notion SDK. This is loosely modeled after concepts found in SQLAlchemy.

Jason Heddings 54 Jan 2, 2023
Token-gate Notion pages

This is a Next.js project bootstrapped with create-next-app. Getting Started First, run the development server: npm run dev # or yarn dev Open http://

John 8 Oct 13, 2022
Python 3 tools for interacting with Notion API

NotionDB Python 3 tools for interacting with Notion API: API client Relational database wrapper Installation pip install notiondb API client from noti

Viet Hoang 14 Nov 24, 2022
A script to automate the process of downloading Markdown and CSV backups of Notion

Automatic-Notion-Backup A script to automate the process of downloading Markdown and CSV backups of Notion. In addition, the data is processed to remo

Jorge Manuel Lozano Gómez 2 Nov 2, 2022
Discord RPC for Notion written in Python

Discord RPC for Notion This is a program that allows you to add your Notion workspace activities to your Discord profile. This project is currently un

Thuliumitation 1 Feb 10, 2022
Notflix - Notion / Netflix and IMDb to organise your movie dates. Happy Valentine <3 from 0x1za

Welcome to notflix ?? This is a project to help organise shows to watch with my

Mwiza Ed' Simbeye 3 Feb 15, 2022
Aws-cidr-finder - A Python CLI tool for finding unused CIDR blocks in AWS VPCs

aws-cidr-finder Overview An Example Installation Configuration Contributing Over

Cooper Walbrun 18 Jul 31, 2022
One version package to rule them all, One version package to find them, One version package to bring them all, and in the darkness bind them.

AwesomeVersion One version package to rule them all, One version package to find them, One version package to bring them all, and in the darkness bind

Joakim Sørensen 39 Dec 31, 2022
This is a small package to interact with the OpenLigaDB API.

OpenLigaDB This is a small package to interact with the OpenLigaDB API. Installation Run the following to install: pip install openligadb Usage from o

null 1 Dec 31, 2021
Python Package For MTN Zambia Momo API. This package can also be used by MTN momo in other countries.

MTN MoMo API Lite Python Client Power your apps with Lite-Python MTN MoMo API Usage Installation Add the latest version of the library to your project

Mathews Musukuma 7 Jan 1, 2023
A small script to migrate or synchronize users & groups from Okta to AWS SSO

aws-sso-sync-okta A small script to migrate or synchronize users & groups from Okta to AWS SSO Changelog Version Remove hardcoded values on variables

Paul 4 Feb 11, 2022
A small discord bot to interface with python-discord's snekbox.

A small discord bot to interface with python-discord's snekbox.

Hassan Abouelela 0 Oct 5, 2021