Skip to content

Commit 960bd23

Browse files
committed
0.5.1 Update
added another preferred-references check
1 parent ba750cc commit 960bd23

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = 'sphinxfortran_ng'
3-
version = '0.5.0'
3+
version = '0.5.1'
44
authors = [{name = "Lorenzo Crippa", email="[email protected]"}]
55
description = "An improved version of the sphinx-fortran python module"
66
readme = "README.md"

src/sphinxfortran_ng/fortran_domain.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,7 @@ class FortranXRefRole(XRefRole):
10701070
def process_link(self, env, refnode, has_explicit_title, title, target):
10711071
refnode['f:module'] = env.temp_data.get('f:module')
10721072
refnode['f:type'] = env.temp_data.get('f:type')
1073+
docname = env.docname
10731074
if not has_explicit_title:
10741075
title = title.lstrip('.') # only has a meaning for the target
10751076
target = target.lstrip('~') # only has a meaning for the title
@@ -1099,8 +1100,20 @@ def process_link(self, env, refnode, has_explicit_title, title, target):
10991100
#if targetshort == ikey.split(f_sep)[-1] and ikey.startswith('f' + f_sep) and (targetlist==[] or (ikey not in targetlist[-1] and targetlist[-1] not in ikey)):
11001101
if targetshort.lower() == ikey.split(f_sep)[-1].lower() and ikey.lower().startswith('f' + f_sep.lower()) and (targetlist == [] or (ikey not in targetlist[-1] and targetlist[-1] not in ikey)):
11011102
targetlist.append(ikey)
1103+
1104+
# Check for preferred cross-references
1105+
if hasattr(env, 'preferred_crossrefs') and docname in env.preferred_crossrefs:
1106+
preferred_crossrefs = env.preferred_crossrefs[docname]
1107+
else:
1108+
preferred_crossrefs = {}
1109+
if target in preferred_crossrefs:
1110+
# If we have a preferred cross-reference, replace the target
1111+
preferred_target = preferred_crossrefs[target]
1112+
if preferred_target in targetlist:
1113+
targetlist = [preferred_target]
1114+
11021115
if len(targetlist)>1:
1103-
print("Warning, duplicate labels for "+title+": ",targetlist)
1116+
print("Warning, duplicate labels for "+target+": ",targetlist)
11041117
target = targetlist[0]
11051118
except:
11061119
pass

0 commit comments

Comments
 (0)