INNER CODE UNIT · Python

slugify

OWASP/wstg · .github/ebooks/list-chapters.py:54

def slugify(text: str) -> str:
    text = text.lower()
    text = re.sub(r"[\s_]+", "-", text)
    text = re.sub(r"[^\w-]", "", text)
    text = re.sub(r"-+", "-", text).strip("-")
    return text


def synthesize_heading(dirpath: str, root: str) -> tuple[str, str]:
    """Return (display title, anchor id) for a directory's chapter heading.

    The id is derived the same way links.lua derives a link target from a
    folder name (numbering stripped, then slugified) so it always matches.
    The display title preserves chapter numbers (0-6) and appendix letters
    (A-F) for clarity in the outline.
    """
    name = os.path.basename(dirpath)
    num_match = DIR_NUMBER_RE.match(name)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…