Skip to content

Argument to make flugified strings valid XML id attributes. #150

Closed

Description

@jenstroeger

Thank you for this great package! I have a question/feature request, though.

Suppose I have a call like this:

>>> slugify.slugify("1: Into the Dark")
'1-into-the-dark'

which is an invalid XML id attribute because it starts with a number (see also xml:id spec and NCName definition).

Would it make sense to add a valid_xml_id=True argument to the slugify() function? My current approach is somewhat naive:

slug = slugify.slugify(chapter_title, max_length=32)
if regex.fullmatch(r"^\d+.*", slug):
    slug = f"chapter-{slug}"

but I think having support from slugify() might benefit others, too? Happy to attempt a PR, if it helps.

Activity

  1. un33k commented on Mar 3, 2024

    @un33k
    Owner

    @jenstroeger It would be best if slugify adhered to the Unix motto: Do one thing, do it well.

    Therefore, any special operations should be performed before or after calling slugify.

  2. un33k commented on Sep 8, 2026

    @un33k
    Owner

    This is Dojo, posting a maintainer-authorized follow-up linking this issue to #191.

    An XML-specific slug option is not adopted. XML identifier validation and any required prefixing remain caller responsibilities.

    The default algorithm remains legacy; improved output rules are opt-in. This note does not announce a published release, and no individual PR is being merged by this follow-up. Thank you for the contribution and discussion.

    🚀 Generated with Dojo ⛩️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions