From 4e7f3da8b58bc028f766fd42a6843b0183e371bc Mon Sep 17 00:00:00 2001 From: ULIVZ <472590061@qq.com> Date: Sun, 3 Jun 2018 03:58:07 +0800 Subject: [PATCH] docs(cn): update for import code snippets (#538) --- docs/guide/markdown.md | 7 +++++++ docs/zh/guide/markdown.md | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/docs/guide/markdown.md b/docs/guide/markdown.md index 98513bd5..5f9548e1 100644 --- a/docs/guide/markdown.md +++ b/docs/guide/markdown.md @@ -226,6 +226,8 @@ export default { ## Import Code Snippets +You can import code snippets from existing files via following syntax: + **Input** ``` @@ -236,6 +238,11 @@ export default { <<< @/test/markdown/fragments/snippet.js{2} +::: tip + Since the import of the code snippets will be executed before webpack compilation, so you can't use the path alias in webpack. the default value of `@` is `process.cwd()`. +::: + + ## Advanced Configuration VuePress uses [markdown-it](https://github.com/markdown-it/markdown-it) as the markdown renderer. A lot of the extensions above are implemented via custom plugins. You can further customize the `markdown-it` instance using the `markdown` option in `.vuepress/config.js`: diff --git a/docs/zh/guide/markdown.md b/docs/zh/guide/markdown.md index 98715800..f5cba428 100644 --- a/docs/zh/guide/markdown.md +++ b/docs/zh/guide/markdown.md @@ -222,6 +222,24 @@ export default { } ``` +## 导入代码段 + +你可以通过下述的语法导入已经存在的文件中的代码段: + +**Input** + +``` +<<< @/test/markdown/fragments/snippet.js{2} +``` + +**Output** + +<<< @/test/markdown/fragments/snippet.js{2} + +::: tip 注意 + 由于代码段的导入将在 webpack 编译之前执行,因此你无法使用 webpack 中的路径别名,此处的 `@` 默认值是 `process.cwd()`。 +::: + ## 进阶配置 VuePress 使用 [markdown-it](https://github.com/markdown-it/markdown-it) 来渲染 Markdown,上述大多数的拓展也都是通过自定义的插件实现的。想要进一步的话,你可以通过 `.vuepress/config.js` 的 `markdown` 选项,来对当前的 `markdown-it` 实例做一些自定义的配置: -- GitLab