From 65702bffbe8ae823b3684ffd413572e549f9bd21 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Thu, 13 Dec 2007 17:49:52 +0000 Subject: [PATCH] avoid all characters that have to be encoded in Scribble-generated HTML anchors svn: r7994 original commit: 914a3ab7844733a169110e1c71fb6bf3514f6b83 --- collects/scribble/html-render.ss | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/collects/scribble/html-render.ss b/collects/scribble/html-render.ss index 38d6c5cc..e1421d01 100644 --- a/collects/scribble/html-render.ss +++ b/collects/scribble/html-render.ss @@ -39,19 +39,28 @@ (main-collects-relative->path p)))) ;; HTML anchors are case-insenstive. To make them - ;; distinct, add a "^" in front of capital letters. + ;; distinct, add a "." in front of capital letters. + ;; Also clean up characters that give browers trouble + ;; (i.e., the ones that are not allowed as-in in URI + ;; codecs) by using "~" followed by a hex encoding. (define (anchor-name v) (let loop ([s (format "~a" v)]) (cond - [(regexp-match-positions #rx"[A-Z:]" s) + [(regexp-match-positions #rx"[A-Z.]" s) + => (lambda (m) + (string-append + (loop (substring s 0 (caar m))) + "." + (substring s (caar m) (cdar m)) + (loop (substring s (cdar m)))))] + [(regexp-match-positions #rx"[^-a-zA-Z0-9_!*'().]" s) => (lambda (m) (string-append (substring s 0 (caar m)) - ":" - (substring s (caar m) (cdar m)) + "~" + (format "~x" (char->integer (string-ref s (caar m)))) (loop (substring s (cdar m)))))] [else s]))) - ;; ---------------------------------------- ;; main mixin