Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update link generation code #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 13 additions & 16 deletions _scripts/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def cleanse(txt):


def datasheet_link(text):
links = ['http', 'www', 'ftp']
links = ['https:', 'http:', 'www.', 'ftp:']

if not text:
text = ''
Expand All @@ -123,24 +123,21 @@ def datasheet_link(text):

el = element

# Strip quote characters
start = ['"', "'", "[", "(", "{", ":"]
end = ['"', "'", "]", ")", "}", ".", ","]

for s in start:
if el.startswith(s):
el = el[1:]

for e in end:
if el.endswith(e):
el = el[:-1]

# Strip illegal characters
quotes = "\"'[]{}():.,; *"

# Remove from start
while any([el.startswith(q) for q in quotes]):
el = el[1:]

# Remove from end
while any([el.endswith(q) for q in quotes]):
el = el[:-1]

# Links must be remote
if any([el.lower().startswith(i) for i in links]):
link = True

elif el.endswith('.pdf') or '.htm' in el:
link = True

if link:
element = '<a href="{link}">{text}</a>'.format(link=el, text=element)

Expand Down