Skip to content

Commit 7a5afc1

Browse files
committed
docs: add guidance on GitHub Markdown autolink pitfalls
Add comprehensive documentation about GitHub Flavored Markdown's automatic linking behavior that can create unintended references. Changes: - Created docs/contributing/github-markdown-pitfalls.md with: - Clarification that GFM features SHOULD be used intentionally - Detailed explanation of #NUMBER autolink issue - Examples of other autolink patterns (@mentions, SHAs, GH-) - Best practices and solutions for avoiding unintended links - Quick reference table for AI agents and contributors - Updated .github/copilot-instructions.md with essential rule #11: - Warns about hash-number patterns in Markdown - Links to the detailed pitfalls documentation - Added 'backlinks' to project-words.txt for spell checking This addresses a common issue where AI agents and contributors inadvertently create links to GitHub issues/PRs when using #NUMBER for enumeration (e.g., 'Task #1', 'Step #2'), which GitHub's autolink feature converts into issue references.
1 parent 0911cfd commit 7a5afc1

File tree

3 files changed

+267
-0
lines changed

3 files changed

+267
-0
lines changed

.github/copilot-instructions.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ These principles should guide all development decisions, code reviews, and featu
9999

100100
10. **When organizing code within modules**: Follow the module organization conventions in [`docs/contributing/module-organization.md`](../docs/contributing/module-organization.md). Use top-down organization with public items first, high-level abstractions before low-level details, and important responsibilities before secondary concerns like error types.
101101

102+
11. **When writing Markdown documentation**: Be aware of GitHub Flavored Markdown's automatic linking behavior. Read [`docs/contributing/github-markdown-pitfalls.md`](../docs/contributing/github-markdown-pitfalls.md) for critical patterns to avoid. **NEVER use hash-number patterns for enumeration or step numbering** - this creates unintended links to GitHub issues/PRs. Use ordered lists or alternative formats instead.
103+
102104
## 🧪 Build & Test
103105

