chore: improve docs relative link linting (#26359)

This commit is contained in:
David Sanders 2020-11-18 11:55:11 -08:00 коммит произвёл GitHub
Родитель d4e53925ba
Коммит e65341e282
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 17 добавлений и 4 удалений

Просмотреть файл

@ -95,14 +95,27 @@ def getBrokenLinks(filepath):
def checkSections(sections, lines): def checkSections(sections, lines):
sectionHeader = sections[1].replace('-', '') invalidCharsRegex = '[^A-Za-z0-9_ \-]'
sectionHeader = sections[1]
regexSectionTitle = re.compile('# (?P<header>.*)') regexSectionTitle = re.compile('# (?P<header>.*)')
for line in lines: for line in lines:
matchHeader = regexSectionTitle.search(line) matchHeader = regexSectionTitle.search(line)
if matchHeader: if matchHeader:
matchHeader = filter(str.isalnum, str(matchHeader.group('header'))) # This does the following to slugify a header name:
if matchHeader.lower() == sectionHeader: # * Replace whitespace with dashes
return True # * Strip anything that's not alphanumeric or a dash
# * Anything quoted with backticks (`) is an exception and will
# not have underscores stripped
matchHeader = str(matchHeader.group('header')).replace(' ', '-')
matchHeader = ''.join(
map(
lambda match: re.sub(invalidCharsRegex, '', match[0])
+ re.sub(invalidCharsRegex + '|_', '', match[1]),
re.findall('(`[^`]+`)|([^`]+)', matchHeader),
)
)
if matchHeader.lower() == sectionHeader:
return True
return False return False