Esempio n. 1
0
    def _make_doc(self, pages, path, root, block, text):
        attrs = block.get("attrs", {})
        blocktype = block.get("type")
        body = block.get("body")
        is_root = blocktype == "root"

        # If a title was not passed in: if this is the root, look for a title
        # block, otherwise use the block text
        title = self._get_title(block) or paths.basename(path)

        container = False
        path = paths.basepath(path)
        if is_root:
            # Store a boolean if this page has subtopics
            subtopics = functions.subblock_by_id(block, "subtopics")
            container = subtopics and bool(subtopics.get("body"))
        else:
            blockid = functions.block_id(block)
            path = "%s#%s" % (path, blockid)

        # Look for a summary block
        summary = self._get_block_text(body, "summary")

        # Look for tags in the page attributes
        tags = attrs.get("tags", "").strip().replace(",", "")

        # Find outgoing links
        outgoing = []
        for link in functions.find_links(block):
            val = link.get("value")
            if val:
                outgoing.append(pages.full_path(path, val))
        outgoing = " ".join(outgoing)

        doctype = attrs.get("type")

        d = {
            "path": path,
            "status": attrs.get("status"),
            "category": "_",
            "content": functions.string(text),
            "title": title,
            "sortkey": attrs.get("sortkey") or title.lower(),
            "summary": summary,
            "grams": title,
            "type": doctype,
            "tags": tags,
            "icon": attrs.get("icon"),
            "links": outgoing,
            "container": container,
            "parent": self._get_path_attr(block, path, attrs, "parent"),
            "bestbet": attrs.get("bestbet"),
        }
        return d
Esempio n. 2
0
def find_parm(root, parmid, label):
    """
    Tries to find a parameter in a help document, based on the parameter ID and
    its label.
    """

    from bookish.util import dump_tree

    section = functions.subblock_by_id(root, "parameters")
    if section:
        parameters = functions.find_items(section, "parameters_item")
        for parmblock in parameters:
            if functions.block_id(parmblock) == parmid:
                return parmblock
            elif functions.string(parmblock.get("text")).strip() == label:
                return parmblock