Normalize whitespace in the arguments of <indexterm>
authorPeter Eisentraut <peter_e@gmx.net>
Sun, 24 Apr 2011 22:12:16 +0000 (01:12 +0300)
committerPeter Eisentraut <peter_e@gmx.net>
Sun, 24 Apr 2011 22:25:43 +0000 (01:25 +0300)
Strip leading and trailing whitespace and replace interior whitespace
by a single space.  This avoids problems with the index generator
producing duplicate index entries for terms that differ only in
whitespace.

Commit dca30da3433c40b5f92f1704c496cda052decef9 actually fixed all the
indexterm elements that would cause this problem at the moment, but in
case it sneaks in again, we're set.

doc/src/sgml/stylesheet.dsl

index b95b357294e9cdcd6e8921a1867438be5656232e..637758ff429eb7d3c7022faed48465a18cc124f3 100644 (file)
 ;; Add more here if needed...
 
 
+;; Replace a sequence of whitespace in a string by a single space
+(define (normalize-whitespace str #!optional (whitespace '(#\space #\U-000D)))
+  (let loop ((characters (string->list str))
+             (result '())
+             (prev-was-space #f))
+    (if (null? characters)
+        (list->string (reverse result))
+        (let ((c (car characters))
+              (rest (cdr characters)))
+          (if (member c whitespace)
+              (if prev-was-space
+                  (loop rest result #t)
+                  (loop rest (cons #\space result) #t))
+              (loop rest (cons c result) #f))))))
+
+
 <!-- HTML output customization ..................................... -->
 
 <![ %output-html; [
      (literal "")))))
 
 
+;; Changed to strip and normalize index term content (overrides
+;; dbindex.dsl)
+(define (htmlindexterm)
+  (let* ((attr    (gi (current-node)))
+         (content (data (current-node)))
+         (string  (strip (normalize-whitespace content))) ;; changed
+         (sortas  (attribute-string (normalize "sortas"))))
+    (make sequence
+      (make formatting-instruction data: attr)
+      (if sortas
+          (make sequence
+            (make formatting-instruction data: "[")
+            (make formatting-instruction data: sortas)
+            (make formatting-instruction data: "]"))
+          (empty-sosofo))
+      (make formatting-instruction data: " ")
+      (make formatting-instruction data: string)
+      (htmlnewline))))
+
+
 ]]> <!-- %output-html -->