dotnet / dotnet/docfx

[Feature Request] Support fenced code block styles that compatible to `learn.microsoft.com`

Open
#9,921 0 comments 0 reactions 0 assignees View on GitHub
markdown
Dominant language
C#
Stars
4.4k
Forks
890
Avg merge
2h 11m
Merged PRs (30d)
10

Description

**Is your feature request related to a problem? Please describe.**

I want to use `learn.microsoft.com` style `codeHeader` for `Fenced Code Block` syntax.

**Samples Image:**

![image](https://github.com/dotnet/docfx/assets/103790468/47f0295a-3973-4616-9ffc-fbaf730bd9ba)
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis/aspnetcore-openapi?view=aspnetcore-9.0&tabs=visual-studio#add-and-configure-openapi-document-generation

On above example. `csharp` fenced code block is rendered with "C#" header div region.

**Describe the solution you'd like**

Add custom `CodeBlockRenderer` implementation to support following features.
- If language is specified (e.g. `csharp`). Display normalize language name at `codeHeader` (e.g. `C#`).
- Change `copy` button location/style to `learn.microsoft.com` style.
- If language and filename is specified (e.g.: `csharp Sample.cs`). Display filename at `codeHeader` (e.g.: Sample.cs) instead of language name. (Some other markdown processor support this kind of features)

**Additional context**
trailing string after `Fenced code block` is defined as [`info string`](https://spec.commonmark.org/0.28/#info-string) by CommonMark Spec.
Thought `info string` format is not standardized.
See: https://talk.commonmark.org/t/code-blocks-extension-for-filenames-and-line-numbers/536/9

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.