Coder Social home page Coder Social logo

notion_to_md's Introduction

notion_to_md

Notion Markdown Exporter in Ruby.

Installation

Use gem to install.

$ gem install 'notion_to_md'

Or add it to the Gemfile.

# Gemfile
gem 'notion_to_md'

Usage

Before using the gem create an integration and generate a secret token. Check notion getting started guide to learn more.

Pass the page id and secret token to the constructor and execute the convert method.

require 'notion_to_md'

notion_converter = NotionToMd::Converter.new(page_id: 'b91d5...', token: 'secret_...')
md = notion_converter.convert

If the secret token is provided as an environment variable โ€”NOTION_TOKENโ€”, there's no need to pass it as an argument to the constructor.

$ export NOTION_TOKEN=<secret_...>
require 'notion_to_md'

notion_converter = NotionToMd::Converter.new(page_id: 'b91d5...')
md = notion_converter.convert

And that's all. The md is a string variable containing the notion page formatted in markdown.

Blocks

Everything in a notion page body is a block object. Therefore, not every type can be mapped to Markdown. Below there's a list of current supported blocks types.

  • paragraph
  • heading_1
  • heading_2
  • heading_3
  • bulleted_list_item
  • numbered_list_item as bulleted_list_item
  • to_do
  • image
  • bookmark
  • callout
  • quote
  • divider
  • table
  • embed
  • code

Nested blocks

Starting with v2, nested blocks are supported. The permitted blocks to have children are:

  • paragraph
  • bulleted_list_item
  • numbered_list_item
  • to_do

Front matter

From version 0.2.0, notion_to_md supports front matter in markdown files.

By default, the front matter section is not included to the document. To do so, provide the :frontmatter option set to true to convert method.

NotionToMd::Converter.new(page_id: 'b91d5...').convert(frontmatter: tue)

Default notion properties are page id, title, created_time, last_edited_time, icon, archived and cover.

---
id: e42383cd-4975-4897-b967-ce453760499f
title: An amazing post
cover: https://img.bank.sh/an_image.jpg
created_time: 2022-01-23T12:31:00.000Z
last_edited_time: 2022-01-23T12:31:00.000Z
icon: ๐Ÿ’ฅ
archived: false
---

In addition to default properties, custom properties are also supported. Custom properties name is parameterized and underscorized before added to front matter. For example, two properties named Multiple Options and Tags will be transformed to multiple_options and tags, respectively.

---
tags: tag1, tag2, tag3
multiple_options: option1, option2
---

The supported property types are:

  • number
  • select
  • multi_select
  • date
  • people
  • files
  • checkbox
  • url
  • email
  • phone_number
  • rich_text, supported but in plain text

Advanced types like formula, relation and rollup are not supported.

Check notion documentation about property values to know more.

Test

rspec

notion_to_md's People

Contributors

emoriarty avatar renovate[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.