def parse_content(self): """restructs nested sections: * consider the contents as Body section if no nested sections * merge content-type to Header section """ if len(self) > 0 and not get_children(self, Section): body = Body() transpose_subnodes(self, body) self += body body.dedent() if self.get("content_type"): headers = get_children(self, Headers) if not headers: header = Headers() header.headers.insert(0, "Content-Type: %s" % self["content_type"]) bodies = get_children(self, Body) if len(bodies) == 0: self.append(header) else: pos = self.index(bodies[0]) self.insert(pos, header) else: for header in headers: header.headers.insert(0, "Content-Type: %s" % self["content_type"])
def visit_document(self, node): if isinstance(node[0], nodes.title): # insert section node if doc has only ONE section section = nodes.section() section['ids'].append(nodes.make_id(node[0].astext())) transpose_subnodes(node, section) node += section
def parse_node(cls, node): section = cls(**node.attributes) transpose_subnodes(node, section) section.validate() section.parse_title() section.parse_content() return section
def parse_section(self, node): matched = re.search("^(.*?)\s*\((.*)\)\s*$", node[0].astext()) if not matched: return objname = matched.group(1).strip() typename = matched.group(2).strip() desc = sphinxnodes.desc(domain="js", desctype="data", objtype="data") sig = sphinxnodes.desc_signature(object="", fullname=objname, first=False) sig["names"].append(objname) sig["ids"].append(objname.replace("$", "_S_")) sig += sphinxnodes.desc_name(text="%s (%s)" % (objname, typename)) content = sphinxnodes.desc_content() node.pop(0) transpose_subnodes(node, content) node.replace_self(desc) desc.append(sig) desc.append(content)
def depart_Action(self, node): http_method = node['http_method'] uri = node['uri'] self.env.domaindata['http'][http_method.lower()][uri] = (self.env.docname, node['identifier'], False) desc = addnodes.desc(domain='http', desctype=http_method.lower(), objtype=http_method.lower()) sig = addnodes.desc_signature(method=http_method.lower(), path=uri, first=False, fullname="%s %s" % (http_method, uri)) sig['ids'].append(http_resource_anchor(http_method, uri)) if node['identifier']: sig += addnodes.desc_name(text="%s %s (%s)" % (http_method, uri, node['identifier'])) else: sig += addnodes.desc_name(text="%s %s" % (http_method, uri)) content = addnodes.desc_content() transpose_subnodes(node, content) node.replace_self(desc) desc.append(sig) desc.append(content)
def depart_Attributes(self, node): bullet_list = nodes.bullet_list() bullet_list += nodes.list_item() transpose_subnodes(node, bullet_list[0]) node.replace_self(bullet_list)