def test_token(): token = Token("name", "tag", 0) assert token.as_dict() == { "type": "name", "tag": "tag", "nesting": 0, "attrs": None, "map": None, "level": 0, "children": None, "content": "", "markup": "", "info": "", "meta": {}, "block": False, "hidden": False, } token.attrSet("a", "b") assert token.attrGet("a") == "b" token.attrJoin("a", "c") assert token.attrGet("a") == "b c" token.attrPush(["x", "y"]) assert token.attrGet("x") == "y" assert token.attrIndex("a") == 0 assert token.attrIndex("x") == 1 assert token.attrIndex("j") == -1
def render_image(self, token: Token): img_node = nodes.image() self.add_line_and_source_path(img_node, token) destination = token.attrGet("src") or "" if self.config.get("relative-images", None) is not None and not is_external_url( destination, None, True): # make the path relative to an "including" document destination = os.path.normpath( os.path.join( self.config.get("relative-images", ""), os.path.normpath(destination), )) img_node["uri"] = destination img_node["alt"] = self.renderInlineAsText(token.children or []) title = token.attrGet("title") if title: img_node["title"] = token.attrGet("title") self.current_node.append(img_node)
def handle_cross_reference(self, token: Token, destination: str): """Create nodes for references that are not immediately resolvable.""" wrap_node = addnodes.pending_xref( refdoc=self.doc_env.docname, reftarget=unquote(destination), reftype="myst", refdomain=None, # Added to enable cross-linking refexplicit=len(token.children or []) > 0, refwarn=True, ) self.add_line_and_source_path(wrap_node, token) title = token.attrGet("title") if title: wrap_node["title"] = title self.current_node.append(wrap_node) inner_node = nodes.inline("", "", classes=["xref", "myst"]) wrap_node.append(inner_node) with self.current_node_context(inner_node): self.render_children(token)