-# Insert a newline after every > because the whole toc is generated as one
-# humungous line that is hard to check. Then split the lines so that each one
-# is a separate element in the vector.
+# Insert a newline after every > except when it is preceded by 'class="quote"',
+# because the whole toc is generated as one humungous line that is hard to
+# check. We have to avoid it in the quote case because that puts a space into
+# the output, and similarly for the </span> the comes afterwards. Easy way out
+# is just not to do it for all </span> occurrences. Unfortunately, Perl does
+# not implement lookbehinds where the alternatives are of different lengths, so
+# we have to take two passes.
+
+
+foreach $line (@toc)
+ {
+ $line =~ s/(?<!class="quote")>\s*/>\n/g;
+ $line =~ s/<\/span>\n/<\/span>/g;
+ }
+
+# Split the lines so that each one is a separate element in the vector.