12
12
from sphinx .errors import ExtensionError
13
13
from sphinx .util .docutils import SphinxDirective
14
14
from sphinx .util .logging import getLogger
15
- from sphinx .util .rst import textwidth
16
15
from sphinx .util .matching import get_matching_files
16
+ from sphinx .util .rst import textwidth
17
17
18
18
__version__ = "0.4dev"
19
19
@@ -60,13 +60,16 @@ def run(self):
60
60
# normalize white space and remove "\n"
61
61
if self .arguments :
62
62
page_tags .extend (
63
- [_normalize_tag (tag ) for tag in self .arguments [0 ].split ("," )]
63
+ [_normalize_display_tag (tag ) for tag in self .arguments [0 ].split ("," )]
64
64
)
65
65
if self .content :
66
66
# self.content: StringList(['different, tags,', 'separated'],
67
67
# items=[(path, lineno), (path, lineno)])
68
68
page_tags .extend (
69
- [_normalize_tag (tag ) for tag in "," .join (self .content ).split ("," )]
69
+ [
70
+ _normalize_display_tag (tag )
71
+ for tag in "," .join (self .content ).split ("," )
72
+ ]
70
73
)
71
74
# Remove empty elements from page_tags
72
75
# (can happen after _normalize_tag())
@@ -153,7 +156,7 @@ class Tag:
153
156
154
157
def __init__ (self , name ):
155
158
self .items = []
156
- self .name = name
159
+ self .name = _normalize_display_tag ( name )
157
160
self .file_basename = _normalize_tag (name , dashes = True )
158
161
159
162
def create_file (
@@ -274,7 +277,7 @@ def __init__(self, entrypath: Path):
274
277
275
278
self .tags = []
276
279
if tagblock :
277
- self .tags = [tag . strip ( ).rstrip ('"' ) for tag in tagblock if tag != "" ]
280
+ self .tags = [_normalize_display_tag ( tag ).rstrip ('"' ) for tag in tagblock if tag != "" ]
278
281
279
282
def assign_to_tags (self , tag_dict ):
280
283
"""Append ourself to tags"""
@@ -300,6 +303,14 @@ def _normalize_tag(tag: str, dashes: bool = False) -> str:
300
303
return re .sub (r"[\s\W]+" , char , tag ).lower ().strip (char )
301
304
302
305
306
+ def _normalize_display_tag (tag : str ) -> str :
307
+ """Strip extra whitespace from a tag name for display purposes.
308
+
309
+ Example: ' Tag:with (extra whitespace) ' -> 'Tag:with (extra whitespace)'
310
+ """
311
+ return re .sub (r"\s+" , " " , tag .strip ('"' ).strip ())
312
+
313
+
303
314
def tagpage (tags , outdir , title , extension , tags_index_head ):
304
315
"""Creates Tag overview page.
305
316
0 commit comments