Scan your whole stack
From OX Research Newsroom
Are you using mdi2esm?
Find out what’s in your code.
Scan your apps free in minutes (opens in a new tab)Latest version: v1.3.1
mdi2esm was last scanned on 29 Nov 2026 at version 1.3.1. Risk score 0 of 100. No malicious behavior was detected.
| Version | Published | Status |
|---|---|---|
| 1.3.1 LATEST | 29 Nov 2026 | No rules fired |
| 1.3.0 | 29 Nov 2026 | No rules fired |
| 1.2.1 | 28 Nov 2026 | No rules fired |
| 1.2.0 | 26 Nov 2026 | Not shown |
| 1.1.0 | 22 Nov 2026 | Not shown |
Findings for v1.3.1. The score is a capped sum of the weights of the rules that fired — not CVSS, not exploitability, and not a probability. It is not comparable across packages with different scan coverage.
The score describes 1.3.1; other versions have their own rules, not their own score.
The publisher’s own README, as collected from the registry.
A markdown-it wrapper with common plugins integrated. It renders Markdown into VitePress-style HTML, with code highlighting, math (KaTeX), Mermaid diagrams, ECharts charts, outlines and image zoom built in. The core markdown stack and Prism are bundled into a single browser-ready ESM artifact; framework and heavy dependencies are left as peers for the host to provide.
这份 README 是包文档;可编辑的能力演示在同目录
demo.md,demo 运行时渲染的就是它。基础语法、容器、GitHub alerts、脚注、任务列表、图标与 emoji 短码、CJK 混排、属性、目录、代码高亮、数学、图表(含表格转图表)、图片缩放,以及宿主注入的组件(<Badge>/<Icon>)和<script setup>都在demo.md里。
{#id} 自定义锚点、frontmatter、GitHub 风格表格、emoji、任务列表、脚注、[[toc]] 目录、自定义容器与 GitHub alerts、代码高亮 / 行高亮 / 聚焦 / diff / 行号、代码片段导入与代码组、数学公式(KaTeX)、图片懒加载,以及 VitePress 风格的类名与样式。:::timeline)、音视频嵌入(!video[]() / !audio[]())、表格配图(ECharts)、Mermaid 图表,以及 <<< / @include 片段包含。:prefix-icon-name: 短码即渲染成 <Icon icon="prefix:name">,图标数据由宿主的 Iconify 仓库提供,包内不内置图标集。mermaidDriver 默认 'pele',可切回原生 'mermaid';两者都是可选 peer,按需动态加载。<script setup> 或 <script>,在浏览器运行时编译成 Vue 组件,相对 import 提升为浏览器原生 ESM,frontmatter / params 注入作用域;解析失败降级为纯 HTML 渲染。产物大小(npm run build 实测,KiB 按 1024 字节折算):
| 产物 | 字节 | 约 KiB |
|---|---|---|
dist/index.js |
513,077 | 501 |
dist/index.min.js |
353,200 | 345 |
dist/index.css |
47,914 | 47 |
dist/index.min.css |
42,609 | 42 |
核心 markdown 栈与 Prism 内联在上面四个产物里;KaTeX / Mermaid / Pele / ECharts / medium-zoom 是可选 peer,按需动态加载,不计入此体积。
package.json 的 engines)。npm i mdi2esm
同时安装 peer 依赖(用到哪些功能装哪些;完整能力需要全部):
npm i mdi2esm vue vue-style-runtime katex mermaid pele echarts
echarts 是可选的:不装时 echarts 围栏降级为源码块,其余功能不受影响。
只出 HTML 字符串(不挂 Vue,纯 innerHTML 场景):
import { renderMarkdown, buildOutline, createConfig } from 'mdi2esm';
const config = createConfig();
const { html, headings } = await renderMarkdown('# 标题\n正文', { config });
const outline = buildOutline(headings);
挂成 Vue 组件——编译结果就是一个普通组件,是否响应式、什么时候重编译都由宿主决定:
import { Icon } from '@iconify/vue';
import { createApp, h } from 'vue';
import { buildOutline, createConfig, createMarkdownComponent } from 'mdi2esm';
import 'mdi2esm/index.min.css';
import 'katex/dist/katex.min.css';
import { VPBadge } from './vp-badge.js'; // 宿主自己写的 <Badge>
const config = createConfig({
mermaidDriver: 'pele', // 默认值;切原生渲染改成 'mermaid'
markdown: {
container: [
{ type: 'demo', title: '自定义容器' },
// 可选:覆写开闭标签渲染,把容器变成宿主自己的组件(签名同 markdown-it-container)
// { type: 'app-demo', openRenderer: () => '<app-demo>\n', closeRenderer: () => '</app-demo>\n' },
],
},
});
// 1. 取源文本:库只吃字符串,跟构建工具无关——fetch、接口返回、textarea 内容都行
const source = await fetch('./demo.md').then((res) => res.text());
// 2. markdown → 组件:frontmatter、Prism 高亮、KaTeX、<script setup> 都在内部处理
const { component, headings } = await createMarkdownComponent(source, '', config);
// 3. md 里用到的组件只注入到这一个实例,不污染全局
component.components = { ...component.components, Icon, Badge: VPBadge };
// 4. headings 是 [{ level, title, slug }],buildOutline 整理成 { title, link, children } 的树
const outline = buildOutline(headings);
createApp({ render: () => h(component) }).mount(document.getElementById('content'));
createMarkdownComponent(source, dir, config, { frontmatter, params }) 的入参都是纯数据:dir 是相对链接、相对 import 的基准目录;返回 { component, headings }。文本变化后的重编译与并发时序也由调用方决定——demo 在 index.html 里就是 await createMarkdownComponent(...) 后替换视图组件,并用递增序号丢弃过期结果。
只要 HTML 字符串、不需要 Vue 组件时,用上面第一节的 renderMarkdown——两者的区别只在于要不要把结果挂成组件。
index.html 里取源文本就是一句 fetch('./demo.md')——库只吃字符串,文本从哪来跟它无关,fetch、接口返回、textarea 内容都一样。
package.json 的 exports:.(默认/生产 → dist/index.min.js,development → dist/index.js),显式 JS 入口 mdi2esm/index、mdi2esm/index.min,样式入口 mdi2esm/index.css、mdi2esm/index.min.css。
dist/index.min.js 本身就是浏览器可加载的 ESM,静态导入只有 vue 和 vue-style-runtime 两个(katex / pele / mermaid / echarts 是动态 import(),用到才加载)。所以连 Vite 都不需要,importmap 映射 peer 即可(echarts 可省略,省略时降级为源码块):
<script type="importmap">
{
"imports": {
"vue": "/node_modules/vue/dist/vue.esm-browser.prod.js",
"vue-style-runtime": "/node_modules/vue-style-runtime/dist/index.min.js",
"pele": "/node_modules/pele/dist/pele.js",
"echarts": "/node_modules/echarts/dist/echarts.esm.min.js"
}
}
</script>
<script type="module">
import { createApp, h } from 'vue';
import { createConfig, createMarkdownComponent } from '/node_modules/mdi2esm/dist/index.min.js';
// 宿主组件就是一个带 template 字符串的对象,没有 SFC,也没有编译步骤
const Badge = {
props: ['text', 'type'],
template: '<span class="badge" :data-type="type"><slot>{{ text }}</slot></span>',
};
const source = await fetch('./demo.md').then((res) => res.text());
const config = createConfig();
// 运行时编译,和打包场景一样
const { component } = await createMarkdownComponent(source, '', config);
component.components = { ...component.components, Badge };
createApp({ render: () => h(component) }).mount('#app');
</script>
Vue 必须是含模板编译器的构建,这条最容易踩。createMarkdownComponent 内部用 compile() 把 Markdown 编成模板,而 runtime-only 版的 compile 是个直接抛错的占位:
| 场景 | 要用的文件 |
|---|---|
| importmap | vue/dist/vue.esm-browser.prod.js(或 .js) |
| Vite / Rollup | resolve.alias: { vue: 'vue/dist/vue.esm-bundler.js' } |
| webpack | resolve.alias: { vue: 'vue/dist/vue.esm-bundler.js' } |
裸 import ... from 'vue' 在打包器里默认解析到 vue.runtime.esm-bundler.js,少了上面这条 alias,createMarkdownComponent 会在 compile is not a function 上挂掉。上面「挂成 Vue 组件」的示例同样要配。
本仓库的 demo 在 index.html(整页自包含:骨架、内联样式、内联脚本——宿主组件 VPBadge 与左编辑右预览逻辑都在里面),由 Vite 接管两种运行方式:
npm run dev:Vite 服务根目录 index.html,内联脚本里的裸导入由 Vite 重写到源码(mdi2esm 经 vite.config.mjs 的 alias 指到 src/index.js)——改 src 立即生效。npm run build && npm run preview:build 把 index.html 当入口打进 dist/,所有导入解析成打包产物,dist 自包含——整个目录发布到 GitHub Pages(或任意静态托管)就能直接演示,无 importmap、无 node_modules 依赖;vite preview 服务 dist。推 v* Tag 时 GitHub Actions(.github/workflows/publish.yml 的 pages job)会构建并把 dist 部署到 gh-pages 分支(仓库 Pages 源需指向 gh-pages / root)。
库有两套互斥的路径模型:传 paths 时走文档站路径模型(四条公式分别处理 md 源文件、文档链接、文档资源与公共资源);未传时走通用的 base 模型。
paths)文档站(多语言 md、语言目录、文档路由与静态资源分离)使用 createConfig({ paths })。paths 字段为 i18nEnabled / omitDefaultLang / urlTransformEnabled / routerBase / docsRouterPath / docStaticPath / defaultLang / langs / lang / routeFullPath,默认值见导出的 DEFAULT_PATHS。四条公式:
md 源文件 = join(routerBase, docStaticPath, lang, docFilePath + '.md')
文档链接 = join(docsRouterPath, routeLang, 去 .md 并归一 index 的 resolvedPath)
文档资源 = join(routerBase, docStaticPath, resolvedPath) // 相对 URL,不含 lang
公共资源 = join(routerBase, path) // 绝对 URL
createConfig({
paths: {
i18nEnabled: true,
routerBase: '/app/',
docsRouterPath: '/help',
docStaticPath: '/content',
defaultLang: 'zh-CN',
langs: ['zh-CN', 'en-US'], // 有效语言标识集合,不是映射表
lang: 'zh-CN', // 也可留空,由 routeFullPath 首段推导
routeFullPath: '/help/guide/',
},
});
// 当前 md:/app/content/zh-CN/guide/index.md
// ./intro.md → /help/guide/intro;./img/a.png → /app/content/guide/img/a.png;/img/logo.png → /app/img/logo.png
lang 同时是 URL 段和 md 物理目录名,默认语言也有独立目录;omitDefaultLang 只影响路由,不影响 md 目录。.md 结尾(相对或根绝对)一律是文档链接,其余相对 URL 是文档资源、绝对 URL 是公共资源;文档目录链接保留尾斜杠。
库内 fetch(<<< / @include / 地图 GeoJSON)走 resolveResource,是独立于上一条的规则:相对路径按文档资源处理,拼 docStaticPath 且不带 lang;根绝对路径(如 /assets/x.json)按公共资源处理,只加 routerBase;外链原样返回。@/ 前缀剥掉后按文档静态根(docStaticPath)拼接,不是站点根。<script setup> 的 import 经 toScriptImport 只加 routerBase。
未传 paths 时,md 里的相对链接、图片、<script setup> 里的相对 import,以及 <<< / @include / 地图 GeoJSON 的静态资源 fetch,最终 URL 都由 createConfig({ base }) 决定。默认 '/',即站点部署在域名根;放到子路径时传实际前缀:
createConfig(); // ./guide/a.md → /guide/a
createConfig({ base: '/docs/' }); // ./guide/a.md → /docs/guide/a
base 不会出现在配置对象上(paths 模式另见上节)——createConfig 内部把它编成 adapters(toHref / toSrc / toScriptImport / resolveResource / fetcher / scriptContext),渲染层与库内 fetch 都只读 config.adapters,不会出现两个真相来源。markdown.include.base 未显式指定时继承同一个 base。需要非标准规则(比如把 index.md 归一成目录、把图片改写到 /public)时,覆写对应那一个函数即可,其余仍按 base 生成:
createConfig({
base: '/doc/',
adapters: {
// guide/index.md → /doc/guide/(默认实现不把 index 归一成目录)
toHref: ({ path, resolved, hash }) => {
if (!/\.md$/i.test(path)) return `/doc/${resolved}${hash}`;
const route = resolved.replace(/\.md$/i, '').replace(/index$/i, '');
return `/doc/${route}${hash}`;
},
},
});
KaTeX 的样式不属于路径配置,库也不注入 <link>:katex/dist/katex.min.css 由宿主自己引入(见上一节)。
裸 HTML 不参与路径改写:Markdown 里的裸 HTML(html: true 会渲染)中的 <a> / <img> 不经过 link_rewrite,子路径/嵌套部署时其中的相对链接不会加 base 前缀。请在 Markdown 中用链接/图片语法,或自行改写裸 HTML。
库内 fetch 可接管:<<< / @include 的静态文件与地图 GeoJSON 统一走 adapters.resolveResource(拼 URL)与 adapters.fetcher(默认全局 fetch)。SSR、带认证头、自定义缓存都可分别覆写;onResolveError 回调可替代默认告警(见 expandSource)。默认外链判定覆盖 http(s)、mailto:、tel:、data:、blob: 与 // 协议相对 URL,其余scheme 也原样返回。
渲染产物的类名沿用 VitePress 风格(.vp-doc、.custom-block 等)。包内附带一套只覆盖渲染产物(.vp-doc 及 .custom-block、.VPBadge 等类名)的样式:
import 'mdi2esm/index.min.css';
也可用未压缩的 mdi2esm/index.css。这套样式不包含站点 header、sidebar、nav、搜索等布局,宿主可以在 :root / .dark 上覆盖 --vp-* 变量做主题定制。代码高亮由 Prism 生成 token 类,配色已包含在样式里;Prism 本身已内联,无需额外安装。
<Badge> 这类主题组件不在包内,但样式随包发布:index.css 已包含 .VPBadge 规则与 --vp-badge-* 变量,宿主只需提供组件脚本。mdoc 已有自己的主题样式,只引脚本、不引这套 CSS;纯 ESM 场景同时引 CSS 与组件即可。
KaTeX 的样式与字体属于 peer,由你安装的 katex 包提供,需自行引入:
import 'katex/dist/katex.min.css';
正文里的 [[toc]] 生成 .table-of-contents(卡片式、按层级缩进),实例见 demo.md。右侧“大纲”栏由 buildOutline(headings) 从 h2–h6 生成,两者互相独立,见下面的「大纲」。
目录行为由 createConfig({ markdown: { toc } }) 配置:
level:目录包含的标题层级,默认 [2, 3];showAutoNumber:标题与目录自动编号(1 / 1.1 / …),默认 false;编号只作展示,不进锚点与 headings;allowMultiToc:是否允许多个 [[toc]],默认 true;设为 false 时只渲染第一个,其余忽略并 console.warn。demo 顶部提供这三个配置的开关(编号 / 多目录 / 层级),改动经 URL 参数写入并重新加载生效——md 是模块级单例,配置在首次渲染时锁定,运行中切换不生效。
库只内置 ClientOnly,md 里用到的自定义组件(<Icon>、<Badge> 等)都由宿主提供——否则模板里的标签解析不到,就是空白。
用 createMarkdownComponent 编译出组件后,把 md 里用到的组件挂到它的 components 上,只对这一个实例生效,不污染全局:
const { component } = await createMarkdownComponent(source, '', config);
component.components = { ...component.components, Icon, Badge: VPBadge };
底层是 Vue 自身的机制,两种写法任选其一:
Find threats in your stack.
OX Radar can check high-priority threats, like critical package CVEs, against your context.
Each incident is marked Detected or Not Detected with a remediation plan and proof all tracked in the Response Center.
The probe returned only these fields for this server — auth requirement, protocol and tool list weren’t observed, so they’re not shown (never guessed).
The publisher’s own links, as the registry reports them. These are not sources for the assessment on this page.