Skip to content

Difference with github in default slug generation #752

@Cimbali

Description

@Cimbali

I think .strip() is wrong in default_slugify():

def default_slugify(title: str) -> str:
"""Default slugify function.
This aims to mimic the GitHub Markdown format, see:
- https://github.com/jch/html-pipeline/blob/master/lib/html/pipeline/toc_filter.rb
- https://gist.github.com/asabaylus/3071099
"""
return _SLUGIFY_CLEAN_REGEX.sub("", title.strip().lower().replace(" ", "-"))

Have a look at this gist testing github slugs, you can hover the links at the left-hand side to check the correct slugs.

If there is a leading/trailing object such as an image, the stripping happens before removing the image (as in myst-parser currently). When slugifying, the image is removed, but no subsequent .strip() happens, which means slugs have a leading/trailing -.

Just removing .strip() should fix the behaviour (but maybe you want to add tests somewhere?)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions