kayjan / bigtree

Tree Implementation and Methods for Python, integrated with list, dictionary, pandas and polars DataFrame.

Home Page:https://bigtree.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature Request - Markdown List Format Support

junxnone opened this issue · comments

commented

available_styles = {
"ansi": ("| ", "|-- ", "`-- "),
"ascii": ("| ", "|-- ", "+-- "),
"const": ("\u2502 ", "\u251c\u2500\u2500 ", "\u2514\u2500\u2500 "),
"const_bold": ("\u2503 ", "\u2523\u2501\u2501 ", "\u2517\u2501\u2501 "),
"rounded": ("\u2502 ", "\u251c\u2500\u2500 ", "\u2570\u2500\u2500 "),
"double": ("\u2551 ", "\u2560\u2550\u2550 ", "\u255a\u2550\u2550 "),
"custom": ("", "", ""),
}

Markdown List

  • 1
    • 1.1
      • 1.1.1
        • 1.1.1.1
    • 1.2
      • 1.2.1
  • 2
    • 2.1
  • 3
  • 4

This seems to be printing bullet points depending on the depth of the node - all bullet points seems to be shaded-square and only the first two depth are shaded and unshaded circles respectively.

You can use custom style and use shaded-square bullet and do an if-else to replace the bullet points of the first two depth.

Below is the sample code that I tried

from bigtree import list_to_tree, yield_tree

# Construct tree
path_list = [
    "root/1/1.1/1.1.1/1.1.1.1",
    "root/1/1.2/1.2.1",
    "root/2/2.1",
    "root/3",
    "root/4",
]
root = list_to_tree(path_list)

# Print tree
for branch, stem, node in yield_tree(root, style="custom", custom_style=("    ", "  \u25AA ", "  \u25AA ")):
    if node.depth == 2:
        stem = stem.replace("\u25AA", "\u2022")
    elif node.depth == 3:
        stem = stem.replace("\u25AA", "\u25E6")
    print(f"{branch}{stem}{node.node_name}")

This results in the output

root
  • 1
      ◦ 1.1
          ▪ 1.1.1
              ▪ 1.1.1.1
      ◦ 1.2
          ▪ 1.2.1
  • 2
      ◦ 2.1
  • 3
  • 4
commented

Thanks a lot for reply and the example code.

it works for me.