Пример #1
0
def find_mirror_nodes(doc):
    """ Return a list of nodes that contain mirror links. """
    mirror_nodes: List[MirrorNode] = []
    for node in doc.get_nodes():
        links = markdown.find_links(node["content"])
        if "note" in node:
            links.extend(markdown.find_links(node["note"]))
        for link in links:
            try:
                url = dynalist.parse_url(link["url"])
            except dynalist.ParseException:
                continue
            if not url:
                continue
            if url["doc_id"] != doc.get_metadata()["file_id"]:
                continue
            if "zoom_node_id" not in url:
                continue
            if not doc.has_node(url["zoom_node_id"]):
                continue
            if not link["title"] == MIRROR_LINK_TEXT:
                continue
            source_node = doc.get_node(url["zoom_node_id"])
            target_node = node
            mirror_nodes.append(MirrorNode(source_node, target_node, link))
            break  # for link in links
    if len(mirror_nodes) > 0:
        logging.info("Found %d mirror nodes.", len(mirror_nodes))
    return mirror_nodes
 def test_dynalist_zoom_query_url(self):
     """ Dynalist URL with zoom and query """
     result = dynalist.parse_url(
         "https://dynalist.io/d/5_zeWJ0rbUeWXOu_svUrFd3h#z=bdBGyB8FtmnVL2JLPWIePLdf&q=pylint")
     expected = {
         "doc_id": "5_zeWJ0rbUeWXOu_svUrFd3h",
         "zoom_node_id": "bdBGyB8FtmnVL2JLPWIePLdf",
         "query": "pylint"
     }
     self.assertEqual(expected, result)
 def test_dynalist_query_url(self):
     """ Dynalist URL with query """
     result = dynalist.parse_url(
         "https://dynalist.io/d/5_zeWJ0rbUeWXOu_svUrFd3h#q=pylint")
     expected = {
         "doc_id": "5_zeWJ0rbUeWXOu_svUrFd3h",
         "zoom_node_id": "",
         "query": "pylint"
     }
     self.assertEqual(expected, result)
 def test_dynalist_url(self):
     """ Plain Dynalist URL """
     result = dynalist.parse_url(
         "https://dynalist.io/d/5_zeWJ0rbUeWXOu_svUrFd3h")
     expected = {
         "doc_id": "5_zeWJ0rbUeWXOu_svUrFd3h",
         "zoom_node_id": "",
         "query": ""
     }
     self.assertEqual(expected, result)
Пример #5
0
def check_bad_internal_links(doc):
    """ Check for internal links that don't point to a valid node. """
    for node in doc.get_nodes():
        links = markdown.find_links(node["content"])
        if "note" in node:
            links.extend(markdown.find_links(node["note"]))
        for link in links:
            try:
                url = dynalist.parse_url(link["url"])
            except dynalist.ParseException:
                continue
            if not url:
                continue
            if url["doc_id"] != doc.get_metadata()["file_id"]:
                continue
            if "zoom_node_id" not in url:
                continue
            if doc.has_node(url["zoom_node_id"]):
                continue
            logging.warning(
                "Target node does not exist:\nNode id: %s\nContent: %s\nBad link: %s",
                node["id"], node["content"], link["url"])
 def test_non_dynalist_url(self):
     """ Some non-Dynalist URL """
     with self.assertRaises(Exception):
         dynalist.parse_url("https://www.example.com")
 def test_empty_url(self):
     """ No url provided -- throw exception """
     with self.assertRaises(Exception):
         dynalist.parse_url("")
     with self.assertRaises(Exception):
         dynalist.parse_url(None)