Markdown 包含其他文件静态渲染工具

1. 前言

在 GitHub 上写文档,很多时候要插入 uml,像 mermaid 这种可以直接在 GitHub/GitLab 中渲染的一般直接写个 code block 进去,但是这样造成一个问题就是如果要放在多个文档中则必须复制多份。于是有个想法油然而生,用注释提供一种静态渲染的方式将代码、uml 这种在 Commit 之前渲染到 Markdown 上,并可以进行更新。于是 ps-md-include 应运而生。

2. 系统需求

PowerShell 6 或更高版本

3. 用法

  1. 在文件中插入 md_include 文件块
# test
<!-- #md_include "Program.cs" from 1 to 3 as code lang csharp -->
<!-- #md_include end -->
  1. 在文件根目录运行 Sync-MarkdownInclude.ps1
  2. 然后 C# 文件就被渲染进去了
# test
<!-- #md_include "Program.cs" from 1 to 3 as code lang csharp -->
```csharp
using System;
using System.Linq;
```
<!-- #md_include end -->

3. 参数

<!-- #md_include "<file path>"[ from <number>[ to <number>]][ as <type>][ lang <lang>] --><!-- #md_include end -->

  1. "":要包含的文件相对路径
  2. [ from ]:从第几行开始读取(默认第一行,非必须填写)
  3. [ to ]:读到第几行(默认文件的最后一行,非必须填写,需要跟在 from 后面)
  4. [ as ]:渲染类型,具有 raw (文本,直接打印文本)、code (代码,会渲染代码块)两种格式(默认 raw,非必须填写)
  5. [ lang ]:代码块的文件类型(默认是 null,非必须填写,需要跟在 as code 后面)

4. 代码

https://github.com/SofiaXu/ps-md-include

posted @ 2022-08-19 09:14  Aoba_xu  阅读(45)  评论(0编辑  收藏  举报