I haven't used the HTML module (though it is, AFAICT, intended for parsing HTML, not writing it). But the examples in the webserver docs (e.g., `send/back`) don't use that module. Instead, they construct responses out of X-expressions.
Judging from your example, perhaps you are mixing up the two? (Or maybe three — the documentation snippet you cited for `style` was from `scribble/html/html`, which is yet another thing.) For example, the quasiquoting on this expression makes it an X-expression, so the tag names (html, body, p) are just quoted symbols, not structs or functions from another module. So as you've written it, it won't work. > `(html > (body (list (p "Hello " (b ,username)) > (p (style "color:red" ; <- how to do this? > "An error occurred processing your request.)) There's no `list` necessary in an X-expression, and the attributes are separated. So the correct X-expression syntax would be: `(html (body (p "Hello " (b ,username)) (p ((style "color:red")) "An error occurred processing your request."))) For styling, you have three choices. 1) Apply the styling directly to the tag as an attribute. As shown above. 2) Apply the styling indirectly through an external CSS file, as John Clements suggested. To do this, you'd need to give your target a 'class' or 'id', and then it would take on whatever styling was defined in the CSS file, e.g., `(html (body (p "Hello " (b ,username)) (p ((class "error")) "An error occurred processing your request."))) 3) Or, since you don't want an external file, you can apply the styling indirectly with inline CSS. You'd still need to give your target a 'class' or 'id', but then the style sheet itself can live inside the X-expression: `(html (style ((type "text/css")) ".error {color: red;}") (body (p "Hello " (b ,username)) (p ((class "error")) "An error occurred processing your request."))) Again, none of these options use external functions. They're just X-expressions and you can generate them however you like. On Aug 24, 2015, at 2:03 PM, George Neuner <gneun...@comcast.net> wrote: > Hi John, > > On 8/24/2015 4:31 PM, John Clements wrote: >> > On Aug 24, 2015, at 12:35 PM, George Neuner <gneun...@comcast.net> wrote: >> > >> > I'm trying to generate some very simple web pages - basically >> > success/failure status for URLs followed from an email. However, I can't >> > seem to figure out how to apply styles - other than predefined headings >> > <h1>, etc. - to the document. >> >> Can you explain in more detail what you mean by “styles”? It sounds like you >> want to take a plain-looking HTML page and change the way it looks—colors, >> fonts, etc. If I’m right about this, then most of what you want will likely >> be accomplished by associating a CSS file with your page. > > That's exactly what I want, but I would like to avoid having separate files > associated with this. I would like to generate the HTML in Racket because I > need to dynamically insert information into it. E.g., > > (send/back > (response/xexpr > `(html > (body (list (p "Hello " (b ,username)) > (p (style "color:red" ; <- how to do this? > "An error occurred processing your request.)) > : > > > as in the web-server documentation (sans the style clause). > > There are examples of reading HTML from a string ... and I suppose I could do > that ... but not of generating styled content directly. > > There is a style struct and a style function in the HTML module, and it seems > like many of the generating functions permit attributes to be attached to > their document nodes, but there don't seem to be any examples, and I am > unable to figure it out from the documentation (which seems quite cryptic in > relation to most Racket documentation). > > George > > -- > You received this message because you are subscribed to the Google Groups > "Racket Users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to racket-users+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.