Notion-to-MD 项目下载及安装教程
1. 项目介绍
Notion-to-MD 是一个 Node.js 包,用于将 Notion 页面转换为 Markdown 格式。它支持嵌套和自定义解析,能够将 Notion 页面、块和块列表转换为 Markdown 格式。
2. 项目下载位置
项目源代码托管在 GitHub 上,可以通过以下命令克隆项目到本地:
git clone https://github.com/souvikinator/notion-to-md.git
3. 项目安装环境配置
3.1 安装 Node.js
首先,确保你的系统上已经安装了 Node.js。你可以通过以下命令检查 Node.js 是否已安装:
node -v
如果未安装,请访问 Node.js 官方网站 下载并安装适合你操作系统的版本。
3.2 安装 npm
npm 是 Node.js 的包管理工具,通常随 Node.js 一起安装。你可以通过以下命令检查 npm 是否已安装:
npm -v
如果未安装,请参考 Node.js 官方文档进行安装。
3.3 环境配置示例
以下是环境配置的示例图片:
4. 项目安装方式
进入项目目录并安装依赖:
cd notion-to-md
npm install
5. 项目处理脚本
5.1 基本使用
以下是一个基本的使用示例,将 Notion 页面转换为 Markdown 格式:
const { Client } = require("@notionhq/client");
const { NotionToMarkdown } = require("notion-to-md");
const fs = require('fs');
const notion = new Client({ auth: "your integration token" });
const n2m = new NotionToMarkdown({ notionClient: notion });
(async () => {
const mdblocks = await n2m.pageToMarkdown("target_page_id");
const mdString = n2m.toMarkdownString(mdblocks);
console.log(mdString);
})();
5.2 自定义转换器
你可以定义自己的自定义转换器来处理特定的 Notion 类型:
const { NotionToMarkdown } = require("notion-to-md");
const n2m = new NotionToMarkdown({ notionClient: notion });
n2m.setCustomTransformer("embed", async (block) => {
const { embed } = block;
if (embed.url) return "";
return `<figure> <iframe src="${embed.url}"></iframe> <figcaption>${await n2m.blockToMarkdown(embed.caption)}</figcaption> </figure>`;
});
const result = n2m.blockToMarkdown(block);
console.log(result);
通过以上步骤,你已经成功下载并安装了 Notion-to-MD 项目,并学会了如何使用它将 Notion 页面转换为 Markdown 格式。