Skip to content

Commit 9412606

Browse files
committed
Normalize whitespace in the arguments of <indexterm>
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 dca30da actually fixed all the indexterm elements that would cause this problem at the moment, but in case it sneaks in again, we're set.
1 parent e6a30a8 commit 9412606

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

doc/src/sgml/stylesheet.dsl

+36
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,22 @@
163163
;; Add more here if needed...
164164

165165

166+
;; Replace a sequence of whitespace in a string by a single space
167+
(define (normalize-whitespace str #!optional (whitespace '(#\space #\U-000D)))
168+
(let loop ((characters (string->list str))
169+
(result '())
170+
(prev-was-space #f))
171+
(if (null? characters)
172+
(list->string (reverse result))
173+
(let ((c (car characters))
174+
(rest (cdr characters)))
175+
(if (member c whitespace)
176+
(if prev-was-space
177+
(loop rest result #t)
178+
(loop rest (cons #\space result) #t))
179+
(loop rest (cons c result) #f))))))
180+
181+
166182
<!-- HTML output customization ..................................... -->
167183

168184
<![ %output-html; [
@@ -414,6 +430,26 @@
414430
(literal "")))))
415431

416432

433+
;; Changed to strip and normalize index term content (overrides
434+
;; dbindex.dsl)
435+
(define (htmlindexterm)
436+
(let* ((attr (gi (current-node)))
437+
(content (data (current-node)))
438+
(string (strip (normalize-whitespace content))) ;; changed
439+
(sortas (attribute-string (normalize "sortas"))))
440+
(make sequence
441+
(make formatting-instruction data: attr)
442+
(if sortas
443+
(make sequence
444+
(make formatting-instruction data: "[")
445+
(make formatting-instruction data: sortas)
446+
(make formatting-instruction data: "]"))
447+
(empty-sosofo))
448+
(make formatting-instruction data: " ")
449+
(make formatting-instruction data: string)
450+
(htmlnewline))))
451+
452+
417453
]]> <!-- %output-html -->
418454

419455

0 commit comments

Comments
 (0)