|
4 | 4 | #if NET7_0_OR_GREATER |
5 | 5 |
|
6 | 6 | using System.Net; |
| 7 | +using OneOf; |
7 | 8 | using static Docfx.Build.HtmlTemplate; |
8 | 9 |
|
9 | 10 | #nullable enable |
@@ -47,28 +48,42 @@ HtmlTemplate Api(Api api) |
47 | 48 | ? default |
48 | 49 | : UnsafeHtml(string.Join(" ", value.metadata.Select(m => $"data-{WebUtility.HtmlEncode(m.Key)}='{WebUtility.HtmlEncode(m.Value)}'"))); |
49 | 50 |
|
50 | | - var isDeprecated = value.deprecated?.Value switch |
| 51 | + var (level, title) = api.Value switch |
51 | 52 | { |
52 | | - bool b when b => true, |
53 | | - string s => true, |
54 | | - _ => false, |
| 53 | + Api1 a1 => (1, a1.api1), |
| 54 | + Api2 a2 => (2, a2.api2), |
| 55 | + Api3 a3 => (3, a3.api3), |
| 56 | + Api4 a4 => (4, a4.api4), |
55 | 57 | }; |
56 | | - var deprecated = isDeprecated ? Html($" <span class='badge rounded-pill text-bg-danger' style='font-size: .5em; vertical-align: middle'>Deprecated</span>") : default; |
57 | | - var deprecatedReason = value.deprecated?.Value is string ds && !string.IsNullOrEmpty(ds) |
58 | | - ? Html($"\n<div class='alert alert-warning' role='alert'>{UnsafeHtml(markup(ds))}</div>") |
59 | | - : default; |
| 58 | + |
| 59 | + var deprecated = DeprecatedBadge(value.deprecated); |
| 60 | + var deprecatedReason = DeprecatedReason(value.deprecated); |
| 61 | + var titleHtml = deprecated is null ? Html($"{title}") : Html($"<span style='text-decoration: line-through'>{title}</span>"); |
60 | 62 |
|
61 | 63 | var src = string.IsNullOrEmpty(value.src) |
62 | 64 | ? default |
63 | 65 | : Html($" <a class='header-action link-secondary' title='View source' href='{value.src}'><i class='bi bi-code-slash'></i></a>"); |
64 | 66 |
|
65 | | - return api.Value switch |
| 67 | + return Html($"<h{level} class='section api' {attributes} id='{value.id}'>{titleHtml} {deprecated} {src}</h{level}> {deprecatedReason}"); |
| 68 | + } |
| 69 | + |
| 70 | + HtmlTemplate? DeprecatedBadge(OneOf<bool, string>? value, string fontSize = ".5em") |
| 71 | + { |
| 72 | + var isDeprecated = value?.Value switch |
66 | 73 | { |
67 | | - Api1 api1 => Html($"<h1 class='section api' {attributes} id='{value.id}'>{api1.api1}{deprecated}{src}</h1>{deprecatedReason}"), |
68 | | - Api2 api2 => Html($"<h2 class='section api' {attributes} id='{value.id}'>{api2.api2}{deprecated}{src}</h2>{deprecatedReason}"), |
69 | | - Api3 api3 => Html($"<h3 class='section api' {attributes} id='{value.id}'>{api3.api3}{deprecated}{src}</h3>{deprecatedReason}"), |
70 | | - Api4 api4 => Html($"<h4 class='section api' {attributes} id='{value.id}'>{api4.api4}{deprecated}{src}</h4>{deprecatedReason}"), |
| 74 | + bool b when b => true, |
| 75 | + string s => true, |
| 76 | + _ => false, |
71 | 77 | }; |
| 78 | + |
| 79 | + return isDeprecated ? Html($" <span class='badge rounded-pill text-bg-danger' style='font-size: {fontSize}; vertical-align: middle'>Deprecated</span>") : null; |
| 80 | + } |
| 81 | + |
| 82 | + HtmlTemplate DeprecatedReason(OneOf<bool, string>? value) |
| 83 | + { |
| 84 | + return value?.Value is string ds && !string.IsNullOrEmpty(ds) |
| 85 | + ? Html($"\n<div class='alert alert-warning' role='alert'>{UnsafeHtml(markup(ds))}</div>") |
| 86 | + : default; |
72 | 87 | } |
73 | 88 |
|
74 | 89 | HtmlTemplate Facts(Facts facts) => facts.facts.Length is 0 ? default : Html( |
@@ -102,17 +117,25 @@ HtmlTemplate Code(Code code) |
102 | 117 | HtmlTemplate Parameters(Parameters parameters) => parameters.parameters.Length is 0 ? default : Html( |
103 | 118 | $"<dl class='parameters'>{parameters.parameters.Select(Parameter)}</dl>"); |
104 | 119 |
|
105 | | - HtmlTemplate Parameter(Parameter parameter) => Html( |
106 | | - $""" |
107 | | - <dt> |
108 | | - {(string.IsNullOrEmpty(parameter.name) ? default |
109 | | - : string.IsNullOrEmpty(parameter.@default) |
110 | | - ? Html($"<code>{parameter.name}</code>") |
111 | | - : Html($"<code>{parameter.name} = {parameter.@default}</code>"))} |
112 | | - {Inline(parameter.type)} |
113 | | - </dt> |
114 | | - <dd>{(string.IsNullOrEmpty(parameter.description) ? default : UnsafeHtml(markup(parameter.description)))}</dd> |
115 | | - """); |
| 120 | + HtmlTemplate Parameter(Parameter parameter) |
| 121 | + { |
| 122 | + var deprecated = DeprecatedBadge(parameter.deprecated, ".9em"); |
| 123 | + var lineThrough = deprecated is not null ? UnsafeHtml(" style='text-decoration: line-through'") : default; |
| 124 | + |
| 125 | + var title = string.IsNullOrEmpty(parameter.name) ? default |
| 126 | + : string.IsNullOrEmpty(parameter.@default) |
| 127 | + ? Html($"<code{lineThrough}>{parameter.name}</code>") |
| 128 | + : Html($"<code{lineThrough}>{parameter.name} = {parameter.@default}</code>"); |
| 129 | + |
| 130 | + return Html( |
| 131 | + $""" |
| 132 | + <dt>{title} {Inline(parameter.type)} {deprecated}</dt> |
| 133 | + <dd> |
| 134 | + {DeprecatedReason(parameter.deprecated)} |
| 135 | + {(string.IsNullOrEmpty(parameter.description) ? default : UnsafeHtml(markup(parameter.description)))} |
| 136 | + </dd> |
| 137 | + """); |
| 138 | + } |
116 | 139 |
|
117 | 140 | HtmlTemplate Inline(Inline? inline) => inline?.Value switch |
118 | 141 | { |
|
0 commit comments