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

Convert markdown list into bigtree

jet10000 opened this issue · comments

commented
* abc
  * 123
  * 456(name='test', age=10)
* efg
* opq
* rst

convert markdown to bigtree

@jet10000 Do you have a use case for this?

Hi, thanks for using bigtree, this function from markdown/text to tree it already available in str_to_tree method. However, it only converts the tree structure and will not be able to infer the node attributes (in your case, the name and age attributes) as the whole string will be interpreted as a node name.

Another tweak I made was that the resulting tree needs to have a distinct root node, meaning that abc, efg, opq, etc. should all have a common parent.

tree_str = """
root
* abc
  * 123
  * 456(name='test', age=10)
* efg
* opq
* rst
"""

from bigtree import str_to_tree
tree = str_to_tree(tree_str, tree_prefix_list=["\* "])  # added \ as it is interpreted as regex

tree.show()

This will result in output,

root
├── abc
│   ├── 123
│   └── 456(name='test', age=10)
├── efg
├── opq
└── rst
commented

@jet10000 Do you have a use case for this?

Organizing and convert book catalogs and then save it to the database, Many book catalogs are written by markdown or text.

* chapter1(page_no=1)
  * node1(page_no=2)
  * node2(page_no=20)
* chaper2(page_no=21)
  * node3(page_no=22)