You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何让GitHub/GitLab Markdown保留rel="me"锚点属性?

在GitHub/GitLab Markdown中保留rel="me"属性的解决方案

问题背景

需要在GitHub/GitLab的Markdown文件(含wiki)中保留rel="me"锚点属性,实现两个核心目标:

  • 完成Mastodon身份验证(无该属性验证直接失败)
  • 让Mastodon用户能便捷跳转至源码仓库
  • 要求单个文件支持多人添加各自的验证链接

测试结论:

  • GitHub/GitLab的GFM(GitHub Flavored Markdown)会自动剥离rel="me"属性
  • Ghostwriter、Codeberg的Markdown处理器可保留该属性(会补充nofollow,但不影响Mastodon验证)
  • 依赖原始视图虽能通过验证,但无法让读者便捷访问源码内容

测试代码片段(翻译后):

考虑以下简单的Markdown片段:

<!-- 用Ghostwriter测试 -->
<!-- 测试以下六行的链接渲染效果 -->
<!-- 第一行 -->
<!-- example.com/@user -->
<!-- https//example.com/@user -->
<!-- https://example.com/@user -->
<!-- <a rel="me" href="https://example.com/@user" target="_blank">User</a> -->
<!-- 最后一行 -->

第一行。

example.com/@user1

http://example.com/@user2

https://example.com/@user3

<a rel="me nofollow" href="https://example.com/@user4" target="_blank">User</a>

最后一行。

可行解决方案

方案一:使用GitHub Pages/GitLab Pages托管独立HTML文件

GitHub/GitLab不会过滤纯HTML文件中的rel="me"属性,这是最直接的解决方式:

  1. 在仓库中新建一个HTML文件(比如profile-links.html),内容示例:
<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <title>身份验证与源码链接</title>
</head>
<body>
  <h2>Mastodon身份验证</h2>
  <!-- 多人可在此添加各自的验证链接 -->
  <p>用户A:<a rel="me" href="https://example.com/@userA" target="_blank">@userA@example.com</a></p>
  <p>用户B:<a rel="me" href="https://example.com/@userB" target="_blank">@userB@example.com</a></p>
  
  <h2>源码仓库入口</h2>
  <p>访问本项目源码:<a href="https://github.com/yourusername/your-repo">GitHub仓库</a></p>
</body>
</html>
  1. 启用仓库的Pages服务(GitHub:Settings → Pages;GitLab:Settings → Pages),获取该HTML文件的访问链接
  2. 将这个HTML链接添加到Mastodon的“身份验证”字段即可完成验证,页面内的源码链接也能让读者直接跳转仓库

方案二:自定义Jekyll模板(适用于GitHub Pages)

如果偏好用Markdown编写内容,可通过Jekyll自定义模板注入rel="me"属性:

  1. 在GitHub Pages仓库中创建_includes/rel-me-link.html模板文件:
<a rel="me nofollow" href="{{ include.href }}" target="_blank">{{ include.text }}</a>
  1. 在Markdown文件中使用Liquid标签调用模板:
{% include rel-me-link.html href="https://example.com/@user" text="@user@example.com" %}
  1. 确保仓库启用Jekyll构建功能,GitHub Pages会渲染出带有rel="me"属性的链接

补充说明

GitHub/GitLab的GFM处理器出于安全和规范考虑,仅允许nofollow、noopener、noreferrer等少数rel属性值,rel="me"不在允许列表中,因此无法直接在Markdown的HTML标签中保留该属性,上述方案是目前最可行的替代方式。

内容的提问来源于stack exchange,提问作者EdFoss

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 13:12:46