16
16
if TYPE_CHECKING :
17
17
from markdown import Markdown
18
18
19
+ _ATTR_VALUE = r'"[^"<>]+"|[^"<> ]+' # Possibly with double quotes around
19
20
AUTO_REF_RE = re .compile (
20
- r "<span data-(?P<kind>autorefs-identifier|autorefs- optional|autorefs- optional-hover)= "
21
- r'("?) (?P<identifier>[^" <>]*)\2 >(?P<title>.*?)</span>' ,
21
+ rf "<span data-(?P<kind>autorefs-(?: identifier|optional|optional-hover))=(?P<identifier> { _ATTR_VALUE } ) "
22
+ rf"(?: class=(?P<class> { _ATTR_VALUE } ))? (?P<attrs> [^ <>]+)? >(?P<title>.*?)</span>" ,
22
23
flags = re .DOTALL ,
23
24
)
24
25
"""A regular expression to match mkdocs-autorefs' special reference markers
@@ -162,9 +163,11 @@ def fix_ref(url_mapper: Callable[[str], str], unmapped: list[str]) -> Callable:
162
163
"""
163
164
164
165
def inner (match : Match ) -> str :
165
- identifier = match ["identifier" ]
166
+ identifier = match ["identifier" ]. strip ( '"' )
166
167
title = match ["title" ]
167
168
kind = match ["kind" ]
169
+ attrs = match ["attrs" ] or ""
170
+ classes = (match ["class" ] or "" ).strip ('"' ).split ()
168
171
169
172
try :
170
173
url = url_mapper (unescape (identifier ))
@@ -180,11 +183,11 @@ def inner(match: Match) -> str:
180
183
181
184
parsed = urlsplit (url )
182
185
external = parsed .scheme or parsed .netloc
183
- classes = ["autorefs" , "autorefs-external" if external else "autorefs-internal" ]
186
+ classes = ["autorefs" , "autorefs-external" if external else "autorefs-internal" , * classes ]
184
187
class_attr = " " .join (classes )
185
188
if kind == "autorefs-optional-hover" :
186
- return f'<a class="{ class_attr } " title="{ identifier } " href="{ escape (url )} ">{ title } </a>'
187
- return f'<a class="{ class_attr } " href="{ escape (url )} ">{ title } </a>'
189
+ return f'<a class="{ class_attr } " title="{ identifier } " href="{ escape (url )} "{ attrs } >{ title } </a>'
190
+ return f'<a class="{ class_attr } " href="{ escape (url )} "{ attrs } >{ title } </a>'
188
191
189
192
return inner
190
193
0 commit comments