
How can I render a Scribble expression/element to a string? For example, in a function I have (string-join
(map
(lambda (term)
(secref term #:doc (list 'lib url)))
terms)
", ")
but string-join
complains that it got a list of link-element
instead of a list of string
. I want to wrap the (secref ...)
in something that converts it to a string.

(Yes, this could also be done with for/list
instead of map
, but that doesn’t really change my question. :wink: )

content->string

But maybe that doesn’t do what you want, because you probably want the string after a resolve pass

Is this within something that will be rendered as a Scribble document?

Yes, I found that it converts to plain text, for example (content->string (bold "text"))
gives just the text, not the text rendered in bold.

What does it mean for a string’s text to be bold? Do you have in mind rendering the content to some format like markdown or HTML?

Yes, here’s some more context, the whole definition of the function: @(define (secref* term-or-terms document)
(define terms
(if (list? term-or-terms)
term-or-terms
(list term-or-terms)))
(define url
(match document
['glossary "racket-glossary/scribblings/glossary.scrbl"]
['guide "scribblings/guide/guide.scrbl"]
['reference "scribblings/reference/reference.scrbl"]
[_ (raise-user-error "invalid document type")]))
(string-join
(for/list ([term terms])
(content->string (bold term))
#;(secref term #:doc (list 'lib url)))
", "))
and it should be used like @itemlist[
@item{@secref*['("Binding" "Let" "Location") 'glossary] @in-g}
@item{@secref*["set!" 'guide] @in-rg}
@item{@secref*["set!" 'reference] @in-rr}]
(@in-g
etc. define just strings.)

Yes, I’m generating HTML from a Scribble document.

I don’t understand why you’re trying to arrive at a string. Since this is part of a Scribble document representation, I think you want “content”. Use add-between
(to create a list) instead of string-join
?

I’ve used a function that returns a single (secref ...)
result without problems, so the secref
result is rendered by Scribble, and it seems I do need this rendering to HTML as part of my function. But maybe there’s another approach?

Ok, I’ll try add-between
.

Yes, that worked. Thank you! :slightly_smiling_face:

Did anyone attend the Racket meet-up ? I was wondering how it went? https://racket.discourse.group/t/racket-meet-up-saturday-7-may-18-00-utc/846?u=spdegabrielle\|https://racket.discourse.group/t/racket-meet-up-saturday-7-may-18-00-utc/846?u=spdegabrielle

@greg The http tests started failing recently (going from 24 seconds to 180 seconds for no reason that I know of): http://drdr.racket-lang.org/60508/racket/share/pkgs/http/http/request.rkt

here is a scheme to c compiler with cps conversion and closure conversion im working on. its written in common lisp though. im going to try to implement racket macros so it can be a racket to c compiler. not entirely working though https://github.com/Jobhdez/scheme-to-c