pelzflorian (Florian Pelz) <pelzflor...@pelzflorian.de> writes: > I did not use SXPath. This one still looks ugly: > > (div (@ (id "powered-by")) > ,@(__ "Powered by <link \ > url=\"https://www.gnu.org/software/guile/\">GNU Guile</link> and \ > <link url=\"https://haunt.dthompson.us/\">Haunt</link>." > `(link > . ,(lambda (tag attr text) > (a-href > (cadadr attr) > text))))) > > I suppose I should have used SXPath for it to get the URL out of the > (@ (url "…")) attribute?
Since the URL isn’t supposed to be translated I wouldn’t present it as part of the translatable text, i.e. the string would be: Powered by <guile>GNU Guile</guile> and <haunt>Haunt</haunt>. And then I’d apply the transformations: (foo s `(guile . ,(lambda (_ . contents) (a-href "https://www.gnu.org/software/guile/" ,@contents))) `(haunt . ,(lambda (_ . contents) (a-href "https://haunt.dthompson.us/" ,@contents)))) You could use sxpath to avoid cadadr, but it wouldn’t be less verbose: (foo s `(link . ,(lambda (_ attr contents) (a-href (car ((sxpath '(url *text*)) attr)) ,contents)))) (Correctly but annoyingly, “sxpath” always returns a list, so we still need to unpack the URL from the result with “car”.) sxpath takes a path as a list of symbols and returns a selector function that takes a nodeset. So the selector function applied to “attr” gets us a list of all “*text*” nodes inside of a “url” node in the argument “attr”. -- Ricardo GPG: BCA6 89B6 3655 3801 C3C6 2150 197A 5888 235F ACAC https://elephly.net