Skip to content
This repository was archived by the owner on Mar 28, 2021. It is now read-only.

Commit e65341e

Browse files
authored
chore: improve docs relative link linting (electron#26359)
1 parent d4e5392 commit e65341e

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

script/check-relative-doc-links.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,27 @@ def getBrokenLinks(filepath):
9595

9696

9797
def checkSections(sections, lines):
98-
sectionHeader = sections[1].replace('-', '')
98+
invalidCharsRegex = '[^A-Za-z0-9_ \-]'
99+
sectionHeader = sections[1]
99100
regexSectionTitle = re.compile('# (?P<header>.*)')
100101
for line in lines:
101102
matchHeader = regexSectionTitle.search(line)
102103
if matchHeader:
103-
matchHeader = filter(str.isalnum, str(matchHeader.group('header')))
104-
if matchHeader.lower() == sectionHeader:
105-
return True
104+
# This does the following to slugify a header name:
105+
# * Replace whitespace with dashes
106+
# * Strip anything that's not alphanumeric or a dash
107+
# * Anything quoted with backticks (`) is an exception and will
108+
# not have underscores stripped
109+
matchHeader = str(matchHeader.group('header')).replace(' ', '-')
110+
matchHeader = ''.join(
111+
map(
112+
lambda match: re.sub(invalidCharsRegex, '', match[0])
113+
+ re.sub(invalidCharsRegex + '|_', '', match[1]),
114+
re.findall('(`[^`]+`)|([^`]+)', matchHeader),
115+
)
116+
)
117+
if matchHeader.lower() == sectionHeader:
118+
return True
106119
return False
107120

108121

0 commit comments

Comments
 (0)