离线 · 无上传 · 浏览器本地完成Offline · no uploads · runs in the browser
Markdown 转 JSON——离线、表格变成对象、不上传Markdown to JSON offline — tables become objects, no upload
Markdown 里最像数据的是表格,最想要的数据格式是 JSON。这一条走两步:先把文档按 GFM 渲染成 HTML(`gfm: true`,所以管道符表格、删除线、任务清单、自动链接都被认出;`breaks: false`,段落里单个换行仍然是续行而不是换行),渲染结果先过 DOMPurify(html + svg 两套 profile,行内的 SVG 图形不会被当垃圾删掉),再交给只解析不执行的 DOMParser 取表格。表格读法是:首行给出键名,其余每行一个对象,取行取格都限定在「这张表自己」的作用域里,所以 `<strong>`、链接、嵌套标记只剩文字,套在单元格里的小表格也不会把它的行摊成外层数据行。文档里两张以上时结果不再是数组,而是一个以 `<h2>` 文字为键的对象——`##` 小标题是这些 `h2` 最常见的来源(setext 式的下划线标题、直接写在文档里的 `<h2>` 也算),而包装文档自己不插入任何标题,所以键与表格的配对完全由文档里真实的 `h2` 决定。一张表也没有时退一步:围栏代码块渲染成 `<pre>`,里面的 JSON 原样解析;再退一步按整页文字尝试;都不成就报错,不返回空数组。全过程在标签页里完成,Markdown 引用的图片一个字节都不会被取。The most data-shaped thing in a Markdown file is its table, and the most useful data shape out of it is JSON. This route is two steps: the document is rendered to HTML as GFM (`gfm: true`, so pipe tables, strikethrough, task lists and autolinks are all recognised, while `breaks: false` keeps a single newline a soft wrap rather than a line break), the markup passes DOMPurify (the html and svg profiles, so an inline SVG diagram is not deleted as junk), and a non-executing DOMParser then reads the tables. In a table the first row supplies the keys and every later row becomes one object, with rows and cells read inside a “this table only” scope — so `<strong>`, links and nested markup leave only words, and a small table inside a cell cannot contribute its rows to the outer one. Two or more tables make the result an object rather than an array, keyed by the text of the document’s `<h2>` elements: a `##` heading is the usual source of those (a setext underline or an `<h2>` written straight into the document counts too), and the document wrapper inserts no heading of its own, so the pairing is decided entirely by real `<h2>` text. With no table at all it falls back one step and parses a fenced code block (which renders as `<pre>`) as JSON, then tries the page’s whole text, and otherwise reports failure instead of handing back an empty array. None of it touches the network: images the Markdown points at are never fetched.
这条链路怎么走How the route runs
MarkdownMarkdown HTMLHTML JSONJSON
共 2 步,由扩展的路径搜索自动选出,中间产物不落盘。2 steps, chosen by the extension's own path search; intermediate results never touch the disk.
会保留什么What carries over
- 表格按 GFM 语法识别:表头行给出键名,每一条数据行成为一个对象,表头行自己不会混进结果Tables are read as GFM syntax: the header row names the keys, each data row becomes one object, and the header row itself never appears in the result
- 只看这张表自己:单元格里的 `**粗体**`、链接与嵌套标记只留下文字,表格套在单元格里也不会凭空多出记录Only the table’s own rows and cells are read, so `**bold**`, links and nested markup leave words behind and a table inside a cell adds no phantom records
- 两张以上的表按 `##` 小标题分组:键就是文档里真实的 `h2` 文字,包装文档不会插入自己的标题来捣乱Two or more tables group under the `##` headings: the keys are the document’s real `<h2>` text, since the wrapper inserts no heading of its own
- 没有表格时读代码块:围栏代码块渲染成 `<pre>`,被包在里面的 JSON 能原样救回来With no table, a fenced code block is read: it renders as `<pre>`, so JSON someone wrapped in a code fence comes back as it stands
如实说明的限制What it does not do
- 分组键与表格按**出现顺序**配对,不是「就近的标题」:两张表之间多写一个不带表格的 `##` 小节,后面的键就整体错位;标题不够时退到 `Sheet2` 这类名字Grouping keys pair with tables by **document order**, not by “nearest heading”: one extra `##` section between two tables shifts every later key; when there are too few headings the name falls back to `Sheet2`
- 代码块回退只看文档里第一个 `<pre>`:它排在真正的 JSON 块之前就会解析失败,即使后面那块是合法 JSONThe code-block fallback reads only the first `<pre>` in the document, so a block ahead of the real JSON fails the parse even when the later one is valid
- 表格那一步的值一律是字符串:JSON 里不会出现真数字与真日期,`00424`、`1,234`、`2024-01-05` 都按写下的字符保留(代码块回退不同——它把那段文字按 JSON 解析,里面的类型就是文档本来写的)Values taken from a table are always strings: no real numbers or dates appear in the JSON, and `00424`, `1,234` and `2024-01-05` keep the characters you wrote (the code-block fallback differs — it parses that text as JSON, so the types inside it are the document’s own)
- 键的三处坑:表头里重复或空白的格子互相覆盖;比表头多出的单元格被丢掉,比表头短的行不会补键;图片单元是空值(`<img>` 没有文字,`alt` 也不进结果),链接地址不保留Three key pitfalls: a repeated or blank header cell overwrites its twin; cells beyond the header row are dropped and short rows gain no keys; an image cell is empty (`<img>` carries no text, `alt` included) and link addresses are not kept
- 两张表转不成 CSV / Excel:这一步给出的是对象,而 JSON 转 CSV 只接受数组,会报「JSON 内容必须是包含数据的数组才能转换为 CSV」——单张表才走得下去Two tables do not reach CSV or Excel: this step hands on an object, and JSON to CSV accepts arrays only, reporting “JSON must be an array containing data to convert to CSV” — only a single table travels on
实操提示Working with it
- 要的是能继续算的数据:接到 JSON 转 CSV 或转 Excel,两张表请拆成两个文件逐张转,别让分组对象撞上「只接受数组」那道闸For data you can compute on: carry the JSON on to CSV or Excel, splitting two tables into two files so the grouped object never meets the “arrays only” gate
- 要的是给人看的文档:Markdown 转 HTML、Word、PDF 都能直接走,不必绕这一圈 JSONFor a document someone reads: Markdown goes to HTML, Word or PDF directly, without this JSON detour
- 要的是纯文字:看 Markdown 转 TXT 那张页的说明,表格在那里会散成按阅读顺序排列的行,与这里的对象结构是两种取舍For plain text: see the Markdown to TXT page — there the table loosens into reading-order lines, a different trade from the objects here
常见问题Questions people actually ask
我的 Markdown 里有两张表,会得到什么?My Markdown has two tables — what do I get?
一个对象,不是数组:键按出现顺序配上文档里的 `<h2>` 文字(Markdown 里通常就是写在那张表上面的 `##`,标题不够时退到 `Sheet2` 这类名字),值各是自己那张表的对象数组。要两份彼此独立的数组,就把两张表放进两个文件分别转。An object rather than an array: the keys are the document’s `<h2>` text matched in document order (in Markdown, usually the `##` you wrote above the table; names fall back to `Sheet2` when there are too few), each holding its own array of objects. For two independent arrays, put the tables in two files and convert separately.
单元格里写了 `**加粗**` 和一个链接,JSON 里是什么?A cell has `**bold**` and a link — what lands in the JSON?
只有文字。表格单元取的是渲染后元素的 `textContent` 并去掉首尾空白,所以标记与 `href` 都不进结果;图片单元因为没有文字而落成空字符串。需要保留链接地址,请先转成 HTML,那里 `href` 还在。Words only. A cell comes from the rendered element’s `textContent` with the ends trimmed, so markup and `href` contribute nothing and an image cell becomes an empty string. Keep the addresses by converting to HTML first — there the `href` survives.
这条路要先把 Markdown 渲染成 HTML,会去加载文档里引用的图片吗?This route renders HTML on the way — does it fetch the images the document references?
不会。marked 只在内存里把字符串变成 HTML 文本,DOMPurify 净化后交给 DOMParser(只解析、不执行),扩展也只有 storage 权限、没有 host 权限,所以指向网络的地址在整个过程里一次都没被请求。No. marked turns the string into HTML text in memory, DOMPurify sanitises it, DOMParser parses without executing, and with the storage permission only and no host permissions, no address the document points at is ever requested.
不需要账号,也不需要联网:装好扩展后点图标,在新标签页里打开工作台,文件从磁盘直接选。No account and no network: install the extension, click its icon, and the workbench opens in a new tab reading straight off your disk.
从 Chrome 应用商店安装Install from the Chrome Web Store 安装步骤Install steps GitHub 源码Source on GitHub