зеркало из https://github.com/electron/electron.git
chore: improve docs relative link linting (#26359)
This commit is contained in:
Родитель
d4e53925ba
Коммит
e65341e282
|
@ -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
|
||||||
|
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче