INNER CODE UNIT · Python

heading_ids

awesome-android-root/awesome-android-root · scripts/check_links.py:35

def heading_ids(text):
    """Map anchor id -> True for every heading (incl. custom {#id} ids)."""
    ids = {}
    counts = {}
    for m in re.finditer(r'^(#{1,6})\s+(.+?)\s*$', text, re.M):
        raw = m.group(2).strip()
        cm = re.match(r'^(.*?)\s*\{#([\w\-]+)\}\s*$', raw)
        if cm:
            base = cm.group(2)
        else:
            base = vp_slugify(raw)
        counts[base] = counts.get(base, 0) + 1
        ids[base if counts[base] == 1 else f'{base}-{counts[base]}'] = True
    return ids


def strip_code(text):
    """Blank out fenced code blocks & inline code so links there are skipped."""

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…