Fix an extremely obscure bug in the help generation.
authorEric S. Raymond <esr@thyrsus.com>
Fri, 15 Sep 2006 20:12:00 +0000 (20:12 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Fri, 15 Sep 2006 20:12:00 +0000 (20:12 +0000)
It was triggered by non-breaking space in xmlto output.

doc/makehelp.py

index 5ff72f45f6f6ab5d055d5b2e91561247d5d03a6c..460fef14dde3fb6a5474eb971c6d0853bc60efd6 100755 (executable)
@@ -15,17 +15,17 @@ beginmarker2 = " ABBREV"
 endmarker2 = "Game History and Modifications"
 
 fp = open("sst-doc.txt", "r")
-savetext = ""
+savetext = []
 state = 0
 while True:
     line = fp.readline()
     if not line:
         break
     if state == 0 and line.startswith(beginmarker1):
-        line = "%% " + line[12:].lstrip()
+        line = "% " + line[12:].lstrip()
         state = 1
     if state == 0 and line.startswith(beginmarker2):
-        savetext += enddelim + "%% ABBREV\n"
+        savetext.append(enddelim + "%% ABBREV\n")
         state = 2
     if state == 1:
         if line.find(endmarker1) > -1:
@@ -34,12 +34,16 @@ while True:
         if line.find(endmarker2) > -1:
             state = 0
     if state:
-        savetext += line.replace("%", "%%")
+        line = line.replace("%", "%%")
+        # Hack Unicode non-breaking spaces into ordinary spaces
+        line = line.replace("\xc2\xa0", " ").replace("\240", "")
+        if line.startswith("Mnemonic:"):
+            while not savetext[-1].strip():
+                savetext.pop()
+        savetext.append(line)
+savetext = "".join(savetext)
 
 # Remove the section titles
 savetext = re.sub("\n+.*\n*Mnemonic:\\s*", "\n********\n%% ", savetext)
 
-# Hack Unicode non-breaking spaces into ordinary spaces
-savetext = savetext.replace("\xc2\xa0", " ").replace("\240", "")
-
 sys.stdout.write(savetext + enddelim)