def make_numbers(self, root: QqTag) -> None: """ Uses tags: number, label, nonumber, flabel :return: """ for tag in root.children_tags(): name = tag.name if ((name in self.counters or name in self.enumerateable_envs) and not (tag.find('number') or tag.exists('nonumber'))): counter = self.get_counter_for_tag(tag) if counter is not None: counter.increase() tag.append_child(QqTag({'number': str(counter)})) if tag.find('label'): label = tag.label_.value self.label_to_number[label] = str(counter) # self.label_to_title[label] = tag.text_content if tag.find('label') and tag.find('number'): self.label_to_number[tag.label_.value] = tag.number_.value if tag.find('label'): self.label_to_tag[tag.label_.value] = tag if tag.find('flabel'): self.flabel_to_tag[tag.flabel_.value.lower()] = tag self.make_numbers(tag)
def handle_figure(self, tag: QqTag) -> str: """ Currently, only python-generated figures and plotly figures are supported. Also one can use \rawhtml to embed arbitrary HTML code (e.g. use D3.js). Example: \figure \label fig:figure \pythonfigure plt.plot([1, 2, 3], [1, 4, 9]) \caption Some figure Uses tags: figure, label, caption, number, showcode, collapsed :param tag: QqTag :return: HTML of figure """ doc, html, text = Doc().tagtext() subtags = ['pythonfigure', 'plotly', 'rawhtml'] langs = { 'pythonfigure': 'python', 'plotly': 'python', 'rawhtml': 'html' } with html("div", klass="figure"): if tag.find("label"): doc.attr(id=self.label2id(tag.label_.value)) label = tag.label_.value else: label = None for child in tag.children_tags(): if child.name in subtags: if tag.exists("showcode"): doc.asis( self.showcode(child, collapsed=tag.exists("collapsed"), lang=langs.get(child.name))) doc.asis(self.handle(child)) elif child.name == 'caption': with html("div", klass="figure_caption"): if label is not None: with html("a", klass="figure_caption_anchor", href="#" + self.label2id(label)): text( join_nonempty(self.localize("Fig."), tag.get("number"))) text(": ") else: text( join_nonempty(self.localize("Fig."), tag.get("number")) + ": ") doc.asis(self.format(child, blanks_to_pars=True)) return doc.getvalue()