Files
md-preview/agent/tests/fixtures/code-samples.md

87 lines
1.3 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 代码配色样例
用于对比 highlight.js 主题:关键字、字符串、注释、类型、数字、内置函数、diff。
## C#
```csharp
using System;
public sealed class Profile
{
private readonly string _name;
public Profile(string name) => _name = name;
// 比较运算符必须保持字面量
public bool IsEmpty() => _name == null || _name.Length == 0;
public override string ToString() => $"Profile({_name})";
}
```
## Rust
```rust
#[derive(Debug, Clone)]
struct Config {
port: u16,
retries: usize,
}
fn main() {
let cfg = Config { port: 8080, retries: 3 };
println!("{cfg:?}"); // 调试输出
}
```
## JavaScript
```javascript
const items = [1, 2, 3].map((n) => n * 2);
function sum(a, b) {
return a + b; // 行注释
}
console.log(sum(1, 2), items);
```
## JSON
```json
{
"name": "md-preview",
"version": "1.4.2",
"offline": true,
"count": 39
}
```
## YAML
```yaml
version: 1
active: 0
tabs:
- D:\Scripts\md-preview\HANDOFF.md
- note.md
```
## PowerShell
```powershell
$env:CARGO_TARGET_DIR = Join-Path $env:TEMP 'mdp-scan-target'
Get-ChildItem -File | Where-Object { $_.Length -gt 1MB }
```
## Diff
```diff
- old line
+ new line
unchanged
```
## 行内代码
使用 `cargo test` 与 `build.ps1`;正文里的 ==高亮== 仍应生效,而 `==literal==` 不应高亮。