Skip to content
Back to skills

1081 Toc Anchor Generation 40a9269d

ASecurity

GitHub generates heading anchors by: 1. Lowercasing the heading text 2. Replacing spaces with `-` 3. Removing special characters 4. Stripping emojis (each emoji leaves a `-` in its place) 5. Appending `-N` suffix for duplicate anchors (where N = 1, 2, 3...)

  • 9 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added October 11, 2026
toolspythongobashtestinggitapi

Works with

  • api

Security analysis

A100/100

Scanned October 11, 2026

npx -y skills add tools-only/X-Skills --skill 1081-toc-anchor-generation_40a9269d --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of 1081 Toc Anchor Generation 40a9269d?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for 1081 Toc Anchor Generation 40a9269d
[![Security: A β€” Skills Directory](https://www.skillsdirectory.com/api/skills/tools-only-1081-toc-anchor-generation-40a9269d/badge)](https://www.skillsdirectory.com/skills/tools-only-1081-toc-anchor-generation-40a9269d)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

SKILL.md
# TOC Anchor Generation

## GitHub Anchor Generation Rules

GitHub generates heading anchors by:
1. Lowercasing the heading text
2. Replacing spaces with `-`
3. Removing special characters
4. Stripping emojis (each emoji leaves a `-` in its place)
5. Appending `-N` suffix for duplicate anchors (where N = 1, 2, 3...)

## Style-Specific Heading Formats

### AWESOME Style
```markdown
## Agent Skills πŸ€–
### General
```
- Category anchor: `#agent-skills-` (one dash from emoji)
- Subcategory anchor: `#general` (no trailing dash)

### CLASSIC Style
```markdown
## Agent Skills πŸ€– [πŸ”](#awesome-claude-code)
<h3>General <a href="#awesome-claude-code">πŸ”</a></h3>
```
- Category anchor: `#agent-skills--` (two dashes: one from πŸ€–, one from πŸ”)
- Subcategory anchor: `#general-` (one dash from πŸ”)

### EXTRA/VISUAL Style
Uses explicit `id` attributes on headings, controlling anchors directly.

## Duplicate "General" Subcategory Handling

Multiple "General" subcategories across categories generate:
- First: `#general` (AWESOME) or `#general-` (CLASSIC)
- Second: `#general-1` (AWESOME) or `#general--1` (CLASSIC)
- Third: `#general-2` (AWESOME) or `#general--2` (CLASSIC)

Note: GitHub uses double-dash before the counter in CLASSIC due to the πŸ” emoji.

## Relevant Source Files

| File | Purpose |
|------|---------|
| `scripts/readme/markup/awesome.py` | AWESOME style TOC generation |
| `scripts/readme/markup/minimal.py` | CLASSIC style TOC generation |
| `scripts/readme/markup/visual.py` | EXTRA style TOC generation |
| `scripts/readme/helpers/readme_utils.py` | `get_anchor_suffix_for_icon()` helper |
| `scripts/testing/validate_toc_anchors.py` | Validation utility |

## Validation

### Manual Validation
```bash
# Validate root README (AWESOME style)
make validate-toc

# Validate CLASSIC style
python3 -m scripts.testing.validate_toc_anchors \
  --html .claude/readme-body-html-non-root-readme.html \
  --readme README_ALTERNATIVES/README_CLASSIC.md
```

### Obtaining GitHub HTML
1. Push README to GitHub
2. View rendered README page
3. Open browser dev tools (F12)
4. Find `<article>` element containing README content
5. Copy inner HTML to `.claude/root-readme-html-article-body.html`

### Automated Tests
```bash
make test  # Includes TOC anchor validation tests
```

## Common Pitfalls

1. **Extra dash before suffix**: `#{anchor}-{suffix}` when `suffix` already contains `-`
2. **Missing back-to-top dash**: CLASSIC style headings include πŸ” which adds a dash
3. **Wrong General counter format**: CLASSIC uses `general--N`, AWESOME uses `general-N`

## HTML Fixture Storage

GitHub-rendered HTML fixtures are stored in `tests/fixtures/github-html/` (version controlled).
Fixture filenames indicate root vs non-root placement to detect potential rendering differences:

| Style | README Path | HTML Fixture | Placement |
|-------|-------------|--------------|-----------|
| AWESOME | `README.md` | `awesome-root.html` | Root |
| CLASSIC | `README_ALTERNATIVES/README_CLASSIC.md` | `classic-non-root.html` | Non-root |
| EXTRA | `README_ALTERNATIVES/README_EXTRA.md` | `extra-non-root.html` | Non-root |
| FLAT | `README_ALTERNATIVES/README_FLAT_ALL_AZ.md` | `flat-non-root.html` | Non-root |

Validation commands:
```bash
# AWESOME (default)
python3 -m scripts.testing.validate_toc_anchors

# Other styles
python3 -m scripts.testing.validate_toc_anchors --style classic
python3 -m scripts.testing.validate_toc_anchors --style extra
python3 -m scripts.testing.validate_toc_anchors --style flat
```

## Validation Status

| Style | Status | Notes |
|-------|--------|-------|
| AWESOME | βœ… | Root README, 30 TOC anchors verified |
| CLASSIC | βœ… | Different anchor format due to πŸ” in headings |
| EXTRA | βœ… | Uses explicit `id` attributes; template anchor fixed |
| FLAT | βœ… | No TOC anchors (flat list format) |

## Future Work

- [ ] Unify anchor generation logic into shared helper with parameterized flags
- [ ] Add CI job to validate TOC anchors on README changes

---

## Architectural Decision: Anchor Generation Unification

**Date**: 2026-01-09

**Context**: TOC anchor generation logic is duplicated across three files (`awesome.py`, `minimal.py`, `visual.py`) with subtle differences due to each style's heading format.

**Options Considered**:

1. **Parameterized flags** - Create shared helper with semantic flags like `has_back_to_top_in_heading`
2. **Unify to ID-based** - Migrate all styles to use explicit `<h2 id="...">` like EXTRA

**Decision**: Option 1 (parameterized flags)

**Rationale**:
- Lower risk: heading markup remains unchanged
- AWESOME style intentionally uses clean markdown (`## Title`) for aesthetic reasons
- ID-based approach would require CLASSIC to restructure its `[πŸ”](#...)` links
- Parameterized flags are self-documenting and decouple anchor logic from style names

**Proposed API**:
```python
def generate_toc_anchor(
    title: str,
    icon: str | None = None,
    has_back_to_top_in_heading: bool = False,
) -> str:
    """Generate TOC anchor for a heading.

    Args:
        title: The heading text (e.g., "Agent Skills")
        icon: Optional trailing emoji icon (e.g., "πŸ€–")
        has_back_to_top_in_heading: True if heading contains πŸ” back-to-top link
    """
```

**Trade-off**: If a style changes its heading format (e.g., CLASSIC removes πŸ”), only the flag value changesβ€”not the shared logic.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.