我有一个 .NET Core模板,想知道如何根据设置的标志隐藏markdown文件中的部分内容?
I have a .NET Core template and wondering how I can hide partial content from markdown file based on the flags set?
您可能会在下面看到,我尝试了在CS项目文件中执行的操作,但是没有用.
As you may see below I tried what I do in CS project files but it didn't work.
# 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-->推荐答案
默认情况下,模板引擎仅在某些文件类型列表中仅支持这些条件运算符,有时语法不同.您可以找到文件列表在协调器的来源中.到目前为止,列表中还没有包含Markdown文件,这就是为什么您在那里没有任何功能的原因.
The templating engine by default only supports these conditional operators only in a certain list of file types, sometimes with varying syntax. You can find that list of files in the source of the orchestrator. As of now, the list does not include Markdown files though, which is why you are not getting any functionality there.
幸运的是,似乎有一种方法可以配置对template.json内的自定义文件类型的特殊自定义操作,它使您可以定义自定义操作例如对于条件运算符.
Fortunately, there appears to be a way to configure special custom operations on custom file types inside the template.json, which allows you to define custom operations e.g. for conditional operators.
添加类似的内容应该可以:
Adding something like this should work:
"SpecialCustomOperations": { "**/*.md": { "operations": [ { "type": "conditional", "configuration": { "if": ["---#if"], "else": ["---#else"], "elseif": ["---#elseif", "---#elif"], "endif": ["---#endif"], "trim" : "true", "wholeLine": "true", } } ] } }它应该允许您在.md文件中使用这样的条件:
It should allow you to use conditionals like this in your .md files:
# This is an example Markdown ---#if (FooBar) Foo bar ---#elif (BarBaz) Bar baz ---#else Baz qux ---#endif请注意,我在这里使用了不同的语法,因为基于单行的语法更易于配置.
Note that I used a different syntax here as a single-line based syntax is a lot easier to configure.
更多推荐
.NET Core模板的markdown语法是什么
发布评论