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

1.3 KiB
Raw Blame History

代码配色样例

用于对比 highlight.js 主题:关键字、字符串、注释、类型、数字、内置函数、diff。

C#

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

#[derive(Debug, Clone)]
struct Config {
    port: u16,
    retries: usize,
}

fn main() {
    let cfg = Config { port: 8080, retries: 3 };
    println!("{cfg:?}"); // 调试输出
}

JavaScript

const items = [1, 2, 3].map((n) => n * 2);
function sum(a, b) {
  return a + b; // 行注释
}
console.log(sum(1, 2), items);

JSON

{
  "name": "md-preview",
  "version": "1.4.2",
  "offline": true,
  "count": 39
}

YAML

version: 1
active: 0
tabs:
  - D:\Scripts\md-preview\HANDOFF.md
  - note.md

PowerShell

$env:CARGO_TARGET_DIR = Join-Path $env:TEMP 'mdp-scan-target'
Get-ChildItem -File | Where-Object { $_.Length -gt 1MB }

Diff

- old line
+ new line
  unchanged

行内代码

使用 cargo test 与 build.ps1;正文里的 ==高亮== 仍应生效,而 ==literal== 不应高亮。