sschwarzer
2022-5-7 14:38:24

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.


sschwarzer
2022-5-7 14:39:09

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


mflatt
2022-5-7 14:52:10

content->string


mflatt
2022-5-7 14:53:03

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


mflatt
2022-5-7 14:53:43

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


sschwarzer
2022-5-7 15:02:47

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.


mflatt
2022-5-7 15:04:15

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?


sschwarzer
2022-5-7 15:04:38

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.)


sschwarzer
2022-5-7 15:05:10

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


mflatt
2022-5-7 15:06:54

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?


sschwarzer
2022-5-7 15:07:02

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?


sschwarzer
2022-5-7 15:07:43

Ok, I’ll try add-between .


sschwarzer
2022-5-7 15:11:03

Yes, that worked. Thank you! :slightly_smiling_face:



samth
2022-5-7 21:50:44

@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


hj93
2022-5-8 03:23:24

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