import re from abc import abstractmethod, ABC class Terminator(ABC): def __init__(self, target): self._target = target self._glossary_cache = {} self._media_dir = None def set_media_dir(self, media_dir): self._media_dir = media_dir def make_terms(self, entry): gid = entry.get_global_identifier() glossary = self.__get_full_glossary(entry) terms = [[gid, glossary]] keys = self.__get_keys(entry) link = f"@@@LINK={gid}" for key in keys: if key.strip() != "": terms.append([key, link]) for subentry_list in self._subentry_lists(entry): for subentry in subentry_list: for term in self.make_terms(subentry): terms.append(term) return terms def __get_full_glossary(self, entry): glossary = [] style_link = f"" glossary.append(style_link) glossary.append(self._glossary(entry)) for x in self._link_glossary_parameters(entry): (subentries, list_title) = x if len(subentries) == 0: continue items = [] for subentry in subentries: exp = subentry.get_first_expression() gid = subentry.get_global_identifier() item = f"