What a Notion Export Actually Contains (and the Three Scripts That Fix the Links)

本文为原文前 6,000 字符的节选翻译,完整内容请查看原文。

What a Notion Export Actually Contains (and the Three Scripts That Fix the Links)

上个月,我将一个使用了两年的 Notion 工作区迁移到了 Obsidian,导出本身从来都不是问题。压缩包准时送达,每个页面都是一个 .md 文件,每个数据库都是一个 CSV 文件。问题在于压缩包里只字未提的内容。这是我希望自己当初能看到的指南:导出文件里到底包含了什么,它悄悄丢弃的六个功能,以及我最终编写的三个小型 Python 脚本,用以解决链接失效的问题。需要说明的是,我销售一套打包了整个迁移项目的工具包——NotionEscape——所以请将此文视为对实际操作机制的偏见性描述,而非评测。无论如何,下文中的结构和丢失列表均可免费使用。

The shape of the export

导出文件的形态

Settings → workspace → Export all content, format Markdown & CSV. Unzip it and you get: one .md file per page, with sub-pages as folders (Parent/Child/Grandchild.md); one CSV per database, one row per entry, sitting beside the database’s own page file; images and attachments in an /images/ folder, referenced from Markdown by absolute /images/… paths; internal page links as either raw notion.so URLs or relative .md links. All four of those break differently in a vault, which is the entire reason a converter alone leaves you with a folder nobody opens.

设置 → 工作区 → 导出所有内容,格式选择 Markdown 和 CSV。解压后你会得到:每个页面对应一个 .md 文件,子页面作为文件夹(父级/子级/孙级.md);每个数据库对应一个 CSV 文件,每行代表一个条目,位于数据库自身的页面文件旁边;图像和附件存放在 /images/ 文件夹中,在 Markdown 中通过绝对路径 /images/… 引用;内部页面链接要么是原始的 notion.so URL,要么是相对的 .md 链接。这四种形式在知识库(vault)中都会以不同的方式失效,这就是为什么仅仅使用转换器只会让你得到一个无人问津的文件夹。

The six features that do not survive

无法保留的六个功能

As of October 2026, plain text, headings, to-dos, simple tables, ordinary links and images by path arrive fine. These six do not: Relations. A relation arrives as the plain text names of the linked pages. No link, no pointer back to the other CSV. The structure is gone and the label survives. Rollups. A rollup only existed between databases, so once relations are labels there is nothing to aggregate. At best you get one value frozen at export time. Formulas. Computed columns arrive as their computed values. Useful values, no logic. Synced blocks. A block reused on twenty pages becomes twenty independent static copies. Edit one and nineteen go stale. Embeds. Live frames (Drive, Figma, video, sheets) do not arrive as live frames. Sometimes a bare URL, sometimes nothing. Database views. Kanban, calendar and filtered views are gone. The CSV behind them is not. Comments, page history and permissions are absent too. None of this is secret — it’s in the export docs in pieces — and it is why the migration is a set of decisions, not a file conversion.

截至 2026 年 10 月,纯文本、标题、待办事项、简单表格、普通链接和通过路径引用的图像都可以正常导出。但以下六项不行:关系(Relations)。关系导出后变成了链接页面的纯文本名称。没有链接,也没有指向另一个 CSV 的指针。结构消失了,只剩下标签。汇总(Rollups)。汇总仅存在于数据库之间,因此一旦关系变成了标签,就没有任何东西可以聚合了。充其量你只能得到一个在导出时冻结的值。公式(Formulas)。计算列导出后变成了计算出的值。只有有用的数值,没有逻辑。同步块(Synced blocks)。在一个页面上重复使用的块会变成二十个独立的静态副本。修改其中一个,另外十九个就会过时。嵌入(Embeds)。实时框架(Drive、Figma、视频、表格)不会以实时框架的形式出现。有时是一个裸 URL,有时什么都没有。数据库视图。看板、日历和筛选视图都消失了。但它们背后的 CSV 文件还在。评论、页面历史记录和权限也都不见了。这些都不是秘密——它们分散在导出文档中——这就是为什么迁移是一系列决策,而不是简单的文件转换。

Rule 3 of the rewriter: the one that actually bites

重写器的第三条规则:真正棘手的部分

The first script I wrote was the smallest and most useful, because absolute /images/foo.png paths are the failure that looks like a broken vault rather than a broken link. _IMG_REF = re.compile(r”(!?[[^]\n]*]()(/images/[^()\s]+)())”) Rewrite /images/… to a local folder, rewrite notion.so page URLs to [[wikilinks]], rewrite relative .md links to vault-relative wikilinks, and touch nothing else. Making it byte-idempotent matters: a second run over already-rewritten text should be identical, or you cannot re-run it after a partial pass. The notion.so URL form is the ugly part, because a page URL looks like workspace/Page-Title-<32 hex chars>, optionally URL-encoded, optionally with ?query or #fragment. Strip the query and fragment first, decode percent runs, discard any leading workspace segment, then treat the final - segment as the title with - as spaces: path = path.split(”?”, 1)[0].split(”#”, 1)[0] path = _percent_decode(path) final = path.rstrip(”/“).split(”/”)[-1] m = _SLUG.match(final) # (.+)-([0-9a-f]{32,}) if not m: return None # not a page URL; leave it byte-untouched title = m.group(1).replace(”-”, ” ”) Every rule has to fall through to “leave it alone” rather than “guess”, or a rewriter becomes a second source of corruption.

