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
Use CSV files as a Nornir Inventory source with hosts, groups and defaults.

nornir_csv Use CSV files as a Nornir Inventory source with hosts, groups and defaults. This can be used as an equivalent to the Simple Inventory plugi

Matheus Augusto da Silva 2 Aug 13, 2022
Simple Discord bot which logs several events in your server

logging-bot Simple Discord bot which logs several events in your server, including: Message Edits Message Deletes Role Adds Role Removes Member joins

1 Feb 14, 2022
A telegram bot for generate fake details. Written in python using telethon

FakeDataGenerator A telegram bot for generate fake details. Written in python using telethon. Mandatory variables API_HASH Get it from my telegram.org

Oxidised-Man 6 Dec 19, 2021
A mass creator for Discord's new channel threads.

discord-thread-flooder A mass creator for Discord's new channel threads. (obv created by https://github.com/imvast) Warning: this may lag ur pc if u h

Vast 6 Nov 04, 2022
Python client for QIWI payment system

Pyqiwi Lib for QIWI payment system Installation pip install pyqiwi Usage from decimal import Decimal from datetime import datetime, timedelta from p

Andrey 12 Jun 03, 2022
Plugin for Sentry which allows sending notification via Telegram messenger.

Sentry Telegram Plugin for Sentry which allows sending notification via Telegram messenger. Presented plugin tested with Sentry from 8.9 to 9.1.1. DIS

Shmele 208 Dec 30, 2022
Injector/automatic translator (using deepL API) for Tsukihime Remake

deepLuna Extractor/Editor/Translator/Injector for Tsukihime Remake About deepLuna, from "deepL", the machine translation service, and "Luna", the name

30 Dec 15, 2022
OSINT tool to get information from a Github and Gitlab profile and find user's email addresses leaked on commits.

gitrecon OSINT tool to get information from a Github or Gitlab profile and find user's email addresses leaked on commits. 📚 How does this work? GitHu

GOΠZO 211 Dec 17, 2022
An opensource chat service that cares about your privacy.

An opensource chat service that cares about your privacy. Instructions to set up a local testing environment: 1) Clone this repository and navigate to

Aiman Al Masoud 2 Dec 03, 2022
Jackrabbit Relay is an API endpoint for stock, forex and cryptocurrency exchanges that accept REST webhooks.

JackrabbitRelay Jackrabbit Relay is an API endpoint for stock, forex and cryptocurrency exchanges that accept REST webhooks. Disclaimer Please note RA

Rose Heart 23 Jan 04, 2023
A repo-watcher to watch for commits on a repo an trigger GitHub action by sending a `repository_dispatch` event to destinantion repo

repo-watcher-dispatch-sender This app is used to send a repository_dispatch event to the destination repo set in config.py or Environmental Variables

Divide Projects™ 2 Feb 06, 2022
A bot to get Statistics like the Playercount from your Minecraft-Server on your Discord-Server

Hey Thanks for reading me. Warning: My English is not the best I have programmed this bot to show me statistics about the player numbers and ping of m

spaffel 12 Sep 24, 2022
Bomber-X - A SMS Bomber made with Python

Bomber-X A SMS Bomber made with Python Linux/Termux apt update apt upgrade apt i

S M Shahriar Zarir 2 Mar 10, 2022
Evernote SDK for Python

Evernote SDK for Python Evernote API version 1.28 This SDK is intended for use with Python 2.X For Evernote's beta Python 3 SDK see https://github.com

Evernote 612 Dec 30, 2022
A updated and improved version from the original Discord-Netflix from Nirewen.

Discord-Netflix A updated version from the original Discord-Netflix from nirewen A Netflix wrapper that uses Discord RPC to show what you're watching

Void 42 Jan 02, 2023
A Python wrapper for the tesseract-ocr API

tesserocr A simple, Pillow-friendly, wrapper around the tesseract-ocr API for Optical Character Recognition (OCR). tesserocr integrates directly with

Fayez 1.7k Jan 03, 2023
NewpaperNews-API - Json data of the news with python

NewsAPI API Documentation BASE_URL = "https://saurav.tech/NewsAPI/" top_headline

Aryaman Prakash 2 Sep 23, 2022
New developed moderation discord bot by archisha

Monitor42 New developed moderation discord bot by αrchιshα#5518. Details Prefix: 42! Commands: Moderation Use 42!help to get command list. Invite http

Kamilla Youver 0 Jun 29, 2022
un outil pour bypasser les code d'états HTTP négatif coté client ( 4xx )

4xxBypasser un outil pour bypasser les code d'états HTTP négatif coté client ( 4xx ) Liscence : MIT license Creator Installation : git clone https://g

21 Dec 25, 2022
Moon-TikTok-Checker - A TikTok Username checking tool that probably 3/4 people use to get rare usernames

Moon Checker (educational Purposes Only) What Is Moon Checker? This is a TikTok

glide 4 Nov 30, 2022