docs: improve relative link linting and fix broken (#26020)

This commit is contained in:
David Sanders 2020-10-19 18:46:27 -07:00 committed by GitHub
parent 042ebdd5b0
commit e6f570d191
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 14 additions and 8 deletions

View file

@ -48,14 +48,20 @@ def getBrokenLinks(filepath):
finally:
f.close()
regexLink = re.compile('\[(.*?)\]\((?P<links>(.*?))\)')
linkRegexLink = re.compile('\[(.*?)\]\((?P<link>(.*?))\)')
referenceLinkRegex = re.compile('^\s{0,3}\[.*?\]:\s*(?P<link>[^<\s]+|<[^<>\r\n]+>)')
links = []
for line in lines:
matchLinks = regexLink.search(line)
matchLinks = linkRegexLink.search(line)
matchReferenceLinks = referenceLinkRegex.search(line)
if matchLinks:
relativeLink = matchLinks.group('links')
relativeLink = matchLinks.group('link')
if not str(relativeLink).startswith('http'):
links.append(relativeLink)
if matchReferenceLinks:
referenceLink = matchReferenceLinks.group('link').strip('<>')
if not str(referenceLink).startswith('http'):
links.append(referenceLink)
for link in links:
sections = link.split('#')