@@ -228,9 +228,16 @@ function xref_unresolved(node)
228
228
occursin (XREF_REGEX, node. element. destination)
229
229
end
230
230
231
-
232
231
function Selectors. matcher (:: Type{XRefResolvers.Header} , node, slug, meta, page, doc, errors)
233
- return (xref_unresolved (node) && anchor_exists (doc. internal. headers, slug))
232
+ xref_unresolved (node) || return false
233
+ dest = xrefname (node. element. destination)
234
+ child = linkcontent (node)
235
+
236
+ if isempty (dest)
237
+ return isa (child, MarkdownAST. Text)
238
+ else
239
+ return ! startswith (dest, " #" ) && occursin (HEADER_REGEX, dest)
240
+ end
234
241
end
235
242
236
243
function Selectors. runner (:: Type{XRefResolvers.Header} , node, slug, meta, page, doc, errors)
248
255
249
256
250
257
function Selectors. matcher (:: Type{XRefResolvers.Docs} , node, slug, meta, page, doc, errors)
251
- return xref_unresolved (node)
258
+ xref_unresolved (node) || return false
259
+
260
+ dest = xrefname (node. element. destination)
261
+ child = linkcontent (node)
262
+
263
+ if isempty (dest)
264
+ return isa (child, MarkdownAST. Code)
265
+ else
266
+ return ! startswith (dest, " #" )
267
+ end
252
268
end
253
269
254
270
function Selectors. runner (:: Type{XRefResolvers.Docs} , node, slug, meta, page, doc, errors)
@@ -341,6 +357,20 @@ function xrefname(link_url::AbstractString)
341
357
return isnothing (m[1 ]) ? " " : strip (m[1 ])
342
358
end
343
359
360
+ function linkcontent (node:: MarkdownAST.Node )
361
+ isa (node. element, MarkdownAST. Link) || return nothing
362
+
363
+ @assert length (node. children) == 1
364
+
365
+ child = first (node. children). element
366
+
367
+ if isa (child, MarkdownAST. Code) || isa (child, MarkdownAST. Text)
368
+ return child
369
+ end
370
+
371
+ @assert false
372
+ end
373
+
344
374
""" Regular expression for an `@ref` link url.
345
375
346
376
This is used by the [`XRefResolvers.XRefResolverPipeline`](@ref), respectively
@@ -350,28 +380,34 @@ pipeline.
350
380
"""
351
381
const XREF_REGEX = r" ^\s *@ref(\s .*)?$"
352
382
383
+ """ Regular expression for a slug
384
+ """
385
+ const HEADER_REGEX = r" ^\" .+\" $"
386
+
353
387
354
388
# Cross referencing headers.
355
389
# --------------------------
356
390
357
391
function namedxref (node:: MarkdownAST.Node , slug, meta, page, doc, errors)
358
392
@assert node. element isa MarkdownAST. Link
359
393
headers = doc. internal. headers
360
- @assert anchor_exists (headers, slug)
361
- # Add the link to list of local uncheck links.
362
- doc. internal. locallinks[node. element] = node. element. destination
363
- # Error checking: `slug` should exist and be unique.
364
- # TODO : handle non-unique slugs.
365
- if anchor_isunique (headers, slug)
366
- # Replace the `@ref` url with a path to the referenced header.
367
- anchor = Documenter. anchor (headers, slug)
368
- pagekey = relpath (anchor. file, doc. user. build)
369
- page = doc. blueprint. pages[pagekey]
370
- node. element = Documenter. PageLink (page, anchor_label (anchor))
394
+ if anchor_exists (headers, slug)
395
+ # Add the link to list of local uncheck links.
396
+ doc. internal. locallinks[node. element] = node. element. destination
397
+ # Error checking: `slug` should exist and be unique.
398
+ # TODO : handle non-unique slugs.
399
+ if anchor_isunique (headers, slug)
400
+ # Replace the `@ref` url with a path to the referenced header.
401
+ anchor = Documenter. anchor (headers, slug)
402
+ pagekey = relpath (anchor. file, doc. user. build)
403
+ page = doc. blueprint. pages[pagekey]
404
+ node. element = Documenter. PageLink (page, anchor_label (anchor))
405
+ else
406
+ push! (errors, " Header with slug '$slug ' is not unique in $(Documenter. locrepr (page. source)) ." )
407
+ end
371
408
else
372
- push! (errors, " Header with slug '$slug ' is not unique in $(Documenter. locrepr (page. source)) ." )
409
+ push! (errors, " Header with slug '$slug ' in $(Documenter. locrepr (page. source)) does not exist ." )
373
410
end
374
- return
375
411
end
376
412
377
413
# Cross referencing docstrings.
0 commit comments