104106
- **Lint**: `cargo run --bin linter all` (comprehensive - tests stable & nightly toolchains)
Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
# GitHub Markdown Pitfalls
2+
3+
This document outlines common pitfalls and unexpected behaviors when writing Markdown documentation that will be rendered on GitHub. GitHub uses GitHub Flavored Markdown (GFM), which includes several automatic linking features that can create unintended references if not carefully considered.
4+
5+
## 🎯 Purpose
6+
7+
**GitHub Flavored Markdown features are powerful and should be used!** This guide is NOT about avoiding GitHub Markdown - it's about understanding its behavior to use it intentionally and avoid surprises.
8+
9+
**When to use GitHub Markdown features:**
10+
11+
-**DO** use `#42` when you want to reference issue/PR #42
12+
-**DO** use `@username` when you want to mention someone
13+
-**DO** use commit SHAs when referencing specific commits
14+
-**DO** use `owner/repo#42` for cross-repository references
15+
16+
**This guide warns about UNINTENDED usage** - patterns that accidentally trigger GitHub's autolink behavior when you didn't mean to create a link.
17+
18+
### Common Problems
19+
20+
These issues are particularly problematic because:
21+
22+
- They create unintended links to issues, pull requests, discussions, or commits
23+
- They may link to unrelated content, confusing readers
24+
- They pollute the referenced entities with backlinks
25+
- They make documentation harder to maintain and understand
26+
27+
## ⚠️ Critical Issue: `#NUMBER` Pattern
28+
29+
### The Problem
30+
31+
**GitHub automatically converts `#NUMBER` patterns into links to issues, pull requests, or discussions.**
32+
33+
GitHub uses a unified numbering system across issues, pull requests, and discussions within a repository. When you write `#42` anywhere in Markdown (including documentation files, comments, issue descriptions, or PR descriptions), GitHub automatically creates a link to entity #42.
34+
35+
### Common Mistakes
36+
37+
#### ❌ Bad: Enumerating with `#NUMBER`
38+
39+
```markdown
40+
## Project Tasks
41+
42+
- Task #1: Set up infrastructure
43+
- Task #2: Configure database
44+
- Task #3: Deploy application
45+
```
46+
47+
**What happens**: GitHub converts these to links:
48+
49+
- Task #1: Set up infrastructure ← Becomes a link to issue/PR/discussion #1
50+
- Task #2: Configure database ← Becomes a link to issue/PR/discussion #2
51+
- Task #3: Deploy application ← Becomes a link to issue/PR/discussion #3
52+
53+
This creates confusing and misleading links to potentially unrelated issues.
54+
55+
#### ❌ Bad: Numbered sections or items
56+
57+
```markdown
58+
## Step #1: Install Dependencies
59+
60+
Follow step #1 carefully.
61+
62+
## Configuration Option #3
63+
64+
The option #3 controls timeout behavior.
65+
```
66+
67+
**What happens**: `#1` and `#3` become links to issues/PRs.
68+
69+
### ✅ Solutions
70+
71+
Use alternative numbering formats that don't trigger GitHub's autolink behavior:
72+
73+
#### Solution 1: Use plain numbers without hash
74+
75+
```markdown
76+
## Project Tasks
77+
78+
- Task 1: Set up infrastructure
79+
- Task 2: Configure database
80+
- Task 3: Deploy application
81+
```
82+
83+
#### Solution 2: Use ordered lists (automatic numbering)
84+
85+
```markdown
86+
## Project Tasks
87+
88+
1. Set up infrastructure
89+
2. Configure database
90+
3. Deploy application
91+
```
92+
93+
#### Solution 3: Use alternative numbering schemes
94+
95+
```markdown
96+
## Project Tasks
97+
98+
- Task (1): Set up infrastructure
99+
- Task [1]: Set up infrastructure
100+
- Task No. 1: Set up infrastructure
101+
- Task number 1: Set up infrastructure
102+
```
103+
104+
#### Solution 4: Use descriptive names instead of numbers
105+
106+
```markdown
107+
## Project Tasks
108+
109+
- Task: Infrastructure Setup
110+
- Task: Database Configuration
111+
- Task: Application Deployment
112+
```
113+
114+
### When `#NUMBER` Is Intentional
115+
116+
**Only use `#NUMBER` when you explicitly want to reference a GitHub entity:**
117+
118+
```markdown
119+
## Recent Changes
120+
121+
- Fixed deployment bug in #42
122+
- Implemented feature requested in #87
123+
- See discussion in #105
124+
125+
Closes #42
126+
```
127+
128+
This is the correct use case - creating intentional links to issues, PRs, or discussions.
129+
130+
## 🔗 Other GitHub Autolink Patterns
131+
132+
GitHub automatically converts several other patterns into links. Be aware of these to avoid unintended linking:
133+
134+
### Commit SHA References
135+
136+
**Pattern**: Any 7-40 character hex string that matches a commit SHA
137+
138+
```markdown
139+
❌ Bad: "The version a5c3785 was released"
140+
✅ Good: "The version a5c3785 (commit) was released" or use backticks: `a5c3785`
141+
```
142+
143+
**What GitHub does**: Converts SHA strings into links to commits
144+
145+
**Solution**: Use backticks to prevent linking: `` `a5c3785` `` or add context to make it clear it's a commit reference.
146+
147+
### User and Team Mentions
148+
149+
**Pattern**: `@username` or `@organization/team-name`
150+
151+
```markdown
152+
❌ Bad: "The @admin should configure this"
153+
✅ Good: "The administrator (with @admin role) should configure this"
154+
```
155+
156+
**What GitHub does**: Converts `@mentions` into links and **sends notifications** to mentioned users/teams
157+
158+
**Solution**: Avoid using `@` for generic role references. Use backticks if you need to show the literal syntax: `` `@username` ``
159+
160+
### Cross-Repository References
161+
162+
**Pattern**: `owner/repo#NUMBER`
163+
164+
```markdown
165+
❌ Bad: "Similar to project-name/repo#15"
166+
✅ Good: "Similar to issue 15 in project-name/repo"
167+
```
168+
169+
**What GitHub does**: Creates links to issues/PRs in other repositories
170+
171+
**Solution**: Use descriptive text and only use this pattern when intentionally referencing another repository's issue.
172+
173+
### GH- Prefix Pattern
174+
175+
**Pattern**: `GH-NUMBER`
176+
177+
```markdown
178+
❌ Bad: "Legacy ticket GH-123"
179+
✅ Good: "Legacy ticket GH_123" or "Legacy ticket (GH-123 in old system)"
180+
```
181+
182+
**What GitHub does**: Converts `GH-NUMBER` into issue/PR links
183+
184+
**Solution**: Use alternative separators (`GH_123`) or add context in parentheses.
185+
186+
## 📋 Best Practices Summary
187+
188+
### Do's ✅
189+
190+
- **Use ordered lists** (1., 2., 3.) for sequential items instead of `#NUMBER`
191+
- **Use backticks** for literal syntax examples: `` `#42` `` shows "#42" without linking
192+
- **Add context** when you must use these patterns: "issue #42" or "commit a5c3785"
193+
- **Test your Markdown** by previewing it on GitHub before committing
194+
- **Use alternative separators** when numbers are needed: `Task-1`, `Item [1]`, `Step (1)`
195+
196+
### Don'ts ❌
197+
198+
- **Don't use `#NUMBER`** for enumeration, step numbers, or general numbering
199+
- **Don't use `@username`** for generic role references (use "administrator" instead)
200+
- **Don't assume patterns are safe** - preview on GitHub to verify
201+
- **Don't use hex strings** carelessly (they might match commit SHAs)
202+
203+
## 🔍 How to Escape These Patterns
204+
205+
If you absolutely must display these patterns literally without linking:
206+
207+
### Use Backticks (Code Formatting)
208+
209+
Backticks prevent autolinking:
210+
211+
```markdown
212+
Use the `#NUMBER` pattern to reference issues.
213+
Mention users with `@username` syntax.
214+
Reference commits using `SHA` hashes like `a5c3785`.
215+
```
216+
217+
### Use Backslash Escaping
218+
219+
Backslashes can escape some Markdown formatting:
220+
221+
```markdown
222+
Use \#42 to avoid linking (may not work in all contexts)
223+
```
224+
225+
**Note**: Backslash escaping doesn't work reliably for all autolink patterns. Backticks are more reliable.
226+
227+
## 🧪 Testing Your Documentation
228+
229+
Before committing documentation:
230+
231+
1. **Preview on GitHub**: Use the GitHub web interface to preview how your Markdown will render
232+
2. **Check for unintended links**: Look for blue, underlined text where you didn't expect links
233+
3. **Verify link targets**: Hover over links to see where they point
234+
4. **Use GitHub's Markdown Preview**: Many editors have GitHub Markdown preview extensions
235+
236+
## 📚 Additional Resources
237+
238+
- [GitHub Flavored Markdown Spec](https://github.github.com/gfm/)
239+
- [GitHub Docs: Basic Writing and Formatting Syntax](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax)
240+
- [GitHub Docs: Autolinked References and URLs](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/autolinked-references-and-urls)
241+
242+
## 🎯 Quick Reference Table
243+
244+
| Pattern | What GitHub Does | Avoid Using For | Safe Alternative |
245+
| --------------- | --------------------------------- | ------------------------- | --------------------------------------- |
246+
| `#42` | Links to issue/PR/discussion #42 | Enumeration, step numbers | `Task 1`, `Step (1)`, ordered lists |
247+
| `@user` | Links to user, sends notification | Generic role references | "administrator", "user role", backticks |
248+
| `a5c3785` (SHA) | Links to commit | Version numbers, IDs | Use backticks: `` `a5c3785` `` |
249+
| `owner/repo#42` | Links to issue in another repo | General references | Descriptive text |
250+
| `GH-42` | Links to issue/PR #42 | Legacy ticket IDs | `GH_42` or add context |
251+
252+
**Note**: These patterns are perfectly valid when you want to create links! This table shows when to avoid them to prevent unintended linking.
253+
254+
## ⚡ For AI Agents
255+
256+
When generating Markdown documentation:
257+
258+
1. **Never use `#NUMBER`** for enumeration - use ordered lists (1., 2., 3.) or alternative formats
259+
2. **Always check** if a pattern might trigger GitHub's autolink behavior
260+
3. **Prefer descriptive text** over shorthand numbering schemes
261+
4. **Use backticks** liberally for literal syntax examples
262+
5. **Think about context**: Will this be viewed on GitHub? Then avoid autolink patterns.
263+
264+
Remember: GitHub's autolink features are designed to make cross-referencing easier, but they can create confusion when used unintentionally in documentation.

project-words.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ appendonly
66
architecting
77
autorestart
88
Avalonia
9+
backlinks
910
browsable
1011
buildx
1112
chdir

0 commit comments

Comments
 (0)