问题
I have a .NET Core template and wondering how I can hide partial content from markdown file based on the flags set?
As you may see below I tried what I do in CS project files but it didn't work.
README.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-->
回答1:
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.
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",
}
}
]
}
}
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.
来源:https://stackoverflow.com/questions/53422381/what-is-the-markdown-syntax-for-net-core-templating