Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Would be nice to be able to manipulate the AST via CMNode rather than having to use underlying cmarkNode #45

Open
NightFlyer opened this issue May 28, 2019 · 3 comments

Comments

@NightFlyer
Copy link
Collaborator

NightFlyer commented May 28, 2019

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, and lastChild). By putting that housekeeping in CMNode, 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.

@NightFlyer
Copy link
Collaborator Author

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.

@NightFlyer
Copy link
Collaborator Author

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.

@NightFlyer
Copy link
Collaborator Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant