syntax-tree

... is a tree structure managing syntax/format information for text. It can be used to build the backing model for a WYSIWYG editor or to do syntax highlighting.

Concepts

Example

rust let mut tree: Tree<()> = Tree::new("Hello World"); tree.set(6, "Hello World".len(), ()); tree.set(0, "Hello World".len(), ()); tree.set(4, 7, ()); tree.insert_str(6, "cold "); println!("{:#?}", tree);

The output should be:

|---o ('Hello cold World') |---o ('Hello cold World') # |-- 'Hell' |-- 'o cold ' # |---o ('World') # |-- 'W' # |-- 'orld'

The o say it is a node with children, the # that there is format/syntax information attached to the node/leaf.

For example we could have passed text-format information instead of the () in the above code:

After the syntax tree processed the formatting, you can just use the pre_order_iter method on the tree to create for example HTML with the formatting information on the nodes in order to create for example formatted HTML text.