@@ -128,13 +128,8 @@ def note_failure(target):
128
128
# own C role, but both match the same regex, so we try both.
129
129
#
130
130
def markup_func_ref_sphinx3 (docname , app , match ):
131
- cdom = app .env .domains ['c' ]
132
- #
133
- # Go through the dance of getting an xref out of the C domain
134
- #
135
131
base_target = match .group (2 )
136
132
target_text = nodes .Text (match .group (0 ))
137
- xref = None
138
133
possible_targets = [base_target ]
139
134
# Check if this document has a namespace, and if so, try
140
135
# cross-referencing inside it first.
@@ -146,22 +141,8 @@ def markup_func_ref_sphinx3(docname, app, match):
146
141
if (target not in Skipfuncs ) and not failure_seen (target ):
147
142
lit_text = nodes .literal (classes = ['xref' , 'c' , 'c-func' ])
148
143
lit_text += target_text
149
- pxref = addnodes .pending_xref ('' , refdomain = 'c' ,
150
- reftype = 'function' ,
151
- reftarget = target ,
152
- modname = None ,
153
- classname = None )
154
- #
155
- # XXX The Latex builder will throw NoUri exceptions here,
156
- # work around that by ignoring them.
157
- #
158
- try :
159
- xref = cdom .resolve_xref (app .env , docname , app .builder ,
160
- 'function' , target , pxref ,
161
- lit_text )
162
- except NoUri :
163
- xref = None
164
-
144
+ xref = add_and_resolve_xref (app , docname , 'c' , 'function' ,
145
+ target , contnode = lit_text )
165
146
if xref :
166
147
return xref
167
148
note_failure (target )
@@ -188,13 +169,8 @@ def markup_c_ref(docname, app, match):
188
169
RE_typedef : 'type' ,
189
170
}
190
171
191
- cdom = app .env .domains ['c' ]
192
- #
193
- # Go through the dance of getting an xref out of the C domain
194
- #
195
172
base_target = match .group (2 )
196
173
target_text = nodes .Text (match .group (0 ))
197
- xref = None
198
174
possible_targets = [base_target ]
199
175
# Check if this document has a namespace, and if so, try
200
176
# cross-referencing inside it first.
@@ -206,21 +182,9 @@ def markup_c_ref(docname, app, match):
206
182
if not (match .re == RE_function and target in Skipfuncs ):
207
183
lit_text = nodes .literal (classes = ['xref' , 'c' , class_str [match .re ]])
208
184
lit_text += target_text
209
- pxref = addnodes .pending_xref ('' , refdomain = 'c' ,
210
- reftype = reftype_str [match .re ],
211
- reftarget = target , modname = None ,
212
- classname = None )
213
- #
214
- # XXX The Latex builder will throw NoUri exceptions here,
215
- # work around that by ignoring them.
216
- #
217
- try :
218
- xref = cdom .resolve_xref (app .env , docname , app .builder ,
219
- reftype_str [match .re ], target , pxref ,
220
- lit_text )
221
- except NoUri :
222
- xref = None
223
-
185
+ xref = add_and_resolve_xref (app , docname , 'c' ,
186
+ reftype_str [match .re ], target ,
187
+ contnode = lit_text )
224
188
if xref :
225
189
return xref
226
190
@@ -231,30 +195,12 @@ def markup_c_ref(docname, app, match):
231
195
# cross reference to that page
232
196
#
233
197
def markup_doc_ref (docname , app , match ):
234
- stddom = app .env .domains ['std' ]
235
- #
236
- # Go through the dance of getting an xref out of the std domain
237
- #
238
198
absolute = match .group (1 )
239
199
target = match .group (2 )
240
200
if absolute :
241
201
target = "/" + target
242
- xref = None
243
- pxref = addnodes .pending_xref ('' , refdomain = 'std' , reftype = 'doc' ,
244
- reftarget = target , modname = None ,
245
- classname = None , refexplicit = False )
246
- #
247
- # XXX The Latex builder will throw NoUri exceptions here,
248
- # work around that by ignoring them.
249
- #
250
- try :
251
- xref = stddom .resolve_xref (app .env , docname , app .builder , 'doc' ,
252
- target , pxref , None )
253
- except NoUri :
254
- xref = None
255
- #
256
- # Return the xref if we got it; otherwise just return the plain text.
257
- #
202
+
203
+ xref = add_and_resolve_xref (app , docname , 'std' , 'doc' , target )
258
204
if xref :
259
205
return xref
260
206
else :
@@ -265,10 +211,6 @@ def markup_doc_ref(docname, app, match):
265
211
# with a cross reference to that page
266
212
#
267
213
def markup_abi_ref (docname , app , match , warning = False ):
268
- stddom = app .env .domains ['std' ]
269
- #
270
- # Go through the dance of getting an xref out of the std domain
271
- #
272
214
kernel_abi = get_kernel_abi ()
273
215
274
216
fname = match .group (1 )
@@ -280,7 +222,18 @@ def markup_abi_ref(docname, app, match, warning=False):
280
222
kernel_abi .log .warning ("%s not found" , fname )
281
223
return nodes .Text (match .group (0 ))
282
224
283
- pxref = addnodes .pending_xref ('' , refdomain = 'std' , reftype = 'ref' ,
225
+ xref = add_and_resolve_xref (app , docname , 'std' , 'ref' , target )
226
+ if xref :
227
+ return xref
228
+ else :
229
+ return nodes .Text (match .group (0 ))
230
+
231
+ def add_and_resolve_xref (app , docname , domain , reftype , target , contnode = None ):
232
+ #
233
+ # Go through the dance of getting an xref out of the corresponding domain
234
+ #
235
+ dom_obj = app .env .domains [domain ]
236
+ pxref = addnodes .pending_xref ('' , refdomain = domain , reftype = reftype ,
284
237
reftarget = target , modname = None ,
285
238
classname = None , refexplicit = False )
286
239
@@ -289,17 +242,15 @@ def markup_abi_ref(docname, app, match, warning=False):
289
242
# work around that by ignoring them.
290
243
#
291
244
try :
292
- xref = stddom .resolve_xref (app .env , docname , app .builder , 'ref' ,
293
- target , pxref , None )
245
+ xref = dom_obj .resolve_xref (app .env , docname , app .builder , reftype ,
246
+ target , pxref , contnode )
294
247
except NoUri :
295
248
xref = None
296
- #
297
- # Return the xref if we got it; otherwise just return the plain text.
298
- #
249
+
299
250
if xref :
300
251
return xref
301
- else :
302
- return nodes . Text ( match . group ( 0 ))
252
+
253
+ return None
303
254
304
255
#
305
256
# Variant of markup_abi_ref() that warns whan a reference is not found
0 commit comments