From 28a9df3159959ce66755c88787fefba221ce02e9 Mon Sep 17 00:00:00 2001
From: Cimbali
Date: Tue, 13 Jun 2023 17:56:13 +0200
Subject: [PATCH] =?UTF-8?q?=F0=9F=91=8C=20Improve=20default=20slug=20gener?=
=?UTF-8?q?ation=20for=20heading=20anchors=20(#753)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This commit makes the slug generation closer to GitHub,
in that, starting/ending whitespace will not be stripped.
For example, ``# ` a` b `c ` `` will now correctly create the slug
`-a-b-c-` and not `a-b-c`
Co-authored-by: Chris Sewell
---
myst_parser/mdit_to_docutils/base.py | 2 +-
tests/test_sphinx/sourcedirs/references/index.md | 4 ++++
.../test_sphinx_builds/test_references.html | 14 ++++++++++++++
.../test_references.resolved.xml | 9 ++++++++-
.../test_sphinx_builds/test_references.xml | 9 ++++++++-
5 files changed, 35 insertions(+), 3 deletions(-)
diff --git a/myst_parser/mdit_to_docutils/base.py b/myst_parser/mdit_to_docutils/base.py
index c70ae8fb..b70db12e 100644
--- a/myst_parser/mdit_to_docutils/base.py
+++ b/myst_parser/mdit_to_docutils/base.py
@@ -1974,7 +1974,7 @@ def default_slugify(title: str) -> str:
- 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(" ", "-"))
+ return _SLUGIFY_CLEAN_REGEX.sub("", title.lower().replace(" ", "-"))
def compute_unique_slug(
diff --git a/tests/test_sphinx/sourcedirs/references/index.md b/tests/test_sphinx/sourcedirs/references/index.md
index 74d0fd6a..5255b475 100644
--- a/tests/test_sphinx/sourcedirs/references/index.md
+++ b/tests/test_sphinx/sourcedirs/references/index.md
@@ -67,3 +67,7 @@ Known explicit [**hallo**](#paragraph-target)
Known with title [](#title-target)
Ambiguous [](#duplicate)
+
+# Image in title ![badge](https://shields.io/or/something.svg)
+
+[link up](#image-in-title-)
diff --git a/tests/test_sphinx/test_sphinx_builds/test_references.html b/tests/test_sphinx/test_sphinx_builds/test_references.html
index 55b13a77..35d1aed7 100644
--- a/tests/test_sphinx/test_sphinx_builds/test_references.html
+++ b/tests/test_sphinx/test_sphinx_builds/test_references.html
@@ -263,6 +263,20 @@
+
diff --git a/tests/test_sphinx/test_sphinx_builds/test_references.resolved.xml b/tests/test_sphinx/test_sphinx_builds/test_references.resolved.xml
index 58d73540..f832d049 100644
--- a/tests/test_sphinx/test_sphinx_builds/test_references.resolved.xml
+++ b/tests/test_sphinx/test_sphinx_builds/test_references.resolved.xml
@@ -1,6 +1,6 @@
-
+
Title with
@@ -150,3 +150,10 @@
duplicate
+
+
+ Image in title
+
+
+
+ link up
diff --git a/tests/test_sphinx/test_sphinx_builds/test_references.xml b/tests/test_sphinx/test_sphinx_builds/test_references.xml
index 5069acec..4968ca2f 100644
--- a/tests/test_sphinx/test_sphinx_builds/test_references.xml
+++ b/tests/test_sphinx/test_sphinx_builds/test_references.xml
@@ -1,6 +1,6 @@
-
+
Title with
@@ -128,3 +128,10 @@
Ambiguous
+
+
+ Image in title
+
+
+
+ link up