Markdown Template (.mt) — Markdown with @importEnglish · 简体中文 EnglishWrite modular Markdown documents in VS Code. Markdown Template adds an Great for technical documentation, API docs, specs, design documents, READMEs, knowledge bases and AI prompt files: anywhere you want to reuse Markdown snippets (partials / transclusion) instead of copying and pasting them. Features
Quick start
|
| Path | Meaning |
|---|---|
parts/a.md, ../a.md |
Relative to the current file |
/abs/path/a.md, ~/notes/a.md |
Absolute path, home directory |
${workspaceFolder}/docs/a.md |
Workspace root |
https://example.com/a.md |
Remote URL (GitHub blob links become raw) |
a.md#Installation |
Only the section under that heading |
| Option | Meaning |
|---|---|
{line_begin=10 line_end=-1} |
Line range (1-based, negative counts from the end) |
{heading_offset=1} |
Shift imported headings one level down |
{as="yaml"} |
Import as a code block in the given language |
{code_block=true} / {code_block=false} |
Show Markdown as raw code, or render a non-Markdown file as Markdown |
{optional=true} |
Skip silently when the file is missing |
Write <!-- @import "a.md" --> instead, and other Markdown tools will treat the line as a comment.
Keyboard shortcuts
| Shortcut | Action |
|---|---|
Ctrl/Cmd+E |
Cycle Source → Assembled → Rendered |
Ctrl/Cmd+Shift+V |
Toggle Source ↔ Rendered (opens the preview from the text editor) |
Shift+Alt+F |
Format the document |
Ctrl/Cmd+F |
Find and replace |
Ctrl/Cmd+Click on an @import path |
Open the imported file or URL |
FAQ
- Prefer the plain text editor? Click Text in the toolbar, or make it the default with
"workbench.editorAssociations": { "*.mt": "default" }. The preview stays available viaCtrl/Cmd+Shift+V. - Use it with other Markdown extensions?
.mtis its own language (mt). To let Markdown-only extensions handle it, add"files.associations": { "*.mt": "markdown" }. - Which settings are there? Open Settings and search for
mt.: default view, remote imports, import depth, preview font and line breaks, scroll sync and more.
简体中文
在 VS Code 里写模块化的 Markdown 文档。 Markdown Template 为 Markdown 增加了 @import 指令:一个 .mt 文件可以引入其它 Markdown 文件、源代码、JSON、YAML、HTML、图片和网络上的 URL 内容。在同一个编辑页里编辑源码、查看拼接后的 Markdown、预览渲染效果,然后一键复制,或导出为一个 .md 文件、一个可以直接打开的 .html 网页。
适合技术文档、接口文档、需求与设计文档、README、知识库、AI 提示词文件:凡是需要复用 Markdown 片段、不想到处复制粘贴的地方都能用上。
功能特色
- Markdown 引入 / 合并:
@import "parts/intro.md"把文件就地合并进来;可以只引入某几行、只引入某个标题下的章节,也可以整体调整标题层级;支持嵌套引入,自动检测循环引用。 - 什么都能引入:Markdown 直接合并;源代码、JSON、YAML、HTML 等任意文件作为带语法高亮的代码块引入;图片按图片显示;
https://网址自动获取并缓存,GitHub 的blob链接自动改成原始文件地址。 - 一个编辑页,三种视图:源码(编辑
.mt原文)、组装(所有@import展开后的结果)、渲染(实时 Markdown 预览);Ctrl/Cmd+E切换,在预览里双击跳回源码对应行,滚动位置互相跟随。 - 实时预览、自动刷新:边写边更新,被引入的文件改动后(即使还没保存)也立即刷新;引入出错时就地标出,并出现在“问题”面板里。
- 导航目录与标题编号:标题自动编号(
1、1.1、1.1.1),被引入文件里的标题一起编号;左侧导航面板(文档目录)点击即可定位,有 git 改动的章节会标出来。 - 批注:用
%%批注%%写审阅意见,编辑页里高亮显示,批注面板集中列出,复制和导出时自动去掉。 - Markdown 表格工具:一键按列对齐所有 Markdown 表格,中文、日文、韩文按两个字符宽计算,表格真正竖直对齐;右键在上方或下方插入表格行;用一行空行把长表格分成几段。
- Markdown 格式化:基于 Prettier,
@import指令行原样保留,确认渲染结果不变才写回。 - 编辑页里的 git:行号旁和滚动条上显示改动,点开可以看内嵌差异,单独暂存或还原某一处改动。
- 复制与导出:复制展开后的 Markdown,导出
.md文件,或导出样式内联、支持深色模式的独立.html文件,用浏览器直接打开。 - 配合 Claude Code:装了 Claude Code 时,工具栏的 Claude 按钮把选中行(没选中时整个文件)的
@文件#12-18引用直接插入 Claude Code 的对话输入框。 - 和 VS Code 一样顺手:语法配色跟随颜色主题;熟悉的快捷键、多光标、查找替换(支持仅在选中区域内);
@import路径自动补全,Ctrl/Cmd+点击打开被引入的文件;撤销、保存、热退出照常;随时可以换回 VS Code 自己的文本编辑器。 - 默认安全:严格的内容安全策略,HTML 经过净化,远程内容不执行脚本;不受信任的工作区里禁用网址引入和工作区外的路径。
- 7 种界面语言:中文、English、Deutsch、Français、日本語、한국어、Русский,可以独立于 VS Code 的显示语言切换。
快速开始
新建文件
guide.mt:# 产品手册 @import "parts/intro.md" @import "parts/api.md#认证" {heading_offset=1} @import "config/settings.json" @import "https://github.com/user/repo/blob/main/CHANGELOG.md" {line_end=20}打开它,默认进入 Markdown Template 编辑页的 源码 视图。
点工具栏的 组装 或 渲染,或按
Ctrl/Cmd+E,查看拼接和渲染的结果。用 复制 或 导出 ▾ → Markdown 文件 / HTML 文件 分享出去。
@import 速查
| 路径写法 | 含义 |
|---|---|
parts/a.md、../a.md |
相对于当前文件所在目录 |
/绝对路径/a.md、~/notes/a.md |
系统绝对路径、家目录 |
${workspaceFolder}/docs/a.md |
工作区根目录 |
https://example.com/a.md |
网络地址(GitHub 的 blob 链接自动改成原始文件地址) |
a.md#安装 |
只引入“安装”这个标题下的章节 |
| 参数 | 含义 |
|---|---|
{line_begin=10 line_end=-1} |
行范围(从 1 开始,负数从末尾倒数) |
{heading_offset=1} |
被引入的标题整体降一级 |
{as="yaml"} |
作为指定语言的代码块引入 |
{code_block=true} / {code_block=false} |
把 Markdown 显示成源码,或把非 Markdown 文件当 Markdown 渲染 |
{optional=true} |
文件不存在时静默跳过 |
写成 <!-- @import "a.md" --> 也可以,用其它 Markdown 工具打开时这一行会被当作注释。
快捷键
| 快捷键 | 作用 |
|---|---|
Ctrl/Cmd+E |
源码 → 组装 → 渲染 循环切换 |
Ctrl/Cmd+Shift+V |
源码 ↔ 渲染(在文本编辑器里则打开预览) |
Shift+Alt+F |
格式化文档 |
Ctrl/Cmd+F |
查找替换 |
Ctrl/Cmd+点击 @import 路径 |
打开被引入的文件或网址 |
常见问题
- 更习惯普通文本编辑器? 点工具栏的 文本,或在设置里加
"workbench.editorAssociations": { "*.mt": "default" }让它成为默认;预览仍然可以用Ctrl/Cmd+Shift+V打开。 - 能和其它 Markdown 插件一起用吗?
.mt是独立的语言mt。想让只认 Markdown 的插件也作用于它,在设置里加"files.associations": { "*.mt": "markdown" }。 - 有哪些设置? 打开设置搜索
mt.:默认视图、网址引入、引入深度、预览字体与换行、滚动跟随等。
License: MIT