Open NightFlyer opened 5 years ago
I'll start to work on this and start with some pull requests. But, let me know if you want Maaku to be "read-only" rather than supporting manipulating the tree.
It appears that in general, the underlying methods to manipulate the values in a node return a boolean as to whether or not the set worked (usually because the node is the wrong type to allow that operation)
I think that in Swift, this would be better captured by throwing an exception if the set doesn't work, because it generally means that the node was the wrong type of node.
I just noticed that libcmark provides some tree manipulation methods, so it will just be a case of making those visible through the Maaku interface.
If I want to manipulate the abstract syntax tree that the parser returns, I currently need to do that by getting the
cmarkNode
and manipulating that myself.It would be nice if
CMNode
provided the functionality needed to change values in the nodes and to manipulate the tree structure.This includes being able to change values in the individual node (such as the heading level), as well as to be able to change the structure of the tree (by changing the order of children or moving a subtree from one part of the tree to another by changing the parent). Note that changing the structure of the tree requires a bit of housekeeping to keep all the pointers correct (
next
,previous
,parent
,firstChild
, andlastChild
). By putting that housekeeping inCMNode
, that will reduce the burden on the users so they don't have to make sure that they're doing the right thing all the time.It is also necessary to be able to create new nodes so they can be added to the tree.
This will allow for creation of apps that want to provide an "org-mode" style of presenting the document to the user: allowing the user to move chunks of the document around as they work.