Пример #1
0
 def iterate(node_: FileNode) -> None:
     prefix_tabs = (node_.get_depth() -
                    int(self.ignore_root_dir)) * '\t'
     path = node_.get_path()
     link = './' + str(path.relative_to(self.root.get_path()))
     if not (node_.get_depth() == 0 and self.ignore_root_dir):
         # Ignore Root Directory, show only top level files (start with children of root directory)
         if path.is_dir():
             if self.full_dir_link:
                 # link for intermediate directory
                 print(
                     f"{prefix_tabs}- [{node_.get_filename()}]({link})",
                     file=self.stringio)
             else:
                 # if this is a directory and contains a README.md, then add a link for this directory
                 # no link for current directory otherwise. This behavior is based on self.dir_link
                 if self.dir_link and (path / "README.md").exists():
                     if self.link_dir_readme:
                         link = './' + \
                                str(path.relative_to(
                                    self.root.get_path()) / 'README.md')
                         print(
                             f"{prefix_tabs}- [{node_.get_filename()}]({link})",
                             file=self.stringio)
                     else:
                         print(
                             f"{prefix_tabs}- [{node_.get_filename()}]({link})",
                             file=self.stringio)
                 else:
                     print(f"{prefix_tabs}- {node_.get_filename()}",
                           file=self.stringio)
         elif path.is_file():
             # current node is a file (should be a markdown), if self.remove_md_ext, .md will be removed from
             # the display name
             display_name = node_.get_filename().replace(".md", "") \
                 if node_.get_filename()[-3:] == ".md" and self.remove_md_ext else node_.get_filename()
             if not (self.no_readme_link and path.name == "README.md"):
                 # README.md files will not get a link when self.no_readme_link is True
                 print(f"{prefix_tabs}- [{display_name}]({link})",
                       file=self.stringio)
         else:
             raise ValueError("Unhandled Error")
     children = node_.get_children()
     for child_node in children:
         iterate(child_node)
Пример #2
0
        def iterate(node_: FileNode) -> Iterable:
            prefix_tabs = node_.get_depth() * '\t'
            if node_.get_path().is_file():
                link = './' + \
                       str(node_.get_path().relative_to(self.root.get_path()))
                yield f"{prefix_tabs}- [{node_.get_filename()}]({link})"
            else:
                yield f"{prefix_tabs}- {node_.get_filename()}"

            children = node_.get_children()
            for child_node in children:
                yield from iterate(child_node)
Пример #3
0
 def iterate(node_: FileNode) -> Iterable:
     prefix_tabs = node_.get_depth() * '\t'
     if node_.is_file():
         yield f"{prefix_tabs}<li>{node_.get_filename()}</li>"
     else:
         yield f"{prefix_tabs}<ul>"
         yield f"{prefix_tabs}\t<lh>{node_.get_filename()}</lh>"
     children = node_.get_children()
     for child_node in children:
         yield from iterate(child_node)
     if node_.is_dir():
         yield f"{prefix_tabs}</ul>"
Пример #4
0
 def iterate(node_: FileNode) -> None:
     print("\t" * node_.get_depth() + node_.get_filename(),
           file=self.stringio)
     if node_.get_children():
         for node in node_.get_children():
             iterate(node)
Пример #5
0
 def iterate(node_: FileNode) -> Iterable:
     prefix_tabs = node_.get_depth() * '\t'
     yield f"{prefix_tabs}- {node_.get_filename()}"
     children = node_.get_children()
     for child_node in children:
         yield from iterate(child_node)