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()
def handle_enumerateable(self, tag: QqTag) -> str: """ Uses tags: label, number, name Add tags used manually from enumerateable_envs :param tag: :return: """ doc, html, text = Doc().tagtext() name = tag.name env_localname = self.localize(self.enumerateable_envs[name]) with html("div", klass="env env__" + name): if tag.find("label"): doc.attr(id=self.label2id(tag.label_.value)) number = tag.get("number", "") with html("span", klass="env-title env-title__" + name): if tag.find("label"): with html("a", klass="env-title env-title__" + name, href="#" + self.label2id(tag.label_.value)): text(join_nonempty(env_localname, number) + ".") else: text(join_nonempty(env_localname, number) + ".") doc.asis(" " + self.format(tag, blanks_to_pars=True)) return "<p>" + doc.getvalue() + "</p>\n<p>"