All Projects → Cobertos → Md2notion

Cobertos / Md2notion

Licence: mit
A better Notion.so Markdown importer

Programming Languages

python
139335 projects - #7 most used programming language
python3
1442 projects

Labels

Projects that are alternatives of or similar to Md2notion

Dat Medium
P2P Markdown Blog for Beaker inspired by Medium.
Stars: ✭ 225 (-3.43%)
Mutual labels:  markdown
Cuimage
cuImage - 图床利器
Stars: ✭ 227 (-2.58%)
Mutual labels:  markdown
Spongedown
Markdown with svg bob support
Stars: ✭ 234 (+0.43%)
Mutual labels:  markdown
Github Profilinator
🚀 This tool contains mini GUI components that you can hook together to automatically generate markdown code for a perfect readme.
Stars: ✭ 225 (-3.43%)
Mutual labels:  markdown
Tint
Tint is not Tufte
Stars: ✭ 226 (-3%)
Mutual labels:  markdown
Gotenberg
A Docker-powered stateless API for PDF files.
Stars: ✭ 3,272 (+1304.29%)
Mutual labels:  markdown
Resume.md
Write your resume in Markdown, style it with CSS, output to HTML and PDF
Stars: ✭ 222 (-4.72%)
Mutual labels:  markdown
Life
Life - a timeline of important events in my life
Stars: ✭ 2,627 (+1027.47%)
Mutual labels:  markdown
Mysql markdown
It can generate markdown structure documents of MySQL succinctly~
Stars: ✭ 227 (-2.58%)
Mutual labels:  markdown
M2r
Markdown to reStructuredText converter
Stars: ✭ 232 (-0.43%)
Mutual labels:  markdown
Lute
🎼 一款对中文语境优化的 Markdown 引擎,支持 Go 和 JavaScript。A structured Markdown engine that supports Go and JavaScript.
Stars: ✭ 222 (-4.72%)
Mutual labels:  markdown
Marp Core
The core of Marp converter
Stars: ✭ 224 (-3.86%)
Mutual labels:  markdown
Frontmatter Markdown Loader
📝 Webpack Loader for: FrontMatter (.md) -> HTML + Attributes (+ React/Vue Component)
Stars: ✭ 228 (-2.15%)
Mutual labels:  markdown
Yosoro
🍧Beautiful Markdown NoteBook. 🏖
Stars: ✭ 2,595 (+1013.73%)
Mutual labels:  markdown
Markdown Tutorial
A comprehensive guide to Markdown / Introduction to Markdown
Stars: ✭ 231 (-0.86%)
Mutual labels:  markdown
Go Termd
Package termd provides terminal markdown rendering, with code block syntax highlighting support.
Stars: ✭ 223 (-4.29%)
Mutual labels:  markdown
Markdown
Markdown 基本语法。
Stars: ✭ 2,841 (+1119.31%)
Mutual labels:  markdown
Emacs Easy Hugo
Emacs major mode for managing hugo
Stars: ✭ 235 (+0.86%)
Mutual labels:  markdown
Tms
基于频道模式的团队沟通协作+轻量级任务看板,支持mardown、富文本、在线表格和思维导图的团队博文wiki,i18n国际化翻译管理的响应式web开源团队协作系统。
Stars: ✭ 232 (-0.43%)
Mutual labels:  markdown
Cwac Anddown
CWAC AndDown: Markdown Utility Library
Stars: ✭ 230 (-1.29%)
Mutual labels:  markdown

build status pypi python versions twitter twitter

Notion.so Markdown Importer

An importer for Markdown files to Notion.so using notion-py

It provides these features over Notion.so's Markdown importer:

  • Picking a Notion.so page to upload to (instead of them all uploading to the root)
  • Code fences keep their original language (or as close as we can match it)
  • Code fences are formatted properly
  • Inline HTML is preserved
  • (Optionally) Upload images that are memtioned in the HTML <img> tags.
  • Markdown frontmatter is preserved
  • Local image references will be uploaded from relative URLs
  • Image alts are loaded as captions instead of as TextBlocks
  • Handles nested lists properly
  • Among other improvements...

Supports Python 3.6+

Usage from CLI

  • pip install md2notion
  • Then run like python -m md2notion [token_v2] [page-url] [...markdown_path_glob_or_url]
  • The markdown at the given path will be added as a new child to the Notion.so note at page-url

There are also some configuration options:

  • --clear-previous: If a child of the note at page-url has the same name as what you're uploading, it will first be removed.
  • --append: Instead of making a new child, it will append the markdown contents to the note at page-url
  • --html-img: Upload images that are memtioned in the HTML <img> tags.

Usage from script

  • pip install md2notion
  • In your Python file:
from notion.client import NotionClient
from notion.block import PageBlock
from md2notion.upload import upload

# Follow the instructions at https://github.com/jamalex/notion-py#quickstart to setup Notion.py
client = NotionClient(token_v2="<token_v2>")
page = client.get_block("https://www.notion.so/myorg/Test-c0d20a71c0944985ae96e661ccc99821")

with open("TestMarkdown.md", "r", encoding="utf-8") as mdFile:
    newPage = page.children.add_new(PageBlock, title="TestMarkdown Upload")
    upload(mdFile, newPage) #Appends the converted contents of TestMarkdown.md to newPage

If you need to process notion-py block descriptors after parsing from Markdown but before uploading, consider using convert and uploadBlock separately. Take a look at upload.py#upload() for more.

from md2notion.upload import convert, uploadBlock

rendered = convert(mdFile)

# Process the rendered array of `notion-py` block descriptors here
# (just dicts with some properties to pass to `notion-py`)

# Upload all the blocks
for blockDescriptor in rendered:
    uploadBlock(blockDescriptor, page, mdFile.name)

If you need to parse Markdown differently from the default, consider subclassing NotionPyRenderer (a BaseRenderer for mistletoe). You can then pass it to upload(..., notionPyRendererCls=NotionPyRenderer) as a parameter.

Example, Custom Hexo Importer

Here's an example that imports a Hexo blog (slghtly hacky).

import io
import os.path
import glob
from pathlib import Path
from notion.block import PageBlock
from notion.client import NotionClient
from md2notion.upload import upload

client = NotionClient(token_v2="<token_v2>")
page = client.get_block("https://www.notion.so/myorg/Test-c0d20a71c0944985ae96e661ccc99821")

for fp in glob.glob("../source/_posts/*.md", recursive=True):
    with open(fp, "r", encoding="utf-8") as mdFile:
        #Preprocess the Markdown frontmatter into yaml code fences
        mdStr = mdFile.read()
        mdChunks = mdStr.split("---")
        mdStr = \
f"""```yaml
{mdChunks[1]}
`` `

{'---'.join(mdChunks[2:])}
"""
        mdFile = io.StringIO(mdStr)
        mdFile.__dict__["name"] = fp #Set this so we can resolve images later

        pageName = os.path.basename(fp)[:40]
        newPage = page.children.add_new(PageBlock, title=pageName)
        print(f"Uploading {fp} to Notion.so at page {pageName}")
        #Get the image relative to the markdown file in the flavor that Hexo
        #stores its images (in a folder with the same name as the md file)
        def convertImagePath(imagePath, mdFilePath):
            return Path(mdFilePath).parent / Path(mdFilePath).stem / Path(imagePath)
        upload(mdFile, newPage, imagePathFunc=convertImagePath)

Contributing

See CONTRIBUTING.md

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].