def cite2static(parent, idx, flags): if len(parent) > 0 and idx < len(parent[0].content): tostatic([parent[0].content[idx]], getFlags(parent, idx, flags)) if "id" in parent[0].content[idx].attrs: ref_id = parent[0].content[idx].attrs["id"] ref_num = len(ref_map) + 1 ref_map[ref_id] = ref_num parent[0].content[idx].content ref = html.Div(Class="cite-ref") ref << ("[" + str(ref_num) + "]") txt = html.Div(Class="cite-txt") txt.content = parent[0].content[idx].content parent[0].content[idx].content = [ref, txt] if ref_id in unresolved: lst = unresolved[ref_id] del unresolved[ref_id] for i in range(0, len(lst)): if '#' in lst[i].attrs["href"][1:]: href = lst[i].attrs["href"][1:].split('-#') lst[i].attrs["href"] = '#' + href[0] lst[i] << ("[" + str(ref_map[href[0]]) + "-" + str(ref_num) + "]") else: lst[i] << ("[" + str(ref_num) + "]") return 1
def listOfAbbrev(): if len(loa_section) > 0: lst = html.Ul() for abbr, title in sorted(abbr_defs.items()): item = html.Li() elem = html.Div(Class="toc-elem") elem << (html.Div() << abbr) elem << (html.Div(Class="toc-def") << title) item << elem lst << item loa_section[0] << lst
def subTableOfContents(titles, idx, level, top): lst = html.Ol() item = None value = 1 app = 1 if idx[0] < len(titles): cur = int(titles[idx[0]][0].name[1:]) - 1 while idx[0] < len(titles) and cur >= level: if cur >= top or "page-skip" in titles[idx[0]][1]: idx[0] += 1 elif cur > level: if item is None: item = html.Li() item << subTableOfContents(titles, idx, level + 1, top) else: title_id = "" title_string = "" if len(titles[idx[0]]) > 0: if len(titles[idx[0]][0].content) > 0 and isinstance( titles[idx[0]][0].content[0], html.Tag) and titles[idx[ 0]][0].content[0].name == "a" and "name" in titles[ idx[0]][0].content[0].attrs: title_id = titles[idx[0]][0].content[0].attrs["name"] title_string = titles[idx[0]][0].text() item = html.Li() if "counter-skip" in titles[idx[0]][1]: item.attrs["class"] = "skip" elif "appendix" in titles[idx[0]][1]: item.attrs["value"] = app item.attrs["class"] = "appendix" app += 1 else: item.attrs["value"] = value value += 1 elem = html.Div(Class="toc-elem") elem << ( html.Div() << (html.A(Class="xref", Href="#" + title_id) << title_string)) elem << html.Div(Class="toc-page", Xref="#" + title_id) item << elem lst << item idx[0] += 1 if idx[0] < len(titles): cur = int(titles[idx[0]][0].name[1:]) - 1 return lst
def listOfTables(): if len(lot_section) > 0: lst = html.Ol() for ref_id, caption in table_caps: caption_string = "" if len(caption) > 0: caption_string = caption[0].text() item = html.Li() elem = html.Div(Class="toc-elem") elem << ( html.Div() << (html.A(Class="xref", Href="#" + ref_id) << caption_string)) elem << html.Div(Class="toc-page", Xref="#" + ref_id) item << elem lst << item lot_section[0] << lst