2323 request , url_for )
2424from markupsafe import Markup
2525from flask_login import login_required , current_user
26- from .knowl import Knowl , knowldb , knowl_title , knowl_exists , knowl_url_prefix , utc_now_naive
26+ from .knowl import Knowl , knowldb , knowl_title , knowl_exists , knowl_url_prefix , knowl_definition , external_definition_link , utc_now_naive
2727from lmfdb .users import admin_required , knowl_reviewer_required
2828from lmfdb .users .pwdmanager import userdb
2929from lmfdb .utils import to_dict , code_snippet_knowl
@@ -170,47 +170,33 @@ def ref_to_link(txt):
170170 thecite = thecite .replace ("\\ " , "" ) # \href --> href
171171
172172 refs = thecite .split ("," )
173- ans = ""
173+ ans = []
174174
175175 # print "refs",refs
176176
177177 for ref in refs :
178178 ref = ref .strip () # because \cite{A, B, C,D} can have spaces
179- this_link = ""
180- if ref .startswith ("href" ):
181- the_link = re .sub (r".*{([^}]+)}{.*" , r"\1" , ref )
182- click_on = re .sub (r".*}{([^}]+)}\s*" , r"\1" , ref )
183- this_link = '{{ LINK_EXT("' + click_on + '","' + the_link + '") | safe}}'
184- elif ref .startswith ("doi" ):
185- ref = ref .replace (":" , "" ) # could be doi:: or doi: or doi
186- the_doi = ref [3 :] # remove the "doi"
187- this_link = '{{ LINK_EXT("DOI:' + the_doi + '","https://doi.org/' + the_doi + '")| safe }}'
188- elif ref .lower ().startswith ("mr" ):
189- ref = ref .replace (":" , "" )
190- the_mr = ref [2 :] # remove the "MR"
191- this_link = '{{ LINK_EXT("MR:' + the_mr + '", '
192- this_link += '"https://mathscinet.ams.org/mathscinet-getitem?mr='
193- this_link += the_mr + '") | safe}}'
194- elif ref .lower ().startswith ("arxiv" ):
195- ref = ref .replace (":" , "" )
196- the_arx = ref [5 :] # remove the "arXiv"
197- this_link = '{{ LINK_EXT("arXiv:' + the_arx + '", '
198- this_link += '"https://arxiv.org/abs/'
199- this_link += the_arx + '")| safe}}'
200- elif ref .lower ().startswith ("zbl" ):
201- ref = ref .replace (":" , "" )
202- the_zbl = ref [3 :] # remove the "Zbl"
203- this_link = '{{ LINK_EXT("Zbl:' + the_zbl + '", '
204- this_link += '"https://zbmath.org/?q=an:'
205- this_link += the_zbl + '")| safe}}'
206-
207- if this_link :
208- if ans :
209- ans += ", "
210- ans += this_link
211-
212- return '[' + ans + ']' + everythingelse
213-
179+ # Special case for href (no colon by design) and for MR (no colon in many existing cases)
180+ for site in ["href" , "mr" ]:
181+ if ref .lower ().startswith (site ):
182+ xid = ref [len (site ):].lstrip (":" )
183+ break
184+ else :
185+ pieces = ref .split (":" )
186+ if len (pieces ) != 2 :
187+ # Improperly formatted ref
188+ continue
189+ site , xid = pieces
190+ site = site .lower ()
191+ try :
192+ url , disp , fragment = external_definition_link (site , xid )
193+ except ValueError :
194+ continue
195+ link = f'{{{{ LINK_EXT("{ disp } ", "{ url } ") | safe}}}}'
196+ if fragment :
197+ link += f" ({ fragment } )"
198+ ans .append (link )
199+ return "[" + ", " .join (ans ) + "]" + everythingelse
214200
215201def md_latex_accents (text ):
216202 r"""
@@ -249,7 +235,12 @@ def md_preprocess(text):
249235
250236@app .context_processor
251237def ctx_knowledge ():
252- return {'Knowl' : Knowl , 'knowl_title' : knowl_title , 'knowl_url_prefix' : knowl_url_prefix , "KNOWL_EXISTS" : knowl_exists }
238+ return {'Knowl' : Knowl ,
239+ 'knowl_title' : knowl_title ,
240+ 'knowl_url_prefix' : knowl_url_prefix ,
241+ "KNOWL_EXISTS" : knowl_exists ,
242+ "knowl_definition" : knowl_definition ,
243+ "external_definition_link" : external_definition_link }
253244
254245
255246@app .template_filter ("render_knowl" )
@@ -263,6 +254,7 @@ def render_knowl_in_template(knowl_content, **kwargs):
263254 {%% from "knowl-defs.html" import KNOWL with context %%}
264255 {%% from "knowl-defs.html" import KNOWL_LINK with context %%}
265256 {%% from "knowl-defs.html" import KNOWL_INC with context %%}
257+ {%% from "knowl-defs.html" import DEFINES with context %%}
266258 {%% from "knowl-defs.html" import TEXT_DATA with context %%}
267259 {%% from "knowl-defs.html" import LINK_EXT with context %%}
268260
@@ -799,6 +791,7 @@ def render_knowl(ID, footer=None, kwargs=None,
799791 {%% from "knowl-defs.html" import KNOWL with context %%}
800792 {%% from "knowl-defs.html" import KNOWL_LINK with context %%}
801793 {%% from "knowl-defs.html" import KNOWL_INC with context %%}
794+ {%% from "knowl-defs.html" import DEFINES with context %%}
802795 {%% from "knowl-defs.html" import TEXT_DATA with context %%}
803796 {%% from "knowl-defs.html" import LINK_EXT with context %%}
804797
0 commit comments