From: Petter Reinholdtsen Date: Mon, 21 Sep 2020 15:16:56 +0000 (+0200) Subject: Add 'see also' entries to glossary output. X-Git-Tag: published-en-nb-2021-07-17~36 X-Git-Url: https://pere.pagekite.me/gitweb/text-mekanikerord.git/commitdiff_plain/a17b773ebf8bfc41d3dc16c2b49a2962d89cf11c Add 'see also' entries to glossary output. --- diff --git a/make-glossary b/make-glossary index bc353f8..51c94bf 100755 --- a/make-glossary +++ b/make-glossary @@ -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))) + 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: + 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 - 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: @@ -105,12 +117,26 @@ def make_glossary_docbook(lang, desccodes, langcodes, output='glossary.xml'): 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,