add optional #:key' argument to tech' and `techlink'

to specify the defined technical term separate from the link content

original commit: 656321dbcb6dd1032fff5dc2ba49ef65ec4a0bfb
This commit is contained in:
Matthew Flatt 2010-08-03 12:48:03 -06:00
parent 8bfe8dddfa
commit 0e875d96bb
2 changed files with 34 additions and 24 deletions

View File

@ -8,12 +8,18 @@
(provide/contract (provide/contract
[deftech (() (#:style? boolean?) #:rest (listof pre-content?) . ->* . element?)] [deftech (() (#:style? boolean?) #:rest (listof pre-content?) . ->* . element?)]
[tech (() (#:doc (or/c module-path? false/c) #:tag-prefixes (or/c (listof string?) false/c)) #:rest (listof pre-content?) . ->* . element?)] [tech (()
[techlink (() (#:doc (or/c module-path? false/c) #:tag-prefixes (or/c (listof string?) false/c)) #:rest (listof pre-content?) . ->* . element?)]) (#:doc (or/c module-path? false/c) #:tag-prefixes (or/c (listof string?) false/c) #:key (or/c string? #f))
#:rest (listof pre-content?)
. ->* . element?)]
[techlink (()
(#:doc (or/c module-path? false/c) #:tag-prefixes (or/c (listof string?) false/c) #:key (or/c string? #f))
#:rest (listof pre-content?)
. ->* . element?)])
(define (*tech make-elem style doc prefix s) (define (*tech make-elem style doc prefix s key)
(let* ([c (decode-content s)] (let* ([c (decode-content s)]
[s (string-foldcase (content->string c))] [s (string-foldcase (or key (content->string c)))]
[s (regexp-replace #rx"ies$" s "y")] [s (regexp-replace #rx"ies$" s "y")]
[s (regexp-replace #rx"s$" s "")] [s (regexp-replace #rx"s$" s "")]
[s (regexp-replace* #px"[-\\s]+" s " ")]) [s (regexp-replace* #px"[-\\s]+" s " ")])
@ -23,7 +29,7 @@
(let* ([e (if style? (let* ([e (if style?
(apply defterm s) (apply defterm s)
(make-element #f (decode-content s)))] (make-element #f (decode-content s)))]
[t (*tech make-target-element #f #f #f (list e))]) [t (*tech make-target-element #f #f #f (list e) #f)])
(make-index-element #f (make-index-element #f
(list t) (list t)
(target-element-tag t) (target-element-tag t)
@ -31,14 +37,14 @@
(list e) (list e)
'tech))) 'tech)))
(define (tech #:doc [doc #f] #:tag-prefixes [prefix #f] . s) (define (tech #:doc [doc #f] #:tag-prefixes [prefix #f] #:key [key #f] . s)
(*tech (lambda (style c tag) (*tech (lambda (style c tag)
(make-link-element (make-link-element
style style
(list (make-element "techinside" c)) (list (make-element "techinside" c))
tag)) tag))
"techoutside" "techoutside"
doc prefix s)) doc prefix s key))
(define (techlink #:doc [doc #f] #:tag-prefixes [prefix #f] . s) (define (techlink #:doc [doc #f] #:tag-prefixes [prefix #f] #:key [key #f] . s)
(*tech make-link-element #f doc prefix s)) (*tech make-link-element #f doc prefix s key))

View File

@ -1022,16 +1022,19 @@ If @racket[style?] is true, then @racket[defterm] is used on
@racket[pre-content].} @racket[pre-content].}
@defproc[(tech [pre-content pre-content?] ... @defproc[(tech [pre-content pre-content?] ...
[#:doc module-path (or/c module-path? false/c) #f] [#:key key (or/c string? #f) #f]
[#:tag-prefixes prefixes (or/c (listof string?) false/c) #f]) [#:doc module-path (or/c module-path? #f) #f]
[#:tag-prefixes prefixes (or/c (listof string?) #f) #f])
element?]{ element?]{
Produces an element for the @tech{decode}d @racket[pre-content], and Produces an element for the @tech{decode}d @racket[pre-content], and
hyperlinks it to the definition of the content as established by hyperlinks it to the definition of the key as established by
@racket[deftech]. The content's string form is normalized in the same @racket[deftech]. If @racket[key] is false, the decoded content is
way as for @racket[deftech]. The @racket[#:doc] and converted to a string (using @racket[content->string]) to use as a
@racket[#:tag-prefixes] arguments support cross-document and key; in either case, the key is normalized in the same way as for
section-specific references, like in @racket[secref]. @racket[deftech]. The @racket[#:doc] and @racket[#:tag-prefixes]
arguments support cross-document and section-specific references, like
in @racket[secref].
With the default style files, the hyperlink created by @racket[tech] With the default style files, the hyperlink created by @racket[tech]
is somewhat quieter than most hyperlinks: the underline in HTML output is somewhat quieter than most hyperlinks: the underline in HTML output
@ -1045,11 +1048,12 @@ defined, but a sentence uses the term ``binding,'' the latter can be
linked to the former using @racketfont["@tech{bind}ing"].} linked to the former using @racketfont["@tech{bind}ing"].}
@defproc[(techlink [pre-content pre-content?] ... @defproc[(techlink [pre-content pre-content?] ...
[#:doc module-path (or/c module-path? false/c) #f] [#:key key (or/c string? #f) #f]
[#:tag-prefixes prefixes (or/c (listof string?) false/c) #f]) [#:doc module-path (or/c module-path? #f) #f]
[#:tag-prefixes prefixes (or/c (listof string?) #f) #f])
element?]{ element?]{
Like @racket[tech], but the link is not a quiet. For example, in HTML Like @racket[tech], but the link is not quiet. For example, in HTML
output, a hyperlink underline appears even when the mouse is not over output, a hyperlink underline appears even when the mouse is not over
the link.} the link.}
@ -1122,12 +1126,12 @@ which is created with @racket[bib-entry]. The entries are typeset in
order as given.} order as given.}
@defproc[(bib-entry [#:key key string?] @defproc[(bib-entry [#:key key string?]
[#:title title (or/c false/c pre-content?)] [#:title title (or/c #f pre-content?)]
[#:is-book? is-book? boolean? #f] [#:is-book? is-book? boolean? #f]
[#:author author (or/c false/c pre-content?) #f] [#:author author (or/c #f pre-content?) #f]
[#:location location (or/c false/c pre-content?) #f] [#:location location (or/c #f pre-content?) #f]
[#:date date (or/c false/c pre-content?) #f] [#:date date (or/c #f pre-content?) #f]
[#:url url (or/c false/c pre-content?) #f]) [#:url url (or/c #f pre-content?) #f])
bib-entry?]{ bib-entry?]{
Creates a bibliography entry. The @racket[key] is used to refer to the Creates a bibliography entry. The @racket[key] is used to refer to the