我编写的第一个脚本是最小也是最有用的,因为绝对路径 /images/foo.png 的失效看起来更像是知识库损坏,而不是简单的链接损坏。_IMG_REF = re.compile(r”(!?[[^]\n]*]()(/images/[^()\s]+)())”) 将 /images/… 重写为本地文件夹,将 notion.so 页面 URL 重写为 [[wikilinks]],将相对 .md 链接重写为知识库相对的 wikilinks,除此之外不做任何改动。确保字节幂等性很重要:对已经重写过的文本进行第二次运行应该保持不变,否则在部分处理后你将无法再次运行它。notion.so 的 URL 格式很麻烦,因为页面 URL 看起来像 workspace/Page-Title-<32位十六进制字符>,可能经过 URL 编码,也可能带有 ?查询或 #片段。首先剥离查询和片段,解码百分号编码,丢弃任何前导的工作区段,然后将最后的 - 段视为标题,并将 - 替换为空格:path = path.split(”?”, 1)[0].split(”#”, 1)[0] path = _percent_decode(path) final = path.rstrip(”/“).split(”/”)[-1] m = _SLUG.match(final) # (.+)-([0-9a-f]{32,}) if not m: return None # 不是页面 URL;保持字节不变 title = m.group(1).replace(”-”, ” ”) 每条规则都必须以“保持原样”而不是“猜测”作为兜底,否则重写器会成为第二种破坏源。

Where the arithmetic has to live

计算逻辑的归宿

The second script turns each database CSV into a Map of Content note — one - [[Title]] line per row, in CSV file order, with | replaced, [[/]] stripped and whitespace collapsed. Deterministic by design: same input bytes, same output bytes, LF endings, no timestamps and no locale dependence, because a diff you cannot trust is worse than no diff. The third stamps one canonical front-matter block on every imported note, so the vault does not end up with three front-matter dialects after an import. All three ship a —selftest that touches no files (python3 06_csv_to_moc.py —selftest → PASS (9 checks), 10 checks, 9 checks), need python3 3.8+ and nothing else — no pip packages, no tokens, no network — and none of them deletes anything. They overwrite only the output path you hand them.

第二个脚本将每个数据库 CSV 转换为内容地图(Map of Content)笔记——每行对应一个 - [[Title]],按 CSV 文件顺序排列,替换掉 |,去除 [[/]] 并合并空白字符。设计上是确定性的:相同的输入字节产生相同的输出字节,使用 LF 换行,没有时间戳,也不依赖本地环境,因为不可信的差异对比比没有差异更糟糕。第三个脚本为每个导入的笔记打上一个规范的 front-matter 块,这样导入后知识库就不会出现三种不同的 front-matter 格式。这三个脚本都附带一个不触碰文件的 —selftest(python3 06_csv_to_moc.py —selftest → PASS (9 项检查), 10 项检查, 9 项检查),只需要 python3 3.8+,无需其他依赖——没有 pip 包、没有令牌、没有网络——而且它们都不会删除任何东西。它们只会覆盖你指定的输出路径。

The part that is actually a project

真正称得上项目的环节

Scripts are maybe an afternoon. The rest is the sequence, and the order is the whole point: pre-flight audit → official export → land in _import/ → normalize → QA → wait out a retention window → decommission. The audit runs before export day, and it produces two things a converter cannot: an inventory (every database with its row count — those counts are the baseline you check the zip against on export day) and a three-way classification per item: keep-as-export — the CSV plus a generated MOC note is enough. Flat lists live here. rebuild — what mattered was the structure, and the export cannot carry it. Rebuilt by hand from the CSV’s values. leave-behind — stale wikis, expired projects. They stay in the archived zip and never enter the vault. That third option is the one people skip, and skipping it is why a migration takes three weekends instead of one. Nothing destructive happens before QA signs off, and decommissioning waits out the retention window you chose in the audit — the account is the backup, so deleting it first destroys the only copy of what did not survive.

脚本编写可能只需要一个下午。剩下的工作是流程,而顺序才是关键所在:飞行前审计 → 正式导出 → 存入 _import/ → 标准化 → 质量保证(QA)→ 等待保留期结束 → 停用。审计在导出日之前进行,它能产生转换器无法提供的两样东西:清单(每个数据库及其行数——这些行数是你导出日核对压缩包的基准)以及每个项目的分类:keep-as-export(按导出保留)——CSV 加上生成的 MOC 笔记就足够了,扁平列表属于此类;rebuild(重建)——结构才是最重要的,而导出无法保留它,需要根据 CSV 的值手动重建;leave-behind(丢弃)——过时的维基、过期的项目,它们留在存档的压缩包中,永远不会进入知识库。第三个选项是人们经常跳过的,而跳过它就是为什么迁移需要三个周末而不是一个的原因。在 QA 确认之前不会进行任何破坏性操作,停用操作会等待你在审计中选择的保留期结束——账户本身就是备份,所以先删除账户会摧毁那些未能幸存的内容的唯一副本。

If you only need the conversion

如果你只需要转换

Two free, open-source tools do the file conversion well and I’d rather say so than sell you a dollar: obsidianmd/obsidian-importer, the official Obsidian plugin for importing Notion exports, and connertennery/Notion-to-Obsidian-Converter. If conversion is the whole job, use those. What neither ships is the surrounding project: the audit.

有两个免费的开源工具可以很好地完成文件转换,我宁愿直说也不想赚你一分钱:obsidianmd/obsidian-importer(官方的 Obsidian 导入插件)和 connertennery/Notion-to-Obsidian-Converter。如果你的工作仅仅是转换,用这些就够了。但它们都没有提供配套的项目管理:审计。