-
Notifications
You must be signed in to change notification settings - Fork 0
/
doc-linking.rkt
24 lines (24 loc) · 1.07 KB
/
doc-linking.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#lang racket
(require "logging.rkt"
scribble/xref
setup/xref
sugar/coerce
txexpr)
(define docs-class "docs")
(define (docs module-path export . xs-in)
(log-emu-debug (format "export is: ~s\n" export))
(define xref (load-collections-xref))
(define linkname (if (null? xs-in) (list export) xs-in))
(define tag (xref-binding->definition-tag xref (list module-path (->symbol export)) #f))
(define-values (path url-tag)
(xref-tag->path+anchor xref tag #:external-root-url "http://pkg-build.racket-lang.org/doc/"))
`(a ((href ,(format "~a#~a" path url-tag)) (class ,docs-class)) ,@linkname))
(define (link-to-docs tx)
(cond [(and (eq? (get-tag tx) 'span)
(attrs-have-key? (get-attrs tx) 'class)
(member (attr-ref tx 'class) '("k" "nb")))
(log-emu-debug (format "export argument is: ~s" (string-join (get-elements tx) "")))
(log-emu-debug (format "remaining arguments are: ~s" (cdr (get-elements tx))))
(docs 'racket (string-join (get-elements tx) ""))]
[else tx]))
(provide link-to-docs)