HTMell-0.1.0.0: Minimal filesystem powered markdown content management system
Copyright(c) 2021-2022 Mirko Westermeier
LicenseMIT
Safe HaskellSafe-Inferred
LanguageHaskell2010

HTMell.Tree

Description

HTMell content tree related types and functions.

Synopsis

The content tree type

type HTree c = Tree (String, Maybe c) #

The main content tree type, having pairs of name and content as nodes

name :: HTree c -> String #

The name of a HTree node

content :: HTree c -> Maybe c #

The content of a HTree node

children :: Tree c -> Forest c #

The children subForest of a HTree node

Basic tree operations

childList :: HTree c -> [(String, HTree c)] #

All child nodes of the given tree, addressed by their name

isLeaf :: HTree c -> Bool #

True iff the given HTree node has no children.

isInnerNode :: HTree c -> Bool #

True iff the given HTree node has children.

String representation

summary :: HTree c -> String #

Very short structural summary of a given tree, considering names only, separated by ",", children in "(" and ")".

Example: The tree loaded from the following filesystem structure

content
 |--- 1_foo.md
 '--- 2_bar
       |--- 42_baz.md
       '--- 17_quux.md

has the summary "(foo,bar(quux,baz))".

drawHTree :: HTree c -> String #

2-dimensional ASCII drawing of the given HTree, based on drawTree.

Content queries

Refer to HTMell for an explanation of how directory and file names correspond to the HTrees names in a content tree.

findNode :: HTree c -> String -> Maybe (HTree c) #

Selects a node inside the given HTree via its name path, separated by "/". For example, the "quux" node in the tree above (summary) would be selected with "/bar/quux".

Tree transformation

processTree #

Arguments

:: (String -> Maybe a -> [HTree b] -> HTree b)

A function that modifies a given deconstructed HTree, represented by the node's name (String), its content (Maybe a) and its child nodes as a Forest of trees. The children are already modified by processTree (bottom-up), thus already having the new content type.

-> HTree a

The tree to modify.

-> HTree b

The modified tree.

Bottom-up inside-out processing of a content tree. Each node will be modified by the given function, possibly changing the tree's HTMellContent instance.