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
Primeira etapa do processo seletivo para a bolsa de migração de conteúdo de Design de Software.

- Este processo já foi concluído. Obrigado pelo seu interesse! Processo Seletivo para a bolsa de migração de conteúdo de Design de Software Primeirame

Toshi Kurauchi 1 Feb 21, 2022
A Telegram bot that add a dynamic caption to musics

Music Channel Manager A Telegram bot that add a dynamic caption to musics Deploy to Heroku What is it ? It manage your music channel. With just adding

13 Oct 18, 2022
471 Dec 24, 2022
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
Me and @nathanmargni did a small analysis on what are the best strategies to win more games of League of Legends.

Me and @nathanmargni did a small analysis on what are the best strategies to win more games of League of Legends.

Christian Berchtold 2 Jan 19, 2022
The Foursquare API client for Python

foursquare Python client for the foursquare API. Philosophy: Map foursquare's endpoints one-to-one Clean, simple, Pythonic calls Only handle raw data,

Mike Lewis 400 Dec 19, 2022
Asynchronous wrapper for wttr.in weather forecast.

aiopywttr Asynchronous wrapper for wttr.in weather forecast. Synchronous version here. Installation pip install aiopywttr Example This example prints

Almaz 4 Dec 24, 2022
GitHub action to deploy serverless functions to YandexCloud

YandexCloud serverless function deploy action Deploy new serverless function version (including function creation if it does not exist). Inputs yc_acc

Много Лосося 4 Apr 10, 2022
Ma2tl - macOS forensic timeline generator using the analysis result DBs of mac apt

ma2tl (mac_apt to timeline) This is a DFIR tool for generating a macOS forensic

Minoru Kobayashi 66 Nov 18, 2022
Secret messaging app which you can use to communicate with your friends by encrypting / decrypting secret messages or sending secret message through mail.

Secret-Whisper A Secret messaging app which you can use to communicate with your friends by encrypting / decrypting secret messages 🤫 or sending secr

3 Jan 01, 2022
A Discord bot made by QwertyIsCoding

QwertyBot QwertyBot A Discord bot made by QwertyIsCoding Explore the docs » View Demo . Report Bug . Request Feature About The Project This Discord bo

4 Oct 08, 2022
EthSema - Binary translator for Ethereum 2.0

EthSema is a novel EVM-to-eWASM bytecode translator that can not only ensure the fidelity of translation but also fix commonly-seen vulnerabilities in smart contracts.

weimin 8 Mar 01, 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
One destination for all the developer's learning resources.

DevResources One destination for all the developer's learning resources. Find all of your learning resources under one roof and add your own. Live ✨ Y

Gaurav Sharma 33 Oct 21, 2022
PepeSniper is an open-source Discord Nitro auto claimer/redeemer made in python.

PepeSniper is an open-source Discord Nitro auto claimer made in python. It sure as hell is not the fastest sniper out there but it gets the job done in a timely and stable manner. It also supports ho

Unknown User 1 Dec 22, 2021
Public API client for GETTR, a "non-bias [sic] social network," designed for data archival and analysis.

GoGettr GoGettr is an API client for GETTR, a "non-bias [sic] social network." (We will not reward their domain with a hyperlink.) GoGettr is built an

Stanford Internet Observatory 72 Dec 14, 2022
Telegram Link Wayback Bot. This bot archives a web page thrown at itself with wayback Machine (Archive.org).

Telegram Link Wayback Bot. This bot archives a web page thrown at itself with wayback Machine (Archive.org).

Hüzünlü Artemis [HuzunluArtemis] 11 Feb 18, 2022
A simple bot discord in PY with moderation controls

Voila un bot discord en py avec les commandes simples de modération tout simplement faut changer les lignes 70 vous mettez votre token de votre bot 53

Ethan 1 Nov 20, 2021
Modified Version Of Media Search bot

Modified Version Of Media Search bot

1 Oct 09, 2021
Fetch fund data from avanza.se using Python and some web scraping with bs4

Py(A)vanza Fetch fund data from avanza.se using Python and some web scraping with bs4. The default way is to display the data in the terminal, apply -

dunderrrrrr 1 Jan 27, 2022