Fixup TOC script sluggification and documentation

This commit is contained in:
Martin Hořeňovský
2018-09-09 16:16:49 +02:00
parent a212fb440b
commit 46e99e258f
4 changed files with 144 additions and 119 deletions

View File

@@ -26,7 +26,7 @@ from scriptCommon import catchPath
minTocEntries = 4
headingExcludeDefault = [1,3,4,5] # use level 2 headers for at default
headingExcludeRelease = [2,3,4,5] # use level 1 headers for release-notes.md
headingExcludeRelease = [1,3,4,5] # use level 1 headers for release-notes.md
documentsDefault = os.path.join(os.path.relpath(catchPath), 'docs/*.md')
releaseNotesName = 'release-notes.md'
@@ -91,18 +91,20 @@ def dashifyHeadline(line):
level = len(stripped_right) - len(stripped_both)
stripped_wspace = stripped_both.strip()
# character replacements
replaced_colon = stripped_wspace.replace('.', '')
replaced_slash = replaced_colon.replace('/', '')
rem_nonvalids = ''.join([c if c in VALIDS
else '-' for c in replaced_slash])
# GitHub's sluggification works in an interesting way
# 1) '+', '/', '(', ')' and so on are just removed
# 2) spaces are converted into '-' directly
# 3) multiple -- are not collapsed
lowered = rem_nonvalids.lower()
dashified = re.sub(r'(-)\1+', r'\1', lowered) # remove duplicate dashes
dashified = dashified.strip('-') # strip dashes from start and end
# exception '&' (double-dash in github)
dashified = dashified.replace('-&-', '--')
dashified = ''
for c in stripped_wspace:
if c in VALIDS:
dashified += c.lower()
elif c.isspace():
dashified += '-'
else:
# Unknown symbols are just removed
continue
return [stripped_wspace, dashified, level]