Source code for app.view.filters.urls

import re

from markupsafe import Markup
from flask import url_for

from app.view.filters.text import highlight

_ORCID_REGEX = re.compile(r'https?://orcid.org/[0-9-]+')


[docs] def ncbi_url(ncbi_id): return f"https://www.ncbi.nlm.nih.gov/datasets/taxonomy/{ncbi_id}/"
[docs] def chebi_url(chebi_id): return f"https://www.ebi.ac.uk/chebi/searchId.do?chebiId={chebi_id}"
def _render_author_name(author, query_words, query_regex): # John D. Name -> Name, J. D. short_given_name = ' '.join([f"{n[0]}." for n in author['given'].split()]) name = f"{author['family']}, {short_given_name}" if query_regex: name = highlight(name, query_words, query_regex) # If there is an ORCID URL, link the user: if "ORCID" in author and re.fullmatch(_ORCID_REGEX, author["ORCID"]): return f"""<a target="_blank" href="{author["ORCID"]}">{name}</a>""" else: return name