Expand description

A handy little tool to create tree diagrams from MD headings

Β§About

This module sits on top of the GenTree structure and contains five functions:

  • A top-level navigator function that takes a Path and a level setting to indicate the level that the output drawing should start at
  • A [parse] function that takes a Path and outputs a list of headings
  • A construct function that builds the GenTree
  • A pretty_print function that traverses the tree and prints the contents to terminal

The overall output should look something like this,

πŸ“„ /document.md
    β”‚
    β”œβ”€β”€ Landlocked
    β”‚    β”œβ”€β”€ Switzerland
    β”‚    β”‚    └── Geneva
    β”‚    β”‚        └── Old Town
    β”‚    β”‚            └── CathΓ©drale Saint-Pierre
    β”‚    └── Bolivia
    β”‚        └── []
    β”‚            └── []
    β”‚                β”œβ”€β”€ Puerta del Sol
    β”‚                └── Puerta de la Luna
    └── Islands
        β”œβ”€β”€ Fresh Water
        └── Australia

Β§Design

This is mostly just an excuse to write recursive tree traversal functions. All functions but the parsing function utilize recursion.

StructsΒ§

Heading

FunctionsΒ§

construct
Constructs a tree of Heading types
navigator
A recursive function that chains the module’s utility functions to pretty-print a table of contents for each Markdown file in the specified directory; The is_file() path contains logic to build a tree from filtered values, skipping headers above the user-supplied level argument; The function also substitues the file name (if any) for all MD files not formatted with Astro’s frontmatter
pretty_print
A wrapper for a recursive preorder(ish) traversal function; Contains logic to print [] on empty trees for more appealing presentation Takes a reference to the GenTree and pretty-prints its contents.