.NET Core 模板的 Markdown 语法是什么

2024-04-15

我有一个.NET Core 模板 https://github.com/cilerler/burcin/blob/master/dist/.template.config/template.json想知道如何根据设置的标志隐藏 markdown 文件中的部分内容?

正如您在下面看到的,我尝试了在 CS 项目文件中所做的操作,但它不起作用。

自述文件.md

# Steps

- createSolutionFile.ps1

<!--#if (CacheSqlServer)-->
- sql-cache.ps1
    1. create database `DistributedCache`
    2. create schema `cache`
    3. run the script
<!--#endif-->

- user-secrets.ps1

<!--#if (EntityFramework)-->
- scaffold.ps1
- migrate.ps1 
<!--#endif-->

- build.ps1

<!--#if (WindowsService)-->
- windows-service.ps1
<!--#endif-->

默认情况下,模板引擎仅在特定的文件类型列表中支持这些条件运算符,有时具有不同的语法。您可以找到该文件列表在协调器的源代码中 https://github.com/dotnet/templating/blob/8986b68/src/Microsoft.TemplateEngine.Orchestrator.RunnableProjects/SimpleConfigModel.cs#L387-L464。截至目前,该列表不包括 Markdown 文件,这就是为什么您没有在那里获得任何功能的原因。

幸运的是,似乎有一种配置方法特殊定制操作 https://github.com/dotnet/templating/wiki/%22Runnable-Project%22-Templates#customoperations-optional-and-specialcustomoperations-optional内的自定义文件类型template.json,它允许您定义自定义操作 https://github.com/dotnet/templating/wiki/%22Runnable-Project%22-Templates#customoperationsoperations-optional例如对于条件运算符。

添加这样的东西应该可以工作:

"SpecialCustomOperations": {
  "**/*.md": {
    "operations": [
      {
        "type": "conditional",
        "configuration": {
          "if": ["---#if"],
          "else": ["---#else"],
          "elseif": ["---#elseif", "---#elif"],
          "endif": ["---#endif"],
          "trim" : "true",
          "wholeLine": "true",
        }
      }
    ]
  }
}

它应该允许您在您的.md files:

# This is an example Markdown

---#if (FooBar)
Foo bar
---#elif (BarBaz)
Bar baz
---#else
Baz qux
---#endif

请注意,我在这里使用了不同的语法,因为基于单行的语法更容易配置。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

.NET Core 模板的 Markdown 语法是什么 的相关文章

随机推荐