CodeWF.Markdown / 文档 / 03 代码与表格
03 代码与表格
这份文件用于检查代码块高亮、复制按钮、长代码行、表格对齐和复杂单元格内容。代码块语言标签应显示在左上方,复制按钮应显示在右上方。
JSON
json
{
"package": "CodeWF.Markdown",
"avalonia": "12.0.2",
"frameworks": ["net8.0", "net9.0", "net10.0", "net10.0"],
"features": {
"images": true,
"tables": true,
"incrementalRendering": true
}
}C#
csharp
public sealed record MarkdownTheme(string Name, string Key);
public static string Normalize(string? value)
{
return string.IsNullOrWhiteSpace(value)
? "Simple"
: value.Trim();
}TypeScript
typescript
type MarkdownTheme = {
name: string;
key: string;
accent: string;
};
const themes: MarkdownTheme[] = [
{ name: "科技蓝", key: "TechnologyBlue", accent: "#006ADC" },
{ name: "全栈蓝", key: "FullStackBlue", accent: "#2563EB" },
];Shell 与长行
bash
dotnet build src/CodeWF.Markdown.Sample/CodeWF.Markdown.Sample.csproj -m:1
echo "This is a deliberately long command line used to check horizontal scrolling inside the code block when a single line is wider than the preview column."当前用法
xml
<md:MarkdownViewer Markdown="{Binding Markdown}" />csharp
MarkdownThemes.OverrideTypographyResources(app, MarkdownTypographyThemes.BlueGlow);对齐表格
| 包 | 版本 | 许可/费用 | 用途 |
|---|---|---|---|
| Avalonia | 12.0.2 | MIT,免费 | UI 框架 |
| Markdig | 1.1.3 | BSD-2-Clause,免费 | Markdown AST |
| TextMateSharp | 2.0.3 | MIT,免费 | 代码高亮 |
| CommunityToolkit.Mvvm | 8.4.2 | MIT,免费 | 示例 ViewModel |
单元格内联元素
| 场景 | 期望 |
|---|---|
inline code |
背景色来自固定资源 Key |
| 加粗文本 | 表格内仍保持粗体 |
| 链接 | 表格内可点击 |
| 很长的说明文字 | 单元格内应自动换行,不应撑破预览宽度 |