惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Apple Machine Learning Research
Apple Machine Learning Research
爱范儿
爱范儿
博客园_首页
博客园 - 【当耐特】
V
Visual Studio Blog
博客园 - 叶小钗
月光博客
月光博客
美团技术团队
J
Java Code Geeks
小众软件
小众软件
Y
Y Combinator Blog
博客园 - Franky
Martin Fowler
Martin Fowler
博客园 - 聂微东
Microsoft Azure Blog
Microsoft Azure Blog
IT之家
IT之家
MyScale Blog
MyScale Blog
人人都是产品经理
人人都是产品经理
Microsoft Security Blog
Microsoft Security Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
阮一峰的网络日志
阮一峰的网络日志
酷 壳 – CoolShell
酷 壳 – CoolShell
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
云风的 BLOG
云风的 BLOG

Donghai's Blog

使用DBeaver连接Dynamics 365 Dataverse | Donghai C# 技术备忘 - LINQ | Donghai 为Astro站点添加Google Analytics | Donghai C# 技术备忘 - LINQ - Donghai’s Blog 20260819 说些什么 | Donghai Dynamics 365 interview questions | Donghai C# 技术备忘 (1) | Donghai Dynamics 365 事件框架、事件执行管道 | Donghai 马拉松配速表 | Donghai 马拉松赛事分级 | Donghai 抖音创作日志(2026年) | Donghai 2026年跑步日志(5月开始) | Donghai 2FA | Donghai 初尝Github Actions | Donghai AstroPaper主题添加Waline评论 | Donghai Dynamics 365集中视图/聚焦视图/Focused View | Donghai AstroPaper主题添加GitHub风格的Markdown警告框 | Donghai AstroPaper主题自定义记录 | Donghai 我日常收藏的优质网站资源导航(持续更新) | Donghai 如何从归档页批量获取URL并提交到Bing Webmaster Tools | Donghai PaperMod 使用 Zeoseven 自定义网页字体 | Donghai 我常用的Prompt | Donghai Hugo默认时区导致本地预览文章不显示 | Donghai 通过手动提交工单解决Bing不收录网站问题 | Donghai 如何访问 Power BI 管理门户(Power BI Admin Portal) | Donghai 还在手敲时间戳?Win11输入法一个技巧,秒输当前时间戳 | Donghai 工作术语备忘录(持续更新) | Donghai 使用XrmToolBox导出安全角色表级权限到Excel | Donghai 24年的年终总结 | Donghai World笔记 | Donghai
Markdown代码语法详解 | Donghai
Donghai · 2019-03-10 · via Donghai's Blog

CAUTION

原来的码语法展示是基于Hugo的,现在本站已更新为Astro,所以展示的是AstroPaper主题下的代码语法展示

本文详细介绍主题中的代码展示方式,从基础的行内代码、pre标签到主题特有的Shiki增强语法,包括代码差异高亮、多行标记等功能。

封面图

Table of contents

Open Table of contents
  • 行内代码
  • 纯 pre 标签代码块
  • 使用反引号的代码块
  • AstroPaper 特有的代码块功能
    • 1. 代码差异高亮
    • 代码差异高亮(多行)

行内代码

`This is Inline Code`

This is Inline Code

纯 pre 标签代码块

<pre>
This is pre text
</pre>
This is pre text

使用反引号的代码块

```html file="data/blog/code-syntax-guide.md"
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>Example HTML5 Document</title>
    <meta
      name="description"
      content="Sample article showcasing basic Markdown ..."
    />
  </head>
  <body>
    <p>Test</p>
  </body>
</html>
```
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>Example HTML5 Document</title>
    <meta
      name="description"
      content="Sample article showcasing basic Markdown ..."
    />
  </head>
  <body>
    <p>Test</p>
  </body>
</html>data/blog/code-syntax-guide.md

AstroPaper 特有的代码块功能

AstroPaper主题集成的 Shiki 代码高亮器的增强语法

1. 代码差异高亮

代码差异高亮

  • <!-- [!code ++] --> 表示新增的代码行
  • <!-- [!code --] --> 表示删除的代码行
  • <!-- [!code highlight] --> 高亮某行
function bubbleSort(arr) {
  let n = arr.length - 1; 
  let n = arr.length; 
  let swapped;
  for (let i = 0; i < n - 1; i++) {
    swapped = false;
    for (let j = 0; j < n - 1 - i; j++) {
      if (arr[j] > arr[j + 1]) {
        let temp = arr[j];
        arr[j] = arr[j + 1];
        arr[j + 1] = temp;
        swapped = true; 
      }
    }
    if (!swapped) break;
  }
  return arr;
}

代码差异高亮(多行)

代码差异高亮(多行)

  • [!code ++:3] 表示从这一行开始,接下来的 3 行都是新增的代码
  • [!code --:3] 表示从这一行开始,接下来的 3 行都是删除的代码
public class HelloWorld {
   public static void main(String[] args) {
       System.out.println("Hello World! --L1");
       System.out.println("Hello World! --L2");
       System.out.println("Hello World! --L3");
       System.out.println("Hello World! --L4");
       System.out.println("Hello World! --L5");
       System.out.println("Hello World! --L6");
       System.out.println("Hello World! --L7");
       System.out.println("Hello World! --L8");
       System.out.println("Hello World! --L9");
       System.out.println("Hello World! --L10");
       System.out.println("Hello World! --L11");
       System.out.println("Hello World! --L12");
       System.out.println("Hello World! --L13");
   }
}

(完)

如果这篇文章刚好帮到了你,欢迎请我喝杯咖啡