]> pere.pagekite.me Git - text-mekanikerord.git/commitdiff
Add 'see also' entries to glossary output.
authorPetter Reinholdtsen <pere@hungry.com>
Mon, 21 Sep 2020 15:16:56 +0000 (17:16 +0200)
committerPetter Reinholdtsen <pere@hungry.com>
Mon, 21 Sep 2020 15:16:56 +0000 (17:16 +0200)
make-glossary

index bc353f8196d70768817cf7b768b03b32c245f40b..51c94bf291b092896226ead78fe549168ba3c88f 100755 (executable)
@@ -75,16 +75,28 @@ def make_glossary_docbook(lang, desccodes, langcodes, output='glossary.xml'):
                 if lang and '[' not in w:
                     w += "[%s]" % lang
                 entry.append(E.indexterm(E.primary(w)))
                 if lang and '[' not in w:
                     w += "[%s]" % lang
                 entry.append(E.indexterm(E.primary(w)))
+    ids = {}
     glossary = E.glossary()
     for e in sorted(words, key=lambda x: langsort(lang, x)):
         ldesc = 'desc-%s' % lang
         if 'topic' in e and lang in topicmap:
             e['topic'] = topicmap[lang][e['topic']]
         if lang in e:
     glossary = E.glossary()
     for e in sorted(words, key=lambda x: langsort(lang, x)):
         ldesc = 'desc-%s' % lang
         if 'topic' in e and lang in topicmap:
             e['topic'] = topicmap[lang][e['topic']]
         if lang in e:
+            w = e[lang].split(',')
+            id = w[0] \
+                .replace('[', '_') \
+                .replace(']', '_') \
+                .replace('(', '_') \
+                .replace(')', '_') \
+                .replace('/', '_') \
+                .replace(' ', '_')
+            while id in ids:
+                id = id + 'x'
+            ids[id] = True
             if ldesc not in e:
                 print("warning: %s missing %s description" % (e[lang], lang))
                 continue
             if ldesc not in e:
                 print("warning: %s missing %s description" % (e[lang], lang))
                 continue
-            entry = E.glossentry()
+            entry = E.glossentry(id=id)
             if list_topic and 'topic' in e:
                 entry.append(E.glossterm('%s [%s]' % (e[lang], e['topic'])))
             else:
             if list_topic and 'topic' in e:
                 entry.append(E.glossterm('%s [%s]' % (e[lang], e['topic'])))
             else:
@@ -105,12 +117,26 @@ def make_glossary_docbook(lang, desccodes, langcodes, output='glossary.xml'):
                                                                e[codestr]))))
             glossary.append(entry)
 
                                                                e[codestr]))))
             glossary.append(entry)
 
-    if False: # failed to set docbook glossary like xmlto and lint want it...
-      glossary =\
-        E.glossary(E.title("x"),
-                   E.glossdiv(E.title("y"),
-                              glossary))
-
+            # Add See also entries pointing to main entry
+            if 1 < len(w):
+                for t in w[1:]:
+                    t = t.strip().lstrip()
+                    entry = E.glossentry()
+                    entry.append(E.glossterm(t))
+                    # FIXME
+                    entry.append(E.glosssee(otherterm=id))
+                glossary.append(entry)
+
+    def glosstermlocale(x):
+        # Look up glossterm (FIXME figure out more robust way)
+        t = x.getchildren()[0].text
+        if t:
+            return locale.strxfrm(t)
+        else:
+            return ""
+    # Sort list to mix seealso entries into their correct location.
+    glossary[:] = sorted(glossary, key=glosstermlocale)
+    
     content = lxml.etree.tostring(glossary,
                                   pretty_print=True,
                                   xml_declaration=True,
     content = lxml.etree.tostring(glossary,
                                   pretty_print=True,
                                   xml_declaration=True,